diff options
author | Mauro Carvalho Chehab <mchehab@redhat.com> | 2009-03-29 04:37:46 -0300 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2009-03-29 04:37:46 -0300 |
commit | be91c19fe859cc841a29603d943e915f7691bc95 (patch) | |
tree | b72344c4a1f05605d2b66cefd90c051737197376 | |
parent | 01a9b73d338c6ac427e752fbc56c85d1ab5259b9 (diff) | |
parent | 2cc0abb17583ba0769357943dee38920a8cd757e (diff) | |
download | mediapointer-dvb-s2-be91c19fe859cc841a29603d943e915f7691bc95.tar.gz mediapointer-dvb-s2-be91c19fe859cc841a29603d943e915f7691bc95.tar.bz2 |
merge: http://linuxtv.org/hg/~mkrufky/tuner
From: Mauro Carvalho Chehab <mchehab@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
207 files changed, 15285 insertions, 45488 deletions
diff --git a/linux/Documentation/dvb/get_dvb_firmware b/linux/Documentation/dvb/get_dvb_firmware index f2e908d7f..2f21ecd4c 100755 --- a/linux/Documentation/dvb/get_dvb_firmware +++ b/linux/Documentation/dvb/get_dvb_firmware @@ -25,7 +25,7 @@ use IO::Handle; "tda10046lifeview", "av7110", "dec2000t", "dec2540t", "dec3000s", "vp7041", "dibusb", "nxt2002", "nxt2004", "or51211", "or51132_qam", "or51132_vsb", "bluebird", - "opera1"); + "opera1", "cx231xx", "cx18", "cx23885", "pvrusb2" ); # Check args syntax() if (scalar(@ARGV) != 1); @@ -37,8 +37,8 @@ for ($i=0; $i < scalar(@components); $i++) { $outfile = eval($cid); die $@ if $@; print STDERR <<EOF; -Firmware $outfile extracted successfully. -Now copy it to either /usr/lib/hotplug/firmware or /lib/firmware +Firmware(s) $outfile extracted successfully. +Now copy it(they) to either /usr/lib/hotplug/firmware or /lib/firmware (depending on configuration of firmware hotplug). EOF exit(0); @@ -345,6 +345,85 @@ sub or51211 { $fwfile; } +sub cx231xx { + my $fwfile = "v4l-cx231xx-avcore-01.fw"; + my $url = "http://linuxtv.org/downloads/firmware/$fwfile"; + my $hash = "7d3bb956dc9df0eafded2b56ba57cc42"; + + checkstandard(); + + wgetfile($fwfile, $url); + verify($fwfile, $hash); + + $fwfile; +} + +sub cx18 { + my $url = "http://linuxtv.org/downloads/firmware/"; + + my %files = ( + 'v4l-cx23418-apu.fw' => '588f081b562f5c653a3db1ad8f65939a', + 'v4l-cx23418-cpu.fw' => 'b6c7ed64bc44b1a6e0840adaeac39d79', + 'v4l-cx23418-dig.fw' => '95bc688d3e7599fd5800161e9971cc55', + ); + + checkstandard(); + + my $allfiles; + foreach my $fwfile (keys %files) { + wgetfile($fwfile, "$url/$fwfile"); + verify($fwfile, $files{$fwfile}); + $allfiles .= " $fwfile"; + } + + $allfiles =~ s/^\s//; + + $allfiles; +} + +sub cx23885 { + my $url = "http://linuxtv.org/downloads/firmware/"; + + my %files = ( + 'v4l-cx23885-avcore-01.fw' => 'a9f8f5d901a7fb42f552e1ee6384f3bb', + 'v4l-cx23885-enc.fw' => 'a9f8f5d901a7fb42f552e1ee6384f3bb', + ); + + checkstandard(); + + my $allfiles; + foreach my $fwfile (keys %files) { + wgetfile($fwfile, "$url/$fwfile"); + verify($fwfile, $files{$fwfile}); + $allfiles .= " $fwfile"; + } + + $allfiles =~ s/^\s//; + + $allfiles; +} + +sub pvrusb2 { + my $url = "http://linuxtv.org/downloads/firmware/"; + + my %files = ( + 'v4l-cx25840.fw' => 'dadb79e9904fc8af96e8111d9cb59320', + ); + + checkstandard(); + + my $allfiles; + foreach my $fwfile (keys %files) { + wgetfile($fwfile, "$url/$fwfile"); + verify($fwfile, $files{$fwfile}); + $allfiles .= " $fwfile"; + } + + $allfiles =~ s/^\s//; + + $allfiles; +} + sub or51132_qam { my $fwfile = "dvb-fe-or51132-qam.fw"; my $url = "http://linuxtv.org/downloads/firmware/$fwfile"; diff --git a/linux/Documentation/video4linux/CARDLIST.bttv b/linux/Documentation/video4linux/CARDLIST.bttv index e17750473..f11c58329 100644 --- a/linux/Documentation/video4linux/CARDLIST.bttv +++ b/linux/Documentation/video4linux/CARDLIST.bttv @@ -157,3 +157,4 @@ 156 -> IVCE-8784 [0000:f050,0001:f050,0002:f050,0003:f050] 157 -> Geovision GV-800(S) (master) [800a:763d] 158 -> Geovision GV-800(S) (slave) [800b:763d,800c:763d,800d:763d] +159 -> ProVideo PV183 [1830:1540,1831:1540,1832:1540,1833:1540,1834:1540,1835:1540,1836:1540,1837:1540] diff --git a/linux/Documentation/video4linux/bttv/README b/linux/Documentation/video4linux/bttv/README index 7ca2154c2..3a367cdb6 100644 --- a/linux/Documentation/video4linux/bttv/README +++ b/linux/Documentation/video4linux/bttv/README @@ -63,8 +63,8 @@ If you have some knowledge and spare time, please try to fix this yourself (patches very welcome of course...) You know: The linux slogan is "Do it yourself". -There is a mailing list: video4linux-list@redhat.com. -https://listman.redhat.com/mailman/listinfo/video4linux-list +There is a mailing list: linux-media@vger.kernel.org +http://vger.kernel.org/vger-lists.html#linux-media If you have trouble with some specific TV card, try to ask there instead of mailing me directly. The chance that someone with the diff --git a/linux/Documentation/video4linux/gspca.txt b/linux/Documentation/video4linux/gspca.txt index 12c8ff705..98529e03a 100644 --- a/linux/Documentation/video4linux/gspca.txt +++ b/linux/Documentation/video4linux/gspca.txt @@ -282,6 +282,7 @@ spca561 10fd:7e50 FlyCam Usb 100 zc3xx 10fd:8050 Typhoon Webshot II USB 300k ov534 1415:2000 Sony HD Eye for PS3 (SLEH 00201) pac207 145f:013a Trust WB-1300N +vc032x 15b8:6001 HP 2.0 Megapixel vc032x 15b8:6002 HP 2.0 Megapixel rz406aa spca501 1776:501c Arowana 300K CMOS Camera t613 17a1:0128 TASCORP JPEG Webcam, NGS Cyclops diff --git a/linux/Documentation/video4linux/v4l2-framework.txt b/linux/Documentation/video4linux/v4l2-framework.txt index 51a7b6db1..a31177390 100644 --- a/linux/Documentation/video4linux/v4l2-framework.txt +++ b/linux/Documentation/video4linux/v4l2-framework.txt @@ -91,7 +91,13 @@ NULL, then you *must* setup v4l2_dev->name before calling v4l2_device_register. The first 'dev' argument is normally the struct device pointer of a pci_dev, usb_device or platform_device. It is rare for dev to be NULL, but it happens -with ISA devices, for example. +with ISA devices or when one device creates multiple PCI devices, thus making +it impossible to associate v4l2_dev with a particular parent. + +You can also supply a notify() callback that can be called by sub-devices to +notify you of events. Whether you need to set this depends on the sub-device. +Any notifications a sub-device supports must be defined in a header in +include/media/<subdevice>.h. You unregister with: @@ -99,6 +105,17 @@ You unregister with: Unregistering will also automatically unregister all subdevs from the device. +If you have a hotpluggable device (e.g. a USB device), then when a disconnect +happens the parent device becomes invalid. Since v4l2_device has a pointer to +that parent device it has to be cleared as well to mark that the parent is +gone. To do this call: + + v4l2_device_disconnect(struct v4l2_device *v4l2_dev); + +This does *not* unregister the subdevs, so you still need to call the +v4l2_device_unregister() function for that. If your driver is not hotpluggable, +then there is no need to call v4l2_device_disconnect(). + Sometimes you need to iterate over all devices registered by a specific driver. This is usually the case if multiple device drivers use the same hardware. E.g. the ivtvfb driver is a framebuffer driver that uses the ivtv @@ -280,6 +297,11 @@ e.g. AUDIO_CONTROLLER and specify that as the group ID value when calling v4l2_device_call_all(). That ensures that it will only go to the subdev that needs it. +If the sub-device needs to notify its v4l2_device parent of an event, then +it can call v4l2_subdev_notify(sd, notification, arg). This macro checks +whether there is a notify() callback defined and returns -ENODEV if not. +Otherwise the result of the notify() call is returned. + The advantage of using v4l2_subdev is that it is a generic struct and does not contain any knowledge about the underlying hardware. So a driver might contain several subdevs that use an I2C bus, but also a subdev that is @@ -414,6 +436,15 @@ You should also set these fields: - ioctl_ops: if you use the v4l2_ioctl_ops to simplify ioctl maintenance (highly recommended to use this and it might become compulsory in the future!), then set this to your v4l2_ioctl_ops struct. +- parent: you only set this if v4l2_device was registered with NULL as + the parent device struct. This only happens in cases where one hardware + device has multiple PCI devices that all share the same v4l2_device core. + + The cx88 driver is an example of this: one core v4l2_device struct, but + it is used by both an raw video PCI device (cx8800) and a MPEG PCI device + (cx8802). Since the v4l2_device cannot be associated with a particular + PCI device it is setup without a parent device. But when the struct + video_device is setup you do know which parent PCI device to use. If you use v4l2_ioctl_ops, then you should set either .unlocked_ioctl or .ioctl to video_ioctl2 in your v4l2_file_operations struct. diff --git a/linux/Documentation/video4linux/v4lgrab.c b/linux/Documentation/video4linux/v4lgrab.c index d6e70bef8..05769cff1 100644 --- a/linux/Documentation/video4linux/v4lgrab.c +++ b/linux/Documentation/video4linux/v4lgrab.c @@ -105,8 +105,8 @@ int main(int argc, char ** argv) struct video_picture vpic; unsigned char *buffer, *src; - int bpp = 24, r, g, b; - unsigned int i, src_depth; + int bpp = 24, r = 0, g = 0, b = 0; + unsigned int i, src_depth = 16; if (fd < 0) { perror(VIDEO_DEV); diff --git a/linux/arch/arm/mach-pxa/pcm990-baseboard.c b/linux/arch/arm/mach-pxa/pcm990-baseboard.c index 0d8acfc2d..d1df34985 100644 --- a/linux/arch/arm/mach-pxa/pcm990-baseboard.c +++ b/linux/arch/arm/mach-pxa/pcm990-baseboard.c @@ -399,14 +399,49 @@ static struct pca953x_platform_data pca9536_data = { .gpio_base = NR_BUILTIN_GPIO + 1, }; -static struct soc_camera_link iclink[] = { - { - .bus_id = 0, /* Must match with the camera ID above */ - .gpio = NR_BUILTIN_GPIO + 1, - }, { - .bus_id = 0, /* Must match with the camera ID above */ - .gpio = -ENXIO, +static int gpio_bus_switch; + +static int pcm990_camera_set_bus_param(struct soc_camera_link *link, + unsigned long flags) +{ + if (gpio_bus_switch <= 0) { + if (flags == SOCAM_DATAWIDTH_10) + return 0; + else + return -EINVAL; + } + + if (flags & SOCAM_DATAWIDTH_8) + gpio_set_value(gpio_bus_switch, 1); + else + gpio_set_value(gpio_bus_switch, 0); + + return 0; +} + +static unsigned long pcm990_camera_query_bus_param(struct soc_camera_link *link) +{ + int ret; + + if (!gpio_bus_switch) { + ret = gpio_request(NR_BUILTIN_GPIO + 1, "camera"); + if (!ret) { + gpio_bus_switch = NR_BUILTIN_GPIO + 1; + gpio_direction_output(gpio_bus_switch, 0); + } else + gpio_bus_switch = -EINVAL; } + + if (gpio_bus_switch > 0) + return SOCAM_DATAWIDTH_8 | SOCAM_DATAWIDTH_10; + else + return SOCAM_DATAWIDTH_10; +} + +static struct soc_camera_link iclink = { + .bus_id = 0, /* Must match with the camera ID above */ + .query_bus_param = pcm990_camera_query_bus_param, + .set_bus_param = pcm990_camera_set_bus_param, }; /* Board I2C devices. */ @@ -417,10 +452,10 @@ static struct i2c_board_info __initdata pcm990_i2c_devices[] = { .platform_data = &pca9536_data, }, { I2C_BOARD_INFO("mt9v022", 0x48), - .platform_data = &iclink[0], /* With extender */ + .platform_data = &iclink, /* With extender */ }, { I2C_BOARD_INFO("mt9m001", 0x5d), - .platform_data = &iclink[0], /* With extender */ + .platform_data = &iclink, /* With extender */ }, }; #endif /* CONFIG_VIDEO_PXA27x ||CONFIG_VIDEO_PXA27x_MODULE */ diff --git a/linux/drivers/media/common/tuners/Kconfig b/linux/drivers/media/common/tuners/Kconfig index 724e6870c..52c3f65b1 100644 --- a/linux/drivers/media/common/tuners/Kconfig +++ b/linux/drivers/media/common/tuners/Kconfig @@ -21,17 +21,17 @@ config MEDIA_TUNER tristate default VIDEO_MEDIA && I2C depends on VIDEO_MEDIA && I2C - select MEDIA_TUNER_XC2028 if !MEDIA_TUNER_CUSTOMIZE - select MEDIA_TUNER_XC5000 if !MEDIA_TUNER_CUSTOMIZE - select MEDIA_TUNER_MT20XX if !MEDIA_TUNER_CUSTOMIZE - select MEDIA_TUNER_TDA8290 if !MEDIA_TUNER_CUSTOMIZE - select MEDIA_TUNER_TEA5761 if !MEDIA_TUNER_CUSTOMIZE - select MEDIA_TUNER_TEA5767 if !MEDIA_TUNER_CUSTOMIZE - select MEDIA_TUNER_SIMPLE if !MEDIA_TUNER_CUSTOMIZE - select MEDIA_TUNER_TDA9887 if !MEDIA_TUNER_CUSTOMIZE - select MEDIA_TUNER_MC44S803 if !MEDIA_TUNER_CUSTOMIZE - -menuconfig MEDIA_TUNER_CUSTOMIZE + select MEDIA_TUNER_XC2028 if !MEDIA_TUNER_CUSTOMISE + select MEDIA_TUNER_XC5000 if !MEDIA_TUNER_CUSTOMISE + select MEDIA_TUNER_MT20XX if !MEDIA_TUNER_CUSTOMISE + select MEDIA_TUNER_TDA8290 if !MEDIA_TUNER_CUSTOMISE + select MEDIA_TUNER_TEA5761 if !MEDIA_TUNER_CUSTOMISE + select MEDIA_TUNER_TEA5767 if !MEDIA_TUNER_CUSTOMISE + select MEDIA_TUNER_SIMPLE if !MEDIA_TUNER_CUSTOMISE + select MEDIA_TUNER_TDA9887 if !MEDIA_TUNER_CUSTOMISE + select MEDIA_TUNER_MC44S803 if !MEDIA_TUNER_CUSTOMISE + +menuconfig MEDIA_TUNER_CUSTOMISE bool "Customize analog and hybrid tuner modules to build" depends on MEDIA_TUNER default n @@ -44,13 +44,13 @@ menuconfig MEDIA_TUNER_CUSTOMIZE If unsure say N. -if MEDIA_TUNER_CUSTOMIZE +if MEDIA_TUNER_CUSTOMISE config MEDIA_TUNER_SIMPLE tristate "Simple tuner support" depends on VIDEO_MEDIA && I2C select MEDIA_TUNER_TDA9887 - default m if MEDIA_TUNER_CUSTOMIZE + default m if MEDIA_TUNER_CUSTOMISE help Say Y here to include support for various simple tuners. @@ -59,28 +59,28 @@ config MEDIA_TUNER_TDA8290 depends on VIDEO_MEDIA && I2C select MEDIA_TUNER_TDA827X select MEDIA_TUNER_TDA18271 - default m if MEDIA_TUNER_CUSTOMIZE + default m if MEDIA_TUNER_CUSTOMISE help Say Y here to include support for Philips TDA8290+8275(a) tuner. config MEDIA_TUNER_TDA827X tristate "Philips TDA827X silicon tuner" depends on VIDEO_MEDIA && I2C - default m if MEDIA_TUNER_CUSTOMIZE + default m if MEDIA_TUNER_CUSTOMISE help A DVB-T silicon tuner module. Say Y when you want to support this tuner. config MEDIA_TUNER_TDA18271 tristate "NXP TDA18271 silicon tuner" depends on VIDEO_MEDIA && I2C - default m if MEDIA_TUNER_CUSTOMIZE + default m if MEDIA_TUNER_CUSTOMISE help A silicon tuner module. Say Y when you want to support this tuner. config MEDIA_TUNER_TDA9887 tristate "TDA 9885/6/7 analog IF demodulator" depends on VIDEO_MEDIA && I2C - default m if MEDIA_TUNER_CUSTOMIZE + default m if MEDIA_TUNER_CUSTOMISE help Say Y here to include support for Philips TDA9885/6/7 analog IF demodulator. @@ -89,63 +89,63 @@ config MEDIA_TUNER_TEA5761 tristate "TEA 5761 radio tuner (EXPERIMENTAL)" depends on VIDEO_MEDIA && I2C depends on EXPERIMENTAL - default m if MEDIA_TUNER_CUSTOMIZE + default m if MEDIA_TUNER_CUSTOMISE help Say Y here to include support for the Philips TEA5761 radio tuner. config MEDIA_TUNER_TEA5767 tristate "TEA 5767 radio tuner" depends on VIDEO_MEDIA && I2C - default m if MEDIA_TUNER_CUSTOMIZE + default m if MEDIA_TUNER_CUSTOMISE help Say Y here to include support for the Philips TEA5767 radio tuner. config MEDIA_TUNER_MT20XX tristate "Microtune 2032 / 2050 tuners" depends on VIDEO_MEDIA && I2C - default m if MEDIA_TUNER_CUSTOMIZE + default m if MEDIA_TUNER_CUSTOMISE help Say Y here to include support for the MT2032 / MT2050 tuner. config MEDIA_TUNER_MT2060 tristate "Microtune MT2060 silicon IF tuner" depends on VIDEO_MEDIA && I2C - default m if MEDIA_TUNER_CUSTOMIZE + default m if MEDIA_TUNER_CUSTOMISE help A driver for the silicon IF tuner MT2060 from Microtune. config MEDIA_TUNER_MT2266 tristate "Microtune MT2266 silicon tuner" depends on VIDEO_MEDIA && I2C - default m if MEDIA_TUNER_CUSTOMIZE + default m if MEDIA_TUNER_CUSTOMISE help A driver for the silicon baseband tuner MT2266 from Microtune. config MEDIA_TUNER_MT2131 tristate "Microtune MT2131 silicon tuner" depends on VIDEO_MEDIA && I2C - default m if MEDIA_TUNER_CUSTOMIZE + default m if MEDIA_TUNER_CUSTOMISE help A driver for the silicon baseband tuner MT2131 from Microtune. config MEDIA_TUNER_QT1010 tristate "Quantek QT1010 silicon tuner" depends on VIDEO_MEDIA && I2C - default m if MEDIA_TUNER_CUSTOMIZE + default m if MEDIA_TUNER_CUSTOMISE help A driver for the silicon tuner QT1010 from Quantek. config MEDIA_TUNER_XC2028 tristate "XCeive xc2028/xc3028 tuners" depends on VIDEO_MEDIA && I2C - default m if MEDIA_TUNER_CUSTOMIZE + default m if MEDIA_TUNER_CUSTOMISE help Say Y here to include support for the xc2028/xc3028 tuners. config MEDIA_TUNER_XC5000 tristate "Xceive XC5000 silicon tuner" depends on VIDEO_MEDIA && I2C - default m if MEDIA_TUNER_CUSTOMIZE + default m if MEDIA_TUNER_CUSTOMISE help A driver for the silicon tuner XC5000 from Xceive. This device is only used inside a SiP called togther with a @@ -154,22 +154,22 @@ config MEDIA_TUNER_XC5000 config MEDIA_TUNER_MXL5005S tristate "MaxLinear MSL5005S silicon tuner" depends on VIDEO_MEDIA && I2C - default m if MEDIA_TUNER_CUSTOMIZE + default m if MEDIA_TUNER_CUSTOMISE help A driver for the silicon tuner MXL5005S from MaxLinear. config MEDIA_TUNER_MXL5007T tristate "MaxLinear MxL5007T silicon tuner" depends on VIDEO_MEDIA && I2C - default m if MEDIA_TUNER_CUSTOMIZE + default m if MEDIA_TUNER_CUSTOMISE help A driver for the silicon tuner MxL5007T from MaxLinear. config MEDIA_TUNER_MC44S803 tristate "Freescale MC44S803 Low Power CMOS Broadband tuners" depends on VIDEO_MEDIA && I2C - default m if MEDIA_TUNER_CUSTOMIZE + default m if MEDIA_TUNER_CUSTOMISE help Say Y here to support the Freescale MC44S803 based tuners -endif # MEDIA_TUNER_CUSTOMIZE +endif # MEDIA_TUNER_CUSTOMISE diff --git a/linux/drivers/media/common/tuners/mxl5005s.c b/linux/drivers/media/common/tuners/mxl5005s.c index 58418277a..bea599fbc 100644 --- a/linux/drivers/media/common/tuners/mxl5005s.c +++ b/linux/drivers/media/common/tuners/mxl5005s.c @@ -4005,12 +4005,11 @@ static int mxl5005s_set_params(struct dvb_frontend *fe, /* Change tuner for new modulation type if reqd */ if (req_mode != state->current_mode) { switch (req_mode) { - case VSB_8: - case QAM_64: - case QAM_256: - case QAM_AUTO: + case MXL_ATSC: + case MXL_QAM: req_bw = MXL5005S_BANDWIDTH_6MHZ; break; + case MXL_DVBT: default: /* Assume DVB-T */ switch (params->u.ofdm.bandwidth) { diff --git a/linux/drivers/media/common/tuners/tda827x.c b/linux/drivers/media/common/tuners/tda827x.c index eb989c241..6653ebcdf 100644 --- a/linux/drivers/media/common/tuners/tda827x.c +++ b/linux/drivers/media/common/tuners/tda827x.c @@ -352,7 +352,7 @@ struct tda827xa_data { u8 gc3; }; -static const struct tda827xa_data tda827xa_dvbt[] = { +static struct tda827xa_data tda827xa_dvbt[] = { { .lomax = 56875000, .svco = 3, .spd = 4, .scr = 0, .sbs = 0, .gc3 = 1}, { .lomax = 67250000, .svco = 0, .spd = 3, .scr = 0, .sbs = 0, .gc3 = 1}, { .lomax = 81250000, .svco = 1, .spd = 3, .scr = 0, .sbs = 0, .gc3 = 1}, @@ -382,6 +382,36 @@ static const struct tda827xa_data tda827xa_dvbt[] = { { .lomax = 0, .svco = 0, .spd = 0, .scr = 0, .sbs = 0, .gc3 = 0} }; +static struct tda827xa_data tda827xa_dvbc[] = { + { .lomax = 50125000, .svco = 2, .spd = 4, .scr = 2, .sbs = 0, .gc3 = 3}, + { .lomax = 58500000, .svco = 3, .spd = 4, .scr = 2, .sbs = 0, .gc3 = 3}, + { .lomax = 69250000, .svco = 0, .spd = 3, .scr = 2, .sbs = 0, .gc3 = 3}, + { .lomax = 83625000, .svco = 1, .spd = 3, .scr = 2, .sbs = 0, .gc3 = 3}, + { .lomax = 97500000, .svco = 2, .spd = 3, .scr = 2, .sbs = 0, .gc3 = 3}, + { .lomax = 100250000, .svco = 2, .spd = 3, .scr = 2, .sbs = 1, .gc3 = 1}, + { .lomax = 117000000, .svco = 3, .spd = 3, .scr = 2, .sbs = 1, .gc3 = 1}, + { .lomax = 138500000, .svco = 0, .spd = 2, .scr = 2, .sbs = 1, .gc3 = 1}, + { .lomax = 167250000, .svco = 1, .spd = 2, .scr = 2, .sbs = 1, .gc3 = 1}, + { .lomax = 187000000, .svco = 2, .spd = 2, .scr = 2, .sbs = 1, .gc3 = 1}, + { .lomax = 200500000, .svco = 2, .spd = 2, .scr = 2, .sbs = 2, .gc3 = 1}, + { .lomax = 234000000, .svco = 3, .spd = 2, .scr = 2, .sbs = 2, .gc3 = 3}, + { .lomax = 277000000, .svco = 0, .spd = 1, .scr = 2, .sbs = 2, .gc3 = 3}, + { .lomax = 325000000, .svco = 1, .spd = 1, .scr = 2, .sbs = 2, .gc3 = 1}, + { .lomax = 334500000, .svco = 1, .spd = 1, .scr = 2, .sbs = 3, .gc3 = 3}, + { .lomax = 401000000, .svco = 2, .spd = 1, .scr = 2, .sbs = 3, .gc3 = 3}, + { .lomax = 468000000, .svco = 3, .spd = 1, .scr = 2, .sbs = 3, .gc3 = 1}, + { .lomax = 535000000, .svco = 0, .spd = 0, .scr = 1, .sbs = 3, .gc3 = 1}, + { .lomax = 554000000, .svco = 0, .spd = 0, .scr = 2, .sbs = 3, .gc3 = 1}, + { .lomax = 638000000, .svco = 1, .spd = 0, .scr = 1, .sbs = 4, .gc3 = 1}, + { .lomax = 669000000, .svco = 1, .spd = 0, .scr = 2, .sbs = 4, .gc3 = 1}, + { .lomax = 720000000, .svco = 2, .spd = 0, .scr = 1, .sbs = 4, .gc3 = 1}, + { .lomax = 802000000, .svco = 2, .spd = 0, .scr = 2, .sbs = 4, .gc3 = 1}, + { .lomax = 835000000, .svco = 3, .spd = 0, .scr = 1, .sbs = 4, .gc3 = 1}, + { .lomax = 885000000, .svco = 3, .spd = 0, .scr = 1, .sbs = 4, .gc3 = 1}, + { .lomax = 911000000, .svco = 3, .spd = 0, .scr = 2, .sbs = 4, .gc3 = 1}, + { .lomax = 0, .svco = 0, .spd = 0, .scr = 0, .sbs = 0, .gc3 = 0} +}; + static struct tda827xa_data tda827xa_analog[] = { { .lomax = 56875000, .svco = 3, .spd = 4, .scr = 0, .sbs = 0, .gc3 = 3}, { .lomax = 67250000, .svco = 0, .spd = 3, .scr = 0, .sbs = 0, .gc3 = 3}, @@ -485,6 +515,7 @@ static int tda827xa_set_params(struct dvb_frontend *fe, struct dvb_frontend_parameters *params) { struct tda827x_priv *priv = fe->tuner_priv; + struct tda827xa_data *frequency_map = tda827xa_dvbt; u8 buf[11]; struct i2c_msg msg = { .addr = priv->i2c_addr, .flags = 0, @@ -511,22 +542,27 @@ static int tda827xa_set_params(struct dvb_frontend *fe, } tuner_freq = params->frequency + if_freq; + if (fe->ops.info.type == FE_QAM) { + dprintk("%s select tda827xa_dvbc\n", __func__); + frequency_map = tda827xa_dvbc; + } + i = 0; - while (tda827xa_dvbt[i].lomax < tuner_freq) { - if(tda827xa_dvbt[i + 1].lomax == 0) + while (frequency_map[i].lomax < tuner_freq) { + if (frequency_map[i + 1].lomax == 0) break; i++; } - N = ((tuner_freq + 31250) / 62500) << tda827xa_dvbt[i].spd; + N = ((tuner_freq + 31250) / 62500) << frequency_map[i].spd; buf[0] = 0; // subaddress buf[1] = N >> 8; buf[2] = N & 0xff; buf[3] = 0; buf[4] = 0x16; - buf[5] = (tda827xa_dvbt[i].spd << 5) + (tda827xa_dvbt[i].svco << 3) + - tda827xa_dvbt[i].sbs; - buf[6] = 0x4b + (tda827xa_dvbt[i].gc3 << 4); + buf[5] = (frequency_map[i].spd << 5) + (frequency_map[i].svco << 3) + + frequency_map[i].sbs; + buf[6] = 0x4b + (frequency_map[i].gc3 << 4); buf[7] = 0x1c; buf[8] = 0x06; buf[9] = 0x24; @@ -585,7 +621,7 @@ static int tda827xa_set_params(struct dvb_frontend *fe, /* correct CP value */ buf[0] = 0x30; - buf[1] = 0x10 + tda827xa_dvbt[i].scr; + buf[1] = 0x10 + frequency_map[i].scr; rc = tuner_transfer(fe, &msg, 1); if (rc < 0) goto err; @@ -600,7 +636,7 @@ static int tda827xa_set_params(struct dvb_frontend *fe, msleep(3); /* freeze AGC1 */ buf[0] = 0x50; - buf[1] = 0x4f + (tda827xa_dvbt[i].gc3 << 4); + buf[1] = 0x4f + (frequency_map[i].gc3 << 4); rc = tuner_transfer(fe, &msg, 1); if (rc < 0) goto err; diff --git a/linux/drivers/media/common/tuners/xc5000.c b/linux/drivers/media/common/tuners/xc5000.c index b0e20bc20..39c415df0 100644 --- a/linux/drivers/media/common/tuners/xc5000.c +++ b/linux/drivers/media/common/tuners/xc5000.c @@ -992,8 +992,6 @@ struct dvb_frontend *xc5000_attach(struct dvb_frontend *fe, case 1: /* new tuner instance */ priv->bandwidth = BANDWIDTH_6_MHZ; - priv->if_khz = cfg->if_khz; - fe->tuner_priv = priv; break; default: @@ -1002,6 +1000,13 @@ struct dvb_frontend *xc5000_attach(struct dvb_frontend *fe, break; } + if (priv->if_khz == 0) { + /* If the IF hasn't been set yet, use the value provided by + the caller (occurs in hybrid devices where the analog + call to xc5000_attach occurs before the digital side) */ + priv->if_khz = cfg->if_khz; + } + /* Check if firmware has been loaded. It is possible that another instance of the driver has loaded the firmware. */ diff --git a/linux/drivers/media/dvb/b2c2/Kconfig b/linux/drivers/media/dvb/b2c2/Kconfig index a8c6249c4..9e5781400 100644 --- a/linux/drivers/media/dvb/b2c2/Kconfig +++ b/linux/drivers/media/dvb/b2c2/Kconfig @@ -13,7 +13,7 @@ config DVB_B2C2_FLEXCOP select DVB_TUNER_ITD1000 if !DVB_FE_CUSTOMISE select DVB_ISL6421 if !DVB_FE_CUSTOMISE select DVB_CX24123 if !DVB_FE_CUSTOMISE - select MEDIA_TUNER_SIMPLE if !MEDIA_TUNER_CUSTOMIZE + select MEDIA_TUNER_SIMPLE if !MEDIA_TUNER_CUSTOMISE select DVB_TUNER_CX24113 if !DVB_FE_CUSTOMISE help Support for the digital TV receiver chip made by B2C2 Inc. included in diff --git a/linux/drivers/media/dvb/bt8xx/Kconfig b/linux/drivers/media/dvb/bt8xx/Kconfig index 27edb0ece..8668e634c 100644 --- a/linux/drivers/media/dvb/bt8xx/Kconfig +++ b/linux/drivers/media/dvb/bt8xx/Kconfig @@ -8,7 +8,7 @@ config DVB_BT8XX select DVB_OR51211 if !DVB_FE_CUSTOMISE select DVB_LGDT330X if !DVB_FE_CUSTOMISE select DVB_ZL10353 if !DVB_FE_CUSTOMISE - select MEDIA_TUNER_SIMPLE if !MEDIA_TUNER_CUSTOMIZE + select MEDIA_TUNER_SIMPLE if !MEDIA_TUNER_CUSTOMISE help Support for PCI cards based on the Bt8xx PCI bridge. Examples are the Nebula cards, the Pinnacle PCTV cards, the Twinhan DST cards, diff --git a/linux/drivers/media/dvb/bt8xx/dst_ca.c b/linux/drivers/media/dvb/bt8xx/dst_ca.c index 68aef6786..e71c269c1 100644 --- a/linux/drivers/media/dvb/bt8xx/dst_ca.c +++ b/linux/drivers/media/dvb/bt8xx/dst_ca.c @@ -648,8 +648,10 @@ free_mem_and_exit: return result; } -static int dst_ca_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long ioctl_arg) +static long dst_ca_ioctl(struct file *file, unsigned int cmd, unsigned long ioctl_arg) { + lock_kernel(); + struct dvb_device* dvbdev = (struct dvb_device*) file->private_data; struct dst_state* state = (struct dst_state*) dvbdev->priv; struct ca_slot_info *p_ca_slot_info; @@ -743,6 +745,7 @@ static int dst_ca_ioctl(struct inode *inode, struct file *file, unsigned int cmd kfree (p_ca_slot_info); kfree (p_ca_caps); + unlock_kernel(); return result; } @@ -780,7 +783,7 @@ static ssize_t dst_ca_write(struct file *file, const char __user *buffer, size_t static const struct file_operations dst_ca_fops = { .owner = THIS_MODULE, - .ioctl = dst_ca_ioctl, + .unlocked_ioctl = dst_ca_ioctl, .open = dst_ca_open, .release = dst_ca_release, .read = dst_ca_read, diff --git a/linux/drivers/media/dvb/bt8xx/dvb-bt8xx.c b/linux/drivers/media/dvb/bt8xx/dvb-bt8xx.c index c4b8b0677..08c63014c 100644 --- a/linux/drivers/media/dvb/bt8xx/dvb-bt8xx.c +++ b/linux/drivers/media/dvb/bt8xx/dvb-bt8xx.c @@ -815,7 +815,7 @@ static int __devinit dvb_bt8xx_probe(struct bttv_sub_device *sub) mutex_init(&card->lock); card->bttv_nr = sub->core->nr; - strncpy(card->card_name, sub->core->name, sizeof(sub->core->name)); + strlcpy(card->card_name, sub->core->v4l2_dev.name, sizeof(card->card_name)); card->i2c_adapter = &sub->core->i2c_adap; switch(sub->core->type) { diff --git a/linux/drivers/media/dvb/dvb-usb/Kconfig b/linux/drivers/media/dvb/dvb-usb/Kconfig index b899d509a..6103caad1 100644 --- a/linux/drivers/media/dvb/dvb-usb/Kconfig +++ b/linux/drivers/media/dvb/dvb-usb/Kconfig @@ -25,7 +25,7 @@ config DVB_USB_A800 depends on DVB_USB select DVB_DIB3000MC select DVB_PLL if !DVB_FE_CUSTOMISE - select MEDIA_TUNER_MT2060 if !MEDIA_TUNER_CUSTOMIZE + select MEDIA_TUNER_MT2060 if !MEDIA_TUNER_CUSTOMISE help Say Y here to support the AVerMedia AverTV DVB-T USB 2.0 (A800) receiver. @@ -34,7 +34,7 @@ config DVB_USB_DIBUSB_MB depends on DVB_USB select DVB_PLL if !DVB_FE_CUSTOMISE select DVB_DIB3000MB - select MEDIA_TUNER_MT2060 if !MEDIA_TUNER_CUSTOMIZE + select MEDIA_TUNER_MT2060 if !MEDIA_TUNER_CUSTOMISE help Support for USB 1.1 and 2.0 DVB-T receivers based on reference designs made by DiBcom (<http://www.dibcom.fr>) equipped with a DiB3000M-B demodulator. @@ -55,7 +55,7 @@ config DVB_USB_DIBUSB_MC tristate "DiBcom USB DVB-T devices (based on the DiB3000M-C/P) (see help for device list)" depends on DVB_USB select DVB_DIB3000MC - select MEDIA_TUNER_MT2060 if !MEDIA_TUNER_CUSTOMIZE + select MEDIA_TUNER_MT2060 if !MEDIA_TUNER_CUSTOMISE help Support for USB2.0 DVB-T receivers based on reference designs made by DiBcom (<http://www.dibcom.fr>) equipped with a DiB3000M-C/P demodulator. @@ -75,11 +75,11 @@ config DVB_USB_DIB0700 select DVB_S5H1411 if !DVB_FE_CUSTOMISE select DVB_LGDT3305 if !DVB_FE_CUSTOMISE select DVB_TUNER_DIB0070 if !DVB_FE_CUSTOMISE - select MEDIA_TUNER_MT2060 if !MEDIA_TUNER_CUSTOMIZE - select MEDIA_TUNER_MT2266 if !MEDIA_TUNER_CUSTOMIZE - select MEDIA_TUNER_XC2028 if !MEDIA_TUNER_CUSTOMIZE - select MEDIA_TUNER_XC5000 if !MEDIA_TUNER_CUSTOMIZE - select MEDIA_TUNER_MXL5007T if !MEDIA_TUNER_CUSTOMIZE + select MEDIA_TUNER_MT2060 if !MEDIA_TUNER_CUSTOMISE + select MEDIA_TUNER_MT2266 if !MEDIA_TUNER_CUSTOMISE + select MEDIA_TUNER_XC2028 if !MEDIA_TUNER_CUSTOMISE + select MEDIA_TUNER_XC5000 if !MEDIA_TUNER_CUSTOMISE + select MEDIA_TUNER_MXL5007T if !MEDIA_TUNER_CUSTOMISE help Support for USB2.0/1.1 DVB receivers based on the DiB0700 USB bridge. The USB bridge is also present in devices having the DiB7700 DVB-T-USB @@ -97,7 +97,7 @@ config DVB_USB_UMT_010 depends on DVB_USB select DVB_PLL if !DVB_FE_CUSTOMISE select DVB_DIB3000MC - select MEDIA_TUNER_MT2060 if !MEDIA_TUNER_CUSTOMIZE + select MEDIA_TUNER_MT2060 if !MEDIA_TUNER_CUSTOMISE select DVB_MT352 if !DVB_FE_CUSTOMISE help Say Y here to support the HanfTek UMT-010 USB2.0 stick-sized DVB-T receiver. @@ -113,9 +113,9 @@ config DVB_USB_CXUSB select DVB_DIB7000P if !DVB_FE_CUSTOMISE select DVB_LGS8GL5 if !DVB_FE_CUSTOMISE select DVB_TUNER_DIB0070 if !DVB_FE_CUSTOMISE - select MEDIA_TUNER_SIMPLE if !MEDIA_TUNER_CUSTOMIZE - select MEDIA_TUNER_XC2028 if !MEDIA_TUNER_CUSTOMIZE - select MEDIA_TUNER_MXL5005S if !MEDIA_TUNER_CUSTOMIZE + select MEDIA_TUNER_SIMPLE if !MEDIA_TUNER_CUSTOMISE + select MEDIA_TUNER_XC2028 if !MEDIA_TUNER_CUSTOMISE + select MEDIA_TUNER_MXL5005S if !MEDIA_TUNER_CUSTOMISE help Say Y here to support the Conexant USB2.0 hybrid reference design. Currently, only DVB and ATSC modes are supported, analog mode @@ -129,8 +129,8 @@ config DVB_USB_M920X depends on DVB_USB select DVB_MT352 if !DVB_FE_CUSTOMISE select DVB_TDA1004X if !DVB_FE_CUSTOMISE - select MEDIA_TUNER_QT1010 if !MEDIA_TUNER_CUSTOMIZE - select MEDIA_TUNER_TDA827X if !MEDIA_TUNER_CUSTOMIZE + select MEDIA_TUNER_QT1010 if !MEDIA_TUNER_CUSTOMISE + select MEDIA_TUNER_TDA827X if !MEDIA_TUNER_CUSTOMISE help Say Y here to support the MSI Mega Sky 580 USB2.0 DVB-T receiver. Currently, only devices with a product id of @@ -141,7 +141,7 @@ config DVB_USB_GL861 tristate "Genesys Logic GL861 USB2.0 support" depends on DVB_USB select DVB_ZL10353 if !DVB_FE_CUSTOMISE - select MEDIA_TUNER_QT1010 if !MEDIA_TUNER_CUSTOMIZE + select MEDIA_TUNER_QT1010 if !MEDIA_TUNER_CUSTOMISE help Say Y here to support the MSI Megasky 580 (55801) DVB-T USB2.0 receiver with USB ID 0db0:5581. @@ -150,7 +150,7 @@ config DVB_USB_AU6610 tristate "Alcor Micro AU6610 USB2.0 support" depends on DVB_USB select DVB_ZL10353 if !DVB_FE_CUSTOMISE - select MEDIA_TUNER_QT1010 if !MEDIA_TUNER_CUSTOMIZE + select MEDIA_TUNER_QT1010 if !MEDIA_TUNER_CUSTOMISE help Say Y here to support the Sigmatek DVB-110 DVB-T USB2.0 receiver. @@ -203,7 +203,7 @@ config DVB_USB_NOVA_T_USB2 depends on DVB_USB select DVB_DIB3000MC select DVB_PLL if !DVB_FE_CUSTOMISE - select MEDIA_TUNER_MT2060 if !MEDIA_TUNER_CUSTOMIZE + select MEDIA_TUNER_MT2060 if !MEDIA_TUNER_CUSTOMISE help Say Y here to support the Hauppauge WinTV-NOVA-T usb2 DVB-T USB2.0 receiver. @@ -239,8 +239,8 @@ config DVB_USB_OPERA1 config DVB_USB_AF9005 tristate "Afatech AF9005 DVB-T USB1.1 support" depends on DVB_USB && EXPERIMENTAL - select MEDIA_TUNER_MT2060 if !MEDIA_TUNER_CUSTOMIZE - select MEDIA_TUNER_QT1010 if !MEDIA_TUNER_CUSTOMIZE + select MEDIA_TUNER_MT2060 if !MEDIA_TUNER_CUSTOMISE + select MEDIA_TUNER_QT1010 if !MEDIA_TUNER_CUSTOMISE help Say Y here to support the Afatech AF9005 based DVB-T USB1.1 receiver and the TerraTec Cinergy T USB XE (Rev.1) @@ -288,7 +288,7 @@ config DVB_USB_DTV5100 tristate "AME DTV-5100 USB2.0 DVB-T support" depends on DVB_USB select DVB_ZL10353 if !DVB_FE_CUSTOMISE - select MEDIA_TUNER_QT1010 if !MEDIA_TUNER_CUSTOMIZE + select MEDIA_TUNER_QT1010 if !MEDIA_TUNER_CUSTOMISE help Say Y here to support the AME DTV-5100 USB2.0 DVB-T receiver. @@ -297,10 +297,18 @@ config DVB_USB_AF9015 depends on DVB_USB && EXPERIMENTAL select DVB_AF9013 select DVB_PLL if !DVB_FE_CUSTOMISE - select MEDIA_TUNER_MT2060 if !MEDIA_TUNER_CUSTOMIZE - select MEDIA_TUNER_QT1010 if !MEDIA_TUNER_CUSTOMIZE - select MEDIA_TUNER_TDA18271 if !MEDIA_TUNER_CUSTOMIZE - select MEDIA_TUNER_MXL5005S if !MEDIA_TUNER_CUSTOMIZE + select MEDIA_TUNER_MT2060 if !MEDIA_TUNER_CUSTOMISE + select MEDIA_TUNER_QT1010 if !MEDIA_TUNER_CUSTOMISE + select MEDIA_TUNER_TDA18271 if !MEDIA_TUNER_CUSTOMISE + select MEDIA_TUNER_MXL5005S if !MEDIA_TUNER_CUSTOMISE select MEDIA_TUNER_MC44S803 if !MEDIA_TUNER_CUSTOMISE help Say Y here to support the Afatech AF9015 based DVB-T USB2.0 receiver + +config DVB_USB_CE6230 + tristate "Intel CE6230 DVB-T USB2.0 support" + depends on DVB_USB && EXPERIMENTAL + select DVB_ZL10353 + select MEDIA_TUNER_MXL5005S if !MEDIA_TUNER_CUSTOMIZE + help + Say Y here to support the Intel CE6230 DVB-T USB2.0 receiver diff --git a/linux/drivers/media/dvb/dvb-usb/Makefile b/linux/drivers/media/dvb/dvb-usb/Makefile index 3122b7cc2..f92734ed7 100644 --- a/linux/drivers/media/dvb/dvb-usb/Makefile +++ b/linux/drivers/media/dvb/dvb-usb/Makefile @@ -76,6 +76,8 @@ obj-$(CONFIG_DVB_USB_AF9015) += dvb-usb-af9015.o dvb-usb-cinergyT2-objs = cinergyT2-core.o cinergyT2-fe.o obj-$(CONFIG_DVB_USB_CINERGY_T2) += dvb-usb-cinergyT2.o +dvb-usb-ce6230-objs = ce6230.o +obj-$(CONFIG_DVB_USB_CE6230) += dvb-usb-ce6230.o EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core/ -Idrivers/media/dvb/frontends/ # due to tuner-xc3028 diff --git a/linux/drivers/media/dvb/dvb-usb/ce6230.c b/linux/drivers/media/dvb/dvb-usb/ce6230.c new file mode 100644 index 000000000..1682af62f --- /dev/null +++ b/linux/drivers/media/dvb/dvb-usb/ce6230.c @@ -0,0 +1,331 @@ +/* + * DVB USB Linux driver for Intel CE6230 DVB-T USB2.0 receiver + * + * Copyright (C) 2009 Antti Palosaari <crope@iki.fi> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ + +#include "ce6230.h" +#include "zl10353.h" +#include "mxl5005s.h" + +/* debug */ +static int dvb_usb_ce6230_debug; +module_param_named(debug, dvb_usb_ce6230_debug, int, 0644); +MODULE_PARM_DESC(debug, "set debugging level" DVB_USB_DEBUG_STATUS); +DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); + +static struct zl10353_config ce6230_zl10353_config; + +static int ce6230_rw_udev(struct usb_device *udev, struct req_t *req) +{ + int ret; + unsigned int pipe; + u8 request; + u8 requesttype; + u16 value; + u16 index; + u8 buf[req->data_len]; + + request = req->cmd; + value = req->value; + index = req->index; + + switch (req->cmd) { + case I2C_READ: + case DEMOD_READ: + case REG_READ: + requesttype = (USB_TYPE_VENDOR | USB_DIR_IN); + break; + case I2C_WRITE: + case DEMOD_WRITE: + case REG_WRITE: + requesttype = (USB_TYPE_VENDOR | USB_DIR_OUT); + break; + default: + err("unknown command:%02x", req->cmd); + ret = -EPERM; + goto error; + } + + if (requesttype == (USB_TYPE_VENDOR | USB_DIR_OUT)) { + /* write */ + memcpy(buf, req->data, req->data_len); + pipe = usb_sndctrlpipe(udev, 0); + } else { + /* read */ + pipe = usb_rcvctrlpipe(udev, 0); + } + + msleep(1); /* avoid I2C errors */ + + ret = usb_control_msg(udev, pipe, request, requesttype, value, index, + buf, sizeof(buf), CE6230_USB_TIMEOUT); + + ce6230_debug_dump(request, requesttype, value, index, buf, + req->data_len, deb_xfer); + + if (ret < 0) + deb_info("%s: usb_control_msg failed:%d\n", __func__, ret); + else + ret = 0; + + /* read request, copy returned data to return buf */ + if (!ret && requesttype == (USB_TYPE_VENDOR | USB_DIR_IN)) + memcpy(req->data, buf, req->data_len); + +error: + return ret; +} + +static int ce6230_ctrl_msg(struct dvb_usb_device *d, struct req_t *req) +{ + return ce6230_rw_udev(d->udev, req); +} + +/* I2C */ +static int ce6230_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[], + int num) +{ + struct dvb_usb_device *d = i2c_get_adapdata(adap); + int i = 0; + struct req_t req; + int ret = 0; + memset(&req, 0, sizeof(&req)); + + if (num > 2) + return -EINVAL; + + if (mutex_lock_interruptible(&d->i2c_mutex) < 0) + return -EAGAIN; + + while (i < num) { + if (num > i + 1 && (msg[i+1].flags & I2C_M_RD)) { + if (msg[i].addr == + ce6230_zl10353_config.demod_address) { + req.cmd = DEMOD_READ; + req.value = msg[i].addr >> 1; + req.index = msg[i].buf[0]; + req.data_len = msg[i+1].len; + req.data = &msg[i+1].buf[0]; + ret = ce6230_ctrl_msg(d, &req); + } else { + err("i2c read not implemented"); + ret = -EPERM; + } + i += 2; + } else { + if (msg[i].addr == + ce6230_zl10353_config.demod_address) { + req.cmd = DEMOD_WRITE; + req.value = msg[i].addr >> 1; + req.index = msg[i].buf[0]; + req.data_len = msg[i].len-1; + req.data = &msg[i].buf[1]; + ret = ce6230_ctrl_msg(d, &req); + } else { + req.cmd = I2C_WRITE; + req.value = 0x2000 + (msg[i].addr >> 1); + req.index = 0x0000; + req.data_len = msg[i].len; + req.data = &msg[i].buf[0]; + ret = ce6230_ctrl_msg(d, &req); + } + i += 1; + } + if (ret) + break; + } + + mutex_unlock(&d->i2c_mutex); + return ret ? ret : i; +} + +static u32 ce6230_i2c_func(struct i2c_adapter *adapter) +{ + return I2C_FUNC_I2C; +} + +static struct i2c_algorithm ce6230_i2c_algo = { + .master_xfer = ce6230_i2c_xfer, + .functionality = ce6230_i2c_func, +#ifdef NEED_ALGO_CONTROL + .algo_control = dummy_algo_control, +#endif +}; + +/* Callbacks for DVB USB */ +static struct zl10353_config ce6230_zl10353_config = { + .demod_address = 0x1e, + .adc_clock = 450000, + .if2 = 45700, + .no_tuner = 1, + .parallel_ts = 1, + .clock_ctl_1 = 0x34, + .pll_0 = 0x0e, +}; + +static int ce6230_zl10353_frontend_attach(struct dvb_usb_adapter *adap) +{ + deb_info("%s:\n", __func__); + adap->fe = dvb_attach(zl10353_attach, &ce6230_zl10353_config, + &adap->dev->i2c_adap); + if (adap->fe == NULL) + return -ENODEV; + return 0; +} + +static struct mxl5005s_config ce6230_mxl5003s_config = { + .i2c_address = 0xc6, + .if_freq = IF_FREQ_4570000HZ, + .xtal_freq = CRYSTAL_FREQ_16000000HZ, + .agc_mode = MXL_SINGLE_AGC, + .tracking_filter = MXL_TF_DEFAULT, + .rssi_enable = MXL_RSSI_ENABLE, + .cap_select = MXL_CAP_SEL_ENABLE, + .div_out = MXL_DIV_OUT_4, + .clock_out = MXL_CLOCK_OUT_DISABLE, + .output_load = MXL5005S_IF_OUTPUT_LOAD_200_OHM, + .top = MXL5005S_TOP_25P2, + .mod_mode = MXL_DIGITAL_MODE, + .if_mode = MXL_ZERO_IF, + .AgcMasterByte = 0x00, +}; + +static int ce6230_mxl5003s_tuner_attach(struct dvb_usb_adapter *adap) +{ + int ret; + deb_info("%s:\n", __func__); + ret = dvb_attach(mxl5005s_attach, adap->fe, &adap->dev->i2c_adap, + &ce6230_mxl5003s_config) == NULL ? -ENODEV : 0; + return ret; +} + +static int ce6230_power_ctrl(struct dvb_usb_device *d, int onoff) +{ + int ret; + deb_info("%s: onoff:%d\n", __func__, onoff); + + /* InterfaceNumber 1 / AlternateSetting 0 idle + InterfaceNumber 1 / AlternateSetting 1 streaming */ + ret = usb_set_interface(d->udev, 1, onoff); + if (ret) + err("usb_set_interface failed with error:%d", ret); + + return ret; +} + +/* DVB USB Driver stuff */ +static struct dvb_usb_device_properties ce6230_properties; + +static int ce6230_probe(struct usb_interface *intf, + const struct usb_device_id *id) +{ + int ret = 0; + struct dvb_usb_device *d = NULL; + + deb_info("%s: interface:%d\n", __func__, + intf->cur_altsetting->desc.bInterfaceNumber); + + if (intf->cur_altsetting->desc.bInterfaceNumber == 1) { + ret = dvb_usb_device_init(intf, &ce6230_properties, THIS_MODULE, + &d, adapter_nr); + if (ret) + err("init failed with error:%d\n", ret); + } + + return ret; +} + +static struct usb_device_id ce6230_table[] = { + { USB_DEVICE(USB_VID_INTEL, USB_PID_INTEL_CE9500) }, + { } /* Terminating entry */ +}; +MODULE_DEVICE_TABLE(usb, ce6230_table); + +static struct dvb_usb_device_properties ce6230_properties = { + .caps = DVB_USB_IS_AN_I2C_ADAPTER, + + .usb_ctrl = DEVICE_SPECIFIC, + .no_reconnect = 1, + + .size_of_priv = 0, + + .num_adapters = 1, + .adapter = { + { + .frontend_attach = ce6230_zl10353_frontend_attach, + .tuner_attach = ce6230_mxl5003s_tuner_attach, + .stream = { + .type = USB_BULK, + .count = 6, + .endpoint = 0x82, + .u = { + .bulk = { + .buffersize = 512, + } + } + }, + } + }, + + .power_ctrl = ce6230_power_ctrl, + + .i2c_algo = &ce6230_i2c_algo, + + .num_device_descs = 1, + .devices = { + { + .name = "Intel CE9500 reference design", + .cold_ids = {NULL}, + .warm_ids = {&ce6230_table[0], NULL}, + }, + } +}; + +static struct usb_driver ce6230_driver = { + .name = "dvb_usb_ce6230", + .probe = ce6230_probe, + .disconnect = dvb_usb_device_exit, + .id_table = ce6230_table, +}; + +/* module stuff */ +static int __init ce6230_module_init(void) +{ + int ret; + deb_info("%s:\n", __func__); + ret = usb_register(&ce6230_driver); + if (ret) + err("usb_register failed with error:%d", ret); + + return ret; +} + +static void __exit ce6230_module_exit(void) +{ + deb_info("%s:\n", __func__); + /* deregister this driver from the USB subsystem */ + usb_deregister(&ce6230_driver); +} + +module_init(ce6230_module_init); +module_exit(ce6230_module_exit); + +MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>"); +MODULE_DESCRIPTION("Driver for Intel CE6230 DVB-T USB2.0"); +MODULE_LICENSE("GPL"); diff --git a/linux/drivers/media/dvb/dvb-usb/ce6230.h b/linux/drivers/media/dvb/dvb-usb/ce6230.h new file mode 100644 index 000000000..97c42482c --- /dev/null +++ b/linux/drivers/media/dvb/dvb-usb/ce6230.h @@ -0,0 +1,69 @@ +/* + * DVB USB Linux driver for Intel CE6230 DVB-T USB2.0 receiver + * + * Copyright (C) 2009 Antti Palosaari <crope@iki.fi> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ + +#ifndef _DVB_USB_CE6230_H_ +#define _DVB_USB_CE6230_H_ + +#define DVB_USB_LOG_PREFIX "ce6230" +#include "dvb-usb.h" + +#define deb_info(args...) dprintk(dvb_usb_ce6230_debug, 0x01, args) +#define deb_rc(args...) dprintk(dvb_usb_ce6230_debug, 0x02, args) +#define deb_xfer(args...) dprintk(dvb_usb_ce6230_debug, 0x04, args) +#define deb_reg(args...) dprintk(dvb_usb_ce6230_debug, 0x08, args) +#define deb_i2c(args...) dprintk(dvb_usb_ce6230_debug, 0x10, args) +#define deb_fw(args...) dprintk(dvb_usb_ce6230_debug, 0x20, args) + +#define ce6230_debug_dump(r, t, v, i, b, l, func) { \ + int loop_; \ + func("%02x %02x %02x %02x %02x %02x %02x %02x", \ + t, r, v & 0xff, v >> 8, i & 0xff, i >> 8, l & 0xff, l >> 8); \ + if (t == (USB_TYPE_VENDOR | USB_DIR_OUT)) \ + func(" >>> "); \ + else \ + func(" <<< "); \ + for (loop_ = 0; loop_ < l; loop_++) \ + func("%02x ", b[loop_]); \ + func("\n");\ +} + +#define CE6230_USB_TIMEOUT 1000 + +struct req_t { + u8 cmd; /* [1] */ + u16 value; /* [2|3] */ + u16 index; /* [4|5] */ + u16 data_len; /* [6|7] */ + u8 *data; +}; + +enum ce6230_cmd { + CONFIG_READ = 0xd0, /* rd 0 (unclear) */ + UNKNOWN_WRITE = 0xc7, /* wr 7 (unclear) */ + I2C_READ = 0xd9, /* rd 9 (unclear) */ + I2C_WRITE = 0xca, /* wr a */ + DEMOD_READ = 0xdb, /* rd b */ + DEMOD_WRITE = 0xcc, /* wr c */ + REG_READ = 0xde, /* rd e */ + REG_WRITE = 0xcf, /* wr f */ +}; + +#endif diff --git a/linux/drivers/media/dvb/dvb-usb/dvb-usb-ids.h b/linux/drivers/media/dvb/dvb-usb/dvb-usb-ids.h index 3dfb27174..0f239c668 100644 --- a/linux/drivers/media/dvb/dvb-usb/dvb-usb-ids.h +++ b/linux/drivers/media/dvb/dvb-usb/dvb-usb-ids.h @@ -33,6 +33,7 @@ #define USB_VID_HANFTEK 0x15f4 #define USB_VID_HAUPPAUGE 0x2040 #define USB_VID_HYPER_PALTEK 0x1025 +#define USB_VID_INTEL 0x8086 #define USB_VID_KWORLD 0xeb2a #define USB_VID_KWORLD_2 0x1b80 #define USB_VID_KYE 0x0458 @@ -96,6 +97,7 @@ #define USB_PID_UNIWILL_STK7700P 0x6003 #define USB_PID_GRANDTEC_DVBT_USB_COLD 0x0fa0 #define USB_PID_GRANDTEC_DVBT_USB_WARM 0x0fa1 +#define USB_PID_INTEL_CE9500 0x9500 #define USB_PID_KWORLD_399U 0xe399 #define USB_PID_KWORLD_395U 0xe396 #define USB_PID_KWORLD_395U_2 0xe39b diff --git a/linux/drivers/media/dvb/frontends/Kconfig b/linux/drivers/media/dvb/frontends/Kconfig index 5c78f6329..a206cee23 100644 --- a/linux/drivers/media/dvb/frontends/Kconfig +++ b/linux/drivers/media/dvb/frontends/Kconfig @@ -437,7 +437,7 @@ config DVB_S5H1409 config DVB_AU8522 tristate "Auvitek AU8522 based" - depends on DVB_CORE && I2C + depends on DVB_CORE && I2C && VIDEO_V4L2 default m if DVB_FE_CUSTOMISE help An ATSC 8VSB and QAM64/256 tuner module. Say Y when you want diff --git a/linux/drivers/media/dvb/frontends/Makefile b/linux/drivers/media/dvb/frontends/Makefile index 2a250399b..65a336aa1 100644 --- a/linux/drivers/media/dvb/frontends/Makefile +++ b/linux/drivers/media/dvb/frontends/Makefile @@ -8,6 +8,7 @@ EXTRA_CFLAGS += -Idrivers/media/common/tuners/ s921-objs := s921_module.o s921_core.o stb0899-objs = stb0899_drv.o stb0899_algo.o stv0900-objs = stv0900_core.o stv0900_sw.o +au8522-objs = au8522_dig.o au8522_decoder.o obj-$(CONFIG_DVB_PLL) += dvb-pll.o obj-$(CONFIG_DVB_STV0299) += stv0299.o diff --git a/linux/drivers/media/dvb/frontends/au8522.h b/linux/drivers/media/dvb/frontends/au8522.h index 7b94f554a..565dcf31a 100644 --- a/linux/drivers/media/dvb/frontends/au8522.h +++ b/linux/drivers/media/dvb/frontends/au8522.h @@ -74,6 +74,22 @@ struct dvb_frontend *au8522_attach(const struct au8522_config *config, } #endif /* CONFIG_DVB_AU8522 */ +/* Other modes may need to be added later */ +enum au8522_video_input { + AU8522_COMPOSITE_CH1 = 1, + AU8522_COMPOSITE_CH2, + AU8522_COMPOSITE_CH3, + AU8522_COMPOSITE_CH4, + AU8522_COMPOSITE_CH4_SIF, + AU8522_SVIDEO_CH13, + AU8522_SVIDEO_CH24, +}; + +enum au8522_audio_input { + AU8522_AUDIO_NONE, + AU8522_AUDIO_SIF, +}; + #endif /* __AU8522_H__ */ /* diff --git a/linux/drivers/media/dvb/frontends/au8522_decoder.c b/linux/drivers/media/dvb/frontends/au8522_decoder.c new file mode 100644 index 000000000..70af9cda7 --- /dev/null +++ b/linux/drivers/media/dvb/frontends/au8522_decoder.c @@ -0,0 +1,846 @@ +/* + * Auvitek AU8522 QAM/8VSB demodulator driver and video decoder + * + * Copyright (C) 2009 Devin Heitmueller <dheitmueller@linuxtv.org> + * Copyright (C) 2005-2008 Auvitek International, Ltd. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * As published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +/* Developer notes: + * + * VBI support is not yet working + * Saturation and hue setting are not yet working + * Enough is implemented here for CVBS and S-Video inputs, but the actual + * analog demodulator code isn't implemented (not needed for xc5000 since it + * has its own demodulator and outputs CVBS) + * + */ + +#include <linux/kernel.h> +#include <linux/slab.h> +#include <linux/videodev2.h> +#include <linux/i2c.h> +#include <linux/delay.h> +#include <media/v4l2-common.h> +#include <media/v4l2-chip-ident.h> +#include <media/v4l2-i2c-drv.h> +#include <media/v4l2-device.h> +#include "compat.h" +#include "au8522.h" +#include "au8522_priv.h" + +MODULE_AUTHOR("Devin Heitmueller"); +MODULE_LICENSE("GPL"); + +static int au8522_analog_debug; + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 22) +static unsigned short normal_i2c[] = { 0x8e >> 1, I2C_CLIENT_END }; + +I2C_CLIENT_INSMOD; +#endif + +module_param_named(analog_debug, au8522_analog_debug, int, 0644); + +MODULE_PARM_DESC(analog_debug, + "Analog debugging messages [0=Off (default) 1=On]"); + +struct au8522_register_config { + u16 reg_name; + u8 reg_val[8]; +}; + + +/* Video Decoder Filter Coefficients + The values are as follows from left to right + 0="ATV RF" 1="ATV RF13" 2="CVBS" 3="S-Video" 4="PAL" 5=CVBS13" 6="SVideo13" +*/ +struct au8522_register_config filter_coef[] = { + {AU8522_FILTER_COEF_R410, {0x25, 0x00, 0x25, 0x25, 0x00, 0x00, 0x00} }, + {AU8522_FILTER_COEF_R411, {0x20, 0x00, 0x20, 0x20, 0x00, 0x00, 0x00} }, + {AU8522_FILTER_COEF_R412, {0x03, 0x00, 0x03, 0x03, 0x00, 0x00, 0x00} }, + {AU8522_FILTER_COEF_R413, {0xe6, 0x00, 0xe6, 0xe6, 0x00, 0x00, 0x00} }, + {AU8522_FILTER_COEF_R414, {0x40, 0x00, 0x40, 0x40, 0x00, 0x00, 0x00} }, + {AU8522_FILTER_COEF_R415, {0x1b, 0x00, 0x1b, 0x1b, 0x00, 0x00, 0x00} }, + {AU8522_FILTER_COEF_R416, {0xc0, 0x00, 0xc0, 0x04, 0x00, 0x00, 0x00} }, + {AU8522_FILTER_COEF_R417, {0x04, 0x00, 0x04, 0x04, 0x00, 0x00, 0x00} }, + {AU8522_FILTER_COEF_R418, {0x8c, 0x00, 0x8c, 0x8c, 0x00, 0x00, 0x00} }, + {AU8522_FILTER_COEF_R419, {0xa0, 0x40, 0xa0, 0xa0, 0x40, 0x40, 0x40} }, + {AU8522_FILTER_COEF_R41A, {0x21, 0x09, 0x21, 0x21, 0x09, 0x09, 0x09} }, + {AU8522_FILTER_COEF_R41B, {0x6c, 0x38, 0x6c, 0x6c, 0x38, 0x38, 0x38} }, + {AU8522_FILTER_COEF_R41C, {0x03, 0xff, 0x03, 0x03, 0xff, 0xff, 0xff} }, + {AU8522_FILTER_COEF_R41D, {0xbf, 0xc7, 0xbf, 0xbf, 0xc7, 0xc7, 0xc7} }, + {AU8522_FILTER_COEF_R41E, {0xa0, 0xdf, 0xa0, 0xa0, 0xdf, 0xdf, 0xdf} }, + {AU8522_FILTER_COEF_R41F, {0x10, 0x06, 0x10, 0x10, 0x06, 0x06, 0x06} }, + {AU8522_FILTER_COEF_R420, {0xae, 0x30, 0xae, 0xae, 0x30, 0x30, 0x30} }, + {AU8522_FILTER_COEF_R421, {0xc4, 0x01, 0xc4, 0xc4, 0x01, 0x01, 0x01} }, + {AU8522_FILTER_COEF_R422, {0x54, 0xdd, 0x54, 0x54, 0xdd, 0xdd, 0xdd} }, + {AU8522_FILTER_COEF_R423, {0xd0, 0xaf, 0xd0, 0xd0, 0xaf, 0xaf, 0xaf} }, + {AU8522_FILTER_COEF_R424, {0x1c, 0xf7, 0x1c, 0x1c, 0xf7, 0xf7, 0xf7} }, + {AU8522_FILTER_COEF_R425, {0x76, 0xdb, 0x76, 0x76, 0xdb, 0xdb, 0xdb} }, + {AU8522_FILTER_COEF_R426, {0x61, 0xc0, 0x61, 0x61, 0xc0, 0xc0, 0xc0} }, + {AU8522_FILTER_COEF_R427, {0xd1, 0x2f, 0xd1, 0xd1, 0x2f, 0x2f, 0x2f} }, + {AU8522_FILTER_COEF_R428, {0x84, 0xd8, 0x84, 0x84, 0xd8, 0xd8, 0xd8} }, + {AU8522_FILTER_COEF_R429, {0x06, 0xfb, 0x06, 0x06, 0xfb, 0xfb, 0xfb} }, + {AU8522_FILTER_COEF_R42A, {0x21, 0xd5, 0x21, 0x21, 0xd5, 0xd5, 0xd5} }, + {AU8522_FILTER_COEF_R42B, {0x0a, 0x3e, 0x0a, 0x0a, 0x3e, 0x3e, 0x3e} }, + {AU8522_FILTER_COEF_R42C, {0xe6, 0x15, 0xe6, 0xe6, 0x15, 0x15, 0x15} }, + {AU8522_FILTER_COEF_R42D, {0x01, 0x34, 0x01, 0x01, 0x34, 0x34, 0x34} }, + +}; +#define NUM_FILTER_COEF (sizeof(filter_coef)\ + / sizeof(struct au8522_register_config)) + + +/* Registers 0x060b through 0x0652 are the LP Filter coefficients + The values are as follows from left to right + 0="SIF" 1="ATVRF/ATVRF13" + Note: the "ATVRF/ATVRF13" mode has never been tested +*/ +struct au8522_register_config lpfilter_coef[] = { + {0x060b, {0x21, 0x0b} }, + {0x060c, {0xad, 0xad} }, + {0x060d, {0x70, 0xf0} }, + {0x060e, {0xea, 0xe9} }, + {0x060f, {0xdd, 0xdd} }, + {0x0610, {0x08, 0x64} }, + {0x0611, {0x60, 0x60} }, + {0x0612, {0xf8, 0xb2} }, + {0x0613, {0x01, 0x02} }, + {0x0614, {0xe4, 0xb4} }, + {0x0615, {0x19, 0x02} }, + {0x0616, {0xae, 0x2e} }, + {0x0617, {0xee, 0xc5} }, + {0x0618, {0x56, 0x56} }, + {0x0619, {0x30, 0x58} }, + {0x061a, {0xf9, 0xf8} }, + {0x061b, {0x24, 0x64} }, + {0x061c, {0x07, 0x07} }, + {0x061d, {0x30, 0x30} }, + {0x061e, {0xa9, 0xed} }, + {0x061f, {0x09, 0x0b} }, + {0x0620, {0x42, 0xc2} }, + {0x0621, {0x1d, 0x2a} }, + {0x0622, {0xd6, 0x56} }, + {0x0623, {0x95, 0x8b} }, + {0x0624, {0x2b, 0x2b} }, + {0x0625, {0x30, 0x24} }, + {0x0626, {0x3e, 0x3e} }, + {0x0627, {0x62, 0xe2} }, + {0x0628, {0xe9, 0xf5} }, + {0x0629, {0x99, 0x19} }, + {0x062a, {0xd4, 0x11} }, + {0x062b, {0x03, 0x04} }, + {0x062c, {0xb5, 0x85} }, + {0x062d, {0x1e, 0x20} }, + {0x062e, {0x2a, 0xea} }, + {0x062f, {0xd7, 0xd2} }, + {0x0630, {0x15, 0x15} }, + {0x0631, {0xa3, 0xa9} }, + {0x0632, {0x1f, 0x1f} }, + {0x0633, {0xf9, 0xd1} }, + {0x0634, {0xc0, 0xc3} }, + {0x0635, {0x4d, 0x8d} }, + {0x0636, {0x21, 0x31} }, + {0x0637, {0x83, 0x83} }, + {0x0638, {0x08, 0x8c} }, + {0x0639, {0x19, 0x19} }, + {0x063a, {0x45, 0xa5} }, + {0x063b, {0xef, 0xec} }, + {0x063c, {0x8a, 0x8a} }, + {0x063d, {0xf4, 0xf6} }, + {0x063e, {0x8f, 0x8f} }, + {0x063f, {0x44, 0x0c} }, + {0x0640, {0xef, 0xf0} }, + {0x0641, {0x66, 0x66} }, + {0x0642, {0xcc, 0xd2} }, + {0x0643, {0x41, 0x41} }, + {0x0644, {0x63, 0x93} }, + {0x0645, {0x8e, 0x8e} }, + {0x0646, {0xa2, 0x42} }, + {0x0647, {0x7b, 0x7b} }, + {0x0648, {0x04, 0x04} }, + {0x0649, {0x00, 0x00} }, + {0x064a, {0x40, 0x40} }, + {0x064b, {0x8c, 0x98} }, + {0x064c, {0x00, 0x00} }, + {0x064d, {0x63, 0xc3} }, + {0x064e, {0x04, 0x04} }, + {0x064f, {0x20, 0x20} }, + {0x0650, {0x00, 0x00} }, + {0x0651, {0x40, 0x40} }, + {0x0652, {0x01, 0x01} }, +}; +#define NUM_LPFILTER_COEF (sizeof(lpfilter_coef)\ + / sizeof(struct au8522_register_config)) + +static inline struct au8522_state *to_state(struct v4l2_subdev *sd) +{ + return container_of(sd, struct au8522_state, sd); +} + +static void setup_vbi(struct au8522_state *state, int aud_input) +{ + int i; + + /* These are set to zero regardless of what mode we're in */ + au8522_writereg(state, AU8522_TVDEC_VBI_CTRL_H_REG017H, 0x00); + au8522_writereg(state, AU8522_TVDEC_VBI_CTRL_L_REG018H, 0x00); + au8522_writereg(state, AU8522_TVDEC_VBI_USER_TOTAL_BITS_REG019H, 0x00); + au8522_writereg(state, AU8522_TVDEC_VBI_USER_TUNIT_H_REG01AH, 0x00); + au8522_writereg(state, AU8522_TVDEC_VBI_USER_TUNIT_L_REG01BH, 0x00); + au8522_writereg(state, AU8522_TVDEC_VBI_USER_THRESH1_REG01CH, 0x00); + au8522_writereg(state, AU8522_TVDEC_VBI_USER_FRAME_PAT2_REG01EH, 0x00); + au8522_writereg(state, AU8522_TVDEC_VBI_USER_FRAME_PAT1_REG01FH, 0x00); + au8522_writereg(state, AU8522_TVDEC_VBI_USER_FRAME_PAT0_REG020H, 0x00); + au8522_writereg(state, AU8522_TVDEC_VBI_USER_FRAME_MASK2_REG021H, + 0x00); + au8522_writereg(state, AU8522_TVDEC_VBI_USER_FRAME_MASK1_REG022H, + 0x00); + au8522_writereg(state, AU8522_TVDEC_VBI_USER_FRAME_MASK0_REG023H, + 0x00); + + /* Setup the VBI registers */ + for (i = 0x30; i < 0x60; i++) + au8522_writereg(state, i, 0x40); + + /* For some reason, every register is 0x40 except register 0x44 + (confirmed via the HVR-950q USB capture) */ + au8522_writereg(state, 0x44, 0x60); + + /* Enable VBI (we always do this regardless of whether the user is + viewing closed caption info) */ + au8522_writereg(state, AU8522_TVDEC_VBI_CTRL_H_REG017H, + AU8522_TVDEC_VBI_CTRL_H_REG017H_CCON); + +} + +static void setup_decoder_defaults(struct au8522_state *state, u8 input_mode) +{ + int i; + int filter_coef_type; + + /* Provide reasonable defaults for picture tuning values */ + au8522_writereg(state, AU8522_TVDEC_SHARPNESSREG009H, 0x07); + au8522_writereg(state, AU8522_TVDEC_BRIGHTNESS_REG00AH, 0xed); + state->brightness = 0xed - 128; + au8522_writereg(state, AU8522_TVDEC_CONTRAST_REG00BH, 0x79); + state->contrast = 0x79; + au8522_writereg(state, AU8522_TVDEC_SATURATION_CB_REG00CH, 0x80); + au8522_writereg(state, AU8522_TVDEC_SATURATION_CR_REG00DH, 0x80); + au8522_writereg(state, AU8522_TVDEC_HUE_H_REG00EH, 0x00); + au8522_writereg(state, AU8522_TVDEC_HUE_L_REG00FH, 0x00); + + /* Other decoder registers */ + au8522_writereg(state, AU8522_TVDEC_INT_MASK_REG010H, 0x00); + + if (input_mode == 0x23) { + /* S-Video input mapping */ + au8522_writereg(state, AU8522_VIDEO_MODE_REG011H, 0x04); + } else { + /* All other modes (CVBS/ATVRF etc.) */ + au8522_writereg(state, AU8522_VIDEO_MODE_REG011H, 0x00); + } + + au8522_writereg(state, AU8522_TVDEC_PGA_REG012H, + AU8522_TVDEC_PGA_REG012H_CVBS); + au8522_writereg(state, AU8522_TVDEC_COMB_MODE_REG015H, + AU8522_TVDEC_COMB_MODE_REG015H_CVBS); + au8522_writereg(state, AU8522_TVDED_DBG_MODE_REG060H, + AU8522_TVDED_DBG_MODE_REG060H_CVBS); + au8522_writereg(state, AU8522_TVDEC_FORMAT_CTRL1_REG061H, + AU8522_TVDEC_FORMAT_CTRL1_REG061H_CVBS13); + au8522_writereg(state, AU8522_TVDEC_FORMAT_CTRL2_REG062H, + AU8522_TVDEC_FORMAT_CTRL2_REG062H_CVBS13); + au8522_writereg(state, AU8522_TVDEC_VCR_DET_LLIM_REG063H, + AU8522_TVDEC_VCR_DET_LLIM_REG063H_CVBS); + au8522_writereg(state, AU8522_TVDEC_VCR_DET_HLIM_REG064H, + AU8522_TVDEC_VCR_DET_HLIM_REG064H_CVBS); + au8522_writereg(state, AU8522_TVDEC_COMB_VDIF_THR1_REG065H, + AU8522_TVDEC_COMB_VDIF_THR1_REG065H_CVBS); + au8522_writereg(state, AU8522_TVDEC_COMB_VDIF_THR2_REG066H, + AU8522_TVDEC_COMB_VDIF_THR2_REG066H_CVBS); + au8522_writereg(state, AU8522_TVDEC_COMB_VDIF_THR3_REG067H, + AU8522_TVDEC_COMB_VDIF_THR3_REG067H_CVBS); + au8522_writereg(state, AU8522_TVDEC_COMB_NOTCH_THR_REG068H, + AU8522_TVDEC_COMB_NOTCH_THR_REG068H_CVBS); + au8522_writereg(state, AU8522_TVDEC_COMB_HDIF_THR1_REG069H, + AU8522_TVDEC_COMB_HDIF_THR1_REG069H_CVBS); + au8522_writereg(state, AU8522_TVDEC_COMB_HDIF_THR2_REG06AH, + AU8522_TVDEC_COMB_HDIF_THR2_REG06AH_CVBS); + au8522_writereg(state, AU8522_TVDEC_COMB_HDIF_THR3_REG06BH, + AU8522_TVDEC_COMB_HDIF_THR3_REG06BH_CVBS); + au8522_writereg(state, AU8522_TVDEC_COMB_DCDIF_THR1_REG06CH, + AU8522_TVDEC_COMB_DCDIF_THR1_REG06CH_CVBS); + au8522_writereg(state, AU8522_TVDEC_COMB_DCDIF_THR2_REG06DH, + AU8522_TVDEC_COMB_DCDIF_THR2_REG06DH_CVBS); + au8522_writereg(state, AU8522_TVDEC_COMB_DCDIF_THR3_REG06EH, + AU8522_TVDEC_COMB_DCDIF_THR3_REG06EH_CVBS); + au8522_writereg(state, AU8522_TVDEC_UV_SEP_THR_REG06FH, + AU8522_TVDEC_UV_SEP_THR_REG06FH_CVBS); + au8522_writereg(state, AU8522_TVDEC_COMB_DC_THR1_NTSC_REG070H, + AU8522_TVDEC_COMB_DC_THR1_NTSC_REG070H_CVBS); + au8522_writereg(state, AU8522_REG071H, AU8522_REG071H_CVBS); + au8522_writereg(state, AU8522_REG072H, AU8522_REG072H_CVBS); + au8522_writereg(state, AU8522_TVDEC_COMB_DC_THR2_NTSC_REG073H, + AU8522_TVDEC_COMB_DC_THR2_NTSC_REG073H_CVBS); + au8522_writereg(state, AU8522_REG074H, AU8522_REG074H_CVBS); + au8522_writereg(state, AU8522_REG075H, AU8522_REG075H_CVBS); + au8522_writereg(state, AU8522_TVDEC_DCAGC_CTRL_REG077H, + AU8522_TVDEC_DCAGC_CTRL_REG077H_CVBS); + au8522_writereg(state, AU8522_TVDEC_PIC_START_ADJ_REG078H, + AU8522_TVDEC_PIC_START_ADJ_REG078H_CVBS); + au8522_writereg(state, AU8522_TVDEC_AGC_HIGH_LIMIT_REG079H, + AU8522_TVDEC_AGC_HIGH_LIMIT_REG079H_CVBS); + au8522_writereg(state, AU8522_TVDEC_MACROVISION_SYNC_THR_REG07AH, + AU8522_TVDEC_MACROVISION_SYNC_THR_REG07AH_CVBS); + au8522_writereg(state, AU8522_TVDEC_INTRP_CTRL_REG07BH, + AU8522_TVDEC_INTRP_CTRL_REG07BH_CVBS); + au8522_writereg(state, AU8522_TVDEC_AGC_LOW_LIMIT_REG0E4H, + AU8522_TVDEC_AGC_LOW_LIMIT_REG0E4H_CVBS); + au8522_writereg(state, AU8522_TOREGAAGC_REG0E5H, + AU8522_TOREGAAGC_REG0E5H_CVBS); + au8522_writereg(state, AU8522_REG016H, AU8522_REG016H_CVBS); + + setup_vbi(state, 0); + + if (input_mode == AU8522_INPUT_CONTROL_REG081H_SVIDEO_CH13 || + input_mode == AU8522_INPUT_CONTROL_REG081H_SVIDEO_CH24) { + /* Despite what the table says, for the HVR-950q we still need + to be in CVBS mode for the S-Video input (reason uknown). */ + /* filter_coef_type = 3; */ + filter_coef_type = 5; + } else { + filter_coef_type = 5; + } + + /* Load the Video Decoder Filter Coefficients */ + for (i = 0; i < NUM_FILTER_COEF; i++) { + au8522_writereg(state, filter_coef[i].reg_name, + filter_coef[i].reg_val[filter_coef_type]); + } + + /* It's not clear what these registers are for, but they are always + set to the same value regardless of what mode we're in */ + au8522_writereg(state, AU8522_REG42EH, 0x87); + au8522_writereg(state, AU8522_REG42FH, 0xa2); + au8522_writereg(state, AU8522_REG430H, 0xbf); + au8522_writereg(state, AU8522_REG431H, 0xcb); + au8522_writereg(state, AU8522_REG432H, 0xa1); + au8522_writereg(state, AU8522_REG433H, 0x41); + au8522_writereg(state, AU8522_REG434H, 0x88); + au8522_writereg(state, AU8522_REG435H, 0xc2); + au8522_writereg(state, AU8522_REG436H, 0x3c); +} + +static void au8522_setup_cvbs_mode(struct au8522_state *state) +{ + /* here we're going to try the pre-programmed route */ + au8522_writereg(state, AU8522_MODULE_CLOCK_CONTROL_REG0A3H, + AU8522_MODULE_CLOCK_CONTROL_REG0A3H_CVBS); + + au8522_writereg(state, AU8522_PGA_CONTROL_REG082H, 0x00); + au8522_writereg(state, AU8522_CLAMPING_CONTROL_REG083H, 0x0e); + au8522_writereg(state, AU8522_PGA_CONTROL_REG082H, 0x10); + + au8522_writereg(state, AU8522_INPUT_CONTROL_REG081H, + AU8522_INPUT_CONTROL_REG081H_CVBS_CH1); + + setup_decoder_defaults(state, AU8522_INPUT_CONTROL_REG081H_CVBS_CH1); + + au8522_writereg(state, AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H, + AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H_CVBS); +} + +static void au8522_setup_cvbs_tuner_mode(struct au8522_state *state) +{ + /* here we're going to try the pre-programmed route */ + au8522_writereg(state, AU8522_MODULE_CLOCK_CONTROL_REG0A3H, + AU8522_MODULE_CLOCK_CONTROL_REG0A3H_CVBS); + + /* It's not clear why they turn off the PGA before enabling the clamp + control, but the Windows trace does it so we will too... */ + au8522_writereg(state, AU8522_PGA_CONTROL_REG082H, 0x00); + + /* Enable clamping control */ + au8522_writereg(state, AU8522_CLAMPING_CONTROL_REG083H, 0x0e); + + /* Turn on the PGA */ + au8522_writereg(state, AU8522_PGA_CONTROL_REG082H, 0x10); + + /* Set input mode to CVBS on channel 4 with SIF audio input enabled */ + au8522_writereg(state, AU8522_INPUT_CONTROL_REG081H, + AU8522_INPUT_CONTROL_REG081H_CVBS_CH4_SIF); + + setup_decoder_defaults(state, + AU8522_INPUT_CONTROL_REG081H_CVBS_CH4_SIF); + + au8522_writereg(state, AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H, + AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H_CVBS); +} + +static void au8522_setup_svideo_mode(struct au8522_state *state) +{ + au8522_writereg(state, AU8522_MODULE_CLOCK_CONTROL_REG0A3H, + AU8522_MODULE_CLOCK_CONTROL_REG0A3H_SVIDEO); + + /* Set input to Y on Channe1, C on Channel 3 */ + au8522_writereg(state, AU8522_INPUT_CONTROL_REG081H, + AU8522_INPUT_CONTROL_REG081H_SVIDEO_CH13); + + /* Disable clamping control (required for S-video) */ + au8522_writereg(state, AU8522_CLAMPING_CONTROL_REG083H, 0x00); + + setup_decoder_defaults(state, + AU8522_INPUT_CONTROL_REG081H_SVIDEO_CH13); + + au8522_writereg(state, AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H, + AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H_CVBS); +} + +/* ----------------------------------------------------------------------- */ + +static void disable_audio_input(struct au8522_state *state) +{ + /* This can probably be optimized */ + au8522_writereg(state, AU8522_AUDIO_VOLUME_L_REG0F2H, 0x00); + au8522_writereg(state, AU8522_AUDIO_VOLUME_R_REG0F3H, 0x00); + au8522_writereg(state, AU8522_AUDIO_VOLUME_REG0F4H, 0x00); + au8522_writereg(state, AU8522_I2C_CONTROL_REG1_REG091H, 0x80); + au8522_writereg(state, AU8522_I2C_CONTROL_REG0_REG090H, 0x84); + + au8522_writereg(state, AU8522_ENA_USB_REG101H, 0x00); + au8522_writereg(state, AU8522_AUDIO_VOLUME_L_REG0F2H, 0x7F); + au8522_writereg(state, AU8522_AUDIO_VOLUME_R_REG0F3H, 0x7F); + au8522_writereg(state, AU8522_REG0F9H, AU8522_REG0F9H_AUDIO); + au8522_writereg(state, AU8522_AUDIO_MODE_REG0F1H, 0x40); + + au8522_writereg(state, AU8522_GPIO_DATA_REG0E2H, 0x11); + msleep(5); + au8522_writereg(state, AU8522_GPIO_DATA_REG0E2H, 0x00); + + au8522_writereg(state, AU8522_SYSTEM_MODULE_CONTROL_1_REG0A5H, 0x04); + au8522_writereg(state, AU8522_AUDIOFREQ_REG606H, 0x03); + au8522_writereg(state, AU8522_I2S_CTRL_2_REG112H, 0x02); + + au8522_writereg(state, AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H, + AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H_CVBS); +} + +/* 0=disable, 1=SIF */ +static void set_audio_input(struct au8522_state *state, int aud_input) +{ + int i; + + /* Note that this function needs to be used in conjunction with setting + the input routing via register 0x81 */ + + if (aud_input == AU8522_AUDIO_NONE) { + disable_audio_input(state); + return; + } + + if (aud_input != AU8522_AUDIO_SIF) { + /* The caller asked for a mode we don't currently support */ + printk(KERN_ERR "Unsupported audio mode requested! mode=%d\n", + aud_input); + return; + } + + /* Load the Audio Decoder Filter Coefficients */ + for (i = 0; i < NUM_LPFILTER_COEF; i++) { + au8522_writereg(state, lpfilter_coef[i].reg_name, + lpfilter_coef[i].reg_val[0]); + } + + /* Setup audio */ + au8522_writereg(state, AU8522_AUDIO_VOLUME_L_REG0F2H, 0x00); + au8522_writereg(state, AU8522_AUDIO_VOLUME_R_REG0F3H, 0x00); + au8522_writereg(state, AU8522_AUDIO_VOLUME_REG0F4H, 0x00); + au8522_writereg(state, AU8522_I2C_CONTROL_REG1_REG091H, 0x80); + au8522_writereg(state, AU8522_I2C_CONTROL_REG0_REG090H, 0x84); + msleep(150); + au8522_writereg(state, AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H, 0x00); + msleep(1); + au8522_writereg(state, AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H, 0x9d); + msleep(50); + au8522_writereg(state, AU8522_AUDIO_VOLUME_L_REG0F2H, 0x7F); + au8522_writereg(state, AU8522_AUDIO_VOLUME_R_REG0F3H, 0x7F); + au8522_writereg(state, AU8522_AUDIO_VOLUME_REG0F4H, 0xff); + msleep(80); + au8522_writereg(state, AU8522_AUDIO_VOLUME_L_REG0F2H, 0x7F); + au8522_writereg(state, AU8522_AUDIO_VOLUME_R_REG0F3H, 0x7F); + au8522_writereg(state, AU8522_REG0F9H, AU8522_REG0F9H_AUDIO); + au8522_writereg(state, AU8522_AUDIO_MODE_REG0F1H, 0x82); + msleep(70); + au8522_writereg(state, AU8522_SYSTEM_MODULE_CONTROL_1_REG0A5H, 0x09); + au8522_writereg(state, AU8522_AUDIOFREQ_REG606H, 0x03); + au8522_writereg(state, AU8522_I2S_CTRL_2_REG112H, 0xc2); +} + +/* ----------------------------------------------------------------------- */ + +static int au8522_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) +{ + struct au8522_state *state = to_state(sd); + + switch (ctrl->id) { + case V4L2_CID_BRIGHTNESS: + state->brightness = ctrl->value; + au8522_writereg(state, AU8522_TVDEC_BRIGHTNESS_REG00AH, + ctrl->value - 128); + break; + case V4L2_CID_CONTRAST: + state->contrast = ctrl->value; + au8522_writereg(state, AU8522_TVDEC_CONTRAST_REG00BH, + ctrl->value); + break; + case V4L2_CID_SATURATION: + case V4L2_CID_HUE: + case V4L2_CID_AUDIO_VOLUME: + case V4L2_CID_AUDIO_BASS: + case V4L2_CID_AUDIO_TREBLE: + case V4L2_CID_AUDIO_BALANCE: + case V4L2_CID_AUDIO_MUTE: + /* Not yet implemented */ + default: + return -EINVAL; + } + + return 0; +} + +static int au8522_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) +{ + struct au8522_state *state = to_state(sd); + + /* Note that we are using values cached in the state structure instead + of reading the registers due to issues with i2c reads not working + properly/consistently yet on the HVR-950q */ + + switch (ctrl->id) { + case V4L2_CID_BRIGHTNESS: + ctrl->value = state->brightness; + break; + case V4L2_CID_CONTRAST: + ctrl->value = state->contrast; + break; + case V4L2_CID_SATURATION: + case V4L2_CID_HUE: + case V4L2_CID_AUDIO_VOLUME: + case V4L2_CID_AUDIO_BASS: + case V4L2_CID_AUDIO_TREBLE: + case V4L2_CID_AUDIO_BALANCE: + case V4L2_CID_AUDIO_MUTE: + /* Not yet supported */ + default: + return -EINVAL; + } + + return 0; +} + +/* ----------------------------------------------------------------------- */ + +static int au8522_g_fmt(struct v4l2_subdev *sd, struct v4l2_format *fmt) +{ + switch (fmt->type) { + default: + return -EINVAL; + } + return 0; +} + +static int au8522_s_fmt(struct v4l2_subdev *sd, struct v4l2_format *fmt) +{ + switch (fmt->type) { + case V4L2_BUF_TYPE_VIDEO_CAPTURE: + /* Not yet implemented */ + break; + default: + return -EINVAL; + } + + return 0; +} + +/* ----------------------------------------------------------------------- */ + +#ifdef CONFIG_VIDEO_ADV_DEBUG +static int au8522_g_register(struct v4l2_subdev *sd, + struct v4l2_dbg_register *reg) +{ + struct i2c_client *client = v4l2_get_subdevdata(sd); + struct au8522_state *state = to_state(sd); + + if (!v4l2_chip_match_i2c_client(client, ®->match)) + return -EINVAL; + if (!capable(CAP_SYS_ADMIN)) + return -EPERM; + reg->val = au8522_readreg(state, reg->reg & 0xffff); + return 0; +} + +static int au8522_s_register(struct v4l2_subdev *sd, + struct v4l2_dbg_register *reg) +{ + struct i2c_client *client = v4l2_get_subdevdata(sd); + struct au8522_state *state = to_state(sd); + + if (!v4l2_chip_match_i2c_client(client, ®->match)) + return -EINVAL; + if (!capable(CAP_SYS_ADMIN)) + return -EPERM; + au8522_writereg(state, reg->reg, reg->val & 0xff); + return 0; +} +#endif + +static int au8522_s_stream(struct v4l2_subdev *sd, int enable) +{ + struct au8522_state *state = to_state(sd); + + if (enable) { + au8522_writereg(state, AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H, + 0x01); + msleep(1); + au8522_writereg(state, AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H, + AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H_CVBS); + } else { + /* This does not completely power down the device + (it only reduces it from around 140ma to 80ma) */ + au8522_writereg(state, AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H, + 1 << 5); + } + return 0; +} + +static int au8522_queryctrl(struct v4l2_subdev *sd, struct v4l2_queryctrl *qc) +{ + switch (qc->id) { + case V4L2_CID_CONTRAST: + return v4l2_ctrl_query_fill(qc, 0, 255, 1, + AU8522_TVDEC_CONTRAST_REG00BH_CVBS); + case V4L2_CID_BRIGHTNESS: + return v4l2_ctrl_query_fill(qc, 0, 255, 1, 128); + case V4L2_CID_SATURATION: + case V4L2_CID_HUE: + /* Not yet implemented */ + default: + break; + } + + qc->type = 0; + return -EINVAL; +} + +static int au8522_reset(struct v4l2_subdev *sd, u32 val) +{ + struct au8522_state *state = to_state(sd); + + au8522_writereg(state, 0xa4, 1 << 5); + + return 0; +} + +static int au8522_s_video_routing(struct v4l2_subdev *sd, + const struct v4l2_routing *route) +{ + struct au8522_state *state = to_state(sd); + + au8522_reset(sd, 0); + + /* Jam open the i2c gate to the tuner. We do this here to handle the + case where the user went into digital mode (causing the gate to be + closed), and then came back to analog mode */ + au8522_writereg(state, 0x106, 1); + + if (route->input == AU8522_COMPOSITE_CH1) { + au8522_setup_cvbs_mode(state); + } else if (route->input == AU8522_SVIDEO_CH13) { + au8522_setup_svideo_mode(state); + } else if (route->input == AU8522_COMPOSITE_CH4_SIF) { + au8522_setup_cvbs_tuner_mode(state); + } else { + printk(KERN_ERR "au8522 mode not currently supported\n"); + return -EINVAL; + } + return 0; +} + +static int au8522_s_audio_routing(struct v4l2_subdev *sd, + const struct v4l2_routing *route) +{ + struct au8522_state *state = to_state(sd); + set_audio_input(state, route->input); + return 0; +} + +static int au8522_g_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *vt) +{ + int val = 0; + struct au8522_state *state = to_state(sd); + u8 lock_status; + + /* Interrogate the decoder to see if we are getting a real signal */ + lock_status = au8522_readreg(state, 0x00); + if (lock_status == 0xa2) + vt->signal = 0x01; + else + vt->signal = 0x00; + + vt->capability |= + V4L2_TUNER_CAP_STEREO | V4L2_TUNER_CAP_LANG1 | + V4L2_TUNER_CAP_LANG2 | V4L2_TUNER_CAP_SAP; + + val = V4L2_TUNER_SUB_MONO; + vt->rxsubchans = val; + vt->audmode = V4L2_TUNER_MODE_STEREO; + return 0; +} + +static int au8522_g_chip_ident(struct v4l2_subdev *sd, + struct v4l2_dbg_chip_ident *chip) +{ + struct au8522_state *state = to_state(sd); + struct i2c_client *client = v4l2_get_subdevdata(sd); + + return v4l2_chip_ident_i2c_client(client, chip, state->id, state->rev); +} + +static int au8522_log_status(struct v4l2_subdev *sd) +{ + /* FIXME: Add some status info here */ + return 0; +} + +/* ----------------------------------------------------------------------- */ + +static const struct v4l2_subdev_core_ops au8522_core_ops = { + .log_status = au8522_log_status, + .g_chip_ident = au8522_g_chip_ident, + .g_ctrl = au8522_g_ctrl, + .s_ctrl = au8522_s_ctrl, + .queryctrl = au8522_queryctrl, + .reset = au8522_reset, +#ifdef CONFIG_VIDEO_ADV_DEBUG + .g_register = au8522_g_register, + .s_register = au8522_s_register, +#endif +}; + +static const struct v4l2_subdev_tuner_ops au8522_tuner_ops = { + .g_tuner = au8522_g_tuner, +}; + +static const struct v4l2_subdev_audio_ops au8522_audio_ops = { + .s_routing = au8522_s_audio_routing, +}; + +static const struct v4l2_subdev_video_ops au8522_video_ops = { + .s_routing = au8522_s_video_routing, + .g_fmt = au8522_g_fmt, + .s_fmt = au8522_s_fmt, + .s_stream = au8522_s_stream, +}; + +static const struct v4l2_subdev_ops au8522_ops = { + .core = &au8522_core_ops, + .tuner = &au8522_tuner_ops, + .audio = &au8522_audio_ops, + .video = &au8522_video_ops, +}; + +/* ----------------------------------------------------------------------- */ + +static int au8522_probe(struct i2c_client *client, + const struct i2c_device_id *did) +{ + struct au8522_state *state; + struct v4l2_subdev *sd; + int instance; + struct au8522_config *demod_config; + + /* Check if the adapter supports the needed features */ + if (!i2c_check_functionality(client->adapter, + I2C_FUNC_SMBUS_BYTE_DATA)) { + return -EIO; + } + + /* allocate memory for the internal state */ + instance = au8522_get_state(&state, client->adapter, client->addr); + switch (instance) { + case 0: + printk(KERN_ERR "au8522_decoder allocation failed\n"); + return -EIO; + case 1: + /* new demod instance */ + printk(KERN_INFO "au8522_decoder creating new instance...\n"); + break; + default: + /* existing demod instance */ + printk(KERN_INFO "au8522_decoder attach existing instance.\n"); + break; + } + + demod_config = kzalloc(sizeof(struct au8522_config), GFP_KERNEL); + demod_config->demod_address = 0x8e >> 1; + + state->config = demod_config; + state->i2c = client->adapter; + + sd = &state->sd; + v4l2_i2c_subdev_init(sd, client, &au8522_ops); + + state->c = client; + state->vid_input = AU8522_COMPOSITE_CH1; + state->aud_input = AU8522_AUDIO_NONE; + state->id = 8522; + state->rev = 0; + + /* Jam open the i2c gate to the tuner */ + au8522_writereg(state, 0x106, 1); + + return 0; +} + +static int au8522_remove(struct i2c_client *client) +{ + struct v4l2_subdev *sd = i2c_get_clientdata(client); + v4l2_device_unregister_subdev(sd); + au8522_release_state(to_state(sd)); + return 0; +} + +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 26) +static const struct i2c_device_id au8522_id[] = { + {"au8522", 0}, + {} +}; + +MODULE_DEVICE_TABLE(i2c, au8522_id); + +#endif +static struct v4l2_i2c_driver_data v4l2_i2c_data = { + .name = "au8522", + .driverid = I2C_DRIVERID_AU8522, + .probe = au8522_probe, + .remove = au8522_remove, +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 26) + .id_table = au8522_id, +#endif +}; diff --git a/linux/drivers/media/dvb/frontends/au8522.c b/linux/drivers/media/dvb/frontends/au8522_dig.c index 1e3ad2302..41aedcc99 100644 --- a/linux/drivers/media/dvb/frontends/au8522.c +++ b/linux/drivers/media/dvb/frontends/au8522_dig.c @@ -27,35 +27,25 @@ #include <linux/delay.h> #include "dvb_frontend.h" #include "au8522.h" - -struct au8522_state { - - struct i2c_adapter *i2c; - - /* configuration settings */ - const struct au8522_config *config; - - struct dvb_frontend frontend; - - u32 current_frequency; - fe_modulation_t current_modulation; - - u32 fe_status; - unsigned int led_state; -}; +#include "au8522_priv.h" static int debug; -#define dprintk(arg...) do { \ - if (debug) \ - printk(arg); \ +/* Despite the name "hybrid_tuner", the framework works just as well for + hybrid demodulators as well... */ +static LIST_HEAD(hybrid_tuner_instance_list); +static DEFINE_MUTEX(au8522_list_mutex); + +#define dprintk(arg...)\ + do { if (debug)\ + printk(arg);\ } while (0) /* 16 bit registers, 8 bit values */ -static int au8522_writereg(struct au8522_state *state, u16 reg, u8 data) +int au8522_writereg(struct au8522_state *state, u16 reg, u8 data) { int ret; - u8 buf [] = { reg >> 8, reg & 0xff, data }; + u8 buf[] = { (reg >> 8) | 0x80, reg & 0xff, data }; struct i2c_msg msg = { .addr = state->config->demod_address, .flags = 0, .buf = buf, .len = 3 }; @@ -69,13 +59,13 @@ static int au8522_writereg(struct au8522_state *state, u16 reg, u8 data) return (ret != 1) ? -1 : 0; } -static u8 au8522_readreg(struct au8522_state *state, u16 reg) +u8 au8522_readreg(struct au8522_state *state, u16 reg) { int ret; - u8 b0 [] = { reg >> 8, reg & 0xff }; - u8 b1 [] = { 0 }; + u8 b0[] = { (reg >> 8) | 0x40, reg & 0xff }; + u8 b1[] = { 0 }; - struct i2c_msg msg [] = { + struct i2c_msg msg[] = { { .addr = state->config->demod_address, .flags = 0, .buf = b0, .len = 2 }, { .addr = state->config->demod_address, .flags = I2C_M_RD, @@ -528,7 +518,7 @@ static int au8522_set_frontend(struct dvb_frontend *fe, /* Reset the demod hardware and reset all of the configuration registers to a default state. */ -static int au8522_init(struct dvb_frontend *fe) +int au8522_init(struct dvb_frontend *fe) { struct au8522_state *state = fe->demodulator_priv; dprintk("%s()\n", __func__); @@ -624,7 +614,7 @@ static int au8522_led_ctrl(struct au8522_state *state, int led) return 0; } -static int au8522_sleep(struct dvb_frontend *fe) +int au8522_sleep(struct dvb_frontend *fe) { struct au8522_state *state = fe->demodulator_priv; dprintk("%s()\n", __func__); @@ -632,6 +622,9 @@ static int au8522_sleep(struct dvb_frontend *fe) /* turn off led */ au8522_led_ctrl(state, 0); + /* Power down the chip */ + au8522_writereg(state, 0xa4, 1 << 5); + state->current_frequency = 0; return 0; @@ -798,23 +791,58 @@ static int au8522_get_tune_settings(struct dvb_frontend *fe, return 0; } +static struct dvb_frontend_ops au8522_ops; + +int au8522_get_state(struct au8522_state **state, struct i2c_adapter *i2c, + u8 client_address) +{ + int ret; + + mutex_lock(&au8522_list_mutex); + ret = hybrid_tuner_request_state(struct au8522_state, (*state), + hybrid_tuner_instance_list, + i2c, client_address, "au8522"); + mutex_unlock(&au8522_list_mutex); + + return ret; +} + +void au8522_release_state(struct au8522_state *state) +{ + mutex_lock(&au8522_list_mutex); + if (state != NULL) + hybrid_tuner_release_state(state); + mutex_unlock(&au8522_list_mutex); +} + + static void au8522_release(struct dvb_frontend *fe) { struct au8522_state *state = fe->demodulator_priv; - kfree(state); + au8522_release_state(state); } -static struct dvb_frontend_ops au8522_ops; - struct dvb_frontend *au8522_attach(const struct au8522_config *config, struct i2c_adapter *i2c) { struct au8522_state *state = NULL; + int instance; /* allocate memory for the internal state */ - state = kmalloc(sizeof(struct au8522_state), GFP_KERNEL); - if (state == NULL) - goto error; + instance = au8522_get_state(&state, i2c, config->demod_address); + switch (instance) { + case 0: + dprintk("%s state allocation failed\n", __func__); + break; + case 1: + /* new demod instance */ + dprintk("%s using new instance\n", __func__); + break; + default: + /* existing demod instance */ + dprintk("%s using existing instance\n", __func__); + break; + } /* setup the state */ state->config = config; @@ -842,7 +870,7 @@ struct dvb_frontend *au8522_attach(const struct au8522_config *config, return &state->frontend; error: - kfree(state); + au8522_release_state(state); return NULL; } EXPORT_SYMBOL(au8522_attach); diff --git a/linux/drivers/media/dvb/frontends/au8522_priv.h b/linux/drivers/media/dvb/frontends/au8522_priv.h new file mode 100644 index 000000000..f328f2b3a --- /dev/null +++ b/linux/drivers/media/dvb/frontends/au8522_priv.h @@ -0,0 +1,412 @@ +/* + Auvitek AU8522 QAM/8VSB demodulator driver + + Copyright (C) 2008 Steven Toth <stoth@linuxtv.org> + Copyright (C) 2008 Devin Heitmueller <dheitmueller@linuxtv.org> + Copyright (C) 2005-2008 Auvitek International, Ltd. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include <linux/kernel.h> +#include <linux/init.h> +#include <linux/module.h> +#include <linux/string.h> +#include <linux/slab.h> +#include <linux/delay.h> +#include <linux/videodev2.h> +#include <media/v4l2-device.h> +#include <linux/i2c.h> +#include "dvb_frontend.h" +#include "au8522.h" +#include "tuner-i2c.h" + +struct au8522_state { + struct i2c_client *c; + struct i2c_adapter *i2c; + + /* Used for sharing of the state between analog and digital mode */ + struct tuner_i2c_props i2c_props; + struct list_head hybrid_tuner_instance_list; + + /* configuration settings */ + const struct au8522_config *config; + + struct dvb_frontend frontend; + + u32 current_frequency; + fe_modulation_t current_modulation; + + u32 fe_status; + unsigned int led_state; + + /* Analog settings */ + struct v4l2_subdev sd; + v4l2_std_id std; + int vid_input; + int aud_input; + u32 id; + u32 rev; + u8 brightness; + u8 contrast; +}; + +/* These are routines shared by both the VSB/QAM demodulator and the analog + decoder */ +int au8522_writereg(struct au8522_state *state, u16 reg, u8 data); +u8 au8522_readreg(struct au8522_state *state, u16 reg); +int au8522_init(struct dvb_frontend *fe); +int au8522_sleep(struct dvb_frontend *fe); + +int au8522_get_state(struct au8522_state **state, struct i2c_adapter *i2c, + u8 client_address); +void au8522_release_state(struct au8522_state *state); + +/* REGISTERS */ +#define AU8522_INPUT_CONTROL_REG081H 0x081 +#define AU8522_PGA_CONTROL_REG082H 0x082 +#define AU8522_CLAMPING_CONTROL_REG083H 0x083 + +#define AU8522_MODULE_CLOCK_CONTROL_REG0A3H 0x0A3 +#define AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H 0x0A4 +#define AU8522_SYSTEM_MODULE_CONTROL_1_REG0A5H 0x0A5 +#define AU8522_AGC_CONTROL_RANGE_REG0A6H 0x0A6 +#define AU8522_SYSTEM_GAIN_CONTROL_REG0A7H 0x0A7 +#define AU8522_TUNER_AGC_RF_STOP_REG0A8H 0x0A8 +#define AU8522_TUNER_AGC_RF_START_REG0A9H 0x0A9 +#define AU8522_TUNER_RF_AGC_DEFAULT_REG0AAH 0x0AA +#define AU8522_TUNER_AGC_IF_STOP_REG0ABH 0x0AB +#define AU8522_TUNER_AGC_IF_START_REG0ACH 0x0AC +#define AU8522_TUNER_AGC_IF_DEFAULT_REG0ADH 0x0AD +#define AU8522_TUNER_AGC_STEP_REG0AEH 0x0AE +#define AU8522_TUNER_GAIN_STEP_REG0AFH 0x0AF + +/* Receiver registers */ +#define AU8522_FRMREGTHRD1_REG0B0H 0x0B0 +#define AU8522_FRMREGAGC1H_REG0B1H 0x0B1 +#define AU8522_FRMREGSHIFT1_REG0B2H 0x0B2 +#define AU8522_TOREGAGC1_REG0B3H 0x0B3 +#define AU8522_TOREGASHIFT1_REG0B4H 0x0B4 +#define AU8522_FRMREGBBH_REG0B5H 0x0B5 +#define AU8522_FRMREGBBM_REG0B6H 0x0B6 +#define AU8522_FRMREGBBL_REG0B7H 0x0B7 +/* 0xB8 TO 0xD7 are the filter coefficients */ +#define AU8522_FRMREGTHRD2_REG0D8H 0x0D8 +#define AU8522_FRMREGAGC2H_REG0D9H 0x0D9 +#define AU8522_TOREGAGC2_REG0DAH 0x0DA +#define AU8522_TOREGSHIFT2_REG0DBH 0x0DB +#define AU8522_FRMREGPILOTH_REG0DCH 0x0DC +#define AU8522_FRMREGPILOTM_REG0DDH 0x0DD +#define AU8522_FRMREGPILOTL_REG0DEH 0x0DE +#define AU8522_TOREGFREQ_REG0DFH 0x0DF + +#define AU8522_RX_PGA_RFOUT_REG0EBH 0x0EB +#define AU8522_RX_PGA_IFOUT_REG0ECH 0x0EC +#define AU8522_RX_PGA_PGAOUT_REG0EDH 0x0ED + +#define AU8522_CHIP_MODE_REG0FEH 0x0FE + +/* I2C bus control registers */ +#define AU8522_I2C_CONTROL_REG0_REG090H 0x090 +#define AU8522_I2C_CONTROL_REG1_REG091H 0x091 +#define AU8522_I2C_STATUS_REG092H 0x092 +#define AU8522_I2C_WR_DATA0_REG093H 0x093 +#define AU8522_I2C_WR_DATA1_REG094H 0x094 +#define AU8522_I2C_WR_DATA2_REG095H 0x095 +#define AU8522_I2C_WR_DATA3_REG096H 0x096 +#define AU8522_I2C_WR_DATA4_REG097H 0x097 +#define AU8522_I2C_WR_DATA5_REG098H 0x098 +#define AU8522_I2C_WR_DATA6_REG099H 0x099 +#define AU8522_I2C_WR_DATA7_REG09AH 0x09A +#define AU8522_I2C_RD_DATA0_REG09BH 0x09B +#define AU8522_I2C_RD_DATA1_REG09CH 0x09C +#define AU8522_I2C_RD_DATA2_REG09DH 0x09D +#define AU8522_I2C_RD_DATA3_REG09EH 0x09E +#define AU8522_I2C_RD_DATA4_REG09FH 0x09F +#define AU8522_I2C_RD_DATA5_REG0A0H 0x0A0 +#define AU8522_I2C_RD_DATA6_REG0A1H 0x0A1 +#define AU8522_I2C_RD_DATA7_REG0A2H 0x0A2 + +#define AU8522_ENA_USB_REG101H 0x101 + +#define AU8522_I2S_CTRL_0_REG110H 0x110 +#define AU8522_I2S_CTRL_1_REG111H 0x111 +#define AU8522_I2S_CTRL_2_REG112H 0x112 + +#define AU8522_FRMREGFFECONTROL_REG121H 0x121 +#define AU8522_FRMREGDFECONTROL_REG122H 0x122 + +#define AU8522_CARRFREQOFFSET0_REG201H 0x201 +#define AU8522_CARRFREQOFFSET1_REG202H 0x202 + +#define AU8522_DECIMATION_GAIN_REG21AH 0x21A +#define AU8522_FRMREGIFSLP_REG21BH 0x21B +#define AU8522_FRMREGTHRDL2_REG21CH 0x21C +#define AU8522_FRMREGSTEP3DB_REG21DH 0x21D +#define AU8522_DAGC_GAIN_ADJUSTMENT_REG21EH 0x21E +#define AU8522_FRMREGPLLMODE_REG21FH 0x21F +#define AU8522_FRMREGCSTHRD_REG220H 0x220 +#define AU8522_FRMREGCRLOCKDMAX_REG221H 0x221 +#define AU8522_FRMREGCRPERIODMASK_REG222H 0x222 +#define AU8522_FRMREGCRLOCK0THH_REG223H 0x223 +#define AU8522_FRMREGCRLOCK1THH_REG224H 0x224 +#define AU8522_FRMREGCRLOCK0THL_REG225H 0x225 +#define AU8522_FRMREGCRLOCK1THL_REG226H 0x226 +#define AU_FRMREGPLLACQPHASESCL_REG227H 0x227 +#define AU8522_FRMREGFREQFBCTRL_REG228H 0x228 + +/* Analog TV Decoder */ +#define AU8522_TVDEC_STATUS_REG000H 0x000 +#define AU8522_TVDEC_INT_STATUS_REG001H 0x001 +#define AU8522_TVDEC_MACROVISION_STATUS_REG002H 0x002 +#define AU8522_TVDEC_SHARPNESSREG009H 0x009 +#define AU8522_TVDEC_BRIGHTNESS_REG00AH 0x00A +#define AU8522_TVDEC_CONTRAST_REG00BH 0x00B +#define AU8522_TVDEC_SATURATION_CB_REG00CH 0x00C +#define AU8522_TVDEC_SATURATION_CR_REG00DH 0x00D +#define AU8522_TVDEC_HUE_H_REG00EH 0x00E +#define AU8522_TVDEC_HUE_L_REG00FH 0x00F +#define AU8522_TVDEC_INT_MASK_REG010H 0x010 +#define AU8522_VIDEO_MODE_REG011H 0x011 +#define AU8522_TVDEC_PGA_REG012H 0x012 +#define AU8522_TVDEC_COMB_MODE_REG015H 0x015 +#define AU8522_REG016H 0x016 +#define AU8522_TVDED_DBG_MODE_REG060H 0x060 +#define AU8522_TVDEC_FORMAT_CTRL1_REG061H 0x061 +#define AU8522_TVDEC_FORMAT_CTRL2_REG062H 0x062 +#define AU8522_TVDEC_VCR_DET_LLIM_REG063H 0x063 +#define AU8522_TVDEC_VCR_DET_HLIM_REG064H 0x064 +#define AU8522_TVDEC_COMB_VDIF_THR1_REG065H 0x065 +#define AU8522_TVDEC_COMB_VDIF_THR2_REG066H 0x066 +#define AU8522_TVDEC_COMB_VDIF_THR3_REG067H 0x067 +#define AU8522_TVDEC_COMB_NOTCH_THR_REG068H 0x068 +#define AU8522_TVDEC_COMB_HDIF_THR1_REG069H 0x069 +#define AU8522_TVDEC_COMB_HDIF_THR2_REG06AH 0x06A +#define AU8522_TVDEC_COMB_HDIF_THR3_REG06BH 0x06B +#define AU8522_TVDEC_COMB_DCDIF_THR1_REG06CH 0x06C +#define AU8522_TVDEC_COMB_DCDIF_THR2_REG06DH 0x06D +#define AU8522_TVDEC_COMB_DCDIF_THR3_REG06EH 0x06E +#define AU8522_TVDEC_UV_SEP_THR_REG06FH 0x06F +#define AU8522_TVDEC_COMB_DC_THR1_NTSC_REG070H 0x070 +#define AU8522_TVDEC_COMB_DC_THR2_NTSC_REG073H 0x073 +#define AU8522_TVDEC_DCAGC_CTRL_REG077H 0x077 +#define AU8522_TVDEC_PIC_START_ADJ_REG078H 0x078 +#define AU8522_TVDEC_AGC_HIGH_LIMIT_REG079H 0x079 +#define AU8522_TVDEC_MACROVISION_SYNC_THR_REG07AH 0x07A +#define AU8522_TVDEC_INTRP_CTRL_REG07BH 0x07B +#define AU8522_TVDEC_PLL_STATUS_REG07EH 0x07E +#define AU8522_TVDEC_FSC_FREQ_REG07FH 0x07F + +#define AU8522_TVDEC_AGC_LOW_LIMIT_REG0E4H 0x0E4 +#define AU8522_TOREGAAGC_REG0E5H 0x0E5 + +#define AU8522_TVDEC_CHROMA_AGC_REG401H 0x401 +#define AU8522_TVDEC_CHROMA_SFT_REG402H 0x402 +#define AU8522_FILTER_COEF_R410 0x410 +#define AU8522_FILTER_COEF_R411 0x411 +#define AU8522_FILTER_COEF_R412 0x412 +#define AU8522_FILTER_COEF_R413 0x413 +#define AU8522_FILTER_COEF_R414 0x414 +#define AU8522_FILTER_COEF_R415 0x415 +#define AU8522_FILTER_COEF_R416 0x416 +#define AU8522_FILTER_COEF_R417 0x417 +#define AU8522_FILTER_COEF_R418 0x418 +#define AU8522_FILTER_COEF_R419 0x419 +#define AU8522_FILTER_COEF_R41A 0x41A +#define AU8522_FILTER_COEF_R41B 0x41B +#define AU8522_FILTER_COEF_R41C 0x41C +#define AU8522_FILTER_COEF_R41D 0x41D +#define AU8522_FILTER_COEF_R41E 0x41E +#define AU8522_FILTER_COEF_R41F 0x41F +#define AU8522_FILTER_COEF_R420 0x420 +#define AU8522_FILTER_COEF_R421 0x421 +#define AU8522_FILTER_COEF_R422 0x422 +#define AU8522_FILTER_COEF_R423 0x423 +#define AU8522_FILTER_COEF_R424 0x424 +#define AU8522_FILTER_COEF_R425 0x425 +#define AU8522_FILTER_COEF_R426 0x426 +#define AU8522_FILTER_COEF_R427 0x427 +#define AU8522_FILTER_COEF_R428 0x428 +#define AU8522_FILTER_COEF_R429 0x429 +#define AU8522_FILTER_COEF_R42A 0x42A +#define AU8522_FILTER_COEF_R42B 0x42B +#define AU8522_FILTER_COEF_R42C 0x42C +#define AU8522_FILTER_COEF_R42D 0x42D + +/* VBI Control Registers */ +#define AU8522_TVDEC_VBI_RX_FIFO_CONTAIN_REG004H 0x004 +#define AU8522_TVDEC_VBI_TX_FIFO_CONTAIN_REG005H 0x005 +#define AU8522_TVDEC_VBI_RX_FIFO_READ_REG006H 0x006 +#define AU8522_TVDEC_VBI_FIFO_STATUS_REG007H 0x007 +#define AU8522_TVDEC_VBI_CTRL_H_REG017H 0x017 +#define AU8522_TVDEC_VBI_CTRL_L_REG018H 0x018 +#define AU8522_TVDEC_VBI_USER_TOTAL_BITS_REG019H 0x019 +#define AU8522_TVDEC_VBI_USER_TUNIT_H_REG01AH 0x01A +#define AU8522_TVDEC_VBI_USER_TUNIT_L_REG01BH 0x01B +#define AU8522_TVDEC_VBI_USER_THRESH1_REG01CH 0x01C +#define AU8522_TVDEC_VBI_USER_FRAME_PAT2_REG01EH 0x01E +#define AU8522_TVDEC_VBI_USER_FRAME_PAT1_REG01FH 0x01F +#define AU8522_TVDEC_VBI_USER_FRAME_PAT0_REG020H 0x020 +#define AU8522_TVDEC_VBI_USER_FRAME_MASK2_REG021H 0x021 +#define AU8522_TVDEC_VBI_USER_FRAME_MASK1_REG022H 0x022 +#define AU8522_TVDEC_VBI_USER_FRAME_MASK0_REG023H 0x023 + +#define AU8522_REG071H 0x071 +#define AU8522_REG072H 0x072 +#define AU8522_REG074H 0x074 +#define AU8522_REG075H 0x075 + +/* Digital Demodulator Registers */ +#define AU8522_FRAME_COUNT0_REG084H 0x084 +#define AU8522_RS_STATUS_G0_REG085H 0x085 +#define AU8522_RS_STATUS_B0_REG086H 0x086 +#define AU8522_RS_STATUS_E_REG087H 0x087 +#define AU8522_DEMODULATION_STATUS_REG088H 0x088 +#define AU8522_TOREGTRESTATUS_REG0E6H 0x0E6 +#define AU8522_TSPORT_CONTROL_REG10BH 0x10B +#define AU8522_TSTHES_REG10CH 0x10C +#define AU8522_FRMREGDFEKEEP_REG301H 0x301 +#define AU8522_DFE_AVERAGE_REG302H 0x302 +#define AU8522_FRMREGEQLERRWIN_REG303H 0x303 +#define AU8522_FRMREGFFEKEEP_REG304H 0x304 +#define AU8522_FRMREGDFECONTROL1_REG305H 0x305 +#define AU8522_FRMREGEQLERRLOW_REG306H 0x306 + +#define AU8522_REG42EH 0x42E +#define AU8522_REG42FH 0x42F +#define AU8522_REG430H 0x430 +#define AU8522_REG431H 0x431 +#define AU8522_REG432H 0x432 +#define AU8522_REG433H 0x433 +#define AU8522_REG434H 0x434 +#define AU8522_REG435H 0x435 +#define AU8522_REG436H 0x436 + +/* GPIO Registers */ +#define AU8522_GPIO_CONTROL_REG0E0H 0x0E0 +#define AU8522_GPIO_STATUS_REG0E1H 0x0E1 +#define AU8522_GPIO_DATA_REG0E2H 0x0E2 + +/* Audio Control Registers */ +#define AU8522_AUDIOAGC_REG0EEH 0x0EE +#define AU8522_AUDIO_STATUS_REG0F0H 0x0F0 +#define AU8522_AUDIO_MODE_REG0F1H 0x0F1 +#define AU8522_AUDIO_VOLUME_L_REG0F2H 0x0F2 +#define AU8522_AUDIO_VOLUME_R_REG0F3H 0x0F3 +#define AU8522_AUDIO_VOLUME_REG0F4H 0x0F4 +#define AU8522_FRMREGAUPHASE_REG0F7H 0x0F7 +#define AU8522_REG0F9H 0x0F9 + +#define AU8522_AUDIOAGC2_REG605H 0x605 +#define AU8522_AUDIOFREQ_REG606H 0x606 + + +/**************************************************************/ + +#define AU8522_INPUT_CONTROL_REG081H_ATSC 0xC4 +#define AU8522_INPUT_CONTROL_REG081H_ATVRF 0xC4 +#define AU8522_INPUT_CONTROL_REG081H_ATVRF13 0xC4 +#define AU8522_INPUT_CONTROL_REG081H_J83B64 0xC4 +#define AU8522_INPUT_CONTROL_REG081H_J83B256 0xC4 +#define AU8522_INPUT_CONTROL_REG081H_CVBS 0x20 +#define AU8522_INPUT_CONTROL_REG081H_CVBS_CH1 0xA2 +#define AU8522_INPUT_CONTROL_REG081H_CVBS_CH2 0xA0 +#define AU8522_INPUT_CONTROL_REG081H_CVBS_CH3 0x69 +#define AU8522_INPUT_CONTROL_REG081H_CVBS_CH4 0x68 +#define AU8522_INPUT_CONTROL_REG081H_CVBS_CH4_SIF 0x28 +/* CH1 AS Y,CH3 AS C */ +#define AU8522_INPUT_CONTROL_REG081H_SVIDEO_CH13 0x23 +/* CH2 AS Y,CH4 AS C */ +#define AU8522_INPUT_CONTROL_REG081H_SVIDEO_CH24 0x20 +#define AU8522_MODULE_CLOCK_CONTROL_REG0A3H_ATSC 0x0C +#define AU8522_MODULE_CLOCK_CONTROL_REG0A3H_J83B64 0x09 +#define AU8522_MODULE_CLOCK_CONTROL_REG0A3H_J83B256 0x09 +#define AU8522_MODULE_CLOCK_CONTROL_REG0A3H_CVBS 0x12 +#define AU8522_MODULE_CLOCK_CONTROL_REG0A3H_ATVRF 0x1A +#define AU8522_MODULE_CLOCK_CONTROL_REG0A3H_ATVRF13 0x1A +#define AU8522_MODULE_CLOCK_CONTROL_REG0A3H_SVIDEO 0x02 + +#define AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H_CLEAR 0x00 +#define AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H_SVIDEO 0x9C +#define AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H_CVBS 0x9D +#define AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H_ATSC 0xE8 +#define AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H_J83B256 0xCA +#define AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H_J83B64 0xCA +#define AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H_ATVRF 0xDD +#define AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H_ATVRF13 0xDD +#define AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H_PAL 0xDD +#define AU8522_SYSTEM_MODULE_CONTROL_0_REG0A4H_FM 0xDD + +#define AU8522_SYSTEM_MODULE_CONTROL_1_REG0A5H_ATSC 0x80 +#define AU8522_SYSTEM_MODULE_CONTROL_1_REG0A5H_J83B256 0x80 +#define AU8522_SYSTEM_MODULE_CONTROL_1_REG0A5H_J83B64 0x80 +#define AU8522_SYSTEM_MODULE_CONTROL_1_REG0A5H_DONGLE_ATSC 0x40 +#define AU8522_SYSTEM_MODULE_CONTROL_1_REG0A5H_DONGLE_J83B256 0x40 +#define AU8522_SYSTEM_MODULE_CONTROL_1_REG0A5H_DONGLE_J83B64 0x40 +#define AU8522_SYSTEM_MODULE_CONTROL_1_REG0A5H_DONGLE_CLEAR 0x00 +#define AU8522_SYSTEM_MODULE_CONTROL_1_REG0A5H_ATVRF 0x01 +#define AU8522_SYSTEM_MODULE_CONTROL_1_REG0A5H_ATVRF13 0x01 +#define AU8522_SYSTEM_MODULE_CONTROL_1_REG0A5H_SVIDEO 0x04 +#define AU8522_SYSTEM_MODULE_CONTROL_1_REG0A5H_CVBS 0x01 +#define AU8522_SYSTEM_MODULE_CONTROL_1_REG0A5H_PWM 0x03 +#define AU8522_SYSTEM_MODULE_CONTROL_1_REG0A5H_IIS 0x09 +#define AU8522_SYSTEM_MODULE_CONTROL_1_REG0A5H_PAL 0x01 +#define AU8522_SYSTEM_MODULE_CONTROL_1_REG0A5H_FM 0x01 + +/* STILL NEED TO BE REFACTORED @@@@@@@@@@@@@@ */ +#define AU8522_TVDEC_CONTRAST_REG00BH_CVBS 0x79 +#define AU8522_TVDEC_SATURATION_CB_REG00CH_CVBS 0x80 +#define AU8522_TVDEC_SATURATION_CR_REG00DH_CVBS 0x80 +#define AU8522_TVDEC_HUE_H_REG00EH_CVBS 0x00 +#define AU8522_TVDEC_HUE_L_REG00FH_CVBS 0x00 +#define AU8522_TVDEC_PGA_REG012H_CVBS 0x0F +#define AU8522_TVDEC_COMB_MODE_REG015H_CVBS 0x00 +#define AU8522_REG016H_CVBS 0x00 +#define AU8522_TVDED_DBG_MODE_REG060H_CVBS 0x00 +#define AU8522_TVDEC_FORMAT_CTRL1_REG061H_CVBS 0x0B +#define AU8522_TVDEC_FORMAT_CTRL1_REG061H_CVBS13 0x03 +#define AU8522_TVDEC_FORMAT_CTRL2_REG062H_CVBS13 0x00 +#define AU8522_TVDEC_VCR_DET_LLIM_REG063H_CVBS 0x19 +#define AU8522_REG0F9H_AUDIO 0x20 +#define AU8522_TVDEC_VCR_DET_HLIM_REG064H_CVBS 0xA7 +#define AU8522_TVDEC_COMB_VDIF_THR1_REG065H_CVBS 0x0A +#define AU8522_TVDEC_COMB_VDIF_THR2_REG066H_CVBS 0x32 +#define AU8522_TVDEC_COMB_VDIF_THR3_REG067H_CVBS 0x19 +#define AU8522_TVDEC_COMB_NOTCH_THR_REG068H_CVBS 0x23 +#define AU8522_TVDEC_COMB_HDIF_THR1_REG069H_CVBS 0x41 +#define AU8522_TVDEC_COMB_HDIF_THR2_REG06AH_CVBS 0x0A +#define AU8522_TVDEC_COMB_HDIF_THR3_REG06BH_CVBS 0x32 +#define AU8522_TVDEC_COMB_DCDIF_THR1_REG06CH_CVBS 0x34 +#define AU8522_TVDEC_COMB_DCDIF_THR2_REG06DH_CVBS 0x05 +#define AU8522_TVDEC_COMB_DCDIF_THR3_REG06EH_CVBS 0x6E +#define AU8522_TVDEC_UV_SEP_THR_REG06FH_CVBS 0x0F +#define AU8522_TVDEC_COMB_DC_THR1_NTSC_REG070H_CVBS 0x80 +#define AU8522_REG071H_CVBS 0x18 +#define AU8522_REG072H_CVBS 0x30 +#define AU8522_TVDEC_COMB_DC_THR2_NTSC_REG073H_CVBS 0xF0 +#define AU8522_REG074H_CVBS 0x80 +#define AU8522_REG075H_CVBS 0xF0 +#define AU8522_TVDEC_DCAGC_CTRL_REG077H_CVBS 0xFB +#define AU8522_TVDEC_PIC_START_ADJ_REG078H_CVBS 0x04 +#define AU8522_TVDEC_AGC_HIGH_LIMIT_REG079H_CVBS 0x00 +#define AU8522_TVDEC_MACROVISION_SYNC_THR_REG07AH_CVBS 0x00 +#define AU8522_TVDEC_INTRP_CTRL_REG07BH_CVBS 0xEE +#define AU8522_TVDEC_AGC_LOW_LIMIT_REG0E4H_CVBS 0xFE +#define AU8522_TOREGAAGC_REG0E5H_CVBS 0x00 +#define AU8522_TVDEC_VBI6A_REG035H_CVBS 0x40 + +/* Enables Closed captioning */ +#define AU8522_TVDEC_VBI_CTRL_H_REG017H_CCON 0x21 diff --git a/linux/drivers/media/dvb/frontends/dvb_dummy_fe.h b/linux/drivers/media/dvb/frontends/dvb_dummy_fe.h index 8210f19d5..1fcb987d6 100644 --- a/linux/drivers/media/dvb/frontends/dvb_dummy_fe.h +++ b/linux/drivers/media/dvb/frontends/dvb_dummy_fe.h @@ -25,8 +25,27 @@ #include <linux/dvb/frontend.h> #include "dvb_frontend.h" +#if defined(CONFIG_DVB_DUMMY_FE) || (defined(CONFIG_DVB_DUMMY_FE_MODULE) && \ +defined(MODULE)) extern struct dvb_frontend* dvb_dummy_fe_ofdm_attach(void); extern struct dvb_frontend* dvb_dummy_fe_qpsk_attach(void); extern struct dvb_frontend* dvb_dummy_fe_qam_attach(void); +#else +static inline struct dvb_frontend *dvb_dummy_fe_ofdm_attach(void) +{ + printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__); + return NULL; +} +static inline struct dvb_frontend *dvb_dummy_fe_qpsk_attach(void) +{ + printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__); + return NULL; +} +static inline struct dvb_frontend *dvb_dummy_fe_qam_attach(void) +{ + printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__); + return NULL; +} +#endif /* CONFIG_DVB_DUMMY_FE */ #endif // DVB_DUMMY_FE_H diff --git a/linux/drivers/media/dvb/frontends/stb6100_cfg.h b/linux/drivers/media/dvb/frontends/stb6100_cfg.h index d3133405d..6314d18c7 100644 --- a/linux/drivers/media/dvb/frontends/stb6100_cfg.h +++ b/linux/drivers/media/dvb/frontends/stb6100_cfg.h @@ -36,7 +36,6 @@ static int stb6100_get_frequency(struct dvb_frontend *fe, u32 *frequency) return err; } *frequency = t_state.frequency; - printk("%s: Frequency=%d\n", __func__, t_state.frequency); } return 0; } @@ -59,7 +58,6 @@ static int stb6100_set_frequency(struct dvb_frontend *fe, u32 frequency) return err; } } - printk("%s: Frequency=%d\n", __func__, t_state.frequency); return 0; } @@ -81,7 +79,6 @@ static int stb6100_get_bandwidth(struct dvb_frontend *fe, u32 *bandwidth) } *bandwidth = t_state.bandwidth; } - printk("%s: Bandwidth=%d\n", __func__, t_state.bandwidth); return 0; } @@ -103,6 +100,5 @@ static int stb6100_set_bandwidth(struct dvb_frontend *fe, u32 bandwidth) return err; } } - printk("%s: Bandwidth=%d\n", __func__, t_state.bandwidth); return 0; } diff --git a/linux/drivers/media/dvb/frontends/stv0900_core.c b/linux/drivers/media/dvb/frontends/stv0900_core.c index 1fde0e255..899b1e7ed 100644 --- a/linux/drivers/media/dvb/frontends/stv0900_core.c +++ b/linux/drivers/media/dvb/frontends/stv0900_core.c @@ -254,7 +254,7 @@ enum fe_stv0900_error stv0900_initialize(struct stv0900_internal *i_params) } msleep(3); - for (i = 0; i < 180; i++) + for (i = 0; i < 182; i++) stv0900_write_reg(i_params, STV0900_InitVal[i][0], STV0900_InitVal[i][1]); if (stv0900_read_reg(i_params, R0900_MID) >= 0x20) { @@ -660,13 +660,18 @@ static s32 stv0900_carr_get_quality(struct dvb_frontend *fe, dprintk(KERN_INFO "%s\n", __func__); - dmd_reg(lock_flag_field, F0900_P1_LOCK_DEFINITIF, F0900_P2_LOCK_DEFINITIF); + dmd_reg(lock_flag_field, F0900_P1_LOCK_DEFINITIF, + F0900_P2_LOCK_DEFINITIF); if (stv0900_get_standard(fe, demod) == STV0900_DVBS2_STANDARD) { - dmd_reg(noise_field1, F0900_P1_NOSPLHT_NORMED1, F0900_P2_NOSPLHT_NORMED1); - dmd_reg(noise_field0, F0900_P1_NOSPLHT_NORMED0, F0900_P2_NOSPLHT_NORMED0); + dmd_reg(noise_field1, F0900_P1_NOSPLHT_NORMED1, + F0900_P2_NOSPLHT_NORMED1); + dmd_reg(noise_field0, F0900_P1_NOSPLHT_NORMED0, + F0900_P2_NOSPLHT_NORMED0); } else { - dmd_reg(noise_field1, F0900_P1_NOSDATAT_NORMED1, F0900_P2_NOSDATAT_NORMED1); - dmd_reg(noise_field0, F0900_P1_NOSDATAT_NORMED0, F0900_P1_NOSDATAT_NORMED0); + dmd_reg(noise_field1, F0900_P1_NOSDATAT_NORMED1, + F0900_P2_NOSDATAT_NORMED1); + dmd_reg(noise_field0, F0900_P1_NOSDATAT_NORMED0, + F0900_P2_NOSDATAT_NORMED0); } if (stv0900_get_bits(i_params, lock_flag_field)) { @@ -674,27 +679,34 @@ static s32 stv0900_carr_get_quality(struct dvb_frontend *fe, regval = 0; msleep(5); for (i = 0; i < 16; i++) { - regval += MAKEWORD(stv0900_get_bits(i_params, noise_field1), - stv0900_get_bits(i_params, noise_field0)); + regval += MAKEWORD(stv0900_get_bits(i_params, + noise_field1), + stv0900_get_bits(i_params, + noise_field0)); msleep(1); } regval /= 16; imin = 0; imax = lookup->size - 1; - if (INRANGE(lookup->table[imin].regval, regval, lookup->table[imax].regval)) { + if (INRANGE(lookup->table[imin].regval, + regval, + lookup->table[imax].regval)) { while ((imax - imin) > 1) { i = (imax + imin) >> 1; - - if (INRANGE(lookup->table[imin].regval, regval, lookup->table[i].regval)) + if (INRANGE(lookup->table[imin].regval, + regval, + lookup->table[i].regval)) imax = i; else imin = i; } c_n = ((regval - lookup->table[imin].regval) - * (lookup->table[imax].realval - lookup->table[imin].realval) - / (lookup->table[imax].regval - lookup->table[imin].regval)) + * (lookup->table[imax].realval + - lookup->table[imin].realval) + / (lookup->table[imax].regval + - lookup->table[imin].regval)) + lookup->table[imin].realval; } else if (regval < lookup->table[imin].regval) c_n = 1000; @@ -706,7 +718,10 @@ static s32 stv0900_carr_get_quality(struct dvb_frontend *fe, static int stv0900_read_snr(struct dvb_frontend *fe, u16 *snr) { - *snr = (16383 / 1030) * (30 + stv0900_carr_get_quality(fe, (const struct stv0900_table *)&stv0900_s2_cn)); + *snr = stv0900_carr_get_quality(fe, + (const struct stv0900_table *)&stv0900_s2_cn); + *snr += 30; + *snr *= (16383 / 1030); return 0; } diff --git a/linux/drivers/media/dvb/frontends/stv0900_init.h b/linux/drivers/media/dvb/frontends/stv0900_init.h index fa8dbe197..ff388b47a 100644 --- a/linux/drivers/media/dvb/frontends/stv0900_init.h +++ b/linux/drivers/media/dvb/frontends/stv0900_init.h @@ -217,7 +217,7 @@ static const struct stv0900_short_frames_car_loop_optim FE_STV0900_S2ShortCarLoo { STV0900_32APSK, 0x1B, 0x1E, 0x1B, 0x1E, 0x1B, 0x1E, 0x3A, 0x3D, 0x2A, 0x2D } }; -static const u16 STV0900_InitVal[180][2] = { +static const u16 STV0900_InitVal[182][2] = { { R0900_OUTCFG , 0x00 }, { R0900_MODECFG , 0xff }, { R0900_AGCRF1CFG , 0x11 }, @@ -396,6 +396,8 @@ static const u16 STV0900_InitVal[180][2] = { { R0900_DATA72CFG , 0x52 }, { R0900_P1_TSCFGM , 0xc0 }, { R0900_P2_TSCFGM , 0xc0 }, + { R0900_P1_TSCFGH , 0xe0 }, /* DVB-CI timings */ + { R0900_P2_TSCFGH , 0xe0 }, /* DVB-CI timings */ { R0900_P1_TSSPEED , 0x40 }, { R0900_P2_TSSPEED , 0x40 }, }; diff --git a/linux/drivers/media/dvb/frontends/zl10353.c b/linux/drivers/media/dvb/frontends/zl10353.c index 96ccc1720..6b58bf961 100644 --- a/linux/drivers/media/dvb/frontends/zl10353.c +++ b/linux/drivers/media/dvb/frontends/zl10353.c @@ -581,6 +581,10 @@ static int zl10353_init(struct dvb_frontend *fe) #endif if (state->config.parallel_ts) zl10353_reset_attach[2] &= ~0x20; + if (state->config.clock_ctl_1) + zl10353_reset_attach[3] = state->config.clock_ctl_1; + if (state->config.pll_0) + zl10353_reset_attach[4] = state->config.pll_0; /* Do a "hard" reset if not already done */ if (zl10353_read_register(state, 0x50) != zl10353_reset_attach[1] || @@ -625,6 +629,7 @@ struct dvb_frontend *zl10353_attach(const struct zl10353_config *config, struct i2c_adapter *i2c) { struct zl10353_state *state = NULL; + int id; /* allocate memory for the internal state */ state = kzalloc(sizeof(struct zl10353_state), GFP_KERNEL); @@ -636,7 +641,8 @@ struct dvb_frontend *zl10353_attach(const struct zl10353_config *config, memcpy(&state->config, config, sizeof(struct zl10353_config)); /* check if the demod is there */ - if (zl10353_read_register(state, CHIP_ID) != ID_ZL10353) + id = zl10353_read_register(state, CHIP_ID); + if ((id != ID_ZL10353) && (id != ID_CE6230) && (id != ID_CE6231)) goto error; /* create dvb_frontend */ diff --git a/linux/drivers/media/dvb/frontends/zl10353.h b/linux/drivers/media/dvb/frontends/zl10353.h index 2287bac46..6e3ca9eed 100644 --- a/linux/drivers/media/dvb/frontends/zl10353.h +++ b/linux/drivers/media/dvb/frontends/zl10353.h @@ -41,6 +41,10 @@ struct zl10353_config /* set if i2c_gate_ctrl disable is required */ u8 disable_i2c_gate_ctrl:1; + + /* clock control registers (0x51-0x54) */ + u8 clock_ctl_1; /* default: 0x46 */ + u8 pll_0; /* default: 0x15 */ }; #if defined(CONFIG_DVB_ZL10353) || (defined(CONFIG_DVB_ZL10353_MODULE) && defined(MODULE)) diff --git a/linux/drivers/media/dvb/frontends/zl10353_priv.h b/linux/drivers/media/dvb/frontends/zl10353_priv.h index 055ff1f7e..e0dd1d3e0 100644 --- a/linux/drivers/media/dvb/frontends/zl10353_priv.h +++ b/linux/drivers/media/dvb/frontends/zl10353_priv.h @@ -22,7 +22,9 @@ #ifndef _ZL10353_PRIV_ #define _ZL10353_PRIV_ -#define ID_ZL10353 0x14 +#define ID_ZL10353 0x14 /* Zarlink ZL10353 */ +#define ID_CE6230 0x18 /* Intel CE6230 */ +#define ID_CE6231 0x19 /* Intel CE6231 */ #define msb(x) (((x) >> 8) & 0xff) #define lsb(x) ((x) & 0xff) @@ -50,6 +52,10 @@ enum zl10353_reg_addr { TPS_RECEIVED_0 = 0x1E, TPS_CURRENT_1 = 0x1F, TPS_CURRENT_0 = 0x20, + CLOCK_CTL_0 = 0x51, + CLOCK_CTL_1 = 0x52, + PLL_0 = 0x53, + PLL_1 = 0x54, RESET = 0x55, AGC_TARGET = 0x56, MCLK_RATIO = 0x5C, diff --git a/linux/drivers/media/dvb/pluto2/pluto2.c b/linux/drivers/media/dvb/pluto2/pluto2.c index 8522757a5..b27073216 100644 --- a/linux/drivers/media/dvb/pluto2/pluto2.c +++ b/linux/drivers/media/dvb/pluto2/pluto2.c @@ -116,6 +116,7 @@ struct pluto { /* irq */ unsigned int overflow; + unsigned int dead; /* dma */ dma_addr_t dma_addr; @@ -344,8 +345,10 @@ static irqreturn_t pluto_irq(int irq, void *dev_id) return IRQ_NONE; if (tscr == 0xffffffff) { - // FIXME: maybe recover somehow - dev_err(&pluto->pdev->dev, "card hung up :(\n"); + if (pluto->dead == 0) + dev_err(&pluto->pdev->dev, "card has hung or been ejected.\n"); + /* It's dead Jim */ + pluto->dead = 1; return IRQ_HANDLED; } diff --git a/linux/drivers/media/dvb/siano/smssdio.c b/linux/drivers/media/dvb/siano/smssdio.c new file mode 100644 index 000000000..31ba8c5af --- /dev/null +++ b/linux/drivers/media/dvb/siano/smssdio.c @@ -0,0 +1,356 @@ +/* + * smssdio.c - Siano 1xxx SDIO interface driver + * + * Copyright 2008 Pierre Ossman + * + * Based on code by Siano Mobile Silicon, Inc., + * Copyright (C) 2006-2008, Uri Shkolnik + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * + * This hardware is a bit odd in that all transfers should be done + * to/from the SMSSDIO_DATA register, yet the "increase address" bit + * always needs to be set. + * + * Also, buffers from the card are always aligned to 128 byte + * boundaries. + */ + +/* + * General cleanup notes: + * + * - only typedefs should be name *_t + * + * - use ERR_PTR and friends for smscore_register_device() + * + * - smscore_getbuffer should zero fields + * + * Fix stop command + */ + +#include <linux/moduleparam.h> +#include <linux/firmware.h> +#include <linux/delay.h> +#include <linux/mmc/card.h> +#include <linux/mmc/sdio_func.h> +#include <linux/mmc/sdio_ids.h> + +#include "smscoreapi.h" +#include "sms-cards.h" + +/* Registers */ + +#define SMSSDIO_DATA 0x00 +#define SMSSDIO_INT 0x04 + +static const struct sdio_device_id smssdio_ids[] = { + {SDIO_DEVICE(SDIO_VENDOR_ID_SIANO, SDIO_DEVICE_ID_SIANO_STELLAR), + .driver_data = SMS1XXX_BOARD_SIANO_STELLAR}, + {SDIO_DEVICE(SDIO_VENDOR_ID_SIANO, SDIO_DEVICE_ID_SIANO_NOVA_A0), + .driver_data = SMS1XXX_BOARD_SIANO_NOVA_A}, + {SDIO_DEVICE(SDIO_VENDOR_ID_SIANO, SDIO_DEVICE_ID_SIANO_NOVA_B0), + .driver_data = SMS1XXX_BOARD_SIANO_NOVA_B}, + {SDIO_DEVICE(SDIO_VENDOR_ID_SIANO, SDIO_DEVICE_ID_SIANO_VEGA_A0), + .driver_data = SMS1XXX_BOARD_SIANO_VEGA}, + {SDIO_DEVICE(SDIO_VENDOR_ID_SIANO, SDIO_DEVICE_ID_SIANO_VENICE), + .driver_data = SMS1XXX_BOARD_SIANO_VEGA}, + { /* end: all zeroes */ }, +}; + +MODULE_DEVICE_TABLE(sdio, smssdio_ids); + +struct smssdio_device { + struct sdio_func *func; + + struct smscore_device_t *coredev; + + struct smscore_buffer_t *split_cb; +}; + +/*******************************************************************/ +/* Siano core callbacks */ +/*******************************************************************/ + +static int smssdio_sendrequest(void *context, void *buffer, size_t size) +{ + int ret; + struct smssdio_device *smsdev; + + smsdev = context; + + sdio_claim_host(smsdev->func); + + while (size >= smsdev->func->cur_blksize) { + ret = sdio_write_blocks(smsdev->func, SMSSDIO_DATA, buffer, 1); + if (ret) + goto out; + + buffer += smsdev->func->cur_blksize; + size -= smsdev->func->cur_blksize; + } + + if (size) { + ret = sdio_write_bytes(smsdev->func, SMSSDIO_DATA, + buffer, size); + if (ret) + goto out; + } + +out: + sdio_release_host(smsdev->func); + + return ret; +} + +/*******************************************************************/ +/* SDIO callbacks */ +/*******************************************************************/ + +static void smssdio_interrupt(struct sdio_func *func) +{ + int ret, isr; + + struct smssdio_device *smsdev; + struct smscore_buffer_t *cb; + struct SmsMsgHdr_ST *hdr; + size_t size; + + smsdev = sdio_get_drvdata(func); + + /* + * The interrupt register has no defined meaning. It is just + * a way of turning of the level triggered interrupt. + */ + isr = sdio_readb(func, SMSSDIO_INT, &ret); + if (ret) { + dev_err(&smsdev->func->dev, + "Unable to read interrupt register!\n"); + return; + } + + if (smsdev->split_cb == NULL) { + cb = smscore_getbuffer(smsdev->coredev); + if (!cb) { + dev_err(&smsdev->func->dev, + "Unable to allocate data buffer!\n"); + return; + } + + ret = sdio_read_blocks(smsdev->func, cb->p, SMSSDIO_DATA, 1); + if (ret) { + dev_err(&smsdev->func->dev, + "Error %d reading initial block!\n", ret); + return; + } + + hdr = cb->p; + + if (hdr->msgFlags & MSG_HDR_FLAG_SPLIT_MSG) { + smsdev->split_cb = cb; + return; + } + + size = hdr->msgLength - smsdev->func->cur_blksize; + } else { + cb = smsdev->split_cb; + hdr = cb->p; + + size = hdr->msgLength - sizeof(struct SmsMsgHdr_ST); + + smsdev->split_cb = NULL; + } + + if (hdr->msgLength > smsdev->func->cur_blksize) { + void *buffer; + + size = ALIGN(size, 128); + buffer = cb->p + hdr->msgLength; + + BUG_ON(smsdev->func->cur_blksize != 128); + + /* + * First attempt to transfer all of it in one go... + */ + ret = sdio_read_blocks(smsdev->func, buffer, + SMSSDIO_DATA, size / 128); + if (ret && ret != -EINVAL) { + smscore_putbuffer(smsdev->coredev, cb); + dev_err(&smsdev->func->dev, + "Error %d reading data from card!\n", ret); + return; + } + + /* + * ..then fall back to one block at a time if that is + * not possible... + * + * (we have to do this manually because of the + * problem with the "increase address" bit) + */ + if (ret == -EINVAL) { + while (size) { + ret = sdio_read_blocks(smsdev->func, + buffer, SMSSDIO_DATA, 1); + if (ret) { + smscore_putbuffer(smsdev->coredev, cb); + dev_err(&smsdev->func->dev, + "Error %d reading " + "data from card!\n", ret); + return; + } + + buffer += smsdev->func->cur_blksize; + if (size > smsdev->func->cur_blksize) + size -= smsdev->func->cur_blksize; + else + size = 0; + } + } + } + + cb->size = hdr->msgLength; + cb->offset = 0; + + smscore_onresponse(smsdev->coredev, cb); +} + +static int smssdio_probe(struct sdio_func *func, + const struct sdio_device_id *id) +{ + int ret; + + int board_id; + struct smssdio_device *smsdev; + struct smsdevice_params_t params; + + board_id = id->driver_data; + + smsdev = kzalloc(sizeof(struct smssdio_device), GFP_KERNEL); + if (!smsdev) + return -ENOMEM; + + smsdev->func = func; + + memset(¶ms, 0, sizeof(struct smsdevice_params_t)); + + params.device = &func->dev; + params.buffer_size = 0x5000; /* ?? */ + params.num_buffers = 22; /* ?? */ + params.context = smsdev; + + snprintf(params.devpath, sizeof(params.devpath), + "sdio\\%s", sdio_func_id(func)); + + params.sendrequest_handler = smssdio_sendrequest; + + params.device_type = sms_get_board(board_id)->type; + + if (params.device_type != SMS_STELLAR) + params.flags |= SMS_DEVICE_FAMILY2; + else { + /* + * FIXME: Stellar needs special handling... + */ + ret = -ENODEV; + goto free; + } + + ret = smscore_register_device(¶ms, &smsdev->coredev); + if (ret < 0) + goto free; + + smscore_set_board_id(smsdev->coredev, board_id); + + sdio_claim_host(func); + + ret = sdio_enable_func(func); + if (ret) + goto release; + + ret = sdio_set_block_size(func, 128); + if (ret) + goto disable; + + ret = sdio_claim_irq(func, smssdio_interrupt); + if (ret) + goto disable; + + sdio_set_drvdata(func, smsdev); + + sdio_release_host(func); + + ret = smscore_start_device(smsdev->coredev); + if (ret < 0) + goto reclaim; + + return 0; + +reclaim: + sdio_claim_host(func); + sdio_release_irq(func); +disable: + sdio_disable_func(func); +release: + sdio_release_host(func); + smscore_unregister_device(smsdev->coredev); +free: + kfree(smsdev); + + return ret; +} + +static void smssdio_remove(struct sdio_func *func) +{ + struct smssdio_device *smsdev; + + smsdev = sdio_get_drvdata(func); + + /* FIXME: racy! */ + if (smsdev->split_cb) + smscore_putbuffer(smsdev->coredev, smsdev->split_cb); + + smscore_unregister_device(smsdev->coredev); + + sdio_claim_host(func); + sdio_release_irq(func); + sdio_disable_func(func); + sdio_release_host(func); + + kfree(smsdev); +} + +static struct sdio_driver smssdio_driver = { + .name = "smssdio", + .id_table = smssdio_ids, + .probe = smssdio_probe, + .remove = smssdio_remove, +}; + +/*******************************************************************/ +/* Module functions */ +/*******************************************************************/ + +int smssdio_register(void) +{ + int ret = 0; + + printk(KERN_INFO "smssdio: Siano SMS1xxx SDIO driver\n"); + printk(KERN_INFO "smssdio: Copyright Pierre Ossman\n"); + + ret = sdio_register_driver(&smssdio_driver); + + return ret; +} + +void smssdio_unregister(void) +{ + sdio_unregister_driver(&smssdio_driver); +} + +MODULE_DESCRIPTION("Siano SMS1xxx SDIO driver"); +MODULE_AUTHOR("Pierre Ossman"); +MODULE_LICENSE("GPL"); diff --git a/linux/drivers/media/dvb/ttpci/Kconfig b/linux/drivers/media/dvb/ttpci/Kconfig index ab0bcd208..772990415 100644 --- a/linux/drivers/media/dvb/ttpci/Kconfig +++ b/linux/drivers/media/dvb/ttpci/Kconfig @@ -108,7 +108,7 @@ config DVB_BUDGET_CI select DVB_STB6100 if !DVB_FE_CUSTOMISE select DVB_LNBP21 if !DVB_FE_CUSTOMISE select DVB_TDA10023 if !DVB_FE_CUSTOMISE - select MEDIA_TUNER_TDA827X if !MEDIA_TUNER_CUSTOMIZE + select MEDIA_TUNER_TDA827X if !MEDIA_TUNER_CUSTOMISE select VIDEO_IR help Support for simple SAA7146 based DVB cards diff --git a/linux/drivers/media/dvb/ttpci/budget-ci.c b/linux/drivers/media/dvb/ttpci/budget-ci.c index 99fcb55d5..1b564eb79 100644 --- a/linux/drivers/media/dvb/ttpci/budget-ci.c +++ b/linux/drivers/media/dvb/ttpci/budget-ci.c @@ -1084,6 +1084,10 @@ static struct tda10023_config tda10023_config = { .deltaf = 0xa511, }; +static struct tda827x_config tda827x_config = { + .config = 0, +}; + /* TT S2-3200 DVB-S (STB0899) Inittab */ static const struct stb0899_s1_reg tt3200_stb0899_s1_init_1[] = { @@ -1422,7 +1426,7 @@ static void frontend_init(struct budget_ci *budget_ci) case 0x101a: /* TT Budget-C-1501 (philips tda10023/philips tda8274A) */ budget_ci->budget.dvb_frontend = dvb_attach(tda10023_attach, &tda10023_config, &budget_ci->budget.i2c_adap, 0x48); if (budget_ci->budget.dvb_frontend) { - if (dvb_attach(tda827x_attach, budget_ci->budget.dvb_frontend, 0x61, &budget_ci->budget.i2c_adap, NULL) == NULL) { + if (dvb_attach(tda827x_attach, budget_ci->budget.dvb_frontend, 0x61, &budget_ci->budget.i2c_adap, &tda827x_config) == NULL) { printk(KERN_ERR "%s: No tda827x found!\n", __func__); dvb_frontend_detach(budget_ci->budget.dvb_frontend); budget_ci->budget.dvb_frontend = NULL; diff --git a/linux/drivers/media/radio/radio-si470x.c b/linux/drivers/media/radio/radio-si470x.c index a5ba4bf21..599fc0dcf 100644 --- a/linux/drivers/media/radio/radio-si470x.c +++ b/linux/drivers/media/radio/radio-si470x.c @@ -1714,7 +1714,7 @@ static int si470x_usb_driver_probe(struct usb_interface *intf, ": If you have some trouble using this driver,\n"); printk(KERN_WARNING DRIVER_NAME ": please report to V4L ML at " - "video4linux-list@redhat.com\n"); + "linux-media@vger.kernel.org\n"); } /* set initial frequency */ diff --git a/linux/drivers/media/video/Kconfig b/linux/drivers/media/video/Kconfig index 27f639763..114bf04a6 100644 --- a/linux/drivers/media/video/Kconfig +++ b/linux/drivers/media/video/Kconfig @@ -707,13 +707,6 @@ config SOC_CAMERA_MT9M001 This driver supports MT9M001 cameras from Micron, monochrome and colour models. -config MT9M001_PCA9536_SWITCH - bool "pca9536 datawidth switch for mt9m001" - depends on SOC_CAMERA_MT9M001 && GENERIC_GPIO - help - Select this if your MT9M001 camera uses a PCA9536 I2C GPIO - extender to switch between 8 and 10 bit datawidth modes - config SOC_CAMERA_MT9M111 tristate "mt9m111 and mt9m112 support" depends on SOC_CAMERA && I2C @@ -733,13 +726,6 @@ config SOC_CAMERA_MT9V022 help This driver supports MT9V022 cameras from Micron -config MT9V022_PCA9536_SWITCH - bool "pca9536 datawidth switch for mt9v022" - depends on SOC_CAMERA_MT9V022 && GENERIC_GPIO - help - Select this if your MT9V022 camera uses a PCA9536 I2C GPIO - extender to switch between 8 and 10 bit datawidth modes - config SOC_CAMERA_TW9910 tristate "tw9910 support" depends on SOC_CAMERA && I2C @@ -803,6 +789,8 @@ source "drivers/media/video/gspca/Kconfig" source "drivers/media/video/pvrusb2/Kconfig" +source "drivers/media/video/hdpvr/Kconfig" + source "drivers/media/video/em28xx/Kconfig" source "drivers/media/video/cx231xx/Kconfig" diff --git a/linux/drivers/media/video/Makefile b/linux/drivers/media/video/Makefile index 99b448e6c..08765d874 100644 --- a/linux/drivers/media/video/Makefile +++ b/linux/drivers/media/video/Makefile @@ -120,6 +120,8 @@ obj-$(CONFIG_USB_PWC) += pwc/ obj-$(CONFIG_USB_ZC0301) += zc0301/ obj-$(CONFIG_USB_GSPCA) += gspca/ +obj-$(CONFIG_VIDEO_HDPVR) += hdpvr/ + obj-$(CONFIG_USB_IBMCAM) += usbvideo/ obj-$(CONFIG_USB_KONICAWC) += usbvideo/ obj-$(CONFIG_USB_VICAM) += usbvideo/ diff --git a/linux/drivers/media/video/au0828/Kconfig b/linux/drivers/media/video/au0828/Kconfig index 20993ae17..05cdf494d 100644 --- a/linux/drivers/media/video/au0828/Kconfig +++ b/linux/drivers/media/video/au0828/Kconfig @@ -1,13 +1,13 @@ config VIDEO_AU0828 tristate "Auvitek AU0828 support" - depends on I2C && INPUT && DVB_CORE && USB + depends on I2C && INPUT && DVB_CORE && USB && VIDEO_V4L2 select I2C_ALGOBIT select VIDEO_TVEEPROM select DVB_AU8522 if !DVB_FE_CUSTOMISE - select MEDIA_TUNER_XC5000 if !MEDIA_TUNER_CUSTOMIZE - select MEDIA_TUNER_MXL5007T if !MEDIA_TUNER_CUSTOMIZE - select MEDIA_TUNER_TDA18271 if !MEDIA_TUNER_CUSTOMIZE + select MEDIA_TUNER_XC5000 if !MEDIA_TUNER_CUSTOMISE + select MEDIA_TUNER_MXL5007T if !MEDIA_TUNER_CUSTOMISE + select MEDIA_TUNER_TDA18271 if !MEDIA_TUNER_CUSTOMISE ---help--- This is a video4linux driver for Auvitek's USB device. diff --git a/linux/drivers/media/video/au0828/Makefile b/linux/drivers/media/video/au0828/Makefile index cd2c58281..4d2623158 100644 --- a/linux/drivers/media/video/au0828/Makefile +++ b/linux/drivers/media/video/au0828/Makefile @@ -1,4 +1,4 @@ -au0828-objs := au0828-core.o au0828-i2c.o au0828-cards.o au0828-dvb.o +au0828-objs := au0828-core.o au0828-i2c.o au0828-cards.o au0828-dvb.o au0828-video.o obj-$(CONFIG_VIDEO_AU0828) += au0828.o diff --git a/linux/drivers/media/video/au0828/au0828-cards.c b/linux/drivers/media/video/au0828/au0828-cards.c index d60123b41..1aabaa7e5 100644 --- a/linux/drivers/media/video/au0828/au0828-cards.c +++ b/linux/drivers/media/video/au0828/au0828-cards.c @@ -21,25 +21,89 @@ #include "au0828.h" #include "au0828-cards.h" +#include "au8522.h" +#include "media/tuner.h" +#include "media/v4l2-common.h" + +void hvr950q_cs5340_audio(void *priv, int enable) +{ + /* Because the HVR-950q shares an i2s bus between the cs5340 and the + au8522, we need to hold cs5340 in reset when using the au8522 */ + struct au0828_dev *dev = priv; + if (enable == 1) + au0828_set(dev, REG_000, 0x10); + else + au0828_clear(dev, REG_000, 0x10); +} struct au0828_board au0828_boards[] = { [AU0828_BOARD_UNKNOWN] = { .name = "Unknown board", + .tuner_type = UNSET, + .tuner_addr = ADDR_UNSET, }, [AU0828_BOARD_HAUPPAUGE_HVR850] = { .name = "Hauppauge HVR850", + .tuner_type = TUNER_XC5000, + .tuner_addr = 0x61, + .input = { + { + .type = AU0828_VMUX_TELEVISION, + .vmux = AU8522_COMPOSITE_CH4_SIF, + .amux = AU8522_AUDIO_SIF, + }, + { + .type = AU0828_VMUX_COMPOSITE, + .vmux = AU8522_COMPOSITE_CH1, + .amux = AU8522_AUDIO_NONE, + .audio_setup = hvr950q_cs5340_audio, + }, + { + .type = AU0828_VMUX_SVIDEO, + .vmux = AU8522_SVIDEO_CH13, + .amux = AU8522_AUDIO_NONE, + .audio_setup = hvr950q_cs5340_audio, + }, + }, }, [AU0828_BOARD_HAUPPAUGE_HVR950Q] = { .name = "Hauppauge HVR950Q", + .tuner_type = TUNER_XC5000, + .tuner_addr = 0x61, + .input = { + { + .type = AU0828_VMUX_TELEVISION, + .vmux = AU8522_COMPOSITE_CH4_SIF, + .amux = AU8522_AUDIO_SIF, + }, + { + .type = AU0828_VMUX_COMPOSITE, + .vmux = AU8522_COMPOSITE_CH1, + .amux = AU8522_AUDIO_NONE, + .audio_setup = hvr950q_cs5340_audio, + }, + { + .type = AU0828_VMUX_SVIDEO, + .vmux = AU8522_SVIDEO_CH13, + .amux = AU8522_AUDIO_NONE, + .audio_setup = hvr950q_cs5340_audio, + }, + }, }, [AU0828_BOARD_HAUPPAUGE_HVR950Q_MXL] = { .name = "Hauppauge HVR950Q rev xxF8", + .tuner_type = UNSET, + .tuner_addr = ADDR_UNSET, }, [AU0828_BOARD_DVICO_FUSIONHDTV7] = { .name = "DViCO FusionHDTV USB", + .tuner_type = UNSET, + .tuner_addr = ADDR_UNSET, }, [AU0828_BOARD_HAUPPAUGE_WOODBURY] = { .name = "Hauppauge Woodbury", + .tuner_type = UNSET, + .tuner_addr = ADDR_UNSET, }, }; @@ -52,7 +116,7 @@ int au0828_tuner_callback(void *priv, int component, int command, int arg) dprintk(1, "%s()\n", __func__); - switch (dev->board) { + switch (dev->boardnr) { case AU0828_BOARD_HAUPPAUGE_HVR850: case AU0828_BOARD_HAUPPAUGE_HVR950Q: case AU0828_BOARD_HAUPPAUGE_HVR950Q_MXL: @@ -81,17 +145,18 @@ static void hauppauge_eeprom(struct au0828_dev *dev, u8 *eeprom_data) struct tveeprom tv; tveeprom_hauppauge_analog(&dev->i2c_client, &tv, eeprom_data); + dev->board.tuner_type = tv.tuner_type; /* Make sure we support the board model */ switch (tv.model) { case 72000: /* WinTV-HVR950q (Retail, IR, ATSC/QAM */ - case 72001: /* WinTV-HVR950q (Retail, IR, ATSC/QAM and basic analog video */ - case 72211: /* WinTV-HVR950q (OEM, IR, ATSC/QAM and basic analog video */ - case 72221: /* WinTV-HVR950q (OEM, IR, ATSC/QAM and basic analog video */ - case 72231: /* WinTV-HVR950q (OEM, IR, ATSC/QAM and basic analog video */ - case 72241: /* WinTV-HVR950q (OEM, No IR, ATSC/QAM and basic analog video */ - case 72251: /* WinTV-HVR950q (Retail, IR, ATSC/QAM and basic analog video */ - case 72301: /* WinTV-HVR850 (Retail, IR, ATSC and basic analog video */ + case 72001: /* WinTV-HVR950q (Retail, IR, ATSC/QAM and analog video */ + case 72211: /* WinTV-HVR950q (OEM, IR, ATSC/QAM and analog video */ + case 72221: /* WinTV-HVR950q (OEM, IR, ATSC/QAM and analog video */ + case 72231: /* WinTV-HVR950q (OEM, IR, ATSC/QAM and analog video */ + case 72241: /* WinTV-HVR950q (OEM, No IR, ATSC/QAM and analog video */ + case 72251: /* WinTV-HVR950q (Retail, IR, ATSC/QAM and analog video */ + case 72301: /* WinTV-HVR850 (Retail, IR, ATSC and analog video */ case 72500: /* WinTV-HVR950q (OEM, No IR, ATSC/QAM */ break; default: @@ -107,15 +172,21 @@ static void hauppauge_eeprom(struct au0828_dev *dev, u8 *eeprom_data) void au0828_card_setup(struct au0828_dev *dev) { static u8 eeprom[256]; + struct tuner_setup tun_setup; + struct v4l2_subdev *sd; + unsigned int mode_mask = T_ANALOG_TV | + T_DIGITAL_TV; dprintk(1, "%s()\n", __func__); + memcpy(&dev->board, &au0828_boards[dev->boardnr], sizeof(dev->board)); + if (dev->i2c_rc == 0) { dev->i2c_client.addr = 0xa0 >> 1; tveeprom_read(&dev->i2c_client, eeprom, sizeof(eeprom)); } - switch (dev->board) { + switch (dev->boardnr) { case AU0828_BOARD_HAUPPAUGE_HVR850: case AU0828_BOARD_HAUPPAUGE_HVR950Q: case AU0828_BOARD_HAUPPAUGE_HVR950Q_MXL: @@ -124,6 +195,32 @@ void au0828_card_setup(struct au0828_dev *dev) hauppauge_eeprom(dev, eeprom+0xa0); break; } + + if (AUVI_INPUT(0).type != AU0828_VMUX_UNDEFINED) { + /* Load the analog demodulator driver (note this would need to + be abstracted out if we ever need to support a different + demod) */ + sd = v4l2_i2c_new_subdev(&dev->i2c_adap, "au8522", "au8522", + 0x8e >> 1); + if (sd == NULL) + printk(KERN_ERR "analog subdev registration failed\n"); + } + + /* Setup tuners */ + if (dev->board.tuner_type != TUNER_ABSENT) { + /* Load the tuner module, which does the attach */ + sd = v4l2_i2c_new_subdev(&dev->i2c_adap, "tuner", "tuner", + dev->board.tuner_addr); + if (sd == NULL) + printk(KERN_ERR "tuner subdev registration fail\n"); + + tun_setup.mode_mask = mode_mask; + tun_setup.type = dev->board.tuner_type; + tun_setup.addr = dev->board.tuner_addr; + tun_setup.tuner_callback = au0828_tuner_callback; + v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_type_addr, + &tun_setup); + } } /* @@ -135,7 +232,7 @@ void au0828_gpio_setup(struct au0828_dev *dev) { dprintk(1, "%s()\n", __func__); - switch (dev->board) { + switch (dev->boardnr) { case AU0828_BOARD_HAUPPAUGE_HVR850: case AU0828_BOARD_HAUPPAUGE_HVR950Q: case AU0828_BOARD_HAUPPAUGE_HVR950Q_MXL: @@ -144,21 +241,23 @@ void au0828_gpio_setup(struct au0828_dev *dev) * 4 - CS5340 * 5 - AU8522 Demodulator * 6 - eeprom W/P + * 7 - power supply * 9 - XC5000 Tuner */ /* Into reset */ au0828_write(dev, REG_003, 0x02); - au0828_write(dev, REG_002, 0x88 | 0x20); + au0828_write(dev, REG_002, 0x80 | 0x20 | 0x10); au0828_write(dev, REG_001, 0x0); au0828_write(dev, REG_000, 0x0); msleep(100); - /* Out of reset */ + /* Out of reset (leave the cs5340 in reset until needed) */ au0828_write(dev, REG_003, 0x02); au0828_write(dev, REG_001, 0x02); - au0828_write(dev, REG_002, 0x88 | 0x20); - au0828_write(dev, REG_000, 0x88 | 0x20 | 0x40); + au0828_write(dev, REG_002, 0x80 | 0x20 | 0x10); + au0828_write(dev, REG_000, 0x80 | 0x40 | 0x20); + msleep(250); break; case AU0828_BOARD_DVICO_FUSIONHDTV7: diff --git a/linux/drivers/media/video/au0828/au0828-core.c b/linux/drivers/media/video/au0828/au0828-core.c index 05e38f41c..ffe1bf019 100644 --- a/linux/drivers/media/video/au0828/au0828-core.c +++ b/linux/drivers/media/video/au0828/au0828-core.c @@ -37,6 +37,8 @@ int au0828_debug; module_param_named(debug, au0828_debug, int, 0644); MODULE_PARM_DESC(debug, "enable debug messages"); +static atomic_t au0828_instance = ATOMIC_INIT(0); + #define _AU0828_BULKPIPE 0x03 #define _BULKPIPESIZE 0xffff @@ -52,13 +54,13 @@ static int recv_control_msg(struct au0828_dev *dev, u16 request, u32 value, u32 au0828_readreg(struct au0828_dev *dev, u16 reg) { recv_control_msg(dev, CMD_REQUEST_IN, 0, reg, dev->ctrlmsg, 1); - dprintk(8, "%s(0x%x) = 0x%x\n", __func__, reg, dev->ctrlmsg[0]); + dprintk(8, "%s(0x%04x) = 0x%02x\n", __func__, reg, dev->ctrlmsg[0]); return dev->ctrlmsg[0]; } u32 au0828_writereg(struct au0828_dev *dev, u16 reg, u32 val) { - dprintk(8, "%s(0x%x, 0x%x)\n", __func__, reg, val); + dprintk(8, "%s(0x%04x, 0x%02x)\n", __func__, reg, val); return send_control_msg(dev, CMD_REQUEST_OUT, val, reg, dev->ctrlmsg, 0); } @@ -147,9 +149,14 @@ static void au0828_usb_disconnect(struct usb_interface *interface) /* Digital TV */ au0828_dvb_unregister(dev); + if (AUVI_INPUT(0).type != AU0828_VMUX_UNDEFINED) + au0828_analog_unregister(dev); + /* I2C */ au0828_i2c_unregister(dev); + v4l2_device_unregister(&dev->v4l2_dev); + usb_set_intfdata(interface, NULL); mutex_lock(&dev->mutex); @@ -163,7 +170,7 @@ static void au0828_usb_disconnect(struct usb_interface *interface) static int au0828_usb_probe(struct usb_interface *interface, const struct usb_device_id *id) { - int ifnum; + int ifnum, retval, i; struct au0828_dev *dev; struct usb_device *usbdev = interface_to_usbdev(interface); @@ -186,10 +193,22 @@ static int au0828_usb_probe(struct usb_interface *interface, mutex_init(&dev->mutex); mutex_init(&dev->dvb.lock); dev->usbdev = usbdev; - dev->board = id->driver_info; + dev->boardnr = id->driver_info; usb_set_intfdata(interface, dev); + /* Create the v4l2_device */ + i = atomic_inc_return(&au0828_instance) - 1; + snprintf(dev->v4l2_dev.name, sizeof(dev->v4l2_dev.name), "%s-%03d", + "au0828", i); + retval = v4l2_device_register(&dev->usbdev->dev, &dev->v4l2_dev); + if (retval) { + printk(KERN_ERR "%s() v4l2_device_register failed\n", + __func__); + kfree(dev); + return -EIO; + } + /* Power Up the bridge */ au0828_write(dev, REG_600, 1 << 4); @@ -202,12 +221,15 @@ static int au0828_usb_probe(struct usb_interface *interface, /* Setup */ au0828_card_setup(dev); + /* Analog TV */ + if (AUVI_INPUT(0).type != AU0828_VMUX_UNDEFINED) + au0828_analog_register(dev, interface); + /* Digital TV */ au0828_dvb_register(dev); printk(KERN_INFO "Registered device AU0828 [%s]\n", - au0828_boards[dev->board].name == NULL ? "Unset" : - au0828_boards[dev->board].name); + dev->board.name == NULL ? "Unset" : dev->board.name); return 0; } diff --git a/linux/drivers/media/video/au0828/au0828-dvb.c b/linux/drivers/media/video/au0828/au0828-dvb.c index 9966f83d5..104f15cc3 100644 --- a/linux/drivers/media/video/au0828/au0828-dvb.c +++ b/linux/drivers/media/video/au0828/au0828-dvb.c @@ -383,7 +383,7 @@ int au0828_dvb_register(struct au0828_dev *dev) dprintk(1, "%s()\n", __func__); /* init frontend */ - switch (dev->board) { + switch (dev->boardnr) { case AU0828_BOARD_HAUPPAUGE_HVR850: case AU0828_BOARD_HAUPPAUGE_HVR950Q: dvb->frontend = dvb_attach(au8522_attach, diff --git a/linux/drivers/media/video/au0828/au0828-i2c.c b/linux/drivers/media/video/au0828/au0828-i2c.c index d8cef6ccc..eb63166f6 100644 --- a/linux/drivers/media/video/au0828/au0828-i2c.c +++ b/linux/drivers/media/video/au0828/au0828-i2c.c @@ -141,13 +141,39 @@ static int i2c_sendbytes(struct i2c_adapter *i2c_adap, dprintk(4, "%s()\n", __func__); au0828_write(dev, REG_2FF, 0x01); - au0828_write(dev, REG_202, 0x07); + + /* FIXME: There is a problem with i2c communications with xc5000 that + requires us to slow down the i2c clock until we have a better + strategy (such as using the secondary i2c bus to do firmware + loading */ + if ((msg->addr << 1) == 0xc2) + au0828_write(dev, REG_202, 0x40); + else + au0828_write(dev, REG_202, 0x07); /* Hardware needs 8 bit addresses */ au0828_write(dev, REG_203, msg->addr << 1); dprintk(4, "SEND: %02x\n", msg->addr); + /* Deal with i2c_scan */ + if (msg->len == 0) { + /* The analog tuner detection code makes use of the SMBUS_QUICK + message (which involves a zero length i2c write). To avoid + checking the status register when we didn't strobe out any + actual bytes to the bus, just do a read check. This is + consistent with how I saw i2c device checking done in the + USB trace of the Windows driver */ + au0828_write(dev, REG_200, 0x20); + if (!i2c_wait_done(i2c_adap)) + return -EIO; + + if (i2c_wait_read_ack(i2c_adap)) + return -EIO; + + return 0; + } + for (i = 0; i < msg->len;) { dprintk(4, " %02x\n", msg->buf[i]); @@ -192,7 +218,15 @@ static int i2c_readbytes(struct i2c_adapter *i2c_adap, dprintk(4, "%s()\n", __func__); au0828_write(dev, REG_2FF, 0x01); - au0828_write(dev, REG_202, 0x07); + + /* FIXME: There is a problem with i2c communications with xc5000 that + requires us to slow down the i2c clock until we have a better + strategy (such as using the secondary i2c bus to do firmware + loading */ + if ((msg->addr << 1) == 0xc2) + au0828_write(dev, REG_202, 0x40); + else + au0828_write(dev, REG_202, 0x07); /* Hardware needs 8 bit addresses */ au0828_write(dev, REG_203, msg->addr << 1); @@ -266,33 +300,6 @@ err: return retval; } -static int attach_inform(struct i2c_client *client) -{ - dprintk(1, "%s i2c attach [addr=0x%x,client=%s]\n", - client->driver->driver.name, client->addr, client->name); - - if (!client->driver->command) - return 0; - - return 0; -} - -static int detach_inform(struct i2c_client *client) -{ - dprintk(1, "i2c detach [client=%s]\n", client->name); - - return 0; -} - -void au0828_call_i2c_clients(struct au0828_dev *dev, - unsigned int cmd, void *arg) -{ - if (dev->i2c_rc != 0) - return; - - i2c_clients_command(&dev->i2c_adap, cmd, arg); -} - static u32 au0828_functionality(struct i2c_adapter *adap) { return I2C_FUNC_SMBUS_EMUL | I2C_FUNC_I2C; @@ -313,9 +320,6 @@ static struct i2c_adapter au0828_i2c_adap_template = { .owner = THIS_MODULE, .id = I2C_HW_B_AU0828, .algo = &au0828_i2c_algo_template, - .class = I2C_CLASS_TV_ANALOG, - .client_register = attach_inform, - .client_unregister = detach_inform, }; static struct i2c_client au0828_i2c_client_template = { @@ -360,9 +364,9 @@ int au0828_i2c_register(struct au0828_dev *dev) strlcpy(dev->i2c_adap.name, DRIVER_NAME, sizeof(dev->i2c_adap.name)); - dev->i2c_algo.data = dev; + dev->i2c_adap.algo = &dev->i2c_algo; dev->i2c_adap.algo_data = dev; - i2c_set_adapdata(&dev->i2c_adap, dev); + i2c_set_adapdata(&dev->i2c_adap, &dev->v4l2_dev); i2c_add_adapter(&dev->i2c_adap); dev->i2c_client.adapter = &dev->i2c_adap; diff --git a/linux/drivers/media/video/au0828/au0828-reg.h b/linux/drivers/media/video/au0828/au0828-reg.h index 1e87fa0c6..b15e4a3b6 100644 --- a/linux/drivers/media/video/au0828/au0828-reg.h +++ b/linux/drivers/media/video/au0828/au0828-reg.h @@ -27,6 +27,9 @@ #define REG_002 0x002 #define REG_003 0x003 +#define AU0828_SENSORCTRL_100 0x100 +#define AU0828_SENSORCTRL_VBI_103 0x103 + #define REG_200 0x200 #define REG_201 0x201 #define REG_202 0x202 @@ -35,4 +38,7 @@ #define REG_209 0x209 #define REG_2FF 0x2ff +/* Audio registers */ +#define AU0828_AUDIOCTRL_50C 0x50C + #define REG_600 0x600 diff --git a/linux/drivers/media/video/au0828/au0828-video.c b/linux/drivers/media/video/au0828/au0828-video.c new file mode 100644 index 000000000..5eac5cde5 --- /dev/null +++ b/linux/drivers/media/video/au0828/au0828-video.c @@ -0,0 +1,1718 @@ +/* + * Auvitek AU0828 USB Bridge (Analog video support) + * + * Copyright (C) 2009 Devin Heitmueller <dheitmueller@linuxtv.org> + * Copyright (C) 2005-2008 Auvitek International, Ltd. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * As published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +/* Developer Notes: + * + * VBI support is not yet working + * The hardware scaler supported is unimplemented + * AC97 audio support is unimplemented (only i2s audio mode) + * + */ + +#include <linux/module.h> +#include <linux/init.h> +#include <linux/device.h> +#include <linux/suspend.h> +#include <linux/version.h> +#include <linux/mm.h> +#include <media/v4l2-common.h> +#include <media/v4l2-ioctl.h> +#include <media/v4l2-chip-ident.h> +#include <media/tuner.h> +#include "compat.h" +#include "au0828.h" +#include "au0828-reg.h" + +static LIST_HEAD(au0828_devlist); +static DEFINE_MUTEX(au0828_sysfs_lock); + +#define AU0828_VERSION_CODE KERNEL_VERSION(0, 0, 1) + +/* ------------------------------------------------------------------ + Videobuf operations + ------------------------------------------------------------------*/ + +static unsigned int isoc_debug; +module_param(isoc_debug, int, 0644); +MODULE_PARM_DESC(isoc_debug, "enable debug messages [isoc transfers]"); + +#define au0828_isocdbg(fmt, arg...) \ +do {\ + if (isoc_debug) { \ + printk(KERN_INFO "au0828 %s :"fmt, \ + __func__ , ##arg); \ + } \ + } while (0) + +static inline void print_err_status(struct au0828_dev *dev, + int packet, int status) +{ + char *errmsg = "Unknown"; + + switch (status) { + case -ENOENT: + errmsg = "unlinked synchronuously"; + break; + case -ECONNRESET: + errmsg = "unlinked asynchronuously"; + break; + case -ENOSR: + errmsg = "Buffer error (overrun)"; + break; + case -EPIPE: + errmsg = "Stalled (device not responding)"; + break; + case -EOVERFLOW: + errmsg = "Babble (bad cable?)"; + break; + case -EPROTO: + errmsg = "Bit-stuff error (bad cable?)"; + break; + case -EILSEQ: + errmsg = "CRC/Timeout (could be anything)"; + break; + case -ETIME: + errmsg = "Device does not respond"; + break; + } + if (packet < 0) { + au0828_isocdbg("URB status %d [%s].\n", status, errmsg); + } else { + au0828_isocdbg("URB packet %d, status %d [%s].\n", + packet, status, errmsg); + } +} + +static int check_dev(struct au0828_dev *dev) +{ + if (dev->dev_state & DEV_DISCONNECTED) { + printk(KERN_INFO "v4l2 ioctl: device not present\n"); + return -ENODEV; + } + + if (dev->dev_state & DEV_MISCONFIGURED) { + printk(KERN_INFO "v4l2 ioctl: device is misconfigured; " + "close and open it again\n"); + return -EIO; + } + return 0; +} + +/* + * IRQ callback, called by URB callback + */ +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 19) +static void au0828_irq_callback(struct urb *urb, struct pt_regs *regs) +#else +static void au0828_irq_callback(struct urb *urb) +#endif +{ + struct au0828_dmaqueue *dma_q = urb->context; + struct au0828_dev *dev = container_of(dma_q, struct au0828_dev, vidq); + int rc, i; + + switch (urb->status) { + case 0: /* success */ + case -ETIMEDOUT: /* NAK */ + break; + case -ECONNRESET: /* kill */ + case -ENOENT: + case -ESHUTDOWN: + au0828_isocdbg("au0828_irq_callback called: status kill\n"); + return; + default: /* unknown error */ + au0828_isocdbg("urb completition error %d.\n", urb->status); + break; + } + + /* Copy data from URB */ + spin_lock(&dev->slock); + rc = dev->isoc_ctl.isoc_copy(dev, urb); + spin_unlock(&dev->slock); + + /* Reset urb buffers */ + for (i = 0; i < urb->number_of_packets; i++) { + urb->iso_frame_desc[i].status = 0; + urb->iso_frame_desc[i].actual_length = 0; + } + urb->status = 0; + + urb->status = usb_submit_urb(urb, GFP_ATOMIC); + if (urb->status) { + au0828_isocdbg("urb resubmit failed (error=%i)\n", + urb->status); + } +} + +/* + * Stop and Deallocate URBs + */ +void au0828_uninit_isoc(struct au0828_dev *dev) +{ + struct urb *urb; + int i; + + au0828_isocdbg("au0828: called au0828_uninit_isoc\n"); + + dev->isoc_ctl.nfields = -1; + for (i = 0; i < dev->isoc_ctl.num_bufs; i++) { + urb = dev->isoc_ctl.urb[i]; + if (urb) { + if (!irqs_disabled()) + usb_kill_urb(urb); + else + usb_unlink_urb(urb); + + if (dev->isoc_ctl.transfer_buffer[i]) { + usb_buffer_free(dev->usbdev, + urb->transfer_buffer_length, + dev->isoc_ctl.transfer_buffer[i], + urb->transfer_dma); + } + usb_free_urb(urb); + dev->isoc_ctl.urb[i] = NULL; + } + dev->isoc_ctl.transfer_buffer[i] = NULL; + } + + kfree(dev->isoc_ctl.urb); + kfree(dev->isoc_ctl.transfer_buffer); + + dev->isoc_ctl.urb = NULL; + dev->isoc_ctl.transfer_buffer = NULL; + dev->isoc_ctl.num_bufs = 0; +} + +/* + * Allocate URBs and start IRQ + */ +int au0828_init_isoc(struct au0828_dev *dev, int max_packets, + int num_bufs, int max_pkt_size, + int (*isoc_copy) (struct au0828_dev *dev, struct urb *urb)) +{ + struct au0828_dmaqueue *dma_q = &dev->vidq; + int i; + int sb_size, pipe; + struct urb *urb; + int j, k; + int rc; + + au0828_isocdbg("au0828: called au0828_prepare_isoc\n"); + + /* De-allocates all pending stuff */ + au0828_uninit_isoc(dev); + + dev->isoc_ctl.isoc_copy = isoc_copy; + dev->isoc_ctl.num_bufs = num_bufs; + + dev->isoc_ctl.urb = kzalloc(sizeof(void *)*num_bufs, GFP_KERNEL); + if (!dev->isoc_ctl.urb) { + au0828_isocdbg("cannot alloc memory for usb buffers\n"); + return -ENOMEM; + } + + dev->isoc_ctl.transfer_buffer = kzalloc(sizeof(void *)*num_bufs, + GFP_KERNEL); + if (!dev->isoc_ctl.transfer_buffer) { + au0828_isocdbg("cannot allocate memory for usb transfer\n"); + kfree(dev->isoc_ctl.urb); + return -ENOMEM; + } + + dev->isoc_ctl.max_pkt_size = max_pkt_size; + dev->isoc_ctl.buf = NULL; + + sb_size = max_packets * dev->isoc_ctl.max_pkt_size; + + /* allocate urbs and transfer buffers */ + for (i = 0; i < dev->isoc_ctl.num_bufs; i++) { + urb = usb_alloc_urb(max_packets, GFP_KERNEL); + if (!urb) { + au0828_isocdbg("cannot alloc isoc_ctl.urb %i\n", i); + au0828_uninit_isoc(dev); + return -ENOMEM; + } + dev->isoc_ctl.urb[i] = urb; + + dev->isoc_ctl.transfer_buffer[i] = usb_buffer_alloc(dev->usbdev, + sb_size, GFP_KERNEL, &urb->transfer_dma); + if (!dev->isoc_ctl.transfer_buffer[i]) { + printk("unable to allocate %i bytes for transfer" + " buffer %i%s\n", + sb_size, i, + in_interrupt() ? " while in int" : ""); + au0828_uninit_isoc(dev); + return -ENOMEM; + } + memset(dev->isoc_ctl.transfer_buffer[i], 0, sb_size); + + pipe = usb_rcvisocpipe(dev->usbdev, + dev->isoc_in_endpointaddr), + + usb_fill_int_urb(urb, dev->usbdev, pipe, + dev->isoc_ctl.transfer_buffer[i], sb_size, + au0828_irq_callback, dma_q, 1); + + urb->number_of_packets = max_packets; + urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP; + + k = 0; + for (j = 0; j < max_packets; j++) { + urb->iso_frame_desc[j].offset = k; + urb->iso_frame_desc[j].length = + dev->isoc_ctl.max_pkt_size; + k += dev->isoc_ctl.max_pkt_size; + } + } + + init_waitqueue_head(&dma_q->wq); + + /* submit urbs and enables IRQ */ + for (i = 0; i < dev->isoc_ctl.num_bufs; i++) { + rc = usb_submit_urb(dev->isoc_ctl.urb[i], GFP_ATOMIC); + if (rc) { + au0828_isocdbg("submit of urb %i failed (error=%i)\n", + i, rc); + au0828_uninit_isoc(dev); + return rc; + } + } + + return 0; +} + +/* + * Announces that a buffer were filled and request the next + */ +static inline void buffer_filled(struct au0828_dev *dev, + struct au0828_dmaqueue *dma_q, + struct au0828_buffer *buf) +{ + /* Advice that buffer was filled */ + au0828_isocdbg("[%p/%d] wakeup\n", buf, buf->vb.i); + + buf->vb.state = VIDEOBUF_DONE; + buf->vb.field_count++; + do_gettimeofday(&buf->vb.ts); + + dev->isoc_ctl.buf = NULL; + + list_del(&buf->vb.queue); + wake_up(&buf->vb.done); +} + +/* + * Identify the buffer header type and properly handles + */ +static void au0828_copy_video(struct au0828_dev *dev, + struct au0828_dmaqueue *dma_q, + struct au0828_buffer *buf, + unsigned char *p, + unsigned char *outp, unsigned long len) +{ + void *fieldstart, *startwrite, *startread; + int linesdone, currlinedone, offset, lencopy, remain; + int bytesperline = dev->width << 1; /* Assumes 16-bit depth @@@@ */ + + if (dma_q->pos + len > buf->vb.size) + len = buf->vb.size - dma_q->pos; + + startread = p; + remain = len; + + /* Interlaces frame */ + if (buf->top_field) + fieldstart = outp; + else + fieldstart = outp + bytesperline; + + linesdone = dma_q->pos / bytesperline; + currlinedone = dma_q->pos % bytesperline; + offset = linesdone * bytesperline * 2 + currlinedone; + startwrite = fieldstart + offset; + lencopy = bytesperline - currlinedone; + lencopy = lencopy > remain ? remain : lencopy; + + if ((char *)startwrite + lencopy > (char *)outp + buf->vb.size) { + au0828_isocdbg("Overflow of %zi bytes past buffer end (1)\n", + ((char *)startwrite + lencopy) - + ((char *)outp + buf->vb.size)); + remain = (char *)outp + buf->vb.size - (char *)startwrite; + lencopy = remain; + } + if (lencopy <= 0) + return; + memcpy(startwrite, startread, lencopy); + + remain -= lencopy; + + while (remain > 0) { + startwrite += lencopy + bytesperline; + startread += lencopy; + if (bytesperline > remain) + lencopy = remain; + else + lencopy = bytesperline; + + if ((char *)startwrite + lencopy > (char *)outp + + buf->vb.size) { + au0828_isocdbg("Overflow %zi bytes past buf end (2)\n", + ((char *)startwrite + lencopy) - + ((char *)outp + buf->vb.size)); + lencopy = remain = (char *)outp + buf->vb.size - + (char *)startwrite; + } + if (lencopy <= 0) + break; + + memcpy(startwrite, startread, lencopy); + + remain -= lencopy; + } + + if (offset > 1440) { + /* We have enough data to check for greenscreen */ + if (outp[0] < 0x60 && outp[1440] < 0x60) + dev->greenscreen_detected = 1; + } + + dma_q->pos += len; +} + +/* + * video-buf generic routine to get the next available buffer + */ +static inline void get_next_buf(struct au0828_dmaqueue *dma_q, + struct au0828_buffer **buf) +{ + struct au0828_dev *dev = container_of(dma_q, struct au0828_dev, vidq); + + if (list_empty(&dma_q->active)) { + au0828_isocdbg("No active queue to serve\n"); + dev->isoc_ctl.buf = NULL; + *buf = NULL; + return; + } + + /* Get the next buffer */ + *buf = list_entry(dma_q->active.next, struct au0828_buffer, vb.queue); + dev->isoc_ctl.buf = *buf; + + return; +} + +/* + * Controls the isoc copy of each urb packet + */ +static inline int au0828_isoc_copy(struct au0828_dev *dev, struct urb *urb) +{ + struct au0828_buffer *buf; + struct au0828_dmaqueue *dma_q = urb->context; + unsigned char *outp = NULL; + int i, len = 0, rc = 1; + unsigned char *p; + unsigned char fbyte; + + if (!dev) + return 0; + + if ((dev->dev_state & DEV_DISCONNECTED) || + (dev->dev_state & DEV_MISCONFIGURED)) + return 0; + + if (urb->status < 0) { + print_err_status(dev, -1, urb->status); + if (urb->status == -ENOENT) + return 0; + } + + buf = dev->isoc_ctl.buf; + if (buf != NULL) + outp = videobuf_to_vmalloc(&buf->vb); + + for (i = 0; i < urb->number_of_packets; i++) { + int status = urb->iso_frame_desc[i].status; + + if (status < 0) { + print_err_status(dev, i, status); + if (urb->iso_frame_desc[i].status != -EPROTO) + continue; + } + + if (urb->iso_frame_desc[i].actual_length <= 0) + continue; + + if (urb->iso_frame_desc[i].actual_length > + dev->max_pkt_size) { + au0828_isocdbg("packet bigger than packet size"); + continue; + } + + p = urb->transfer_buffer + urb->iso_frame_desc[i].offset; + fbyte = p[0]; + len = urb->iso_frame_desc[i].actual_length - 4; + p += 4; + + if (fbyte & 0x80) { + len -= 4; + p += 4; + au0828_isocdbg("Video frame %s\n", + (fbyte & 0x40) ? "odd" : "even"); + if (!(fbyte & 0x40)) { + if (buf != NULL) + buffer_filled(dev, dma_q, buf); + get_next_buf(dma_q, &buf); + if (buf == NULL) + outp = NULL; + else + outp = videobuf_to_vmalloc(&buf->vb); + } + + if (buf != NULL) { + if (fbyte & 0x40) + buf->top_field = 1; + else + buf->top_field = 0; + } + + dma_q->pos = 0; + } + if (buf != NULL) + au0828_copy_video(dev, dma_q, buf, p, outp, len); + } + return rc; +} + +static int +buffer_setup(struct videobuf_queue *vq, unsigned int *count, + unsigned int *size) +{ + struct au0828_fh *fh = vq->priv_data; + *size = (fh->dev->width * fh->dev->height * 16 + 7) >> 3; + + if (0 == *count) + *count = AU0828_DEF_BUF; + + if (*count < AU0828_MIN_BUF) + *count = AU0828_MIN_BUF; + return 0; +} + +/* This is called *without* dev->slock held; please keep it that way */ +static void free_buffer(struct videobuf_queue *vq, struct au0828_buffer *buf) +{ + struct au0828_fh *fh = vq->priv_data; + struct au0828_dev *dev = fh->dev; + unsigned long flags = 0; + if (in_interrupt()) + BUG(); + + /* We used to wait for the buffer to finish here, but this didn't work + because, as we were keeping the state as VIDEOBUF_QUEUED, + videobuf_queue_cancel marked it as finished for us. + (Also, it could wedge forever if the hardware was misconfigured.) + + This should be safe; by the time we get here, the buffer isn't + queued anymore. If we ever start marking the buffers as + VIDEOBUF_ACTIVE, it won't be, though. + */ + spin_lock_irqsave(&dev->slock, flags); + if (dev->isoc_ctl.buf == buf) + dev->isoc_ctl.buf = NULL; + spin_unlock_irqrestore(&dev->slock, flags); + + videobuf_vmalloc_free(&buf->vb); + buf->vb.state = VIDEOBUF_NEEDS_INIT; +} + +static int +buffer_prepare(struct videobuf_queue *vq, struct videobuf_buffer *vb, + enum v4l2_field field) +{ + struct au0828_fh *fh = vq->priv_data; + struct au0828_buffer *buf = container_of(vb, struct au0828_buffer, vb); + struct au0828_dev *dev = fh->dev; + int rc = 0, urb_init = 0; + + buf->vb.size = (fh->dev->width * fh->dev->height * 16 + 7) >> 3; + + if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size) + return -EINVAL; + + buf->vb.width = dev->width; + buf->vb.height = dev->height; + buf->vb.field = field; + + if (VIDEOBUF_NEEDS_INIT == buf->vb.state) { + rc = videobuf_iolock(vq, &buf->vb, NULL); + if (rc < 0) { + printk(KERN_INFO "videobuf_iolock failed\n"); + goto fail; + } + } + + if (!dev->isoc_ctl.num_bufs) + urb_init = 1; + + if (urb_init) { + rc = au0828_init_isoc(dev, AU0828_ISO_PACKETS_PER_URB, + AU0828_MAX_ISO_BUFS, dev->max_pkt_size, + au0828_isoc_copy); + if (rc < 0) { + printk(KERN_INFO "au0828_init_isoc failed\n"); + goto fail; + } + } + + buf->vb.state = VIDEOBUF_PREPARED; + return 0; + +fail: + free_buffer(vq, buf); + return rc; +} + +static void +buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb) +{ + struct au0828_buffer *buf = container_of(vb, + struct au0828_buffer, + vb); + struct au0828_fh *fh = vq->priv_data; + struct au0828_dev *dev = fh->dev; + struct au0828_dmaqueue *vidq = &dev->vidq; + + buf->vb.state = VIDEOBUF_QUEUED; + list_add_tail(&buf->vb.queue, &vidq->active); +} + +static void buffer_release(struct videobuf_queue *vq, + struct videobuf_buffer *vb) +{ + struct au0828_buffer *buf = container_of(vb, + struct au0828_buffer, + vb); + + free_buffer(vq, buf); +} + +static struct videobuf_queue_ops au0828_video_qops = { + .buf_setup = buffer_setup, + .buf_prepare = buffer_prepare, + .buf_queue = buffer_queue, + .buf_release = buffer_release, +}; + +/* ------------------------------------------------------------------ + V4L2 interface + ------------------------------------------------------------------*/ + +static int au0828_i2s_init(struct au0828_dev *dev) +{ + /* Enable i2s mode */ + au0828_writereg(dev, AU0828_AUDIOCTRL_50C, 0x01); + return 0; +} + +/* + * Auvitek au0828 analog stream enable + * Please set interface0 to AS5 before enable the stream + */ +int au0828_analog_stream_enable(struct au0828_dev *d) +{ + dprintk(1, "au0828_analog_stream_enable called\n"); + au0828_writereg(d, AU0828_SENSORCTRL_VBI_103, 0x00); + au0828_writereg(d, 0x106, 0x00); + /* set x position */ + au0828_writereg(d, 0x110, 0x00); + au0828_writereg(d, 0x111, 0x00); + au0828_writereg(d, 0x114, 0xa0); + au0828_writereg(d, 0x115, 0x05); + /* set y position */ + au0828_writereg(d, 0x112, 0x02); + au0828_writereg(d, 0x113, 0x00); + au0828_writereg(d, 0x116, 0xf2); + au0828_writereg(d, 0x117, 0x00); + au0828_writereg(d, AU0828_SENSORCTRL_100, 0xb3); + + return 0; +} + +int au0828_analog_stream_disable(struct au0828_dev *d) +{ + dprintk(1, "au0828_analog_stream_disable called\n"); + au0828_writereg(d, AU0828_SENSORCTRL_100, 0x0); + return 0; +} + +void au0828_analog_stream_reset(struct au0828_dev *dev) +{ + dprintk(1, "au0828_analog_stream_reset called\n"); + au0828_writereg(dev, AU0828_SENSORCTRL_100, 0x0); + mdelay(30); + au0828_writereg(dev, AU0828_SENSORCTRL_100, 0xb3); +} + +/* + * Some operations needs to stop current streaming + */ +static int au0828_stream_interrupt(struct au0828_dev *dev) +{ + int ret = 0; + + dev->stream_state = STREAM_INTERRUPT; + if (dev->dev_state == DEV_DISCONNECTED) + return -ENODEV; + else if (ret) { + dev->dev_state = DEV_MISCONFIGURED; + dprintk(1, "%s device is misconfigured!\n", __func__); + return ret; + } + return 0; +} + +/* + * au0828_release_resources + * unregister v4l2 devices + */ +void au0828_analog_unregister(struct au0828_dev *dev) +{ + dprintk(1, "au0828_release_resources called\n"); + mutex_lock(&au0828_sysfs_lock); + + if (dev->vdev) { + list_del(&dev->au0828list); + video_unregister_device(dev->vdev); + } + if (dev->vbi_dev) + video_unregister_device(dev->vbi_dev); + + mutex_unlock(&au0828_sysfs_lock); +} + + +/* Usage lock check functions */ +static int res_get(struct au0828_fh *fh) +{ + struct au0828_dev *dev = fh->dev; + int rc = 0; + + /* This instance already has stream_on */ + if (fh->stream_on) + return rc; + + if (dev->stream_on) + return -EBUSY; + + dev->stream_on = 1; + fh->stream_on = 1; + return rc; +} + +static int res_check(struct au0828_fh *fh) +{ + return fh->stream_on; +} + +static void res_free(struct au0828_fh *fh) +{ + struct au0828_dev *dev = fh->dev; + + fh->stream_on = 0; + dev->stream_on = 0; +} + +static int au0828_v4l2_open(struct file *filp) +{ + int minor = video_devdata(filp)->minor; + int ret = 0; + struct au0828_dev *h, *dev = NULL; + struct au0828_fh *fh; + int type = 0; + struct list_head *list; + + list_for_each(list, &au0828_devlist) { + h = list_entry(list, struct au0828_dev, au0828list); + if (h->vdev->minor == minor) { + dev = h; + type = V4L2_BUF_TYPE_VIDEO_CAPTURE; + } +#ifdef VBI_IS_WORKING + if (h->vbi_dev->minor == minor) { + dev = h; + type = V4L2_BUF_TYPE_VBI_CAPTURE; + } +#endif + } + + if (NULL == dev) + return -ENODEV; + + fh = kzalloc(sizeof(struct au0828_fh), GFP_KERNEL); + if (NULL == fh) { + dprintk(1, "Failed allocate au0828_fh struct!\n"); + return -ENOMEM; + } + + fh->type = type; + fh->dev = dev; + filp->private_data = fh; + + if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE && dev->users == 0) { + /* set au0828 interface0 to AS5 here again */ + ret = usb_set_interface(dev->usbdev, 0, 5); + if (ret < 0) { + printk(KERN_INFO "Au0828 can't set alternate to 5!\n"); + return -EBUSY; + } + dev->width = NTSC_STD_W; + dev->height = NTSC_STD_H; + dev->frame_size = dev->width * dev->height * 2; + dev->field_size = dev->width * dev->height; + dev->bytesperline = dev->width * 2; + + au0828_analog_stream_enable(dev); + au0828_analog_stream_reset(dev); + + /* If we were doing ac97 instead of i2s, it would go here...*/ + au0828_i2s_init(dev); + + dev->stream_state = STREAM_OFF; + dev->dev_state |= DEV_INITIALIZED; + } + + dev->users++; + + videobuf_queue_vmalloc_init(&fh->vb_vidq, &au0828_video_qops, + NULL, &dev->slock, fh->type, + V4L2_FIELD_INTERLACED, + sizeof(struct au0828_buffer), fh); + + return ret; +} + +static int au0828_v4l2_close(struct file *filp) +{ + int ret; + struct au0828_fh *fh = filp->private_data; + struct au0828_dev *dev = fh->dev; + + mutex_lock(&dev->lock); + if (res_check(fh)) + res_free(fh); + + if (dev->users == 1) { + videobuf_stop(&fh->vb_vidq); + videobuf_mmap_free(&fh->vb_vidq); + + if (dev->dev_state & DEV_DISCONNECTED) { + au0828_analog_unregister(dev); + mutex_unlock(&dev->lock); + kfree(dev); + return 0; + } + + au0828_analog_stream_disable(dev); + + au0828_uninit_isoc(dev); + + /* When close the device, set the usb intf0 into alt0 to free + USB bandwidth */ + ret = usb_set_interface(dev->usbdev, 0, 0); + if (ret < 0) + printk(KERN_INFO "Au0828 can't set alternate to 0!\n"); + } + + kfree(fh); + dev->users--; + wake_up_interruptible_nr(&dev->open, 1); + mutex_unlock(&dev->lock); + return 0; +} + +static ssize_t au0828_v4l2_read(struct file *filp, char __user *buf, + size_t count, loff_t *pos) +{ + struct au0828_fh *fh = filp->private_data; + struct au0828_dev *dev = fh->dev; + int rc; + + rc = check_dev(dev); + if (rc < 0) + return rc; + + if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) { + mutex_lock(&dev->lock); + rc = res_get(fh); + mutex_unlock(&dev->lock); + + if (unlikely(rc < 0)) + return rc; + + return videobuf_read_stream(&fh->vb_vidq, buf, count, pos, 0, + filp->f_flags & O_NONBLOCK); + } + return 0; +} + +static unsigned int au0828_v4l2_poll(struct file *filp, poll_table *wait) +{ + struct au0828_fh *fh = filp->private_data; + struct au0828_dev *dev = fh->dev; + int rc; + + rc = check_dev(dev); + if (rc < 0) + return rc; + + mutex_lock(&dev->lock); + rc = res_get(fh); + mutex_unlock(&dev->lock); + + if (unlikely(rc < 0)) + return POLLERR; + + if (V4L2_BUF_TYPE_VIDEO_CAPTURE != fh->type) + return POLLERR; + + return videobuf_poll_stream(filp, &fh->vb_vidq, wait); +} + +static int au0828_v4l2_mmap(struct file *filp, struct vm_area_struct *vma) +{ + struct au0828_fh *fh = filp->private_data; + struct au0828_dev *dev = fh->dev; + int rc; + + rc = check_dev(dev); + if (rc < 0) + return rc; + + mutex_lock(&dev->lock); + rc = res_get(fh); + mutex_unlock(&dev->lock); + + if (unlikely(rc < 0)) + return rc; + + rc = videobuf_mmap_mapper(&fh->vb_vidq, vma); + + dprintk(2, "vma start=0x%08lx, size=%ld, ret=%d\n", + (unsigned long)vma->vm_start, + (unsigned long)vma->vm_end-(unsigned long)vma->vm_start, + rc); + + return rc; +} + +static int au0828_set_format(struct au0828_dev *dev, unsigned int cmd, + struct v4l2_format *format) +{ + int ret; + int width = format->fmt.pix.width; + int height = format->fmt.pix.height; + unsigned int maxwidth, maxheight; + + maxwidth = 720; + maxheight = 480; + +#ifdef VBI_IS_WORKING + if (format->type == V4L2_BUF_TYPE_SLICED_VBI_CAPTURE) { + dprintk(1, "VBI format set: to be supported!\n"); + return 0; + } + if (format->type == V4L2_BUF_TYPE_VBI_CAPTURE) + return 0; +#endif + if (format->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) + return -EINVAL; + + /* If they are demanding a format other than the one we support, + bail out (tvtime asks for UYVY and then retries with YUYV) */ + if (format->fmt.pix.pixelformat != V4L2_PIX_FMT_UYVY) + return -EINVAL; + + /* format->fmt.pix.width only support 720 and height 480 */ + if (width != 720) + width = 720; + if (height != 480) + height = 480; + + format->fmt.pix.width = width; + format->fmt.pix.height = height; + format->fmt.pix.pixelformat = V4L2_PIX_FMT_UYVY; + format->fmt.pix.bytesperline = width * 2; + format->fmt.pix.sizeimage = width * height * 2; + format->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; + format->fmt.pix.field = V4L2_FIELD_INTERLACED; + + if (cmd == VIDIOC_TRY_FMT) + return 0; + + /* maybe set new image format, driver current only support 720*480 */ + dev->width = width; + dev->height = height; + dev->frame_size = width * height * 2; + dev->field_size = width * height; + dev->bytesperline = width * 2; + + if (dev->stream_state == STREAM_ON) { + dprintk(1, "VIDIOC_SET_FMT: interrupting stream!\n"); + ret = au0828_stream_interrupt(dev); + if (ret != 0) { + dprintk(1, "error interrupting video stream!\n"); + return ret; + } + } + + /* set au0828 interface0 to AS5 here again */ + ret = usb_set_interface(dev->usbdev, 0, 5); + if (ret < 0) { + printk(KERN_INFO "Au0828 can't set alt setting to 5!\n"); + return -EBUSY; + } + + au0828_analog_stream_enable(dev); + + return 0; +} + + +static int vidioc_queryctrl(struct file *file, void *priv, + struct v4l2_queryctrl *qc) +{ + struct au0828_fh *fh = priv; + struct au0828_dev *dev = fh->dev; + v4l2_device_call_all(&dev->v4l2_dev, 0, core, queryctrl, qc); + if (qc->type) + return 0; + else + return -EINVAL; +} + +static int vidioc_querycap(struct file *file, void *priv, + struct v4l2_capability *cap) +{ + struct au0828_fh *fh = priv; + struct au0828_dev *dev = fh->dev; + + strlcpy(cap->driver, "au0828", sizeof(cap->driver)); + strlcpy(cap->card, dev->board.name, sizeof(cap->card)); + strlcpy(cap->bus_info, dev->v4l2_dev.name, sizeof(cap->bus_info)); + + cap->version = AU0828_VERSION_CODE; + + /*set the device capabilities */ + cap->capabilities = V4L2_CAP_VIDEO_CAPTURE | +#ifdef VBI_IS_WORKING + V4L2_CAP_VBI_CAPTURE | +#endif + V4L2_CAP_AUDIO | + V4L2_CAP_READWRITE | + V4L2_CAP_STREAMING | + V4L2_CAP_TUNER; + return 0; +} + +static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv, + struct v4l2_fmtdesc *f) +{ + if (f->index) + return -EINVAL; + + f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; + strcpy(f->description, "Packed YUV2"); + + f->flags = 0; + f->pixelformat = V4L2_PIX_FMT_UYVY; + + return 0; +} + +static int vidioc_g_fmt_vid_cap(struct file *file, void *priv, + struct v4l2_format *f) +{ + struct au0828_fh *fh = priv; + struct au0828_dev *dev = fh->dev; + + f->fmt.pix.width = dev->width; + f->fmt.pix.height = dev->height; + f->fmt.pix.pixelformat = V4L2_PIX_FMT_UYVY; + f->fmt.pix.bytesperline = dev->bytesperline; + f->fmt.pix.sizeimage = dev->frame_size; + f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; /* NTSC/PAL */ + f->fmt.pix.field = V4L2_FIELD_INTERLACED; + return 0; +} + +static int vidioc_try_fmt_vid_cap(struct file *file, void *priv, + struct v4l2_format *f) +{ + struct au0828_fh *fh = priv; + struct au0828_dev *dev = fh->dev; + + return au0828_set_format(dev, VIDIOC_TRY_FMT, f); +} + +static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, + struct v4l2_format *f) +{ + struct au0828_fh *fh = priv; + struct au0828_dev *dev = fh->dev; + int rc; + + if (videobuf_queue_is_busy(&fh->vb_vidq)) { + printk(KERN_INFO "%s queue busy\n", __func__); + rc = -EBUSY; + goto out; + } + + if (dev->stream_on && !fh->stream_on) { + printk(KERN_INFO "%s device in use by another fh\n", __func__); + rc = -EBUSY; + goto out; + } + + return au0828_set_format(dev, VIDIOC_S_FMT, f); +out: + return rc; +} + +static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id * norm) +{ + struct au0828_fh *fh = priv; + struct au0828_dev *dev = fh->dev; + + /* FIXME: when we support something other than NTSC, we are going to + have to make the au0828 bridge adjust the size of its capture + buffer, which is currently hardcoded at 720x480 */ + + v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_std, *norm); + return 0; +} + +static int vidioc_enum_input(struct file *file, void *priv, + struct v4l2_input *input) +{ + struct au0828_fh *fh = priv; + struct au0828_dev *dev = fh->dev; + unsigned int tmp; + + static const char *inames[] = { + [AU0828_VMUX_UNDEFINED] = "Undefined", + [AU0828_VMUX_COMPOSITE] = "Composite", + [AU0828_VMUX_SVIDEO] = "S-Video", + [AU0828_VMUX_CABLE] = "Cable TV", + [AU0828_VMUX_TELEVISION] = "Television", + [AU0828_VMUX_DVB] = "DVB", + [AU0828_VMUX_DEBUG] = "tv debug" + }; + + tmp = input->index; + + if (tmp > AU0828_MAX_INPUT) + return -EINVAL; + if (AUVI_INPUT(tmp).type == 0) + return -EINVAL; + + input->index = tmp; + strcpy(input->name, inames[AUVI_INPUT(tmp).type]); + if ((AUVI_INPUT(tmp).type == AU0828_VMUX_TELEVISION) || + (AUVI_INPUT(tmp).type == AU0828_VMUX_CABLE)) + input->type |= V4L2_INPUT_TYPE_TUNER; + else + input->type |= V4L2_INPUT_TYPE_CAMERA; + + input->std = dev->vdev->tvnorms; + + return 0; +} + +static int vidioc_g_input(struct file *file, void *priv, unsigned int *i) +{ + struct au0828_fh *fh = priv; + struct au0828_dev *dev = fh->dev; + *i = dev->ctrl_input; + return 0; +} + +static int vidioc_s_input(struct file *file, void *priv, unsigned int index) +{ + struct au0828_fh *fh = priv; + struct au0828_dev *dev = fh->dev; + int i; + struct v4l2_routing route; + + dprintk(1, "VIDIOC_S_INPUT in function %s, input=%d\n", __func__, + index); + if (index >= AU0828_MAX_INPUT) + return -EINVAL; + if (AUVI_INPUT(index).type == 0) + return -EINVAL; + dev->ctrl_input = index; + + switch (AUVI_INPUT(index).type) { + case AU0828_VMUX_SVIDEO: + dev->input_type = AU0828_VMUX_SVIDEO; + break; + case AU0828_VMUX_COMPOSITE: + dev->input_type = AU0828_VMUX_COMPOSITE; + break; + case AU0828_VMUX_TELEVISION: + dev->input_type = AU0828_VMUX_TELEVISION; + break; + default: + dprintk(1, "VIDIOC_S_INPUT unknown input type set [%d]\n", + AUVI_INPUT(index).type); + break; + } + + route.input = AUVI_INPUT(index).vmux; + route.output = 0; + v4l2_device_call_all(&dev->v4l2_dev, 0, video, s_routing, &route); + + for (i = 0; i < AU0828_MAX_INPUT; i++) { + int enable = 0; + if (AUVI_INPUT(i).audio_setup == NULL) + continue; + + if (i == index) + enable = 1; + else + enable = 0; + if (enable) { + (AUVI_INPUT(i).audio_setup)(dev, enable); + } else { + /* Make sure we leave it turned on if some + other input is routed to this callback */ + if ((AUVI_INPUT(i).audio_setup) != + ((AUVI_INPUT(index).audio_setup))) { + (AUVI_INPUT(i).audio_setup)(dev, enable); + } + } + } + + route.input = AUVI_INPUT(index).amux; + v4l2_device_call_all(&dev->v4l2_dev, 0, audio, s_routing, &route); + return 0; +} + +static int vidioc_g_audio(struct file *file, void *priv, struct v4l2_audio *a) +{ + struct au0828_fh *fh = priv; + struct au0828_dev *dev = fh->dev; + unsigned int index = a->index; + + if (a->index > 1) + return -EINVAL; + + index = dev->ctrl_ainput; + if (index == 0) + strcpy(a->name, "Television"); + else + strcpy(a->name, "Line in"); + + a->capability = V4L2_AUDCAP_STEREO; + a->index = index; + return 0; +} + +static int vidioc_s_audio(struct file *file, void *priv, struct v4l2_audio *a) +{ + struct au0828_fh *fh = priv; + struct au0828_dev *dev = fh->dev; + if (a->index != dev->ctrl_ainput) + return -EINVAL; + return 0; +} + +static int vidioc_g_ctrl(struct file *file, void *priv, + struct v4l2_control *ctrl) +{ + struct au0828_fh *fh = priv; + struct au0828_dev *dev = fh->dev; + + v4l2_device_call_all(&dev->v4l2_dev, 0, core, g_ctrl, ctrl); + return 0; + +} + +static int vidioc_s_ctrl(struct file *file, void *priv, + struct v4l2_control *ctrl) +{ + struct au0828_fh *fh = priv; + struct au0828_dev *dev = fh->dev; + v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_ctrl, ctrl); + return 0; +} + +static int vidioc_g_tuner(struct file *file, void *priv, struct v4l2_tuner *t) +{ + struct au0828_fh *fh = priv; + struct au0828_dev *dev = fh->dev; + + if (t->index != 0) + return -EINVAL; + + strcpy(t->name, "Auvitek tuner"); + v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, g_tuner, t); + return 0; +} + +static int vidioc_s_tuner(struct file *file, void *priv, + struct v4l2_tuner *t) +{ + struct au0828_fh *fh = priv; + struct au0828_dev *dev = fh->dev; + + if (t->index != 0) + return -EINVAL; + + t->type = V4L2_TUNER_ANALOG_TV; + v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_tuner, t); + dprintk(1, "VIDIOC_S_TUNER: signal = %x, afc = %x\n", t->signal, + t->afc); + return 0; + +} + +static int vidioc_g_frequency(struct file *file, void *priv, + struct v4l2_frequency *freq) +{ + struct au0828_fh *fh = priv; + struct au0828_dev *dev = fh->dev; + + freq->type = V4L2_TUNER_ANALOG_TV; + freq->frequency = dev->ctrl_freq; + return 0; +} + +static int vidioc_s_frequency(struct file *file, void *priv, + struct v4l2_frequency *freq) +{ + struct au0828_fh *fh = priv; + struct au0828_dev *dev = fh->dev; + + if (freq->tuner != 0) + return -EINVAL; + if (freq->type != V4L2_TUNER_ANALOG_TV) + return -EINVAL; + + dev->ctrl_freq = freq->frequency; + + v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_frequency, freq); + + au0828_analog_stream_reset(dev); + + return 0; +} + +static int vidioc_g_chip_ident(struct file *file, void *priv, + struct v4l2_dbg_chip_ident *chip) +{ + struct au0828_fh *fh = priv; + struct au0828_dev *dev = fh->dev; + chip->ident = V4L2_IDENT_NONE; + chip->revision = 0; + + if (v4l2_chip_match_host(&chip->match)) { + chip->ident = V4L2_IDENT_AU0828; + return 0; + } + + v4l2_device_call_all(&dev->v4l2_dev, 0, core, g_chip_ident, chip); + if (chip->ident == V4L2_IDENT_NONE) + return -EINVAL; + + return 0; +} + +static int vidioc_cropcap(struct file *file, void *priv, + struct v4l2_cropcap *cc) +{ + struct au0828_fh *fh = priv; + struct au0828_dev *dev = fh->dev; + + if (cc->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) + return -EINVAL; + + cc->bounds.left = 0; + cc->bounds.top = 0; + cc->bounds.width = dev->width; + cc->bounds.height = dev->height; + + cc->defrect = cc->bounds; + + cc->pixelaspect.numerator = 54; + cc->pixelaspect.denominator = 59; + + return 0; +} + +static int vidioc_streamon(struct file *file, void *priv, + enum v4l2_buf_type type) +{ + struct au0828_fh *fh = priv; + struct au0828_dev *dev = fh->dev; + int rc; + + rc = check_dev(dev); + if (rc < 0) + return rc; + + if (type == V4L2_BUF_TYPE_VIDEO_CAPTURE) { + au0828_analog_stream_enable(dev); + v4l2_device_call_all(&dev->v4l2_dev, 0, video, s_stream, 1); + } + + mutex_lock(&dev->lock); + rc = res_get(fh); + + if (likely(rc >= 0)) + rc = videobuf_streamon(&fh->vb_vidq); + mutex_unlock(&dev->lock); + + return rc; +} + +static int vidioc_streamoff(struct file *file, void *priv, + enum v4l2_buf_type type) +{ + struct au0828_fh *fh = priv; + struct au0828_dev *dev = fh->dev; + int i; + int ret; + int rc; + + rc = check_dev(dev); + if (rc < 0) + return rc; + + if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) + return -EINVAL; + if (type != fh->type) + return -EINVAL; + + if (type == V4L2_BUF_TYPE_VIDEO_CAPTURE) { + v4l2_device_call_all(&dev->v4l2_dev, 0, video, s_stream, 0); + ret = au0828_stream_interrupt(dev); + if (ret != 0) + return ret; + } + + for (i = 0; i < AU0828_MAX_INPUT; i++) { + if (AUVI_INPUT(i).audio_setup == NULL) + continue; + (AUVI_INPUT(i).audio_setup)(dev, 0); + } + + mutex_lock(&dev->lock); + videobuf_streamoff(&fh->vb_vidq); + res_free(fh); + mutex_unlock(&dev->lock); + + return 0; +} + +#ifdef CONFIG_VIDEO_ADV_DEBUG +static int vidioc_g_register(struct file *file, void *priv, + struct v4l2_dbg_register *reg) +{ + struct au0828_fh *fh = priv; + struct au0828_dev *dev = fh->dev; + + switch (reg->match.type) { + case V4L2_CHIP_MATCH_I2C_DRIVER: + v4l2_device_call_all(&dev->v4l2_dev, 0, core, g_register, reg); + return 0; + default: + return -EINVAL; + } +} + +static int vidioc_s_register(struct file *file, void *priv, + struct v4l2_dbg_register *reg) +{ + struct au0828_fh *fh = priv; + struct au0828_dev *dev = fh->dev; + + switch (reg->match.type) { + case V4L2_CHIP_MATCH_I2C_DRIVER: + v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_register, reg); + return 0; + default: + return -EINVAL; + } + return 0; +} +#endif + +static int vidioc_reqbufs(struct file *file, void *priv, + struct v4l2_requestbuffers *rb) +{ + struct au0828_fh *fh = priv; + struct au0828_dev *dev = fh->dev; + int rc; + + rc = check_dev(dev); + if (rc < 0) + return rc; + + return videobuf_reqbufs(&fh->vb_vidq, rb); +} + +static int vidioc_querybuf(struct file *file, void *priv, + struct v4l2_buffer *b) +{ + struct au0828_fh *fh = priv; + struct au0828_dev *dev = fh->dev; + int rc; + + rc = check_dev(dev); + if (rc < 0) + return rc; + + return videobuf_querybuf(&fh->vb_vidq, b); +} + +static int vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *b) +{ + struct au0828_fh *fh = priv; + struct au0828_dev *dev = fh->dev; + int rc; + + rc = check_dev(dev); + if (rc < 0) + return rc; + + return videobuf_qbuf(&fh->vb_vidq, b); +} + +static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *b) +{ + struct au0828_fh *fh = priv; + struct au0828_dev *dev = fh->dev; + int rc; + + rc = check_dev(dev); + if (rc < 0) + return rc; + + /* Workaround for a bug in the au0828 hardware design that sometimes + results in the colorspace being inverted */ + if (dev->greenscreen_detected == 1) { + dprintk(1, "Detected green frame. Resetting stream...\n"); + au0828_analog_stream_reset(dev); + dev->greenscreen_detected = 0; + } + + return videobuf_dqbuf(&fh->vb_vidq, b, file->f_flags & O_NONBLOCK); +} + +#ifdef CONFIG_VIDEO_V4L1_COMPAT +static int vidiocgmbuf(struct file *file, void *priv, struct video_mbuf *mbuf) +{ + struct au0828_fh *fh = priv; + + return videobuf_cgmbuf(&fh->vb_vidq, mbuf, 8); +} +#endif + +static struct v4l2_file_operations au0828_v4l_fops = { + .owner = THIS_MODULE, + .open = au0828_v4l2_open, + .release = au0828_v4l2_close, + .read = au0828_v4l2_read, + .poll = au0828_v4l2_poll, + .mmap = au0828_v4l2_mmap, + .ioctl = video_ioctl2, +}; + +static const struct v4l2_ioctl_ops video_ioctl_ops = { + .vidioc_querycap = vidioc_querycap, + .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap, + .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap, + .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap, + .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap, +#ifdef VBI_IS_WORKING + .vidioc_g_fmt_vbi_cap = vidioc_g_fmt_vbi_cap, + .vidioc_try_fmt_vbi_cap = vidioc_s_fmt_vbi_cap, + .vidioc_s_fmt_vbi_cap = vidioc_s_fmt_vbi_cap, +#endif + .vidioc_g_audio = vidioc_g_audio, + .vidioc_s_audio = vidioc_s_audio, + .vidioc_cropcap = vidioc_cropcap, +#ifdef VBI_IS_WORKING + .vidioc_g_fmt_sliced_vbi_cap = vidioc_g_fmt_sliced_vbi_cap, + .vidioc_try_fmt_sliced_vbi_cap = vidioc_try_set_sliced_vbi_cap, + .vidioc_s_fmt_sliced_vbi_cap = vidioc_try_set_sliced_vbi_cap, +#endif + .vidioc_reqbufs = vidioc_reqbufs, + .vidioc_querybuf = vidioc_querybuf, + .vidioc_qbuf = vidioc_qbuf, + .vidioc_dqbuf = vidioc_dqbuf, + .vidioc_s_std = vidioc_s_std, + .vidioc_enum_input = vidioc_enum_input, + .vidioc_g_input = vidioc_g_input, + .vidioc_s_input = vidioc_s_input, + .vidioc_queryctrl = vidioc_queryctrl, + .vidioc_g_ctrl = vidioc_g_ctrl, + .vidioc_s_ctrl = vidioc_s_ctrl, + .vidioc_streamon = vidioc_streamon, + .vidioc_streamoff = vidioc_streamoff, + .vidioc_g_tuner = vidioc_g_tuner, + .vidioc_s_tuner = vidioc_s_tuner, + .vidioc_g_frequency = vidioc_g_frequency, + .vidioc_s_frequency = vidioc_s_frequency, +#ifdef CONFIG_VIDEO_ADV_DEBUG + .vidioc_g_register = vidioc_g_register, + .vidioc_s_register = vidioc_s_register, +#endif + .vidioc_g_chip_ident = vidioc_g_chip_ident, +#ifdef CONFIG_VIDEO_V4L1_COMPAT + .vidiocgmbuf = vidiocgmbuf, +#endif +}; + +static const struct video_device au0828_video_template = { + .fops = &au0828_v4l_fops, + .release = video_device_release, + .ioctl_ops = &video_ioctl_ops, + .minor = -1, + .tvnorms = V4L2_STD_NTSC_M, + .current_norm = V4L2_STD_NTSC_M, +}; + +/**************************************************************************/ + +int au0828_analog_register(struct au0828_dev *dev, + struct usb_interface *interface) +{ + int retval = -ENOMEM; + struct usb_host_interface *iface_desc; + struct usb_endpoint_descriptor *endpoint; + int i; + + dprintk(1, "au0828_analog_register called!\n"); + + /* set au0828 usb interface0 to as5 */ + retval = usb_set_interface(dev->usbdev, + interface->cur_altsetting->desc.bInterfaceNumber, 5); + if (retval != 0) { + printk(KERN_INFO "Failure setting usb interface0 to as5\n"); + return retval; + } + + /* Figure out which endpoint has the isoc interface */ + iface_desc = interface->cur_altsetting; + for (i = 0; i < iface_desc->desc.bNumEndpoints; i++) { + endpoint = &iface_desc->endpoint[i].desc; + if (((endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK) + == USB_DIR_IN) && + ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) + == USB_ENDPOINT_XFER_ISOC)) { + + /* we find our isoc in endpoint */ + u16 tmp = le16_to_cpu(endpoint->wMaxPacketSize); + dev->max_pkt_size = (tmp & 0x07ff) * + (((tmp & 0x1800) >> 11) + 1); + dev->isoc_in_endpointaddr = endpoint->bEndpointAddress; + } + } + if (!(dev->isoc_in_endpointaddr)) { + printk(KERN_INFO "Could not locate isoc endpoint\n"); + kfree(dev); + return -ENODEV; + } + + init_waitqueue_head(&dev->open); + spin_lock_init(&dev->slock); + mutex_init(&dev->lock); + + INIT_LIST_HEAD(&dev->vidq.active); + INIT_LIST_HEAD(&dev->vidq.queued); + + dev->width = NTSC_STD_W; + dev->height = NTSC_STD_H; + dev->field_size = dev->width * dev->height; + dev->frame_size = dev->field_size << 1; + dev->bytesperline = dev->width << 1; + dev->ctrl_ainput = 0; + + /* allocate and fill v4l2 video struct */ + dev->vdev = video_device_alloc(); + if (NULL == dev->vdev) { + dprintk(1, "Can't allocate video_device.\n"); + return -ENOMEM; + } + +#ifdef VBI_IS_WORKING + dev->vbi_dev = video_device_alloc(); + if (NULL == dev->vbi_dev) { + dprintk(1, "Can't allocate vbi_device.\n"); + kfree(dev->vdev); + return -ENOMEM; + } +#endif + + /* Fill the video capture device struct */ + *dev->vdev = au0828_video_template; + dev->vdev->parent = &dev->usbdev->dev; + strcpy(dev->vdev->name, "au0828a video"); + +#ifdef VBI_IS_WORKING + /* Setup the VBI device */ + *dev->vbi_dev = au0828_video_template; + dev->vbi_dev->parent = &dev->usbdev->dev; + strcpy(dev->vbi_dev->name, "au0828a vbi"); +#endif + + list_add_tail(&dev->au0828list, &au0828_devlist); + + /* Register the v4l2 device */ + retval = video_register_device(dev->vdev, VFL_TYPE_GRABBER, -1); + if (retval != 0) { + dprintk(1, "unable to register video device (error = %d).\n", + retval); + list_del(&dev->au0828list); + video_device_release(dev->vdev); + return -ENODEV; + } + +#ifdef VBI_IS_WORKING + /* Register the vbi device */ + retval = video_register_device(dev->vbi_dev, VFL_TYPE_VBI, -1); + if (retval != 0) { + dprintk(1, "unable to register vbi device (error = %d).\n", + retval); + list_del(&dev->au0828list); + video_device_release(dev->vbi_dev); + video_device_release(dev->vdev); + return -ENODEV; + } +#endif + + dprintk(1, "%s completed!\n", __func__); + + return 0; +} + diff --git a/linux/drivers/media/video/au0828/au0828.h b/linux/drivers/media/video/au0828/au0828.h index 9d6a1161d..6ed1a6129 100644 --- a/linux/drivers/media/video/au0828/au0828.h +++ b/linux/drivers/media/video/au0828/au0828.h @@ -24,6 +24,11 @@ #include <linux/i2c-algo-bit.h> #include <media/tveeprom.h> +/* Analog */ +#include <linux/videodev2.h> +#include <media/videobuf-vmalloc.h> +#include <media/v4l2-device.h> + /* DVB */ #include "demux.h" #include "dmxdev.h" @@ -39,8 +44,45 @@ #define URB_COUNT 16 #define URB_BUFSIZE (0xe522) +/* Analog constants */ +#define NTSC_STD_W 720 +#define NTSC_STD_H 480 + +#define AU0828_INTERLACED_DEFAULT 1 +#define V4L2_CID_PRIVATE_SHARPNESS (V4L2_CID_PRIVATE_BASE + 0) + +/* Defination for AU0828 USB transfer */ +#define AU0828_MAX_ISO_BUFS 12 /* maybe resize this value in the future */ +#define AU0828_ISO_PACKETS_PER_URB 10 + +#define AU0828_MIN_BUF 4 +#define AU0828_DEF_BUF 8 + +#define AU0828_MAX_INPUT 4 + +enum au0828_itype { + AU0828_VMUX_UNDEFINED = 0, + AU0828_VMUX_COMPOSITE, + AU0828_VMUX_SVIDEO, + AU0828_VMUX_CABLE, + AU0828_VMUX_TELEVISION, + AU0828_VMUX_DVB, + AU0828_VMUX_DEBUG +}; + +struct au0828_input { + enum au0828_itype type; + unsigned int vmux; + unsigned int amux; + void (*audio_setup) (void *priv, int enable); +}; + struct au0828_board { char *name; + unsigned int tuner_type; + unsigned char tuner_addr; + struct au0828_input input[AU0828_MAX_INPUT]; + }; struct au0828_dvb { @@ -55,31 +97,143 @@ struct au0828_dvb { int feeding; }; +enum au0828_stream_state { + STREAM_OFF, + STREAM_INTERRUPT, + STREAM_ON +}; + +#define AUVI_INPUT(nr) (dev->board.input[nr]) + +/* device state */ +enum au0828_dev_state { + DEV_INITIALIZED = 0x01, + DEV_DISCONNECTED = 0x02, + DEV_MISCONFIGURED = 0x04 +}; + +struct au0828_fh { + struct au0828_dev *dev; + unsigned int stream_on:1; /* Locks streams */ + struct videobuf_queue vb_vidq; + enum v4l2_buf_type type; +}; + +struct au0828_usb_isoc_ctl { + /* max packet size of isoc transaction */ + int max_pkt_size; + + /* number of allocated urbs */ + int num_bufs; + + /* urb for isoc transfers */ + struct urb **urb; + + /* transfer buffers for isoc transfer */ + char **transfer_buffer; + + /* Last buffer command and region */ + u8 cmd; + int pos, size, pktsize; + + /* Last field: ODD or EVEN? */ + int field; + + /* Stores incomplete commands */ + u32 tmp_buf; + int tmp_buf_len; + + /* Stores already requested buffers */ + struct au0828_buffer *buf; + + /* Stores the number of received fields */ + int nfields; + + /* isoc urb callback */ + int (*isoc_copy) (struct au0828_dev *dev, struct urb *urb); + +}; + +/* buffer for one video frame */ +struct au0828_buffer { + /* common v4l buffer stuff -- must be first */ + struct videobuf_buffer vb; + + struct list_head frame; + int top_field; + int receiving; +}; + +struct au0828_dmaqueue { + struct list_head active; + struct list_head queued; + + wait_queue_head_t wq; + + /* Counters to control buffer fill */ + int pos; +}; + struct au0828_dev { struct mutex mutex; struct usb_device *usbdev; - int board; + int boardnr; + struct au0828_board board; u8 ctrlmsg[64]; /* I2C */ struct i2c_adapter i2c_adap; - struct i2c_algo_bit_data i2c_algo; + struct i2c_algorithm i2c_algo; struct i2c_client i2c_client; u32 i2c_rc; /* Digital */ struct au0828_dvb dvb; + /* Analog */ + struct list_head au0828list; + struct v4l2_device v4l2_dev; + int users; + unsigned int stream_on:1; /* Locks streams */ + struct video_device *vdev; + struct video_device *vbi_dev; + int width; + int height; + u32 field_size; + u32 frame_size; + u32 bytesperline; + int type; + u8 ctrl_ainput; + __u8 isoc_in_endpointaddr; + u8 isoc_init_ok; + int greenscreen_detected; + unsigned int frame_count; + int ctrl_freq; + int input_type; + unsigned int ctrl_input; + enum au0828_dev_state dev_state; + enum au0828_stream_state stream_state; + wait_queue_head_t open; + + struct mutex lock; + + /* Isoc control struct */ + struct au0828_dmaqueue vidq; + struct au0828_usb_isoc_ctl isoc_ctl; + spinlock_t slock; + + /* usb transfer */ + int alt; /* alternate */ + int max_pkt_size; /* max packet size of isoc transaction */ + int num_alt; /* Number of alternative settings */ + unsigned int *alt_max_pkt_size; /* array of wMaxPacketSize */ + struct urb *urb[AU0828_MAX_ISO_BUFS]; /* urb for isoc transfers */ + char *transfer_buffer[AU0828_MAX_ISO_BUFS];/* transfer buffers for isoc + transfer */ + /* USB / URB Related */ int urb_streaming; struct urb *urbs[URB_COUNT]; - -}; - -struct au0828_buff { - struct au0828_dev *dev; - struct urb *purb; - struct list_head buff_list; }; /* ----------------------------------------------------------- */ @@ -111,8 +265,13 @@ extern void au0828_card_setup(struct au0828_dev *dev); /* au0828-i2c.c */ extern int au0828_i2c_register(struct au0828_dev *dev); extern int au0828_i2c_unregister(struct au0828_dev *dev); -extern void au0828_call_i2c_clients(struct au0828_dev *dev, - unsigned int cmd, void *arg); + +/* ----------------------------------------------------------- */ +/* au0828-video.c */ +int au0828_analog_register(struct au0828_dev *dev, + struct usb_interface *interface); +int au0828_analog_stream_disable(struct au0828_dev *d); +void au0828_analog_unregister(struct au0828_dev *dev); /* ----------------------------------------------------------- */ /* au0828-dvb.c */ diff --git a/linux/drivers/media/video/bt819.c b/linux/drivers/media/video/bt819.c index 9f9596c7c..b8c084acf 100644 --- a/linux/drivers/media/video/bt819.c +++ b/linux/drivers/media/video/bt819.c @@ -32,13 +32,13 @@ #include <linux/types.h> #include <linux/ioctl.h> #include <linux/delay.h> -#include <asm/uaccess.h> #include <linux/i2c.h> #include <linux/i2c-id.h> #include <linux/videodev2.h> #include <media/v4l2-device.h> #include <media/v4l2-chip-ident.h> #include <media/v4l2-i2c-drv.h> +#include <media/bt819.h> #include "compat.h" MODULE_DESCRIPTION("Brooktree-819 video decoder driver"); @@ -256,7 +256,11 @@ static int bt819_s_std(struct v4l2_subdev *sd, v4l2_std_id std) v4l2_dbg(1, debug, sd, "set norm %llx\n", (unsigned long long)std); + if (sd->v4l2_dev == NULL || sd->v4l2_dev->notify == NULL) + v4l2_err(sd, "no notify found!\n"); + if (std & V4L2_STD_NTSC) { + v4l2_subdev_notify(sd, BT819_FIFO_RESET_LOW, 0); bt819_setbit(decoder, 0x01, 0, 1); bt819_setbit(decoder, 0x01, 1, 0); bt819_setbit(decoder, 0x01, 5, 0); @@ -265,6 +269,7 @@ static int bt819_s_std(struct v4l2_subdev *sd, v4l2_std_id std) /* bt819_setbit(decoder, 0x1a, 5, 1); */ timing = &timing_data[1]; } else if (std & V4L2_STD_PAL) { + v4l2_subdev_notify(sd, BT819_FIFO_RESET_LOW, 0); bt819_setbit(decoder, 0x01, 0, 1); bt819_setbit(decoder, 0x01, 1, 1); bt819_setbit(decoder, 0x01, 5, 1); @@ -289,6 +294,7 @@ static int bt819_s_std(struct v4l2_subdev *sd, v4l2_std_id std) bt819_write(decoder, 0x08, (timing->hscale >> 8) & 0xff); bt819_write(decoder, 0x09, timing->hscale & 0xff); decoder->norm = std; + v4l2_subdev_notify(sd, BT819_FIFO_RESET_HIGH, 0); return 0; } @@ -301,7 +307,11 @@ static int bt819_s_routing(struct v4l2_subdev *sd, const struct v4l2_routing *ro if (route->input < 0 || route->input > 7) return -EINVAL; + if (sd->v4l2_dev == NULL || sd->v4l2_dev->notify == NULL) + v4l2_err(sd, "no notify found!\n"); + if (decoder->input != route->input) { + v4l2_subdev_notify(sd, BT819_FIFO_RESET_LOW, 0); decoder->input = route->input; /* select mode */ if (decoder->input == 0) { @@ -311,6 +321,7 @@ static int bt819_s_routing(struct v4l2_subdev *sd, const struct v4l2_routing *ro bt819_setbit(decoder, 0x0b, 6, 1); bt819_setbit(decoder, 0x1a, 1, 0); } + v4l2_subdev_notify(sd, BT819_FIFO_RESET_HIGH, 0); } return 0; } diff --git a/linux/drivers/media/video/bt8xx/bttv-cards.c b/linux/drivers/media/video/bt8xx/bttv-cards.c index 57448806c..d2136141e 100644 --- a/linux/drivers/media/video/bt8xx/bttv-cards.c +++ b/linux/drivers/media/video/bt8xx/bttv-cards.c @@ -321,6 +321,16 @@ static struct CARD { { 0x763d800b, BTTV_BOARD_GEOVISION_GV800S_SL, "GeoVision GV-800(S) (slave)" }, { 0x763d800c, BTTV_BOARD_GEOVISION_GV800S_SL, "GeoVision GV-800(S) (slave)" }, { 0x763d800d, BTTV_BOARD_GEOVISION_GV800S_SL, "GeoVision GV-800(S) (slave)" }, + + { 0x15401830, BTTV_BOARD_PV183, "Provideo PV183-1" }, + { 0x15401831, BTTV_BOARD_PV183, "Provideo PV183-2" }, + { 0x15401832, BTTV_BOARD_PV183, "Provideo PV183-3" }, + { 0x15401833, BTTV_BOARD_PV183, "Provideo PV183-4" }, + { 0x15401834, BTTV_BOARD_PV183, "Provideo PV183-5" }, + { 0x15401835, BTTV_BOARD_PV183, "Provideo PV183-6" }, + { 0x15401836, BTTV_BOARD_PV183, "Provideo PV183-7" }, + { 0x15401837, BTTV_BOARD_PV183, "Provideo PV183-8" }, + { 0, -1, NULL } }; @@ -2910,6 +2920,20 @@ struct tvcard bttv_tvcards[] = { .no_tda9875 = 1, .muxsel_hook = gv800s_muxsel, }, + [BTTV_BOARD_PV183] = { + .name = "ProVideo PV183", /* 0x9f */ + .video_inputs = 2, + /* .audio_inputs= 0, */ + .svhs = NO_SVHS, + .gpiomask = 0, + .muxsel = MUXSEL(2, 3), + .gpiomux = { 0 }, + .needs_tvaudio = 0, + .no_msp34xx = 1, + .pll = PLL_28, + .tuner_type = TUNER_ABSENT, + .tuner_addr = ADDR_UNSET, + }, }; static const unsigned int bttv_num_tvcards = ARRAY_SIZE(bttv_tvcards); @@ -2953,7 +2977,7 @@ void __devinit bttv_idcard(struct bttv *btv) btv->c.nr, btv->cardid & 0xffff, (btv->cardid >> 16) & 0xffff); printk(KERN_DEBUG "please mail id, board name and " - "the correct card= insmod option to video4linux-list@redhat.com\n"); + "the correct card= insmod option to linux-media@vger.kernel.org\n"); } } diff --git a/linux/drivers/media/video/bt8xx/bttv-driver.c b/linux/drivers/media/video/bt8xx/bttv-driver.c index d34898f95..acb7b5e3d 100644 --- a/linux/drivers/media/video/bt8xx/bttv-driver.c +++ b/linux/drivers/media/video/bt8xx/bttv-driver.c @@ -171,7 +171,7 @@ static ssize_t show_card(struct class_device *cd, char *buf) #endif { struct video_device *vfd = container_of(cd, struct video_device, dev); - struct bttv *btv = dev_get_drvdata(vfd->parent); + struct bttv *btv = video_get_drvdata(vfd); return sprintf(buf, "%d\n", btv ? btv->c.type : UNSET); } #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 19) @@ -3720,14 +3720,14 @@ static void bttv_risc_disasm(struct bttv *btv, unsigned int i,j,n; printk("%s: risc disasm: %p [dma=0x%08lx]\n", - btv->c.name, risc->cpu, (unsigned long)risc->dma); + btv->c.v4l2_dev.name, risc->cpu, (unsigned long)risc->dma); for (i = 0; i < (risc->size >> 2); i += n) { - printk("%s: 0x%lx: ", btv->c.name, + printk("%s: 0x%lx: ", btv->c.v4l2_dev.name, (unsigned long)(risc->dma + (i<<2))); n = bttv_risc_decode(le32_to_cpu(risc->cpu[i])); for (j = 1; j < n; j++) printk("%s: 0x%lx: 0x%08x [ arg #%d ]\n", - btv->c.name, (unsigned long)(risc->dma + ((i+j)<<2)), + btv->c.v4l2_dev.name, (unsigned long)(risc->dma + ((i+j)<<2)), risc->cpu[i+j], j); if (0 == risc->cpu[i]) break; @@ -4207,7 +4207,7 @@ static struct video_device *vdev_init(struct bttv *btv, return NULL; *vfd = *template; vfd->minor = -1; - vfd->parent = &btv->c.pci->dev; + vfd->v4l2_dev = &btv->c.v4l2_dev; vfd->release = video_device_release; vfd->debug = bttv_debug; video_set_drvdata(vfd, btv); @@ -4326,8 +4326,13 @@ static int __devinit bttv_probe(struct pci_dev *dev, return -ENOMEM; printk(KERN_INFO "bttv: Bt8xx card found (%d).\n", bttv_num); bttvs[bttv_num] = btv = kzalloc(sizeof(*btv), GFP_KERNEL); + if (btv == NULL) { + printk(KERN_ERR "bttv: out of memory.\n"); + return -ENOMEM; + } btv->c.nr = bttv_num; - sprintf(btv->c.name,"bttv%d",btv->c.nr); + snprintf(btv->c.v4l2_dev.name, sizeof(btv->c.v4l2_dev.name), + "bttv%d", btv->c.nr); /* initialize structs / fill in defaults */ mutex_init(&btv->lock); @@ -4364,7 +4369,7 @@ static int __devinit bttv_probe(struct pci_dev *dev, } if (!request_mem_region(pci_resource_start(dev,0), pci_resource_len(dev,0), - btv->c.name)) { + btv->c.v4l2_dev.name)) { printk(KERN_WARNING "bttv%d: can't request iomem (0x%llx).\n", btv->c.nr, (unsigned long long)pci_resource_start(dev,0)); @@ -4372,7 +4377,12 @@ static int __devinit bttv_probe(struct pci_dev *dev, } pci_set_master(dev); pci_set_command(dev); - pci_set_drvdata(dev,btv); + + result = v4l2_device_register(&dev->dev, &btv->c.v4l2_dev); + if (result < 0) { + printk(KERN_WARNING "bttv%d: v4l2_device_register() failed\n", btv->c.nr); + goto fail0; + } pci_read_config_byte(dev, PCI_CLASS_REVISION, &btv->revision); pci_read_config_byte(dev, PCI_LATENCY_TIMER, &lat); @@ -4396,7 +4406,7 @@ static int __devinit bttv_probe(struct pci_dev *dev, /* disable irqs, register irq handler */ btwrite(0, BT848_INT_MASK); result = request_irq(btv->c.pci->irq, bttv_irq, - IRQF_SHARED | IRQF_DISABLED,btv->c.name,(void *)btv); + IRQF_SHARED | IRQF_DISABLED, btv->c.v4l2_dev.name, (void *)btv); if (result < 0) { printk(KERN_ERR "bttv%d: can't get IRQ %d\n", bttv_num,btv->c.pci->irq); @@ -4480,21 +4490,24 @@ static int __devinit bttv_probe(struct pci_dev *dev, bttv_num++; return 0; - fail2: +fail2: free_irq(btv->c.pci->irq,btv); - fail1: +fail1: + v4l2_device_unregister(&btv->c.v4l2_dev); + +fail0: if (btv->bt848_mmio) iounmap(btv->bt848_mmio); release_mem_region(pci_resource_start(btv->c.pci,0), pci_resource_len(btv->c.pci,0)); - pci_set_drvdata(dev,NULL); return result; } static void __devexit bttv_remove(struct pci_dev *pci_dev) { - struct bttv *btv = pci_get_drvdata(pci_dev); + struct v4l2_device *v4l2_dev = pci_get_drvdata(pci_dev); + struct bttv *btv = to_bttv(v4l2_dev); if (bttv_verbose) printk("bttv%d: unloading\n",btv->c.nr); @@ -4528,7 +4541,7 @@ static void __devexit bttv_remove(struct pci_dev *pci_dev) release_mem_region(pci_resource_start(btv->c.pci,0), pci_resource_len(btv->c.pci,0)); - pci_set_drvdata(pci_dev, NULL); + v4l2_device_unregister(&btv->c.v4l2_dev); bttvs[btv->c.nr] = NULL; kfree(btv); @@ -4538,7 +4551,8 @@ static void __devexit bttv_remove(struct pci_dev *pci_dev) #ifdef CONFIG_PM static int bttv_suspend(struct pci_dev *pci_dev, pm_message_t state) { - struct bttv *btv = pci_get_drvdata(pci_dev); + struct v4l2_device *v4l2_dev = pci_get_drvdata(pci_dev); + struct bttv *btv = to_bttv(v4l2_dev); struct bttv_buffer_set idle; unsigned long flags; @@ -4573,7 +4587,8 @@ static int bttv_suspend(struct pci_dev *pci_dev, pm_message_t state) static int bttv_resume(struct pci_dev *pci_dev) { - struct bttv *btv = pci_get_drvdata(pci_dev); + struct v4l2_device *v4l2_dev = pci_get_drvdata(pci_dev); + struct bttv *btv = to_bttv(v4l2_dev); unsigned long flags; int err; diff --git a/linux/drivers/media/video/bt8xx/bttv-i2c.c b/linux/drivers/media/video/bt8xx/bttv-i2c.c index 3e7812c5a..c35f09cf4 100644 --- a/linux/drivers/media/video/bt8xx/bttv-i2c.c +++ b/linux/drivers/media/video/bt8xx/bttv-i2c.c @@ -231,7 +231,8 @@ bttv_i2c_readbytes(struct bttv *btv, const struct i2c_msg *msg, int last) static int bttv_i2c_xfer(struct i2c_adapter *i2c_adap, struct i2c_msg *msgs, int num) { - struct bttv *btv = i2c_get_adapdata(i2c_adap); + struct v4l2_device *v4l2_dev = i2c_get_adapdata(i2c_adap); + struct bttv *btv = to_bttv(v4l2_dev); int retval = 0; int i; @@ -270,7 +271,8 @@ static const struct i2c_algorithm bttv_algo = { static int attach_inform(struct i2c_client *client) { - struct bttv *btv = i2c_get_adapdata(client->adapter); + struct v4l2_device *v4l2_dev = i2c_get_adapdata(client->adapter); + struct bttv *btv = to_bttv(v4l2_dev); int addr=ADDR_UNSET; @@ -430,7 +432,7 @@ int __devinit init_bttv_i2c(struct bttv *btv) "bt%d #%d [%s]", btv->id, btv->c.nr, btv->use_i2c_hw ? "hw" : "sw"); - i2c_set_adapdata(&btv->c.i2c_adap, btv); + i2c_set_adapdata(&btv->c.i2c_adap, &btv->c.v4l2_dev); btv->i2c_client.adapter = &btv->c.i2c_adap; if (bttv_tvcards[btv->c.type].no_video) @@ -446,7 +448,7 @@ int __devinit init_bttv_i2c(struct bttv *btv) btv->i2c_rc = i2c_bit_add_bus(&btv->c.i2c_adap); } if (0 == btv->i2c_rc && i2c_scan) - do_i2c_scan(btv->c.name,&btv->i2c_client); + do_i2c_scan(btv->c.v4l2_dev.name, &btv->i2c_client); return btv->i2c_rc; } diff --git a/linux/drivers/media/video/bt8xx/bttv.h b/linux/drivers/media/video/bt8xx/bttv.h index 93a1e989a..947f6e51a 100644 --- a/linux/drivers/media/video/bt8xx/bttv.h +++ b/linux/drivers/media/video/bt8xx/bttv.h @@ -17,6 +17,7 @@ #include <linux/videodev2.h> #include <linux/i2c.h> #include "compat.h" +#include <media/v4l2-device.h> #include <media/ir-common.h> #include <media/ir-kbd-i2c.h> #include <media/i2c-addr.h> @@ -184,6 +185,7 @@ #define BTTV_BOARD_IVCE8784 0x9c #define BTTV_BOARD_GEOVISION_GV800S 0x9d #define BTTV_BOARD_GEOVISION_GV800S_SL 0x9e +#define BTTV_BOARD_PV183 0x9f /* more card-specific defines */ @@ -197,6 +199,7 @@ struct bttv_core { /* device structs */ + struct v4l2_device v4l2_dev; struct pci_dev *pci; struct i2c_adapter i2c_adap; struct list_head subs; /* struct bttv_sub_device */ @@ -204,7 +207,6 @@ struct bttv_core { /* device config */ unsigned int nr; /* dev nr (for printk("bttv%d: ..."); */ unsigned int type; /* card type (pointer into tvcards[]) */ - char name[8]; /* dev name */ }; struct bttv; diff --git a/linux/drivers/media/video/bt8xx/bttvp.h b/linux/drivers/media/video/bt8xx/bttvp.h index 113f28320..5915c261e 100644 --- a/linux/drivers/media/video/bt8xx/bttvp.h +++ b/linux/drivers/media/video/bt8xx/bttvp.h @@ -460,6 +460,11 @@ struct bttv { __s32 crop_start; }; +static inline struct bttv *to_bttv(struct v4l2_device *v4l2_dev) +{ + return container_of(v4l2_dev, struct bttv, c.v4l2_dev); +} + /* our devices */ #define BTTV_MAX 32 extern unsigned int bttv_num; diff --git a/linux/drivers/media/video/cafe_ccic.c b/linux/drivers/media/video/cafe_ccic.c index b6c328187..2619d77ef 100644 --- a/linux/drivers/media/video/cafe_ccic.c +++ b/linux/drivers/media/video/cafe_ccic.c @@ -11,6 +11,12 @@ * * Written by Jonathan Corbet, corbet@lwn.net. * + * v4l2_device/v4l2_subdev conversion by: + * Copyright (C) 2009 Hans Verkuil <hverkuil@xs4all.nl> + * + * Note: this conversion is untested! Please contact the linux-media + * mailinglist if you can test this, together with the test results. + * * This file may be distributed under the terms of the GNU General * Public License, version 2. */ @@ -26,7 +32,7 @@ #include <linux/spinlock.h> #include <linux/videodev2.h> #include "compat.h" -#include <media/v4l2-common.h> +#include <media/v4l2-device.h> #include <media/v4l2-ioctl.h> #include <media/v4l2-chip-ident.h> #include <linux/device.h> @@ -34,7 +40,6 @@ #include <linux/list.h> #include <linux/dma-mapping.h> #include <linux/delay.h> -#include <linux/debugfs.h> #include <linux/jiffies.h> #include <linux/vmalloc.h> @@ -137,6 +142,7 @@ struct cafe_sio_buffer { */ struct cafe_camera { + struct v4l2_device v4l2_dev; enum cafe_state state; unsigned long flags; /* Buffer status, mainly (dev_lock) */ int users; /* How many open FDs */ @@ -146,9 +152,10 @@ struct cafe_camera * Subsystem structures. */ struct pci_dev *pdev; - struct video_device v4ldev; + struct video_device vdev; struct i2c_adapter i2c_adapter; - struct i2c_client *sensor; + struct v4l2_subdev *sensor; + unsigned short sensor_addr; unsigned char __iomem *regs; struct list_head dev_list; /* link to other devices */ @@ -181,10 +188,6 @@ struct cafe_camera /* Misc */ wait_queue_head_t smbus_wait; /* Waiting on i2c events */ wait_queue_head_t iowait; /* Waiting on frame data */ -#ifdef CONFIG_VIDEO_ADV_DEBUG - struct dentry *dfs_regs; - struct dentry *dfs_cam_regs; -#endif }; /* @@ -196,6 +199,13 @@ struct cafe_camera #define CF_DMA_ACTIVE 3 /* A frame is incoming */ #define CF_CONFIG_NEEDED 4 /* Must configure hardware */ +#define sensor_call(cam, o, f, args...) \ + v4l2_subdev_call(cam->sensor, o, f, ##args) + +static inline struct cafe_camera *to_cam(struct v4l2_device *dev) +{ + return container_of(dev, struct cafe_camera, v4l2_dev); +} /* @@ -239,59 +249,7 @@ static void cafe_set_config_needed(struct cafe_camera *cam, int needed) /* ---------------------------------------------------------------------*/ -/* - * We keep a simple list of known devices to search at open time. - */ -static LIST_HEAD(cafe_dev_list); -static DEFINE_MUTEX(cafe_dev_list_lock); - -static void cafe_add_dev(struct cafe_camera *cam) -{ - mutex_lock(&cafe_dev_list_lock); - list_add_tail(&cam->dev_list, &cafe_dev_list); - mutex_unlock(&cafe_dev_list_lock); -} - -static void cafe_remove_dev(struct cafe_camera *cam) -{ - mutex_lock(&cafe_dev_list_lock); - list_del(&cam->dev_list); - mutex_unlock(&cafe_dev_list_lock); -} -static struct cafe_camera *cafe_find_dev(int minor) -{ - struct cafe_camera *cam; - - mutex_lock(&cafe_dev_list_lock); - list_for_each_entry(cam, &cafe_dev_list, dev_list) { - if (cam->v4ldev.minor == minor) - goto done; - } - cam = NULL; - done: - mutex_unlock(&cafe_dev_list_lock); - return cam; -} - - -static struct cafe_camera *cafe_find_by_pdev(struct pci_dev *pdev) -{ - struct cafe_camera *cam; - - mutex_lock(&cafe_dev_list_lock); - list_for_each_entry(cam, &cafe_dev_list, dev_list) { - if (cam->pdev == pdev) - goto done; - } - cam = NULL; - done: - mutex_unlock(&cafe_dev_list_lock); - return cam; -} - - -/* ------------------------------------------------------------------------ */ /* * Device register I/O */ @@ -482,24 +440,11 @@ static int cafe_smbus_xfer(struct i2c_adapter *adapter, u16 addr, unsigned short flags, char rw, u8 command, int size, union i2c_smbus_data *data) { - struct cafe_camera *cam = i2c_get_adapdata(adapter); + struct v4l2_device *v4l2_dev = i2c_get_adapdata(adapter); + struct cafe_camera *cam = to_cam(v4l2_dev); int ret = -EINVAL; /* - * Refuse to talk to anything but OV cam chips. We should - * never even see an attempt to do so, but one never knows. - */ -#if 0 /* client needs to talk during attach process */ - if (! cam->sensor) { - cam_err(cam, "SMBUS xfer with no client\n"); - return -EINVAL; - } -#endif - if (cam->sensor && addr != cam->sensor->addr) { - cam_err(cam, "funky smbus addr %d\n", addr); - return -EINVAL; - } - /* * This interface would appear to only do byte data ops. OK * it can do word too, but the cam chip has no use for that. */ @@ -537,38 +482,9 @@ static struct i2c_algorithm cafe_smbus_algo = { }; /* Somebody is on the bus */ -static int cafe_cam_init(struct cafe_camera *cam); static void cafe_ctlr_stop_dma(struct cafe_camera *cam); static void cafe_ctlr_power_down(struct cafe_camera *cam); -static int cafe_smbus_attach(struct i2c_client *client) -{ - struct cafe_camera *cam = i2c_get_adapdata(client->adapter); - - /* - * Don't talk to chips we don't recognize. - */ - if (client->driver->id == I2C_DRIVERID_OV7670) { - cam->sensor = client; - return cafe_cam_init(cam); - } - return -EINVAL; -} - -static int cafe_smbus_detach(struct i2c_client *client) -{ - struct cafe_camera *cam = i2c_get_adapdata(client->adapter); - - if (cam->sensor == client) { - cafe_ctlr_stop_dma(cam); - cafe_ctlr_power_down(cam); - cam_err(cam, "lost the sensor!\n"); - cam->sensor = NULL; /* Bummer, no camera */ - cam->state = S_NOTREADY; - } - return 0; -} - static int cafe_smbus_setup(struct cafe_camera *cam) { struct i2c_adapter *adap = &cam->i2c_adapter; @@ -577,12 +493,10 @@ static int cafe_smbus_setup(struct cafe_camera *cam) cafe_smbus_enable_irq(cam); adap->id = I2C_HW_SMBUS_CAFE; adap->owner = THIS_MODULE; - adap->client_register = cafe_smbus_attach; - adap->client_unregister = cafe_smbus_detach; adap->algo = &cafe_smbus_algo; strcpy(adap->name, "cafe_ccic"); adap->dev.parent = &cam->pdev->dev; - i2c_set_adapdata(adap, cam); + i2c_set_adapdata(adap, &cam->v4l2_dev); ret = i2c_add_adapter(adap); if (ret) printk(KERN_ERR "Unable to register cafe i2c adapter\n"); @@ -816,9 +730,9 @@ static void cafe_ctlr_power_up(struct cafe_camera *cam) * Control 1 is power down, set to 0 to operate. */ cafe_reg_write(cam, REG_GPR, GPR_C1EN|GPR_C0EN); /* pwr up, reset */ -// mdelay(1); /* Marvell says 1ms will do it */ +/* mdelay(1); */ /* Marvell says 1ms will do it */ cafe_reg_write(cam, REG_GPR, GPR_C1EN|GPR_C0EN|GPR_C0); -// mdelay(1); /* Enough? */ +/* mdelay(1); */ /* Enough? */ spin_unlock_irqrestore(&cam->dev_lock, flags); msleep(5); /* Just to be sure */ } @@ -840,23 +754,9 @@ static void cafe_ctlr_power_down(struct cafe_camera *cam) * Communications with the sensor. */ -static int __cafe_cam_cmd(struct cafe_camera *cam, int cmd, void *arg) -{ - struct i2c_client *sc = cam->sensor; - int ret; - - if (sc == NULL || sc->driver == NULL || sc->driver->command == NULL) - return -EINVAL; - ret = sc->driver->command(sc, cmd, arg); - if (ret == -EPERM) /* Unsupported command */ - return 0; - return ret; -} - static int __cafe_cam_reset(struct cafe_camera *cam) { - int zero = 0; - return __cafe_cam_cmd(cam, VIDIOC_INT_RESET, &zero); + return sensor_call(cam, core, reset, 0); } /* @@ -876,14 +776,13 @@ static int cafe_cam_init(struct cafe_camera *cam) if (ret) goto out; chip.match.type = V4L2_CHIP_MATCH_I2C_ADDR; - chip.match.addr = cam->sensor->addr; - ret = __cafe_cam_cmd(cam, VIDIOC_DBG_G_CHIP_IDENT, &chip); + chip.match.addr = cam->sensor_addr; + ret = sensor_call(cam, core, g_chip_ident, &chip); if (ret) goto out; cam->sensor_type = chip.ident; -// if (cam->sensor->addr != OV7xx0_SID) { if (cam->sensor_type != V4L2_IDENT_OV7670) { - cam_err(cam, "Unsupported sensor type %d", cam->sensor->addr); + cam_err(cam, "Unsupported sensor type 0x%x", cam->sensor_type); ret = -EINVAL; goto out; } @@ -907,21 +806,21 @@ static int cafe_cam_set_flip(struct cafe_camera *cam) memset(&ctrl, 0, sizeof(ctrl)); ctrl.id = V4L2_CID_VFLIP; ctrl.value = flip; - return __cafe_cam_cmd(cam, VIDIOC_S_CTRL, &ctrl); + return sensor_call(cam, core, s_ctrl, &ctrl); } static int cafe_cam_configure(struct cafe_camera *cam) { struct v4l2_format fmt; - int ret, zero = 0; + int ret; if (cam->state != S_IDLE) return -EINVAL; fmt.fmt.pix = cam->pix_format; - ret = __cafe_cam_cmd(cam, VIDIOC_INT_INIT, &zero); + ret = sensor_call(cam, core, init, 0); if (ret == 0) - ret = __cafe_cam_cmd(cam, VIDIOC_S_FMT, &fmt); + ret = sensor_call(cam, video, s_fmt, &fmt); /* * OV7670 does weird things if flip is set *before* format... */ @@ -1481,11 +1380,8 @@ static int cafe_v4l_mmap(struct file *filp, struct vm_area_struct *vma) static int cafe_v4l_open(struct file *filp) { - struct cafe_camera *cam; + struct cafe_camera *cam = video_drvdata(filp); - cam = cafe_find_dev(video_devdata(filp)->minor); - if (cam == NULL) - return -ENODEV; filp->private_data = cam; mutex_lock(&cam->s_mutex); @@ -1539,11 +1435,11 @@ static unsigned int cafe_v4l_poll(struct file *filp, static int cafe_vidioc_queryctrl(struct file *filp, void *priv, struct v4l2_queryctrl *qc) { - struct cafe_camera *cam = filp->private_data; + struct cafe_camera *cam = priv; int ret; mutex_lock(&cam->s_mutex); - ret = __cafe_cam_cmd(cam, VIDIOC_QUERYCTRL, qc); + ret = sensor_call(cam, core, queryctrl, qc); mutex_unlock(&cam->s_mutex); return ret; } @@ -1552,11 +1448,11 @@ static int cafe_vidioc_queryctrl(struct file *filp, void *priv, static int cafe_vidioc_g_ctrl(struct file *filp, void *priv, struct v4l2_control *ctrl) { - struct cafe_camera *cam = filp->private_data; + struct cafe_camera *cam = priv; int ret; mutex_lock(&cam->s_mutex); - ret = __cafe_cam_cmd(cam, VIDIOC_G_CTRL, ctrl); + ret = sensor_call(cam, core, g_ctrl, ctrl); mutex_unlock(&cam->s_mutex); return ret; } @@ -1565,11 +1461,11 @@ static int cafe_vidioc_g_ctrl(struct file *filp, void *priv, static int cafe_vidioc_s_ctrl(struct file *filp, void *priv, struct v4l2_control *ctrl) { - struct cafe_camera *cam = filp->private_data; + struct cafe_camera *cam = priv; int ret; mutex_lock(&cam->s_mutex); - ret = __cafe_cam_cmd(cam, VIDIOC_S_CTRL, ctrl); + ret = sensor_call(cam, core, s_ctrl, ctrl); mutex_unlock(&cam->s_mutex); return ret; } @@ -1611,7 +1507,7 @@ static int cafe_vidioc_enum_fmt_vid_cap(struct file *filp, if (fmt->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) return -EINVAL; mutex_lock(&cam->s_mutex); - ret = __cafe_cam_cmd(cam, VIDIOC_ENUM_FMT, fmt); + ret = sensor_call(cam, video, enum_fmt, fmt); mutex_unlock(&cam->s_mutex); return ret; } @@ -1624,7 +1520,7 @@ static int cafe_vidioc_try_fmt_vid_cap(struct file *filp, void *priv, int ret; mutex_lock(&cam->s_mutex); - ret = __cafe_cam_cmd(cam, VIDIOC_TRY_FMT, fmt); + ret = sensor_call(cam, video, try_fmt, fmt); mutex_unlock(&cam->s_mutex); return ret; } @@ -1733,7 +1629,7 @@ static int cafe_vidioc_g_parm(struct file *filp, void *priv, int ret; mutex_lock(&cam->s_mutex); - ret = __cafe_cam_cmd(cam, VIDIOC_G_PARM, parms); + ret = sensor_call(cam, video, g_parm, parms); mutex_unlock(&cam->s_mutex); parms->parm.capture.readbuffers = n_dma_bufs; return ret; @@ -1746,20 +1642,52 @@ static int cafe_vidioc_s_parm(struct file *filp, void *priv, int ret; mutex_lock(&cam->s_mutex); - ret = __cafe_cam_cmd(cam, VIDIOC_S_PARM, parms); + ret = sensor_call(cam, video, s_parm, parms); mutex_unlock(&cam->s_mutex); parms->parm.capture.readbuffers = n_dma_bufs; return ret; } +static int cafe_vidioc_g_chip_ident(struct file *file, void *priv, + struct v4l2_dbg_chip_ident *chip) +{ + struct cafe_camera *cam = priv; + + chip->ident = V4L2_IDENT_NONE; + chip->revision = 0; + if (v4l2_chip_match_host(&chip->match)) { + chip->ident = V4L2_IDENT_CAFE; + return 0; + } + return sensor_call(cam, core, g_chip_ident, chip); +} -static void cafe_v4l_dev_release(struct video_device *vd) +#ifdef CONFIG_VIDEO_ADV_DEBUG +static int cafe_vidioc_g_register(struct file *file, void *priv, + struct v4l2_dbg_register *reg) { - struct cafe_camera *cam = container_of(vd, struct cafe_camera, v4ldev); + struct cafe_camera *cam = priv; - kfree(cam); + if (v4l2_chip_match_host(®->match)) { + reg->val = cafe_reg_read(cam, reg->reg); + reg->size = 4; + return 0; + } + return sensor_call(cam, core, g_register, reg); } +static int cafe_vidioc_s_register(struct file *file, void *priv, + struct v4l2_dbg_register *reg) +{ + struct cafe_camera *cam = priv; + + if (v4l2_chip_match_host(®->match)) { + cafe_reg_write(cam, reg->reg, reg->val); + return 0; + } + return sensor_call(cam, core, s_register, reg); +} +#endif /* * This template device holds all of those v4l2 methods; we @@ -1797,6 +1725,11 @@ static const struct v4l2_ioctl_ops cafe_v4l_ioctl_ops = { .vidioc_s_ctrl = cafe_vidioc_s_ctrl, .vidioc_g_parm = cafe_vidioc_g_parm, .vidioc_s_parm = cafe_vidioc_s_parm, + .vidioc_g_chip_ident = cafe_vidioc_g_chip_ident, +#ifdef CONFIG_VIDEO_ADV_DEBUG + .vidioc_g_register = cafe_vidioc_g_register, + .vidioc_s_register = cafe_vidioc_s_register, +#endif }; static struct video_device cafe_v4l_template = { @@ -1807,15 +1740,10 @@ static struct video_device cafe_v4l_template = { .fops = &cafe_v4l_fops, .ioctl_ops = &cafe_v4l_ioctl_ops, - .release = cafe_v4l_dev_release, + .release = video_device_release_empty, }; - - - - - /* ---------------------------------------------------------------------- */ /* * Interrupt handler stuff @@ -1969,127 +1897,6 @@ static irqreturn_t cafe_irq(int irq, void *data) /* -------------------------------------------------------------------------- */ -#ifdef CONFIG_VIDEO_ADV_DEBUG -/* - * Debugfs stuff. - */ - -static char cafe_debug_buf[1024]; -static struct dentry *cafe_dfs_root; - -static void cafe_dfs_setup(void) -{ - cafe_dfs_root = debugfs_create_dir("cafe_ccic", NULL); - if (IS_ERR(cafe_dfs_root)) { - cafe_dfs_root = NULL; /* Never mind */ - printk(KERN_NOTICE "cafe_ccic unable to set up debugfs\n"); - } -} - -static void cafe_dfs_shutdown(void) -{ - if (cafe_dfs_root) - debugfs_remove(cafe_dfs_root); -} - -static int cafe_dfs_open(struct inode *inode, struct file *file) -{ - file->private_data = inode->i_private; - return 0; -} - -static ssize_t cafe_dfs_read_regs(struct file *file, - char __user *buf, size_t count, loff_t *ppos) -{ - struct cafe_camera *cam = file->private_data; - char *s = cafe_debug_buf; - int offset; - - for (offset = 0; offset < 0x44; offset += 4) - s += sprintf(s, "%02x: %08x\n", offset, - cafe_reg_read(cam, offset)); - for (offset = 0x88; offset <= 0x90; offset += 4) - s += sprintf(s, "%02x: %08x\n", offset, - cafe_reg_read(cam, offset)); - for (offset = 0xb4; offset <= 0xbc; offset += 4) - s += sprintf(s, "%02x: %08x\n", offset, - cafe_reg_read(cam, offset)); - for (offset = 0x3000; offset <= 0x300c; offset += 4) - s += sprintf(s, "%04x: %08x\n", offset, - cafe_reg_read(cam, offset)); - return simple_read_from_buffer(buf, count, ppos, cafe_debug_buf, - s - cafe_debug_buf); -} - -static const struct file_operations cafe_dfs_reg_ops = { - .owner = THIS_MODULE, - .read = cafe_dfs_read_regs, - .open = cafe_dfs_open -}; - -static ssize_t cafe_dfs_read_cam(struct file *file, - char __user *buf, size_t count, loff_t *ppos) -{ - struct cafe_camera *cam = file->private_data; - char *s = cafe_debug_buf; - int offset; - - if (! cam->sensor) - return -EINVAL; - for (offset = 0x0; offset < 0x8a; offset++) - { - u8 v; - - cafe_smbus_read_data(cam, cam->sensor->addr, offset, &v); - s += sprintf(s, "%02x: %02x\n", offset, v); - } - return simple_read_from_buffer(buf, count, ppos, cafe_debug_buf, - s - cafe_debug_buf); -} - -static const struct file_operations cafe_dfs_cam_ops = { - .owner = THIS_MODULE, - .read = cafe_dfs_read_cam, - .open = cafe_dfs_open -}; - - - -static void cafe_dfs_cam_setup(struct cafe_camera *cam) -{ - char fname[40]; - - if (!cafe_dfs_root) - return; - sprintf(fname, "regs-%d", cam->v4ldev.num); - cam->dfs_regs = debugfs_create_file(fname, 0444, cafe_dfs_root, - cam, &cafe_dfs_reg_ops); - sprintf(fname, "cam-%d", cam->v4ldev.num); - cam->dfs_cam_regs = debugfs_create_file(fname, 0444, cafe_dfs_root, - cam, &cafe_dfs_cam_ops); -} - - -static void cafe_dfs_cam_shutdown(struct cafe_camera *cam) -{ - if (! IS_ERR(cam->dfs_regs)) - debugfs_remove(cam->dfs_regs); - if (! IS_ERR(cam->dfs_cam_regs)) - debugfs_remove(cam->dfs_cam_regs); -} - -#else - -#define cafe_dfs_setup() -#define cafe_dfs_shutdown() -#define cafe_dfs_cam_setup(cam) -#define cafe_dfs_cam_shutdown(cam) -#endif /* CONFIG_VIDEO_ADV_DEBUG */ - - - - -/* ------------------------------------------------------------------------*/ /* * PCI interface stuff. */ @@ -2107,6 +1914,10 @@ static int cafe_pci_probe(struct pci_dev *pdev, cam = kzalloc(sizeof(struct cafe_camera), GFP_KERNEL); if (cam == NULL) goto out; + ret = v4l2_device_register(&pdev->dev, &cam->v4l2_dev); + if (ret) + goto out_free; + mutex_init(&cam->s_mutex); mutex_lock(&cam->s_mutex); spin_lock_init(&cam->dev_lock); @@ -2125,14 +1936,14 @@ static int cafe_pci_probe(struct pci_dev *pdev, */ ret = pci_enable_device(pdev); if (ret) - goto out_free; + goto out_unreg; pci_set_master(pdev); ret = -EIO; cam->regs = pci_iomap(pdev, 0, 0); if (! cam->regs) { printk(KERN_ERR "Unable to ioremap cafe-ccic regs\n"); - goto out_free; + goto out_unreg; } ret = request_irq(pdev->irq, cafe_irq, IRQF_SHARED, "cafe-ccic", cam); if (ret) @@ -2152,17 +1963,31 @@ static int cafe_pci_probe(struct pci_dev *pdev, ret = cafe_smbus_setup(cam); if (ret) goto out_freeirq; + + cam->sensor_addr = 0x42; + cam->sensor = v4l2_i2c_new_subdev(&cam->i2c_adapter, + "ov7670", "ov7670", cam->sensor_addr); + if (cam->sensor == NULL) { + ret = -ENODEV; + goto out_smbus; + } + ret = cafe_cam_init(cam); + if (ret) + goto out_smbus; + /* * Get the v4l2 setup done. */ mutex_lock(&cam->s_mutex); - cam->v4ldev = cafe_v4l_template; - cam->v4ldev.debug = 0; -// cam->v4ldev.debug = V4L2_DEBUG_IOCTL_ARG; - cam->v4ldev.parent = &pdev->dev; - ret = video_register_device(&cam->v4ldev, VFL_TYPE_GRABBER, -1); + cam->vdev = cafe_v4l_template; + cam->vdev.debug = 0; +/* cam->vdev.debug = V4L2_DEBUG_IOCTL_ARG;*/ + cam->vdev.v4l2_dev = &cam->v4l2_dev; + ret = video_register_device(&cam->vdev, VFL_TYPE_GRABBER, -1); if (ret) goto out_smbus; + video_set_drvdata(&cam->vdev, cam); + /* * If so requested, try to get our DMA buffers now. */ @@ -2172,21 +1997,21 @@ static int cafe_pci_probe(struct pci_dev *pdev, " will try again later."); } - cafe_dfs_cam_setup(cam); mutex_unlock(&cam->s_mutex); - cafe_add_dev(cam); return 0; - out_smbus: +out_smbus: cafe_smbus_shutdown(cam); - out_freeirq: +out_freeirq: cafe_ctlr_power_down(cam); free_irq(pdev->irq, cam); - out_iounmap: +out_iounmap: pci_iounmap(pdev, cam->regs); - out_free: +out_free: + v4l2_device_unregister(&cam->v4l2_dev); +out_unreg: kfree(cam); - out: +out: return ret; } @@ -2197,25 +2022,23 @@ static int cafe_pci_probe(struct pci_dev *pdev, static void cafe_shutdown(struct cafe_camera *cam) { /* FIXME: Make sure we take care of everything here */ - cafe_dfs_cam_shutdown(cam); if (cam->n_sbufs > 0) /* What if they are still mapped? Shouldn't be, but... */ cafe_free_sio_buffers(cam); - cafe_remove_dev(cam); cafe_ctlr_stop_dma(cam); cafe_ctlr_power_down(cam); cafe_smbus_shutdown(cam); cafe_free_dma_bufs(cam); free_irq(cam->pdev->irq, cam); pci_iounmap(cam->pdev, cam->regs); - video_unregister_device(&cam->v4ldev); - /* kfree(cam); done in v4l_release () */ + video_unregister_device(&cam->vdev); } static void cafe_pci_remove(struct pci_dev *pdev) { - struct cafe_camera *cam = cafe_find_by_pdev(pdev); + struct v4l2_device *v4l2_dev = dev_get_drvdata(&pdev->dev); + struct cafe_camera *cam = to_cam(v4l2_dev); if (cam == NULL) { printk(KERN_WARNING "pci_remove on unknown pdev %p\n", pdev); @@ -2225,6 +2048,8 @@ static void cafe_pci_remove(struct pci_dev *pdev) if (cam->users > 0) cam_warn(cam, "Removing a device with users!\n"); cafe_shutdown(cam); + v4l2_device_unregister(&cam->v4l2_dev); + kfree(cam); /* No unlock - it no longer exists */ } @@ -2235,7 +2060,8 @@ static void cafe_pci_remove(struct pci_dev *pdev) */ static int cafe_pci_suspend(struct pci_dev *pdev, pm_message_t state) { - struct cafe_camera *cam = cafe_find_by_pdev(pdev); + struct v4l2_device *v4l2_dev = dev_get_drvdata(&pdev->dev); + struct cafe_camera *cam = to_cam(v4l2_dev); int ret; enum cafe_state cstate; @@ -2253,7 +2079,8 @@ static int cafe_pci_suspend(struct pci_dev *pdev, pm_message_t state) static int cafe_pci_resume(struct pci_dev *pdev) { - struct cafe_camera *cam = cafe_find_by_pdev(pdev); + struct v4l2_device *v4l2_dev = dev_get_drvdata(&pdev->dev); + struct cafe_camera *cam = to_cam(v4l2_dev); int ret = 0; ret = pci_restore_state(pdev); @@ -2314,13 +2141,11 @@ static int __init cafe_init(void) printk(KERN_NOTICE "Marvell M88ALP01 'CAFE' Camera Controller version %d\n", CAFE_VERSION); - cafe_dfs_setup(); ret = pci_register_driver(&cafe_pci_driver); if (ret) { printk(KERN_ERR "Unable to register cafe_ccic driver\n"); goto out; } - request_module("ov7670"); /* FIXME want something more general */ ret = 0; out: @@ -2331,7 +2156,6 @@ static int __init cafe_init(void) static void __exit cafe_exit(void) { pci_unregister_driver(&cafe_pci_driver); - cafe_dfs_shutdown(); } module_init(cafe_init); diff --git a/linux/drivers/media/video/cx18/Kconfig b/linux/drivers/media/video/cx18/Kconfig index 8940b5387..e8a50a611 100644 --- a/linux/drivers/media/video/cx18/Kconfig +++ b/linux/drivers/media/video/cx18/Kconfig @@ -9,7 +9,7 @@ config VIDEO_CX18 select VIDEO_CX2341X select VIDEO_CS5345 select DVB_S5H1409 if !DVB_FE_CUSTOMISE - select MEDIA_TUNER_MXL5005S if !MEDIA_TUNER_CUSTOMIZE + select MEDIA_TUNER_MXL5005S if !MEDIA_TUNER_CUSTOMISE ---help--- This is a video4linux driver for Conexant cx23418 based PCI combo video recorder devices. diff --git a/linux/drivers/media/video/cx18/cx18-vbi.c b/linux/drivers/media/video/cx18/cx18-vbi.c index 355737bff..c2aef4add 100644 --- a/linux/drivers/media/video/cx18/cx18-vbi.c +++ b/linux/drivers/media/video/cx18/cx18-vbi.c @@ -88,6 +88,8 @@ static void copy_vbi_data(struct cx18 *cx, int lines, u32 pts_stamp) size = 4 + ((43 * line + 3) & ~3); } else { memcpy(dst + sd, "itv0", 4); + cpu_to_le32s(&linemask[0]); + cpu_to_le32s(&linemask[1]); memcpy(dst + sd + 4, &linemask[0], 8); size = 12 + ((43 * line + 3) & ~3); } @@ -103,54 +105,72 @@ static void copy_vbi_data(struct cx18 *cx, int lines, u32 pts_stamp) /* Compress raw VBI format, removes leading SAV codes and surplus space after the frame. Returns new compressed size. */ -static u32 compress_raw_buf(struct cx18 *cx, u8 *buf, u32 size) +static u32 compress_raw_buf(struct cx18 *cx, u8 *buf, u32 size, u32 hdr_size) { u32 line_size = vbi_active_samples; u32 lines = cx->vbi.count * 2; - u8 sav1 = raw_vbi_sav_rp[0]; - u8 sav2 = raw_vbi_sav_rp[1]; u8 *q = buf; u8 *p; int i; + /* Skip the header */ + buf += hdr_size; + for (i = 0; i < lines; i++) { p = buf + i * line_size; /* Look for SAV code */ if (p[0] != 0xff || p[1] || p[2] || - (p[3] != sav1 && p[3] != sav2)) + (p[3] != raw_vbi_sav_rp[0] && + p[3] != raw_vbi_sav_rp[1])) break; - memcpy(q, p + 4, line_size - 4); - q += line_size - 4; + if (i == lines - 1) { + /* last line is hdr_size bytes short - extrapolate it */ + memcpy(q, p + 4, line_size - 4 - hdr_size); + q += line_size - 4 - hdr_size; + p += line_size - hdr_size - 1; + memset(q, (int) *p, hdr_size); + } else { + memcpy(q, p + 4, line_size - 4); + q += line_size - 4; + } } return lines * (line_size - 4); } - -/* Compressed VBI format, all found sliced blocks put next to one another - Returns new compressed size */ -static u32 compress_sliced_buf(struct cx18 *cx, u32 line, u8 *buf, - u32 size, u8 eav) +static u32 compress_sliced_buf(struct cx18 *cx, u8 *buf, u32 size, + const u32 hdr_size) { struct v4l2_decode_vbi_line vbi; int i; + u32 line = 0; u32 line_size = cx->is_60hz ? vbi_hblank_samples_60Hz : vbi_hblank_samples_50Hz; /* find the first valid line */ - for (i = 0; i < size; i++, buf++) { - if (buf[0] == 0xff && !buf[1] && !buf[2] && buf[3] == eav) + for (i = hdr_size, buf += hdr_size; i < size; i++, buf++) { + if (buf[0] == 0xff && !buf[1] && !buf[2] && + (buf[3] == sliced_vbi_eav_rp[0] || + buf[3] == sliced_vbi_eav_rp[1])) break; } - size -= i; + /* + * The last line is short by hdr_size bytes, but for the remaining + * checks against size, we pretend that it is not, by counting the + * header bytes we knowingly skipped + */ + size -= (i - hdr_size); if (size < line_size) return line; + for (i = 0; i < size / line_size; i++) { u8 *p = buf + i * line_size; /* Look for EAV code */ - if (p[0] != 0xff || p[1] || p[2] || p[3] != eav) + if (p[0] != 0xff || p[1] || p[2] || + (p[3] != sliced_vbi_eav_rp[0] && + p[3] != sliced_vbi_eav_rp[1])) continue; vbi.p = p + 4; v4l2_subdev_call(cx->sd_av, video, decode_vbi_line, &vbi); @@ -168,8 +188,17 @@ static u32 compress_sliced_buf(struct cx18 *cx, u32 line, u8 *buf, void cx18_process_vbi_data(struct cx18 *cx, struct cx18_buffer *buf, int streamtype) { + /* + * The CX23418 provides a 12 byte header in its raw VBI buffers to us: + * 0x3fffffff [4 bytes of something] [4 byte presentation time stamp] + */ + struct vbi_data_hdr { + __be32 magic; + __be32 unknown; + __be32 pts; + } *hdr = (struct vbi_data_hdr *) buf->buf; + u8 *p = (u8 *) buf->buf; - __be32 *q = (__be32 *) buf->buf; u32 size = buf->bytesused; u32 pts; int lines; @@ -180,32 +209,15 @@ void cx18_process_vbi_data(struct cx18 *cx, struct cx18_buffer *buf, /* * The CX23418 sends us data that is 32 bit little-endian swapped, * but we want the raw VBI bytes in the order they were in the raster - * line. This has a side effect of making the 12 byte header big endian + * line. This has a side effect of making the header big endian */ cx18_buf_swap(buf); - /* - * The CX23418 provides a 12 byte header in it's raw VBI buffers to us: - * 0x3fffffff [4 bytes of something] [4 byte presentation time stamp?] - */ - /* Raw VBI data */ if (cx18_raw_vbi(cx)) { - u8 type; - - /* - * We've set up to get a frame's worth of VBI data at a time. - * Skip 12 bytes of header prefixing the first field. - */ - size -= 12; - memcpy(p, &buf->buf[12], size); - type = p[3]; - /* Extrapolate the last 12 bytes of the frame's last line */ - memset(&p[size], (int) p[size - 1], 12); - size += 12; - - size = buf->bytesused = compress_raw_buf(cx, p, size); + size = buf->bytesused = + compress_raw_buf(cx, p, size, sizeof(struct vbi_data_hdr)); /* * Hack needed for compatibility with old VBI software. @@ -219,26 +231,11 @@ void cx18_process_vbi_data(struct cx18 *cx, struct cx18_buffer *buf, /* Sliced VBI data with data insertion */ - pts = (be32_to_cpu(q[0]) == 0x3fffffff) ? be32_to_cpu(q[2]) : 0; + pts = (be32_to_cpu(hdr->magic) == 0x3fffffff) ? be32_to_cpu(hdr->pts) + : 0; - /* - * For calls to compress_sliced_buf(), ensure there are an integral - * number of lines by shifting the real data up over the 12 bytes header - * that got stuffed in. - * FIXME - there's a smarter way to do this with pointers, but for some - * reason I can't get it to work correctly right now. - */ - memcpy(p, &buf->buf[12], size-12); + lines = compress_sliced_buf(cx, p, size, sizeof(struct vbi_data_hdr)); - /* first field */ - lines = compress_sliced_buf(cx, 0, p, size / 2, sliced_vbi_eav_rp[0]); - /* - * second field - * In case the second half does not always begin at the exact address, - * start a bit earlier (hence 32). - */ - lines = compress_sliced_buf(cx, lines, p + size / 2 - 32, - size / 2 + 32, sliced_vbi_eav_rp[1]); /* always return at least one empty line */ if (lines == 0) { cx->vbi.sliced_data[0].id = 0; diff --git a/linux/drivers/media/video/cx231xx/Kconfig b/linux/drivers/media/video/cx231xx/Kconfig index 7a6700fb0..477d4ab5e 100644 --- a/linux/drivers/media/video/cx231xx/Kconfig +++ b/linux/drivers/media/video/cx231xx/Kconfig @@ -1,35 +1,35 @@ config VIDEO_CX231XX - tristate "Conexant cx231xx USB video capture support" - depends on VIDEO_DEV && I2C && INPUT - select VIDEO_TUNER - select VIDEO_TVEEPROM - select VIDEO_IR - select VIDEOBUF_VMALLOC - select VIDEO_CX25840 - select VIDEO_CX231XX_ALSA + tristate "Conexant cx231xx USB video capture support" + depends on VIDEO_DEV && I2C && INPUT + select VIDEO_TUNER + select VIDEO_TVEEPROM + select VIDEO_IR + select VIDEOBUF_VMALLOC + select VIDEO_CX25840 - ---help--- - This is a video4linux driver for Conexant 231xx USB based TV cards. + ---help--- + This is a video4linux driver for Conexant 231xx USB based TV cards. - To compile this driver as a module, choose M here: the - module will be called cx231xx + To compile this driver as a module, choose M here: the + module will be called cx231xx config VIDEO_CX231XX_ALSA - tristate "Conexant Cx231xx ALSA audio module" - depends on VIDEO_CX231XX && SND - select SND_PCM + tristate "Conexant Cx231xx ALSA audio module" + depends on VIDEO_CX231XX && SND + select SND_PCM - ---help--- - This is an ALSA driver for Cx231xx USB based TV cards. + ---help--- + This is an ALSA driver for Cx231xx USB based TV cards. - To compile this driver as a module, choose M here: the - module will be called cx231xx-alsa + To compile this driver as a module, choose M here: the + module will be called cx231xx-alsa config VIDEO_CX231XX_DVB - tristate "DVB/ATSC Support for Cx231xx based TV cards" - depends on VIDEO_CX231XX && DVB_CORE - select VIDEOBUF_DVB - select MEDIA_TUNER_XC5000 if !DVB_FE_CUSTOMISE - ---help--- - This adds support for DVB cards based on the - Conexant cx231xx chips. + tristate "DVB/ATSC Support for Cx231xx based TV cards" + depends on VIDEO_CX231XX && DVB_CORE + select VIDEOBUF_DVB + select MEDIA_TUNER_XC5000 if !DVB_FE_CUSTOMISE + + ---help--- + This adds support for DVB cards based on the + Conexant cx231xx chips. diff --git a/linux/drivers/media/video/cx231xx/Makefile b/linux/drivers/media/video/cx231xx/Makefile index 1dad93619..755dd0ce6 100644 --- a/linux/drivers/media/video/cx231xx/Makefile +++ b/linux/drivers/media/video/cx231xx/Makefile @@ -1,8 +1,10 @@ cx231xx-objs := cx231xx-video.o cx231xx-i2c.o cx231xx-cards.o cx231xx-core.o \ cx231xx-avcore.o cx231xx-pcb-cfg.o cx231xx-vbi.o +cx231xx-alsa-objs := cx231xx-audio.o + obj-$(CONFIG_VIDEO_CX231XX) += cx231xx.o -obj-$(CONFIG_VIDEO_CX231XX_ALSA) += cx231xx-audio.o +obj-$(CONFIG_VIDEO_CX231XX_ALSA) += cx231xx-alsa.o obj-$(CONFIG_VIDEO_CX231XX_DVB) += cx231xx-dvb.o EXTRA_CFLAGS += -Idrivers/media/video diff --git a/linux/drivers/media/video/cx231xx/cx231xx-audio.c b/linux/drivers/media/video/cx231xx/cx231xx-audio.c index b6f099042..0f7fb3ca7 100644 --- a/linux/drivers/media/video/cx231xx/cx231xx-audio.c +++ b/linux/drivers/media/video/cx231xx/cx231xx-audio.c @@ -599,7 +599,7 @@ static int cx231xx_audio_init(struct cx231xx *dev) bEndpointAddress); adev->num_alt = uif->num_altsetting; - cx231xx_info(": EndPoint Addr 0x%x, Alternate settings: %i\n", + cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n", adev->end_point_addr, adev->num_alt); adev->alt_max_pkt_size = kmalloc(32 * adev->num_alt, GFP_KERNEL); diff --git a/linux/drivers/media/video/cx231xx/cx231xx-avcore.c b/linux/drivers/media/video/cx231xx/cx231xx-avcore.c index 226299d62..1be3881be 100644 --- a/linux/drivers/media/video/cx231xx/cx231xx-avcore.c +++ b/linux/drivers/media/video/cx231xx/cx231xx-avcore.c @@ -40,54 +40,77 @@ #include "cx231xx.h" /****************************************************************************** - * C O L I B R I - B L O C K C O N T R O L functions * + -: BLOCK ARRANGEMENT :- + I2S block ----------------------| + [I2S audio] | + | + Analog Front End --> Direct IF -|-> Cx25840 --> Audio + [video & audio] | [Audio] + | + |-> Cx25840 --> Video + [Video] + +*******************************************************************************/ + +/****************************************************************************** + * A F E - B L O C K C O N T R O L functions * + * [ANALOG FRONT END] * ******************************************************************************/ -int cx231xx_colibri_init_super_block(struct cx231xx *dev, u32 ref_count) +static int afe_write_byte(struct cx231xx *dev, u16 saddr, u8 data) +{ + return cx231xx_write_i2c_data(dev, AFE_DEVICE_ADDRESS, + saddr, 2, data, 1); +} + +static int afe_read_byte(struct cx231xx *dev, u16 saddr, u8 *data) +{ + int status; + u32 temp = 0; + + status = cx231xx_read_i2c_data(dev, AFE_DEVICE_ADDRESS, + saddr, 2, &temp, 1); + *data = (u8) temp; + return status; +} + +int cx231xx_afe_init_super_block(struct cx231xx *dev, u32 ref_count) { int status = 0; u8 temp = 0; - u32 colibri_power_status = 0; + u8 afe_power_status = 0; int i = 0; /* super block initialize */ temp = (u8) (ref_count & 0xff); - status = cx231xx_write_i2c_data(dev, Colibri_DEVICE_ADDRESS, - SUP_BLK_TUNE2, 2, temp, 1); + status = afe_write_byte(dev, SUP_BLK_TUNE2, temp); if (status < 0) return status; - status = cx231xx_read_i2c_data(dev, Colibri_DEVICE_ADDRESS, - SUP_BLK_TUNE2, 2, - &colibri_power_status, 1); + status = afe_read_byte(dev, SUP_BLK_TUNE2, &afe_power_status); if (status < 0) return status; temp = (u8) ((ref_count & 0x300) >> 8); temp |= 0x40; - status = cx231xx_write_i2c_data(dev, Colibri_DEVICE_ADDRESS, - SUP_BLK_TUNE1, 2, temp, 1); + status = afe_write_byte(dev, SUP_BLK_TUNE1, temp); if (status < 0) return status; - status = cx231xx_write_i2c_data(dev, Colibri_DEVICE_ADDRESS, - SUP_BLK_PLL2, 2, 0x0f, 1); + status = afe_write_byte(dev, SUP_BLK_PLL2, 0x0f); if (status < 0) return status; /* enable pll */ - while (colibri_power_status != 0x18) { - status = cx231xx_write_i2c_data(dev, Colibri_DEVICE_ADDRESS, - SUP_BLK_PWRDN, 2, 0x18, 1); + while (afe_power_status != 0x18) { + status = afe_write_byte(dev, SUP_BLK_PWRDN, 0x18); if (status < 0) { cx231xx_info( ": Init Super Block failed in send cmd\n"); break; } - status = cx231xx_read_i2c_data(dev, Colibri_DEVICE_ADDRESS, - SUP_BLK_PWRDN, 2, - &colibri_power_status, 1); - colibri_power_status &= 0xff; + status = afe_read_byte(dev, SUP_BLK_PWRDN, &afe_power_status); + afe_power_status &= 0xff; if (status < 0) { cx231xx_info( ": Init Super Block failed in receive cmd\n"); @@ -106,101 +129,75 @@ int cx231xx_colibri_init_super_block(struct cx231xx *dev, u32 ref_count) return status; /* start tuning filter */ - status = cx231xx_write_i2c_data(dev, Colibri_DEVICE_ADDRESS, - SUP_BLK_TUNE3, 2, 0x40, 1); + status = afe_write_byte(dev, SUP_BLK_TUNE3, 0x40); if (status < 0) return status; msleep(5); /* exit tuning */ - status = - cx231xx_write_i2c_data(dev, Colibri_DEVICE_ADDRESS, SUP_BLK_TUNE3, - 2, 0x00, 1); + status = afe_write_byte(dev, SUP_BLK_TUNE3, 0x00); return status; } -int cx231xx_colibri_init_channels(struct cx231xx *dev) +int cx231xx_afe_init_channels(struct cx231xx *dev) { int status = 0; /* power up all 3 channels, clear pd_buffer */ - status = cx231xx_write_i2c_data(dev, Colibri_DEVICE_ADDRESS, - ADC_PWRDN_CLAMP_CH1, 2, 0x00, 1); - status = cx231xx_write_i2c_data(dev, Colibri_DEVICE_ADDRESS, - ADC_PWRDN_CLAMP_CH2, 2, 0x00, 1); - status = cx231xx_write_i2c_data(dev, Colibri_DEVICE_ADDRESS, - ADC_PWRDN_CLAMP_CH3, 2, 0x00, 1); + status = afe_write_byte(dev, ADC_PWRDN_CLAMP_CH1, 0x00); + status = afe_write_byte(dev, ADC_PWRDN_CLAMP_CH2, 0x00); + status = afe_write_byte(dev, ADC_PWRDN_CLAMP_CH3, 0x00); /* Enable quantizer calibration */ - status = cx231xx_write_i2c_data(dev, Colibri_DEVICE_ADDRESS, - ADC_COM_QUANT, 2, 0x02, 1); + status = afe_write_byte(dev, ADC_COM_QUANT, 0x02); /* channel initialize, force modulator (fb) reset */ - status = cx231xx_write_i2c_data(dev, Colibri_DEVICE_ADDRESS, - ADC_FB_FRCRST_CH1, 2, 0x17, 1); - status = cx231xx_write_i2c_data(dev, Colibri_DEVICE_ADDRESS, - ADC_FB_FRCRST_CH2, 2, 0x17, 1); - status = cx231xx_write_i2c_data(dev, Colibri_DEVICE_ADDRESS, - ADC_FB_FRCRST_CH3, 2, 0x17, 1); + status = afe_write_byte(dev, ADC_FB_FRCRST_CH1, 0x17); + status = afe_write_byte(dev, ADC_FB_FRCRST_CH2, 0x17); + status = afe_write_byte(dev, ADC_FB_FRCRST_CH3, 0x17); /* start quantilizer calibration */ - status = cx231xx_write_i2c_data(dev, Colibri_DEVICE_ADDRESS, - ADC_CAL_ATEST_CH1, 2, 0x10, 1); - status = cx231xx_write_i2c_data(dev, Colibri_DEVICE_ADDRESS, - ADC_CAL_ATEST_CH2, 2, 0x10, 1); - status = cx231xx_write_i2c_data(dev, Colibri_DEVICE_ADDRESS, - ADC_CAL_ATEST_CH3, 2, 0x10, 1); + status = afe_write_byte(dev, ADC_CAL_ATEST_CH1, 0x10); + status = afe_write_byte(dev, ADC_CAL_ATEST_CH2, 0x10); + status = afe_write_byte(dev, ADC_CAL_ATEST_CH3, 0x10); msleep(5); /* exit modulator (fb) reset */ - status = cx231xx_write_i2c_data(dev, Colibri_DEVICE_ADDRESS, - ADC_FB_FRCRST_CH1, 2, 0x07, 1); - status = cx231xx_write_i2c_data(dev, Colibri_DEVICE_ADDRESS, - ADC_FB_FRCRST_CH2, 2, 0x07, 1); - status = cx231xx_write_i2c_data(dev, Colibri_DEVICE_ADDRESS, - ADC_FB_FRCRST_CH3, 2, 0x07, 1); + status = afe_write_byte(dev, ADC_FB_FRCRST_CH1, 0x07); + status = afe_write_byte(dev, ADC_FB_FRCRST_CH2, 0x07); + status = afe_write_byte(dev, ADC_FB_FRCRST_CH3, 0x07); /* enable the pre_clamp in each channel for single-ended input */ - status = cx231xx_write_i2c_data(dev, Colibri_DEVICE_ADDRESS, - ADC_NTF_PRECLMP_EN_CH1, 2, 0xf0, 1); - status = cx231xx_write_i2c_data(dev, Colibri_DEVICE_ADDRESS, - ADC_NTF_PRECLMP_EN_CH2, 2, 0xf0, 1); - status = cx231xx_write_i2c_data(dev, Colibri_DEVICE_ADDRESS, - ADC_NTF_PRECLMP_EN_CH3, 2, 0xf0, 1); + status = afe_write_byte(dev, ADC_NTF_PRECLMP_EN_CH1, 0xf0); + status = afe_write_byte(dev, ADC_NTF_PRECLMP_EN_CH2, 0xf0); + status = afe_write_byte(dev, ADC_NTF_PRECLMP_EN_CH3, 0xf0); /* use diode instead of resistor, so set term_en to 0, res_en to 0 */ - status = cx231xx_reg_mask_write(dev, Colibri_DEVICE_ADDRESS, 8, + status = cx231xx_reg_mask_write(dev, AFE_DEVICE_ADDRESS, 8, ADC_QGAIN_RES_TRM_CH1, 3, 7, 0x00); - status = cx231xx_reg_mask_write(dev, Colibri_DEVICE_ADDRESS, 8, + status = cx231xx_reg_mask_write(dev, AFE_DEVICE_ADDRESS, 8, ADC_QGAIN_RES_TRM_CH2, 3, 7, 0x00); - status = cx231xx_reg_mask_write(dev, Colibri_DEVICE_ADDRESS, 8, + status = cx231xx_reg_mask_write(dev, AFE_DEVICE_ADDRESS, 8, ADC_QGAIN_RES_TRM_CH3, 3, 7, 0x00); /* dynamic element matching off */ - status = cx231xx_write_i2c_data(dev, Colibri_DEVICE_ADDRESS, - ADC_DCSERVO_DEM_CH1, 2, 0x03, 1); - status = cx231xx_write_i2c_data(dev, Colibri_DEVICE_ADDRESS, - ADC_DCSERVO_DEM_CH2, 2, 0x03, 1); - status = cx231xx_write_i2c_data(dev, Colibri_DEVICE_ADDRESS, - ADC_DCSERVO_DEM_CH3, 2, 0x03, 1); + status = afe_write_byte(dev, ADC_DCSERVO_DEM_CH1, 0x03); + status = afe_write_byte(dev, ADC_DCSERVO_DEM_CH2, 0x03); + status = afe_write_byte(dev, ADC_DCSERVO_DEM_CH3, 0x03); return status; } -int cx231xx_colibri_setup_AFE_for_baseband(struct cx231xx *dev) +int cx231xx_afe_setup_AFE_for_baseband(struct cx231xx *dev) { - u32 c_value = 0; + u8 c_value = 0; int status = 0; - status = - cx231xx_read_i2c_data(dev, Colibri_DEVICE_ADDRESS, - ADC_PWRDN_CLAMP_CH2, 2, &c_value, 1); + status = afe_read_byte(dev, ADC_PWRDN_CLAMP_CH2, &c_value); c_value &= (~(0x50)); - status = - cx231xx_write_i2c_data(dev, Colibri_DEVICE_ADDRESS, - ADC_PWRDN_CLAMP_CH2, 2, c_value, 1); + status = afe_write_byte(dev, ADC_PWRDN_CLAMP_CH2, c_value); return status; } @@ -214,52 +211,44 @@ int cx231xx_colibri_setup_AFE_for_baseband(struct cx231xx *dev) channel 2 ----- pin 5 to pin8(in reg is 5-8) channel 3 ----- pin 9 to pin 12(in reg is 9-11) */ -int cx231xx_colibri_set_input_mux(struct cx231xx *dev, u32 input_mux) +int cx231xx_afe_set_input_mux(struct cx231xx *dev, u32 input_mux) { u8 ch1_setting = (u8) input_mux; u8 ch2_setting = (u8) (input_mux >> 8); u8 ch3_setting = (u8) (input_mux >> 16); int status = 0; - u32 value = 0; + u8 value = 0; if (ch1_setting != 0) { - status = - cx231xx_read_i2c_data(dev, Colibri_DEVICE_ADDRESS, - ADC_INPUT_CH1, 2, &value, 1); + status = afe_read_byte(dev, ADC_INPUT_CH1, &value); value &= (!INPUT_SEL_MASK); value |= (ch1_setting - 1) << 4; value &= 0xff; - status = cx231xx_write_i2c_data(dev, Colibri_DEVICE_ADDRESS, - ADC_INPUT_CH1, 2, value, 1); + status = afe_write_byte(dev, ADC_INPUT_CH1, value); } if (ch2_setting != 0) { - status = - cx231xx_read_i2c_data(dev, Colibri_DEVICE_ADDRESS, - ADC_INPUT_CH2, 2, &value, 1); + status = afe_read_byte(dev, ADC_INPUT_CH2, &value); value &= (!INPUT_SEL_MASK); value |= (ch2_setting - 1) << 4; value &= 0xff; - status = cx231xx_write_i2c_data(dev, Colibri_DEVICE_ADDRESS, - ADC_INPUT_CH2, 2, value, 1); + status = afe_write_byte(dev, ADC_INPUT_CH2, value); } /* For ch3_setting, the value to put in the register is 7 less than the input number */ if (ch3_setting != 0) { - status = cx231xx_read_i2c_data(dev, Colibri_DEVICE_ADDRESS, - ADC_INPUT_CH3, 2, &value, 1); + status = afe_read_byte(dev, ADC_INPUT_CH3, &value); value &= (!INPUT_SEL_MASK); value |= (ch3_setting - 1) << 4; value &= 0xff; - status = cx231xx_write_i2c_data(dev, Colibri_DEVICE_ADDRESS, - ADC_INPUT_CH3, 2, value, 1); + status = afe_write_byte(dev, ADC_INPUT_CH3, value); } return status; } -int cx231xx_colibri_set_mode(struct cx231xx *dev, enum AFE_MODE mode) +int cx231xx_afe_set_mode(struct cx231xx *dev, enum AFE_MODE mode) { int status = 0; @@ -273,7 +262,7 @@ int cx231xx_colibri_set_mode(struct cx231xx *dev, enum AFE_MODE mode) /* SetupAFEforLowIF(); */ break; case AFE_MODE_BASEBAND: - status = cx231xx_colibri_setup_AFE_for_baseband(dev); + status = cx231xx_afe_setup_AFE_for_baseband(dev); break; case AFE_MODE_EU_HI_IF: /* SetupAFEforEuHiIF(); */ @@ -286,110 +275,76 @@ int cx231xx_colibri_set_mode(struct cx231xx *dev, enum AFE_MODE mode) break; } - if ((mode != dev->colibri_mode) && + if ((mode != dev->afe_mode) && (dev->video_input == CX231XX_VMUX_TELEVISION)) - status = cx231xx_colibri_adjust_ref_count(dev, + status = cx231xx_afe_adjust_ref_count(dev, CX231XX_VMUX_TELEVISION); - dev->colibri_mode = mode; + dev->afe_mode = mode; return status; } -int cx231xx_colibri_update_power_control(struct cx231xx *dev, +int cx231xx_afe_update_power_control(struct cx231xx *dev, enum AV_MODE avmode) { - u32 colibri_power_status = 0; + u8 afe_power_status = 0; int status = 0; switch (dev->model) { case CX231XX_BOARD_CNXT_RDE_250: case CX231XX_BOARD_CNXT_RDU_250: if (avmode == POLARIS_AVMODE_ANALOGT_TV) { - while (colibri_power_status != (FLD_PWRDN_TUNING_BIAS | + while (afe_power_status != (FLD_PWRDN_TUNING_BIAS | FLD_PWRDN_ENABLE_PLL)) { - status = cx231xx_write_i2c_data(dev, - Colibri_DEVICE_ADDRESS, - SUP_BLK_PWRDN, 2, + status = afe_write_byte(dev, SUP_BLK_PWRDN, FLD_PWRDN_TUNING_BIAS | - FLD_PWRDN_ENABLE_PLL, - 1); - status |= cx231xx_read_i2c_data(dev, - Colibri_DEVICE_ADDRESS, - SUP_BLK_PWRDN, 2, - &colibri_power_status, - 1); + FLD_PWRDN_ENABLE_PLL); + status |= afe_read_byte(dev, SUP_BLK_PWRDN, + &afe_power_status); if (status < 0) break; } - status = cx231xx_write_i2c_data(dev, - Colibri_DEVICE_ADDRESS, - ADC_PWRDN_CLAMP_CH1, 2, 0x00, - 1); - status |= cx231xx_write_i2c_data(dev, - Colibri_DEVICE_ADDRESS, - ADC_PWRDN_CLAMP_CH2, 2, 0x00, - 1); - status |= cx231xx_write_i2c_data(dev, - Colibri_DEVICE_ADDRESS, - ADC_PWRDN_CLAMP_CH3, 2, 0x00, - 1); + status = afe_write_byte(dev, ADC_PWRDN_CLAMP_CH1, + 0x00); + status |= afe_write_byte(dev, ADC_PWRDN_CLAMP_CH2, + 0x00); + status |= afe_write_byte(dev, ADC_PWRDN_CLAMP_CH3, + 0x00); } else if (avmode == POLARIS_AVMODE_DIGITAL) { - status = cx231xx_write_i2c_data(dev, - Colibri_DEVICE_ADDRESS, - ADC_PWRDN_CLAMP_CH1, 2, 0x70, - 1); - status |= cx231xx_write_i2c_data(dev, - Colibri_DEVICE_ADDRESS, - ADC_PWRDN_CLAMP_CH2, 2, 0x70, - 1); - status |= cx231xx_write_i2c_data(dev, - Colibri_DEVICE_ADDRESS, - ADC_PWRDN_CLAMP_CH3, 2, 0x70, - 1); - - status |= cx231xx_read_i2c_data(dev, - Colibri_DEVICE_ADDRESS, - SUP_BLK_PWRDN, 2, - &colibri_power_status, 1); - colibri_power_status |= FLD_PWRDN_PD_BANDGAP | + status = afe_write_byte(dev, ADC_PWRDN_CLAMP_CH1, + 0x70); + status |= afe_write_byte(dev, ADC_PWRDN_CLAMP_CH2, + 0x70); + status |= afe_write_byte(dev, ADC_PWRDN_CLAMP_CH3, + 0x70); + + status |= afe_read_byte(dev, SUP_BLK_PWRDN, + &afe_power_status); + afe_power_status |= FLD_PWRDN_PD_BANDGAP | FLD_PWRDN_PD_BIAS | FLD_PWRDN_PD_TUNECK; - status |= cx231xx_write_i2c_data(dev, - Colibri_DEVICE_ADDRESS, - SUP_BLK_PWRDN, 2, - colibri_power_status, 1); + status |= afe_write_byte(dev, SUP_BLK_PWRDN, + afe_power_status); } else if (avmode == POLARIS_AVMODE_ENXTERNAL_AV) { - while (colibri_power_status != (FLD_PWRDN_TUNING_BIAS | + while (afe_power_status != (FLD_PWRDN_TUNING_BIAS | FLD_PWRDN_ENABLE_PLL)) { - status = cx231xx_write_i2c_data(dev, - Colibri_DEVICE_ADDRESS, - SUP_BLK_PWRDN, 2, + status = afe_write_byte(dev, SUP_BLK_PWRDN, FLD_PWRDN_TUNING_BIAS | - FLD_PWRDN_ENABLE_PLL, - 1); - status |= cx231xx_read_i2c_data(dev, - Colibri_DEVICE_ADDRESS, - SUP_BLK_PWRDN, 2, - &colibri_power_status, - 1); + FLD_PWRDN_ENABLE_PLL); + status |= afe_read_byte(dev, SUP_BLK_PWRDN, + &afe_power_status); if (status < 0) break; } - status |= cx231xx_write_i2c_data(dev, - Colibri_DEVICE_ADDRESS, - ADC_PWRDN_CLAMP_CH1, 2, 0x00, - 1); - status |= cx231xx_write_i2c_data(dev, - Colibri_DEVICE_ADDRESS, - ADC_PWRDN_CLAMP_CH2, 2, 0x00, - 1); - status |= cx231xx_write_i2c_data(dev, - Colibri_DEVICE_ADDRESS, - ADC_PWRDN_CLAMP_CH3, 2, 0x00, - 1); + status |= afe_write_byte(dev, ADC_PWRDN_CLAMP_CH1, + 0x00); + status |= afe_write_byte(dev, ADC_PWRDN_CLAMP_CH2, + 0x00); + status |= afe_write_byte(dev, ADC_PWRDN_CLAMP_CH3, + 0x00); } else { cx231xx_info("Invalid AV mode input\n"); status = -1; @@ -397,92 +352,56 @@ int cx231xx_colibri_update_power_control(struct cx231xx *dev, break; default: if (avmode == POLARIS_AVMODE_ANALOGT_TV) { - while (colibri_power_status != (FLD_PWRDN_TUNING_BIAS | + while (afe_power_status != (FLD_PWRDN_TUNING_BIAS | FLD_PWRDN_ENABLE_PLL)) { - status = cx231xx_write_i2c_data(dev, - Colibri_DEVICE_ADDRESS, - SUP_BLK_PWRDN, 2, + status = afe_write_byte(dev, SUP_BLK_PWRDN, FLD_PWRDN_TUNING_BIAS | - FLD_PWRDN_ENABLE_PLL, - 1); - status |= cx231xx_read_i2c_data(dev, - Colibri_DEVICE_ADDRESS, - SUP_BLK_PWRDN, 2, - &colibri_power_status, - 1); + FLD_PWRDN_ENABLE_PLL); + status |= afe_read_byte(dev, SUP_BLK_PWRDN, + &afe_power_status); if (status < 0) break; } - status |= cx231xx_write_i2c_data(dev, - Colibri_DEVICE_ADDRESS, - ADC_PWRDN_CLAMP_CH1, 2, - 0x40, 1); - status |= cx231xx_write_i2c_data(dev, - Colibri_DEVICE_ADDRESS, - ADC_PWRDN_CLAMP_CH2, 2, - 0x40, 1); - status |= cx231xx_write_i2c_data(dev, - Colibri_DEVICE_ADDRESS, - ADC_PWRDN_CLAMP_CH3, 2, - 0x00, 1); + status |= afe_write_byte(dev, ADC_PWRDN_CLAMP_CH1, + 0x40); + status |= afe_write_byte(dev, ADC_PWRDN_CLAMP_CH2, + 0x40); + status |= afe_write_byte(dev, ADC_PWRDN_CLAMP_CH3, + 0x00); } else if (avmode == POLARIS_AVMODE_DIGITAL) { - status = cx231xx_write_i2c_data(dev, - Colibri_DEVICE_ADDRESS, - ADC_PWRDN_CLAMP_CH1, 2, - 0x70, 1); - status |= cx231xx_write_i2c_data(dev, - Colibri_DEVICE_ADDRESS, - ADC_PWRDN_CLAMP_CH2, 2, - 0x70, 1); - status |= cx231xx_write_i2c_data(dev, - Colibri_DEVICE_ADDRESS, - ADC_PWRDN_CLAMP_CH3, 2, - 0x70, 1); - - status |= cx231xx_read_i2c_data(dev, - Colibri_DEVICE_ADDRESS, - SUP_BLK_PWRDN, 2, - &colibri_power_status, - 1); - colibri_power_status |= FLD_PWRDN_PD_BANDGAP | + status = afe_write_byte(dev, ADC_PWRDN_CLAMP_CH1, + 0x70); + status |= afe_write_byte(dev, ADC_PWRDN_CLAMP_CH2, + 0x70); + status |= afe_write_byte(dev, ADC_PWRDN_CLAMP_CH3, + 0x70); + + status |= afe_read_byte(dev, SUP_BLK_PWRDN, + &afe_power_status); + afe_power_status |= FLD_PWRDN_PD_BANDGAP | FLD_PWRDN_PD_BIAS | FLD_PWRDN_PD_TUNECK; - status |= cx231xx_write_i2c_data(dev, - Colibri_DEVICE_ADDRESS, - SUP_BLK_PWRDN, 2, - colibri_power_status, - 1); + status |= afe_write_byte(dev, SUP_BLK_PWRDN, + afe_power_status); } else if (avmode == POLARIS_AVMODE_ENXTERNAL_AV) { - while (colibri_power_status != (FLD_PWRDN_TUNING_BIAS | + while (afe_power_status != (FLD_PWRDN_TUNING_BIAS | FLD_PWRDN_ENABLE_PLL)) { - status = cx231xx_write_i2c_data(dev, - Colibri_DEVICE_ADDRESS, - SUP_BLK_PWRDN, 2, + status = afe_write_byte(dev, SUP_BLK_PWRDN, FLD_PWRDN_TUNING_BIAS | - FLD_PWRDN_ENABLE_PLL, - 1); - status |= cx231xx_read_i2c_data(dev, - Colibri_DEVICE_ADDRESS, - SUP_BLK_PWRDN, 2, - &colibri_power_status, - 1); + FLD_PWRDN_ENABLE_PLL); + status |= afe_read_byte(dev, SUP_BLK_PWRDN, + &afe_power_status); if (status < 0) break; } - status |= cx231xx_write_i2c_data(dev, - Colibri_DEVICE_ADDRESS, - ADC_PWRDN_CLAMP_CH1, 2, - 0x00, 1); - status |= cx231xx_write_i2c_data(dev, - Colibri_DEVICE_ADDRESS, - ADC_PWRDN_CLAMP_CH2, 2, - 0x00, 1); - status |= cx231xx_write_i2c_data(dev, - Colibri_DEVICE_ADDRESS, - ADC_PWRDN_CLAMP_CH3, 2, - 0x40, 1); + status |= afe_write_byte(dev, ADC_PWRDN_CLAMP_CH1, + 0x00); + status |= afe_write_byte(dev, ADC_PWRDN_CLAMP_CH2, + 0x00); + status |= afe_write_byte(dev, ADC_PWRDN_CLAMP_CH3, + 0x40); } else { cx231xx_info("Invalid AV mode input\n"); status = -1; @@ -492,48 +411,44 @@ int cx231xx_colibri_update_power_control(struct cx231xx *dev, return status; } -int cx231xx_colibri_adjust_ref_count(struct cx231xx *dev, u32 video_input) +int cx231xx_afe_adjust_ref_count(struct cx231xx *dev, u32 video_input) { - u32 input_mode = 0; - u32 ntf_mode = 0; + u8 input_mode = 0; + u8 ntf_mode = 0; int status = 0; dev->video_input = video_input; if (video_input == CX231XX_VMUX_TELEVISION) { - status = cx231xx_read_i2c_data(dev, Colibri_DEVICE_ADDRESS, - ADC_INPUT_CH3, 2, &input_mode, 1); - status = cx231xx_read_i2c_data(dev, Colibri_DEVICE_ADDRESS, - ADC_NTF_PRECLMP_EN_CH3, 2, &ntf_mode, - 1); + status = afe_read_byte(dev, ADC_INPUT_CH3, &input_mode); + status = afe_read_byte(dev, ADC_NTF_PRECLMP_EN_CH3, + &ntf_mode); } else { - status = cx231xx_read_i2c_data(dev, Colibri_DEVICE_ADDRESS, - ADC_INPUT_CH1, 2, &input_mode, 1); - status = cx231xx_read_i2c_data(dev, Colibri_DEVICE_ADDRESS, - ADC_NTF_PRECLMP_EN_CH1, 2, &ntf_mode, - 1); + status = afe_read_byte(dev, ADC_INPUT_CH1, &input_mode); + status = afe_read_byte(dev, ADC_NTF_PRECLMP_EN_CH1, + &ntf_mode); } input_mode = (ntf_mode & 0x3) | ((input_mode & 0x6) << 1); switch (input_mode) { case SINGLE_ENDED: - dev->colibri_ref_count = 0x23C; + dev->afe_ref_count = 0x23C; break; case LOW_IF: - dev->colibri_ref_count = 0x24C; + dev->afe_ref_count = 0x24C; break; case EU_IF: - dev->colibri_ref_count = 0x258; + dev->afe_ref_count = 0x258; break; case US_IF: - dev->colibri_ref_count = 0x260; + dev->afe_ref_count = 0x260; break; default: break; } - status = cx231xx_colibri_init_super_block(dev, dev->colibri_ref_count); + status = cx231xx_afe_init_super_block(dev, dev->afe_ref_count); return status; } @@ -541,6 +456,35 @@ int cx231xx_colibri_adjust_ref_count(struct cx231xx *dev, u32 video_input) /****************************************************************************** * V I D E O / A U D I O D E C O D E R C O N T R O L functions * ******************************************************************************/ +static int vid_blk_write_byte(struct cx231xx *dev, u16 saddr, u8 data) +{ + return cx231xx_write_i2c_data(dev, VID_BLK_I2C_ADDRESS, + saddr, 2, data, 1); +} + +static int vid_blk_read_byte(struct cx231xx *dev, u16 saddr, u8 *data) +{ + int status; + u32 temp = 0; + + status = cx231xx_read_i2c_data(dev, VID_BLK_I2C_ADDRESS, + saddr, 2, &temp, 1); + *data = (u8) temp; + return status; +} + +static int vid_blk_write_word(struct cx231xx *dev, u16 saddr, u32 data) +{ + return cx231xx_write_i2c_data(dev, VID_BLK_I2C_ADDRESS, + saddr, 2, data, 4); +} + +static int vid_blk_read_word(struct cx231xx *dev, u16 saddr, u32 *data) +{ + return cx231xx_read_i2c_data(dev, VID_BLK_I2C_ADDRESS, + saddr, 2, data, 4); +} + int cx231xx_set_video_input_mux(struct cx231xx *dev, u8 input) { int status = 0; @@ -601,29 +545,27 @@ int cx231xx_set_decoder_video_input(struct cx231xx *dev, u32 value = 0; if (pin_type != dev->video_input) { - status = cx231xx_colibri_adjust_ref_count(dev, pin_type); + status = cx231xx_afe_adjust_ref_count(dev, pin_type); if (status < 0) { cx231xx_errdev("%s: adjust_ref_count :Failed to set" - "Colibri input mux - errCode [%d]!\n", + "AFE input mux - errCode [%d]!\n", __func__, status); return status; } } - /* call colibri block to set video inputs */ - status = cx231xx_colibri_set_input_mux(dev, input); + /* call afe block to set video inputs */ + status = cx231xx_afe_set_input_mux(dev, input); if (status < 0) { cx231xx_errdev("%s: set_input_mux :Failed to set" - " Colibri input mux - errCode [%d]!\n", + " AFE input mux - errCode [%d]!\n", __func__, status); return status; } switch (pin_type) { case CX231XX_VMUX_COMPOSITE1: - status = cx231xx_read_i2c_data(dev, - HAMMERHEAD_I2C_ADDRESS, - AFE_CTRL, 2, &value, 4); + status = vid_blk_read_word(dev, AFE_CTRL, &value); value |= (0 << 13) | (1 << 4); value &= ~(1 << 5); @@ -631,18 +573,15 @@ int cx231xx_set_decoder_video_input(struct cx231xx *dev, value &= (~(0x1ff8000)); /* set FUNC_MODE[24:23] = 2 IF_MOD[22:15] = 0 */ value |= 0x1000000; - status = cx231xx_write_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, - AFE_CTRL, 2, value, 4); + status = vid_blk_write_word(dev, AFE_CTRL, value); - status = cx231xx_read_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, - OUT_CTRL1, 2, &value, 4); + status = vid_blk_read_word(dev, OUT_CTRL1, &value); value |= (1 << 7); - status = cx231xx_write_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, - OUT_CTRL1, 2, value, 4); + status = vid_blk_write_word(dev, OUT_CTRL1, value); /* Set vip 1.1 output mode */ status = cx231xx_read_modify_write_i2c_dword(dev, - HAMMERHEAD_I2C_ADDRESS, + VID_BLK_I2C_ADDRESS, OUT_CTRL1, FLD_OUT_MODE, OUT_MODE_VIP11); @@ -657,8 +596,7 @@ int cx231xx_set_decoder_video_input(struct cx231xx *dev, } /* Read the DFE_CTRL1 register */ - status = cx231xx_read_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, - DFE_CTRL1, 2, &value, 4); + status = vid_blk_read_word(dev, DFE_CTRL1, &value); /* enable the VBI_GATE_EN */ value |= FLD_VBI_GATE_EN; @@ -667,35 +605,31 @@ int cx231xx_set_decoder_video_input(struct cx231xx *dev, value |= FLD_VGA_AUTO_EN; /* Write it back */ - status = cx231xx_write_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, - DFE_CTRL1, 2, value, 4); + status = vid_blk_write_word(dev, DFE_CTRL1, value); /* Disable auto config of registers */ status = cx231xx_read_modify_write_i2c_dword(dev, - HAMMERHEAD_I2C_ADDRESS, + VID_BLK_I2C_ADDRESS, MODE_CTRL, FLD_ACFG_DIS, cx231xx_set_field(FLD_ACFG_DIS, 1)); /* Set CVBS input mode */ status = cx231xx_read_modify_write_i2c_dword(dev, - HAMMERHEAD_I2C_ADDRESS, + VID_BLK_I2C_ADDRESS, MODE_CTRL, FLD_INPUT_MODE, cx231xx_set_field(FLD_INPUT_MODE, INPUT_MODE_CVBS_0)); break; case CX231XX_VMUX_SVIDEO: /* Disable the use of DIF */ - status = cx231xx_read_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, - AFE_CTRL, 2, &value, 4); + status = vid_blk_read_word(dev, AFE_CTRL, &value); /* set [24:23] [22:15] to 0 */ value &= (~(0x1ff8000)); /* set FUNC_MODE[24:23] = 2 IF_MOD[22:15] = 0 DCR_BYP_CH2[4:4] = 1; */ value |= 0x1000010; - status = cx231xx_write_i2c_data(dev, - HAMMERHEAD_I2C_ADDRESS, - AFE_CTRL, 2, value, 4); + status = vid_blk_write_word(dev, AFE_CTRL, value); /* Tell DIF object to go to baseband mode */ status = cx231xx_dif_set_standard(dev, DIF_USE_BASEBAND); @@ -707,9 +641,7 @@ int cx231xx_set_decoder_video_input(struct cx231xx *dev, } /* Read the DFE_CTRL1 register */ - status = cx231xx_read_i2c_data(dev, - HAMMERHEAD_I2C_ADDRESS, - DFE_CTRL1, 2, &value, 4); + status = vid_blk_read_word(dev, DFE_CTRL1, &value); /* enable the VBI_GATE_EN */ value |= FLD_VBI_GATE_EN; @@ -718,27 +650,23 @@ int cx231xx_set_decoder_video_input(struct cx231xx *dev, value |= FLD_VGA_AUTO_EN; /* Write it back */ - status = cx231xx_write_i2c_data(dev, - HAMMERHEAD_I2C_ADDRESS, - DFE_CTRL1, 2, value, 4); + status = vid_blk_write_word(dev, DFE_CTRL1, value); /* Disable auto config of registers */ status = cx231xx_read_modify_write_i2c_dword(dev, - HAMMERHEAD_I2C_ADDRESS, + VID_BLK_I2C_ADDRESS, MODE_CTRL, FLD_ACFG_DIS, cx231xx_set_field(FLD_ACFG_DIS, 1)); /* Set YC input mode */ status = cx231xx_read_modify_write_i2c_dword(dev, - HAMMERHEAD_I2C_ADDRESS, + VID_BLK_I2C_ADDRESS, MODE_CTRL, FLD_INPUT_MODE, cx231xx_set_field(FLD_INPUT_MODE, INPUT_MODE_YC_1)); /* Chroma to ADC2 */ - status = cx231xx_read_i2c_data(dev, - HAMMERHEAD_I2C_ADDRESS, - AFE_CTRL, 2, &value, 4); + status = vid_blk_read_word(dev, AFE_CTRL, &value); value |= FLD_CHROMA_IN_SEL; /* set the chroma in select */ /* Clear VGA_SEL_CH2 and VGA_SEL_CH3 (bits 7 and 8) @@ -746,11 +674,9 @@ int cx231xx_set_decoder_video_input(struct cx231xx *dev, rather than audio. Only one of the two will be in use. */ value &= ~(FLD_VGA_SEL_CH2 | FLD_VGA_SEL_CH3); - status = cx231xx_write_i2c_data(dev, - HAMMERHEAD_I2C_ADDRESS, - AFE_CTRL, 2, value, 4); + status = vid_blk_write_word(dev, AFE_CTRL, value); - status = cx231xx_colibri_set_mode(dev, AFE_MODE_BASEBAND); + status = cx231xx_afe_set_mode(dev, AFE_MODE_BASEBAND); break; case CX231XX_VMUX_TELEVISION: case CX231XX_VMUX_CABLE: @@ -760,10 +686,7 @@ int cx231xx_set_decoder_video_input(struct cx231xx *dev, case CX231XX_BOARD_CNXT_RDU_250: /* Disable the use of DIF */ - status = cx231xx_read_i2c_data(dev, - HAMMERHEAD_I2C_ADDRESS, - AFE_CTRL, 2, - &value, 4); + status = vid_blk_read_word(dev, AFE_CTRL, &value); value |= (0 << 13) | (1 << 4); value &= ~(1 << 5); @@ -771,24 +694,15 @@ int cx231xx_set_decoder_video_input(struct cx231xx *dev, value &= (~(0x1FF8000)); /* set FUNC_MODE[24:23] = 2 IF_MOD[22:15] = 0 */ value |= 0x1000000; - status = cx231xx_write_i2c_data(dev, - HAMMERHEAD_I2C_ADDRESS, - AFE_CTRL, 2, - value, 4); - - status = cx231xx_read_i2c_data(dev, - HAMMERHEAD_I2C_ADDRESS, - OUT_CTRL1, 2, - &value, 4); + status = vid_blk_write_word(dev, AFE_CTRL, value); + + status = vid_blk_read_word(dev, OUT_CTRL1, &value); value |= (1 << 7); - status = cx231xx_write_i2c_data(dev, - HAMMERHEAD_I2C_ADDRESS, - OUT_CTRL1, 2, - value, 4); + status = vid_blk_write_word(dev, OUT_CTRL1, value); /* Set vip 1.1 output mode */ status = cx231xx_read_modify_write_i2c_dword(dev, - HAMMERHEAD_I2C_ADDRESS, + VID_BLK_I2C_ADDRESS, OUT_CTRL1, FLD_OUT_MODE, OUT_MODE_VIP11); @@ -803,10 +717,7 @@ int cx231xx_set_decoder_video_input(struct cx231xx *dev, } /* Read the DFE_CTRL1 register */ - status = cx231xx_read_i2c_data(dev, - HAMMERHEAD_I2C_ADDRESS, - DFE_CTRL1, 2, - &value, 4); + status = vid_blk_read_word(dev, DFE_CTRL1, &value); /* enable the VBI_GATE_EN */ value |= FLD_VBI_GATE_EN; @@ -815,20 +726,17 @@ int cx231xx_set_decoder_video_input(struct cx231xx *dev, value |= FLD_VGA_AUTO_EN; /* Write it back */ - status = cx231xx_write_i2c_data(dev, - HAMMERHEAD_I2C_ADDRESS, - DFE_CTRL1, 2, - value, 4); + status = vid_blk_write_word(dev, DFE_CTRL1, value); /* Disable auto config of registers */ status = cx231xx_read_modify_write_i2c_dword(dev, - HAMMERHEAD_I2C_ADDRESS, + VID_BLK_I2C_ADDRESS, MODE_CTRL, FLD_ACFG_DIS, cx231xx_set_field(FLD_ACFG_DIS, 1)); /* Set CVBS input mode */ status = cx231xx_read_modify_write_i2c_dword(dev, - HAMMERHEAD_I2C_ADDRESS, + VID_BLK_I2C_ADDRESS, MODE_CTRL, FLD_INPUT_MODE, cx231xx_set_field(FLD_INPUT_MODE, INPUT_MODE_CVBS_0)); @@ -846,25 +754,16 @@ int cx231xx_set_decoder_video_input(struct cx231xx *dev, } /* Make sure bypass is cleared */ - status = cx231xx_read_i2c_data(dev, - HAMMERHEAD_I2C_ADDRESS, - DIF_MISC_CTRL, - 2, &value, 4); + status = vid_blk_read_word(dev, DIF_MISC_CTRL, &value); /* Clear the bypass bit */ value &= ~FLD_DIF_DIF_BYPASS; /* Enable the use of the DIF block */ - status = cx231xx_write_i2c_data(dev, - HAMMERHEAD_I2C_ADDRESS, - DIF_MISC_CTRL, - 2, value, 4); + status = vid_blk_write_word(dev, DIF_MISC_CTRL, value); /* Read the DFE_CTRL1 register */ - status = cx231xx_read_i2c_data(dev, - HAMMERHEAD_I2C_ADDRESS, - DFE_CTRL1, 2, - &value, 4); + status = vid_blk_read_word(dev, DFE_CTRL1, &value); /* Disable the VBI_GATE_EN */ value &= ~FLD_VBI_GATE_EN; @@ -874,10 +773,7 @@ int cx231xx_set_decoder_video_input(struct cx231xx *dev, value |= FLD_VGA_AUTO_EN | FLD_AGC_AUTO_EN | 0x00200000; /* Write it back */ - status = cx231xx_write_i2c_data(dev, - HAMMERHEAD_I2C_ADDRESS, - DFE_CTRL1, 2, - value, 4); + status = vid_blk_write_word(dev, DFE_CTRL1, value); /* Wait until AGC locks up */ msleep(1); @@ -886,39 +782,30 @@ int cx231xx_set_decoder_video_input(struct cx231xx *dev, value &= ~(FLD_VGA_AUTO_EN); /* Write it back */ - status = cx231xx_write_i2c_data(dev, - HAMMERHEAD_I2C_ADDRESS, - DFE_CTRL1, 2, - value, 4); + status = vid_blk_write_word(dev, DFE_CTRL1, value); /* Enable Polaris B0 AGC output */ - status = cx231xx_read_i2c_data(dev, - HAMMERHEAD_I2C_ADDRESS, - PIN_CTRL, 2, - &value, 4); + status = vid_blk_read_word(dev, PIN_CTRL, &value); value |= (FLD_OEF_AGC_RF) | (FLD_OEF_AGC_IFVGA) | (FLD_OEF_AGC_IF); - status = cx231xx_write_i2c_data(dev, - HAMMERHEAD_I2C_ADDRESS, - PIN_CTRL, 2, - value, 4); + status = vid_blk_write_word(dev, PIN_CTRL, value); /* Set vip 1.1 output mode */ status = cx231xx_read_modify_write_i2c_dword(dev, - HAMMERHEAD_I2C_ADDRESS, + VID_BLK_I2C_ADDRESS, OUT_CTRL1, FLD_OUT_MODE, OUT_MODE_VIP11); /* Disable auto config of registers */ status = cx231xx_read_modify_write_i2c_dword(dev, - HAMMERHEAD_I2C_ADDRESS, + VID_BLK_I2C_ADDRESS, MODE_CTRL, FLD_ACFG_DIS, cx231xx_set_field(FLD_ACFG_DIS, 1)); /* Set CVBS input mode */ status = cx231xx_read_modify_write_i2c_dword(dev, - HAMMERHEAD_I2C_ADDRESS, + VID_BLK_I2C_ADDRESS, MODE_CTRL, FLD_INPUT_MODE, cx231xx_set_field(FLD_INPUT_MODE, INPUT_MODE_CVBS_0)); @@ -928,17 +815,11 @@ int cx231xx_set_decoder_video_input(struct cx231xx *dev, /* Clear clamp for channels 2 and 3 (bit 16-17) */ /* Clear droop comp (bit 19-20) */ /* Set VGA_SEL (for audio control) (bit 7-8) */ - status = cx231xx_read_i2c_data(dev, - HAMMERHEAD_I2C_ADDRESS, - AFE_CTRL, 2, - &value, 4); + status = vid_blk_read_word(dev, AFE_CTRL, &value); value |= FLD_VGA_SEL_CH3 | FLD_VGA_SEL_CH2; - status = cx231xx_write_i2c_data(dev, - HAMMERHEAD_I2C_ADDRESS, - AFE_CTRL, 2, - value, 4); + status = vid_blk_write_word(dev, AFE_CTRL, value); break; } @@ -947,17 +828,14 @@ int cx231xx_set_decoder_video_input(struct cx231xx *dev, /* Set raw VBI mode */ status = cx231xx_read_modify_write_i2c_dword(dev, - HAMMERHEAD_I2C_ADDRESS, + VID_BLK_I2C_ADDRESS, OUT_CTRL1, FLD_VBIHACTRAW_EN, cx231xx_set_field(FLD_VBIHACTRAW_EN, 1)); - status = cx231xx_read_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, - OUT_CTRL1, 2, - &value, 4); + status = vid_blk_read_word(dev, OUT_CTRL1, &value); if (value & 0x02) { value |= (1 << 19); - status = cx231xx_write_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, - OUT_CTRL1, 2, value, 4); + status = vid_blk_write_word(dev, OUT_CTRL1, value); } return status; @@ -976,9 +854,7 @@ int cx231xx_do_mode_ctrl_overrides(struct cx231xx *dev) (unsigned int)dev->norm); /* Change the DFE_CTRL3 bp_percent to fix flagging */ - status = cx231xx_write_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, - DFE_CTRL3, 2, - 0xCD3F0280, 4); + status = vid_blk_write_word(dev, DFE_CTRL3, 0xCD3F0280); if (dev->norm & (V4L2_STD_NTSC | V4L2_STD_PAL_M)) { cx231xx_info("do_mode_ctrl_overrides NTSC\n"); @@ -986,22 +862,22 @@ int cx231xx_do_mode_ctrl_overrides(struct cx231xx *dev) /* Move the close caption lines out of active video, adjust the active video start point */ status = cx231xx_read_modify_write_i2c_dword(dev, - HAMMERHEAD_I2C_ADDRESS, + VID_BLK_I2C_ADDRESS, VERT_TIM_CTRL, FLD_VBLANK_CNT, 0x18); status = cx231xx_read_modify_write_i2c_dword(dev, - HAMMERHEAD_I2C_ADDRESS, + VID_BLK_I2C_ADDRESS, VERT_TIM_CTRL, FLD_VACTIVE_CNT, 0x1E6000); status = cx231xx_read_modify_write_i2c_dword(dev, - HAMMERHEAD_I2C_ADDRESS, + VID_BLK_I2C_ADDRESS, VERT_TIM_CTRL, FLD_V656BLANK_CNT, 0x1E000000); status = cx231xx_read_modify_write_i2c_dword(dev, - HAMMERHEAD_I2C_ADDRESS, + VID_BLK_I2C_ADDRESS, HORIZ_TIM_CTRL, FLD_HBLANK_CNT, cx231xx_set_field @@ -1009,12 +885,12 @@ int cx231xx_do_mode_ctrl_overrides(struct cx231xx *dev) } else if (dev->norm & V4L2_STD_SECAM) { cx231xx_info("do_mode_ctrl_overrides SECAM\n"); status = cx231xx_read_modify_write_i2c_dword(dev, - HAMMERHEAD_I2C_ADDRESS, + VID_BLK_I2C_ADDRESS, VERT_TIM_CTRL, FLD_VBLANK_CNT, 0x24); /* Adjust the active video horizontal start point */ status = cx231xx_read_modify_write_i2c_dword(dev, - HAMMERHEAD_I2C_ADDRESS, + VID_BLK_I2C_ADDRESS, HORIZ_TIM_CTRL, FLD_HBLANK_CNT, cx231xx_set_field @@ -1022,12 +898,12 @@ int cx231xx_do_mode_ctrl_overrides(struct cx231xx *dev) } else { cx231xx_info("do_mode_ctrl_overrides PAL\n"); status = cx231xx_read_modify_write_i2c_dword(dev, - HAMMERHEAD_I2C_ADDRESS, + VID_BLK_I2C_ADDRESS, VERT_TIM_CTRL, FLD_VBLANK_CNT, 0x24); /* Adjust the active video horizontal start point */ status = cx231xx_read_modify_write_i2c_dword(dev, - HAMMERHEAD_I2C_ADDRESS, + VID_BLK_I2C_ADDRESS, HORIZ_TIM_CTRL, FLD_HBLANK_CNT, cx231xx_set_field @@ -1047,7 +923,7 @@ int cx231xx_set_audio_input(struct cx231xx *dev, u8 input) ainput = AUDIO_INPUT_TUNER_TV; break; case CX231XX_AMUX_LINE_IN: - status = cx231xx_flatiron_set_audio_input(dev, input); + status = cx231xx_i2s_blk_set_audio_input(dev, input); ainput = AUDIO_INPUT_LINE; break; default: @@ -1064,71 +940,55 @@ int cx231xx_set_audio_decoder_input(struct cx231xx *dev, { u32 dwval; int status; - u32 gen_ctrl; + u8 gen_ctrl; u32 value = 0; /* Put it in soft reset */ - status = cx231xx_read_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, - GENERAL_CTL, 2, &gen_ctrl, 1); + status = vid_blk_read_byte(dev, GENERAL_CTL, &gen_ctrl); gen_ctrl |= 1; - status = cx231xx_write_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, - GENERAL_CTL, 2, gen_ctrl, 1); + status = vid_blk_write_byte(dev, GENERAL_CTL, gen_ctrl); switch (audio_input) { case AUDIO_INPUT_LINE: /* setup AUD_IO control from Merlin paralle output */ value = cx231xx_set_field(FLD_AUD_CHAN1_SRC, AUD_CHAN_SRC_PARALLEL); - status = cx231xx_write_i2c_data(dev, - HAMMERHEAD_I2C_ADDRESS, - AUD_IO_CTRL, 2, value, 4); + status = vid_blk_write_word(dev, AUD_IO_CTRL, value); /* setup input to Merlin, SRC2 connect to AC97 bypass upsample-by-2, slave mode, sony mode, left justify adr 091c, dat 01000000 */ - status = cx231xx_read_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, - AC97_CTL, - 2, &dwval, 4); + status = vid_blk_read_word(dev, AC97_CTL, &dwval); - status = cx231xx_write_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, - AC97_CTL, 2, - (dwval | FLD_AC97_UP2X_BYPASS), 4); + status = vid_blk_write_word(dev, AC97_CTL, + (dwval | FLD_AC97_UP2X_BYPASS)); /* select the parallel1 and SRC3 */ - status = cx231xx_write_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, - BAND_OUT_SEL, 2, + status = vid_blk_write_word(dev, BAND_OUT_SEL, cx231xx_set_field(FLD_SRC3_IN_SEL, 0x0) | cx231xx_set_field(FLD_SRC3_CLK_SEL, 0x0) | - cx231xx_set_field(FLD_PARALLEL1_SRC_SEL, 0x0), - 4); + cx231xx_set_field(FLD_PARALLEL1_SRC_SEL, 0x0)); /* unmute all, AC97 in, independence mode adr 08d0, data 0x00063073 */ - status = cx231xx_write_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, - PATH1_CTL1, 2, 0x00063073, 4); + status = vid_blk_write_word(dev, PATH1_CTL1, 0x00063073); /* set AVC maximum threshold, adr 08d4, dat ffff0024 */ - status = cx231xx_read_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, - PATH1_VOL_CTL, 2, &dwval, 4); - status = cx231xx_write_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, - PATH1_VOL_CTL, 2, - (dwval | FLD_PATH1_AVC_THRESHOLD), - 4); + status = vid_blk_read_word(dev, PATH1_VOL_CTL, &dwval); + status = vid_blk_write_word(dev, PATH1_VOL_CTL, + (dwval | FLD_PATH1_AVC_THRESHOLD)); /* set SC maximum threshold, adr 08ec, dat ffffb3a3 */ - status = cx231xx_read_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, - PATH1_SC_CTL, 2, &dwval, 4); - status = cx231xx_write_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, - PATH1_SC_CTL, 2, - (dwval | FLD_PATH1_SC_THRESHOLD), 4); + status = vid_blk_read_word(dev, PATH1_SC_CTL, &dwval); + status = vid_blk_write_word(dev, PATH1_SC_CTL, + (dwval | FLD_PATH1_SC_THRESHOLD)); break; case AUDIO_INPUT_TUNER_TV: default: /* Setup SRC sources and clocks */ - status = cx231xx_write_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, - BAND_OUT_SEL, 2, + status = vid_blk_write_word(dev, BAND_OUT_SEL, cx231xx_set_field(FLD_SRC6_IN_SEL, 0x00) | cx231xx_set_field(FLD_SRC6_CLK_SEL, 0x01) | cx231xx_set_field(FLD_SRC5_IN_SEL, 0x00) | @@ -1141,29 +1001,26 @@ int cx231xx_set_audio_decoder_input(struct cx231xx *dev, cx231xx_set_field(FLD_AC97_SRC_SEL, 0x03) | cx231xx_set_field(FLD_I2S_SRC_SEL, 0x00) | cx231xx_set_field(FLD_PARALLEL2_SRC_SEL, 0x02) | - cx231xx_set_field(FLD_PARALLEL1_SRC_SEL, 0x01), 4); + cx231xx_set_field(FLD_PARALLEL1_SRC_SEL, 0x01)); /* Setup the AUD_IO control */ - status = cx231xx_write_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, - AUD_IO_CTRL, 2, + status = vid_blk_write_word(dev, AUD_IO_CTRL, cx231xx_set_field(FLD_I2S_PORT_DIR, 0x00) | cx231xx_set_field(FLD_I2S_OUT_SRC, 0x00) | cx231xx_set_field(FLD_AUD_CHAN3_SRC, 0x00) | cx231xx_set_field(FLD_AUD_CHAN2_SRC, 0x00) | - cx231xx_set_field(FLD_AUD_CHAN1_SRC, 0x03), 4); + cx231xx_set_field(FLD_AUD_CHAN1_SRC, 0x03)); - status = cx231xx_write_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, - PATH1_CTL1, 2, 0x1F063870, 4); + status = vid_blk_write_word(dev, PATH1_CTL1, 0x1F063870); /* setAudioStandard(_audio_standard); */ - status = cx231xx_write_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, - PATH1_CTL1, 2, 0x00063870, 4); + status = vid_blk_write_word(dev, PATH1_CTL1, 0x00063870); switch (dev->model) { case CX231XX_BOARD_CNXT_RDE_250: case CX231XX_BOARD_CNXT_RDU_250: status = cx231xx_read_modify_write_i2c_dword(dev, - HAMMERHEAD_I2C_ADDRESS, + VID_BLK_I2C_ADDRESS, CHIP_CTRL, FLD_SIF_EN, cx231xx_set_field(FLD_SIF_EN, 1)); @@ -1181,17 +1038,14 @@ int cx231xx_set_audio_decoder_input(struct cx231xx *dev, break; case AUDIO_INPUT_MUTE: - status = cx231xx_write_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, - PATH1_CTL1, 2, 0x1F011012, 4); + status = vid_blk_write_word(dev, PATH1_CTL1, 0x1F011012); break; } /* Take it out of soft reset */ - status = cx231xx_read_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, - GENERAL_CTL, 2, &gen_ctrl, 1); + status = vid_blk_read_byte(dev, GENERAL_CTL, &gen_ctrl); gen_ctrl &= ~1; - status = cx231xx_write_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, - GENERAL_CTL, 2, gen_ctrl, 1); + status = vid_blk_write_byte(dev, GENERAL_CTL, gen_ctrl); return status; } @@ -1209,12 +1063,10 @@ int cx231xx_resolution_set(struct cx231xx *dev) get_scale(dev, width, height, &hscale, &vscale); /* set horzontal scale */ - status = cx231xx_write_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, - HSCALE_CTRL, 2, hscale, 4); + status = vid_blk_write_word(dev, HSCALE_CTRL, hscale); /* set vertical scale */ - status = cx231xx_write_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, - VSCALE_CTRL, 2, vscale, 4); + status = vid_blk_write_word(dev, VSCALE_CTRL, vscale); return status; } @@ -1227,11 +1079,9 @@ int cx231xx_init_ctrl_pin_status(struct cx231xx *dev) u32 value; int status = 0; - status = cx231xx_read_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, PIN_CTRL, - 2, &value, 4); + status = vid_blk_read_word(dev, PIN_CTRL, &value); value |= (~dev->board.ctl_pin_status_mask); - status = cx231xx_write_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, PIN_CTRL, - 2, value, 4); + status = vid_blk_write_word(dev, PIN_CTRL, value); return status; } @@ -1296,82 +1146,82 @@ int cx231xx_dif_configure_C2HH_for_low_IF(struct cx231xx *dev, u32 mode, /* C2HH */ /* lo if big signal */ status = cx231xx_reg_mask_write(dev, - HAMMERHEAD_I2C_ADDRESS, 32, + VID_BLK_I2C_ADDRESS, 32, AFE_CTRL_C2HH_SRC_CTRL, 30, 31, 0x1); /* FUNC_MODE = DIF */ status = cx231xx_reg_mask_write(dev, - HAMMERHEAD_I2C_ADDRESS, 32, + VID_BLK_I2C_ADDRESS, 32, AFE_CTRL_C2HH_SRC_CTRL, 23, 24, function_mode); /* IF_MODE */ status = cx231xx_reg_mask_write(dev, - HAMMERHEAD_I2C_ADDRESS, 32, + VID_BLK_I2C_ADDRESS, 32, AFE_CTRL_C2HH_SRC_CTRL, 15, 22, 0xFF); /* no inv */ status = cx231xx_reg_mask_write(dev, - HAMMERHEAD_I2C_ADDRESS, 32, + VID_BLK_I2C_ADDRESS, 32, AFE_CTRL_C2HH_SRC_CTRL, 9, 9, 0x1); } else if (standard != DIF_USE_BASEBAND) { if (standard & V4L2_STD_MN) { /* lo if big signal */ status = cx231xx_reg_mask_write(dev, - HAMMERHEAD_I2C_ADDRESS, 32, + VID_BLK_I2C_ADDRESS, 32, AFE_CTRL_C2HH_SRC_CTRL, 30, 31, 0x1); /* FUNC_MODE = DIF */ status = cx231xx_reg_mask_write(dev, - HAMMERHEAD_I2C_ADDRESS, 32, + VID_BLK_I2C_ADDRESS, 32, AFE_CTRL_C2HH_SRC_CTRL, 23, 24, function_mode); /* IF_MODE */ status = cx231xx_reg_mask_write(dev, - HAMMERHEAD_I2C_ADDRESS, 32, + VID_BLK_I2C_ADDRESS, 32, AFE_CTRL_C2HH_SRC_CTRL, 15, 22, 0xb); /* no inv */ status = cx231xx_reg_mask_write(dev, - HAMMERHEAD_I2C_ADDRESS, 32, + VID_BLK_I2C_ADDRESS, 32, AFE_CTRL_C2HH_SRC_CTRL, 9, 9, 0x1); /* 0x124, AUD_CHAN1_SRC = 0x3 */ status = cx231xx_reg_mask_write(dev, - HAMMERHEAD_I2C_ADDRESS, 32, + VID_BLK_I2C_ADDRESS, 32, AUD_IO_CTRL, 0, 31, 0x00000003); } else if ((standard == V4L2_STD_PAL_I) | (standard & V4L2_STD_SECAM)) { /* C2HH setup */ /* lo if big signal */ status = cx231xx_reg_mask_write(dev, - HAMMERHEAD_I2C_ADDRESS, 32, + VID_BLK_I2C_ADDRESS, 32, AFE_CTRL_C2HH_SRC_CTRL, 30, 31, 0x1); /* FUNC_MODE = DIF */ status = cx231xx_reg_mask_write(dev, - HAMMERHEAD_I2C_ADDRESS, 32, + VID_BLK_I2C_ADDRESS, 32, AFE_CTRL_C2HH_SRC_CTRL, 23, 24, function_mode); /* IF_MODE */ status = cx231xx_reg_mask_write(dev, - HAMMERHEAD_I2C_ADDRESS, 32, + VID_BLK_I2C_ADDRESS, 32, AFE_CTRL_C2HH_SRC_CTRL, 15, 22, 0xF); /* no inv */ status = cx231xx_reg_mask_write(dev, - HAMMERHEAD_I2C_ADDRESS, 32, + VID_BLK_I2C_ADDRESS, 32, AFE_CTRL_C2HH_SRC_CTRL, 9, 9, 0x1); } else { /* default PAL BG */ /* C2HH setup */ /* lo if big signal */ status = cx231xx_reg_mask_write(dev, - HAMMERHEAD_I2C_ADDRESS, 32, + VID_BLK_I2C_ADDRESS, 32, AFE_CTRL_C2HH_SRC_CTRL, 30, 31, 0x1); /* FUNC_MODE = DIF */ status = cx231xx_reg_mask_write(dev, - HAMMERHEAD_I2C_ADDRESS, 32, + VID_BLK_I2C_ADDRESS, 32, AFE_CTRL_C2HH_SRC_CTRL, 23, 24, function_mode); /* IF_MODE */ status = cx231xx_reg_mask_write(dev, - HAMMERHEAD_I2C_ADDRESS, 32, + VID_BLK_I2C_ADDRESS, 32, AFE_CTRL_C2HH_SRC_CTRL, 15, 22, 0xE); /* no inv */ status = cx231xx_reg_mask_write(dev, - HAMMERHEAD_I2C_ADDRESS, 32, + VID_BLK_I2C_ADDRESS, 32, AFE_CTRL_C2HH_SRC_CTRL, 9, 9, 0x1); } } @@ -1387,9 +1237,7 @@ int cx231xx_dif_set_standard(struct cx231xx *dev, u32 standard) cx231xx_info("%s: setStandard to %x\n", __func__, standard); - status = cx231xx_read_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, - DIF_MISC_CTRL, 2, &dif_misc_ctrl_value, - 4); + status = vid_blk_read_word(dev, DIF_MISC_CTRL, &dif_misc_ctrl_value); if (standard != DIF_USE_BASEBAND) dev->norm = standard; @@ -1408,182 +1256,154 @@ int cx231xx_dif_set_standard(struct cx231xx *dev, u32 standard) if (standard == DIF_USE_BASEBAND) { /* base band */ /* There is a different SRC_PHASE_INC value for baseband vs. DIF */ - status = cx231xx_write_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, - DIF_SRC_PHASE_INC, 2, 0xDF7DF83, - 4); - status = cx231xx_read_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, - DIF_MISC_CTRL, 2, - &dif_misc_ctrl_value, 4); + status = vid_blk_write_word(dev, DIF_SRC_PHASE_INC, 0xDF7DF83); + status = vid_blk_read_word(dev, DIF_MISC_CTRL, + &dif_misc_ctrl_value); dif_misc_ctrl_value |= FLD_DIF_DIF_BYPASS; - status = cx231xx_write_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, - DIF_MISC_CTRL, 2, - dif_misc_ctrl_value, 4); + status = vid_blk_write_word(dev, DIF_MISC_CTRL, + dif_misc_ctrl_value); } else if (standard & V4L2_STD_PAL_D) { - status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32, DIF_PLL_CTRL, 0, 31, 0x6503bc0c); - status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32, DIF_PLL_CTRL1, 0, 31, 0xbd038c85); - status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32, DIF_PLL_CTRL2, 0, 31, 0x1db4640a); - status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32, DIF_PLL_CTRL3, 0, 31, 0x00008800); - status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32, DIF_AGC_IF_REF, 0, 31, 0x444C1380); - status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32, DIF_AGC_CTRL_IF, 0, 31, 0xDA302600); - status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32, DIF_AGC_CTRL_INT, 0, 31, 0xDA261700); - status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32, DIF_AGC_CTRL_RF, 0, 31, 0xDA262600); - status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32, DIF_AGC_IF_INT_CURRENT, 0, 31, 0x26001700); - status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32, DIF_AGC_RF_CURRENT, 0, 31, 0x00002660); - status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32, DIF_VIDEO_AGC_CTRL, 0, 31, 0x72500800); - status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32, DIF_VID_AUD_OVERRIDE, 0, 31, 0x27000100); - status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32, DIF_AV_SEP_CTRL, 0, 31, 0x3F3934EA); - status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32, DIF_COMP_FLT_CTRL, 0, 31, 0x00000000); - status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32, DIF_SRC_PHASE_INC, 0, 31, 0x1befbf06); - status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32, DIF_SRC_GAIN_CONTROL, 0, 31, 0x000035e8); - status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32, DIF_RPT_VARIANCE, 0, 31, 0x00000000); /* Save the Spec Inversion value */ dif_misc_ctrl_value &= FLD_DIF_SPEC_INV; dif_misc_ctrl_value |= 0x3a023F11; } else if (standard & V4L2_STD_PAL_I) { - status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32, DIF_PLL_CTRL, 0, 31, 0x6503bc0c); - status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32, DIF_PLL_CTRL1, 0, 31, 0xbd038c85); - status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32, DIF_PLL_CTRL2, 0, 31, 0x1db4640a); - status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32, DIF_PLL_CTRL3, 0, 31, 0x00008800); - status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32, DIF_AGC_IF_REF, 0, 31, 0x444C1380); - status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32, DIF_AGC_CTRL_IF, 0, 31, 0xDA302600); - status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32, DIF_AGC_CTRL_INT, 0, 31, 0xDA261700); - status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32, DIF_AGC_CTRL_RF, 0, 31, 0xDA262600); - status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32, DIF_AGC_IF_INT_CURRENT, 0, 31, 0x26001700); - status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32, DIF_AGC_RF_CURRENT, 0, 31, 0x00002660); - status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32, DIF_VIDEO_AGC_CTRL, 0, 31, 0x72500800); - status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32, DIF_VID_AUD_OVERRIDE, 0, 31, 0x27000100); - status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32, DIF_AV_SEP_CTRL, 0, 31, 0x5F39A934); - status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32, DIF_COMP_FLT_CTRL, 0, 31, 0x00000000); - status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32, DIF_SRC_PHASE_INC, 0, 31, 0x1befbf06); - status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32, DIF_SRC_GAIN_CONTROL, 0, 31, 0x000035e8); - status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32, DIF_RPT_VARIANCE, 0, 31, 0x00000000); /* Save the Spec Inversion value */ dif_misc_ctrl_value &= FLD_DIF_SPEC_INV; dif_misc_ctrl_value |= 0x3a033F11; } else if (standard & V4L2_STD_PAL_M) { /* improved Low Frequency Phase Noise */ - status = cx231xx_write_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, - DIF_PLL_CTRL, 2, 0xFF01FF0C, 4); - status = cx231xx_write_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, - DIF_PLL_CTRL1, 2, 0xbd038c85, - 4); - status = cx231xx_write_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, - DIF_PLL_CTRL2, 2, 0x1db4640a, 4); - status = cx231xx_write_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, - DIF_PLL_CTRL3, 2, 0x00008800, 4); - status = cx231xx_write_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, - DIF_AGC_IF_REF, 2, 0x444C1380, 4); - status = cx231xx_write_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, - DIF_AGC_IF_INT_CURRENT, 2, - 0x26001700, 4); - status = cx231xx_write_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, - DIF_AGC_RF_CURRENT, 2, 0x00002660, - 4); - status = cx231xx_write_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, - DIF_VIDEO_AGC_CTRL, 2, 0x72500800, - 4); - status = cx231xx_write_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, - DIF_VID_AUD_OVERRIDE, 2, 0x27000100, - 4); - status = cx231xx_write_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, - DIF_AV_SEP_CTRL, 2, 0x012c405d, 4); - status = cx231xx_write_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, - DIF_COMP_FLT_CTRL, 2, 0x009f50c1, 4); - status = cx231xx_write_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, - DIF_SRC_PHASE_INC, 2, 0x1befbf06, 4); - status = cx231xx_write_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, - DIF_SRC_GAIN_CONTROL, 2, 0x000035e8, - 4); - status = cx231xx_write_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, - DIF_SOFT_RST_CTRL_REVB, 2, - 0x00000000, 4); + status = vid_blk_write_word(dev, DIF_PLL_CTRL, 0xFF01FF0C); + status = vid_blk_write_word(dev, DIF_PLL_CTRL1, 0xbd038c85); + status = vid_blk_write_word(dev, DIF_PLL_CTRL2, 0x1db4640a); + status = vid_blk_write_word(dev, DIF_PLL_CTRL3, 0x00008800); + status = vid_blk_write_word(dev, DIF_AGC_IF_REF, 0x444C1380); + status = vid_blk_write_word(dev, DIF_AGC_IF_INT_CURRENT, + 0x26001700); + status = vid_blk_write_word(dev, DIF_AGC_RF_CURRENT, + 0x00002660); + status = vid_blk_write_word(dev, DIF_VIDEO_AGC_CTRL, + 0x72500800); + status = vid_blk_write_word(dev, DIF_VID_AUD_OVERRIDE, + 0x27000100); + status = vid_blk_write_word(dev, DIF_AV_SEP_CTRL, 0x012c405d); + status = vid_blk_write_word(dev, DIF_COMP_FLT_CTRL, + 0x009f50c1); + status = vid_blk_write_word(dev, DIF_SRC_PHASE_INC, + 0x1befbf06); + status = vid_blk_write_word(dev, DIF_SRC_GAIN_CONTROL, + 0x000035e8); + status = vid_blk_write_word(dev, DIF_SOFT_RST_CTRL_REVB, + 0x00000000); /* Save the Spec Inversion value */ dif_misc_ctrl_value &= FLD_DIF_SPEC_INV; dif_misc_ctrl_value |= 0x3A0A3F10; } else if (standard & (V4L2_STD_PAL_N | V4L2_STD_PAL_Nc)) { /* improved Low Frequency Phase Noise */ - status = cx231xx_write_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, - DIF_PLL_CTRL, 2, 0xFF01FF0C, 4); - status = cx231xx_write_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, - DIF_PLL_CTRL1, 2, 0xbd038c85, 4); - status = cx231xx_write_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, - DIF_PLL_CTRL2, 2, 0x1db4640a, 4); - status = cx231xx_write_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, - DIF_PLL_CTRL3, 2, 0x00008800, 4); - status = cx231xx_write_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, - DIF_AGC_IF_REF, 2, 0x444C1380, 4); - status = cx231xx_write_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, - DIF_AGC_IF_INT_CURRENT, 2, - 0x26001700, 4); - status = cx231xx_write_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, - DIF_AGC_RF_CURRENT, 2, 0x00002660, - 4); - status = cx231xx_write_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, - DIF_VIDEO_AGC_CTRL, 2, 0x72500800, - 4); - status = cx231xx_write_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, - DIF_VID_AUD_OVERRIDE, 2, 0x27000100, - 4); - status = cx231xx_write_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, - DIF_AV_SEP_CTRL, 2, 0x012c405d, 4); - status = cx231xx_write_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, - DIF_COMP_FLT_CTRL, 2, 0x009f50c1, 4); - status = cx231xx_write_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, - DIF_SRC_PHASE_INC, 2, 0x1befbf06, 4); - status = cx231xx_write_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, - DIF_SRC_GAIN_CONTROL, 2, 0x000035e8, - 4); - status = cx231xx_write_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, - DIF_SOFT_RST_CTRL_REVB, 2, - 0x00000000, 4); + status = vid_blk_write_word(dev, DIF_PLL_CTRL, 0xFF01FF0C); + status = vid_blk_write_word(dev, DIF_PLL_CTRL1, 0xbd038c85); + status = vid_blk_write_word(dev, DIF_PLL_CTRL2, 0x1db4640a); + status = vid_blk_write_word(dev, DIF_PLL_CTRL3, 0x00008800); + status = vid_blk_write_word(dev, DIF_AGC_IF_REF, 0x444C1380); + status = vid_blk_write_word(dev, DIF_AGC_IF_INT_CURRENT, + 0x26001700); + status = vid_blk_write_word(dev, DIF_AGC_RF_CURRENT, + 0x00002660); + status = vid_blk_write_word(dev, DIF_VIDEO_AGC_CTRL, + 0x72500800); + status = vid_blk_write_word(dev, DIF_VID_AUD_OVERRIDE, + 0x27000100); + status = vid_blk_write_word(dev, DIF_AV_SEP_CTRL, + 0x012c405d); + status = vid_blk_write_word(dev, DIF_COMP_FLT_CTRL, + 0x009f50c1); + status = vid_blk_write_word(dev, DIF_SRC_PHASE_INC, + 0x1befbf06); + status = vid_blk_write_word(dev, DIF_SRC_GAIN_CONTROL, + 0x000035e8); + status = vid_blk_write_word(dev, DIF_SOFT_RST_CTRL_REVB, + 0x00000000); /* Save the Spec Inversion value */ dif_misc_ctrl_value &= FLD_DIF_SPEC_INV; dif_misc_ctrl_value = 0x3A093F10; @@ -1591,45 +1411,45 @@ int cx231xx_dif_set_standard(struct cx231xx *dev, u32 standard) (V4L2_STD_SECAM_B | V4L2_STD_SECAM_D | V4L2_STD_SECAM_G | V4L2_STD_SECAM_K | V4L2_STD_SECAM_K1)) { - status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32, DIF_PLL_CTRL, 0, 31, 0x6503bc0c); - status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32, DIF_PLL_CTRL1, 0, 31, 0xbd038c85); - status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32, DIF_PLL_CTRL2, 0, 31, 0x1db4640a); - status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32, DIF_PLL_CTRL3, 0, 31, 0x00008800); - status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32, DIF_AGC_IF_REF, 0, 31, 0x888C0380); - status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32, DIF_AGC_CTRL_IF, 0, 31, 0xe0262600); - status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32, DIF_AGC_CTRL_INT, 0, 31, 0xc2171700); - status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32, DIF_AGC_CTRL_RF, 0, 31, 0xc2262600); - status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32, DIF_AGC_IF_INT_CURRENT, 0, 31, 0x26001700); - status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32, DIF_AGC_RF_CURRENT, 0, 31, 0x00002660); - status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32, DIF_VID_AUD_OVERRIDE, 0, 31, 0x27000100); - status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32, DIF_AV_SEP_CTRL, 0, 31, 0x3F3530ec); - status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32, DIF_COMP_FLT_CTRL, 0, 31, 0x00000000); - status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32, DIF_SRC_PHASE_INC, 0, 31, 0x1befbf06); - status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32, DIF_SRC_GAIN_CONTROL, 0, 31, 0x000035e8); - status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32, DIF_RPT_VARIANCE, 0, 31, 0x00000000); - status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32, DIF_VIDEO_AGC_CTRL, 0, 31, 0xf4000000); @@ -1638,45 +1458,45 @@ int cx231xx_dif_set_standard(struct cx231xx *dev, u32 standard) dif_misc_ctrl_value |= 0x3a023F11; } else if (standard & (V4L2_STD_SECAM_L | V4L2_STD_SECAM_LC)) { /* Is it SECAM_L1? */ - status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32, DIF_PLL_CTRL, 0, 31, 0x6503bc0c); - status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32, DIF_PLL_CTRL1, 0, 31, 0xbd038c85); - status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32, DIF_PLL_CTRL2, 0, 31, 0x1db4640a); - status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32, DIF_PLL_CTRL3, 0, 31, 0x00008800); - status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32, DIF_AGC_IF_REF, 0, 31, 0x888C0380); - status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32, DIF_AGC_CTRL_IF, 0, 31, 0xe0262600); - status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32, DIF_AGC_CTRL_INT, 0, 31, 0xc2171700); - status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32, DIF_AGC_CTRL_RF, 0, 31, 0xc2262600); - status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32, DIF_AGC_IF_INT_CURRENT, 0, 31, 0x26001700); - status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32, DIF_AGC_RF_CURRENT, 0, 31, 0x00002660); - status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32, DIF_VID_AUD_OVERRIDE, 0, 31, 0x27000100); - status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32, DIF_AV_SEP_CTRL, 0, 31, 0x3F3530ec); - status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32, DIF_COMP_FLT_CTRL, 0, 31, 0x00000000); - status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32, DIF_SRC_PHASE_INC, 0, 31, 0x1befbf06); - status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32, DIF_SRC_GAIN_CONTROL, 0, 31, 0x000035e8); - status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32, DIF_RPT_VARIANCE, 0, 31, 0x00000000); - status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32, DIF_VIDEO_AGC_CTRL, 0, 31, 0xf2560000); @@ -1694,91 +1514,78 @@ int cx231xx_dif_set_standard(struct cx231xx *dev, u32 standard) the pll freq word is 0x03420c49 */ - status = cx231xx_write_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, - DIF_PLL_CTRL, 2, 0x6503BC0C, 4); - status = cx231xx_write_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, - DIF_PLL_CTRL1, 2, 0xBD038C85, 4); - status = cx231xx_write_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, - DIF_PLL_CTRL2, 2, 0x1DB4640A, 4); - status = cx231xx_write_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, - DIF_PLL_CTRL3, 2, 0x00008800, 4); - status = cx231xx_write_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, - DIF_AGC_IF_REF, 2, 0x444C0380, 4); - status = cx231xx_write_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, - DIF_AGC_IF_INT_CURRENT, 2, - 0x26001700, 4); - status = cx231xx_write_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, - DIF_AGC_RF_CURRENT, 2, 0x00002660, - 4); - status = cx231xx_write_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, - DIF_VIDEO_AGC_CTRL, 2, 0x04000800, - 4); - status = cx231xx_write_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, - DIF_VID_AUD_OVERRIDE, 2, 0x27000100, - 4); - status = cx231xx_write_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, - DIF_AV_SEP_CTRL, 2, 0x01296e1f, 4); - - status = cx231xx_write_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, - DIF_COMP_FLT_CTRL, 2, 0x009f50c1, 4); - status = cx231xx_write_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, - DIF_SRC_PHASE_INC, 2, 0x1befbf06, 4); - status = cx231xx_write_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, - DIF_SRC_GAIN_CONTROL, 2, 0x000035e8, - 4); - - status = cx231xx_write_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, - DIF_AGC_CTRL_IF, 2, 0xC2262600, 4); - status = cx231xx_write_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, - DIF_AGC_CTRL_INT, 2, 0xC2262600, 4); - status = cx231xx_write_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, - DIF_AGC_CTRL_RF, 2, 0xC2262600, 4); + status = vid_blk_write_word(dev, DIF_PLL_CTRL, 0x6503BC0C); + status = vid_blk_write_word(dev, DIF_PLL_CTRL1, 0xBD038C85); + status = vid_blk_write_word(dev, DIF_PLL_CTRL2, 0x1DB4640A); + status = vid_blk_write_word(dev, DIF_PLL_CTRL3, 0x00008800); + status = vid_blk_write_word(dev, DIF_AGC_IF_REF, 0x444C0380); + status = vid_blk_write_word(dev, DIF_AGC_IF_INT_CURRENT, + 0x26001700); + status = vid_blk_write_word(dev, DIF_AGC_RF_CURRENT, + 0x00002660); + status = vid_blk_write_word(dev, DIF_VIDEO_AGC_CTRL, + 0x04000800); + status = vid_blk_write_word(dev, DIF_VID_AUD_OVERRIDE, + 0x27000100); + status = vid_blk_write_word(dev, DIF_AV_SEP_CTRL, 0x01296e1f); + + status = vid_blk_write_word(dev, DIF_COMP_FLT_CTRL, + 0x009f50c1); + status = vid_blk_write_word(dev, DIF_SRC_PHASE_INC, + 0x1befbf06); + status = vid_blk_write_word(dev, DIF_SRC_GAIN_CONTROL, + 0x000035e8); + + status = vid_blk_write_word(dev, DIF_AGC_CTRL_IF, 0xC2262600); + status = vid_blk_write_word(dev, DIF_AGC_CTRL_INT, + 0xC2262600); + status = vid_blk_write_word(dev, DIF_AGC_CTRL_RF, 0xC2262600); /* Save the Spec Inversion value */ dif_misc_ctrl_value &= FLD_DIF_SPEC_INV; dif_misc_ctrl_value |= 0x3a003F10; } else { /* default PAL BG */ - status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32, DIF_PLL_CTRL, 0, 31, 0x6503bc0c); - status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32, DIF_PLL_CTRL1, 0, 31, 0xbd038c85); - status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32, DIF_PLL_CTRL2, 0, 31, 0x1db4640a); - status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32, DIF_PLL_CTRL3, 0, 31, 0x00008800); - status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32, DIF_AGC_IF_REF, 0, 31, 0x444C1380); - status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32, DIF_AGC_CTRL_IF, 0, 31, 0xDA302600); - status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32, DIF_AGC_CTRL_INT, 0, 31, 0xDA261700); - status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32, DIF_AGC_CTRL_RF, 0, 31, 0xDA262600); - status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32, DIF_AGC_IF_INT_CURRENT, 0, 31, 0x26001700); - status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32, DIF_AGC_RF_CURRENT, 0, 31, 0x00002660); - status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32, DIF_VIDEO_AGC_CTRL, 0, 31, 0x72500800); - status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32, DIF_VID_AUD_OVERRIDE, 0, 31, 0x27000100); - status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32, DIF_AV_SEP_CTRL, 0, 31, 0x3F3530EC); - status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32, DIF_COMP_FLT_CTRL, 0, 31, 0x00A653A8); - status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32, DIF_SRC_PHASE_INC, 0, 31, 0x1befbf06); - status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32, DIF_SRC_GAIN_CONTROL, 0, 31, 0x000035e8); - status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + status = cx231xx_reg_mask_write(dev, VID_BLK_I2C_ADDRESS, 32, DIF_RPT_VARIANCE, 0, 31, 0x00000000); /* Save the Spec Inversion value */ dif_misc_ctrl_value &= FLD_DIF_SPEC_INV; @@ -1796,9 +1603,7 @@ int cx231xx_dif_set_standard(struct cx231xx *dev, u32 standard) dif_misc_ctrl_value = 0x7a080000; /* Write the calculated value for misc ontrol register */ - status = - cx231xx_write_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, DIF_MISC_CTRL, - 2, dif_misc_ctrl_value, 4); + status = vid_blk_write_word(dev, DIF_MISC_CTRL, dif_misc_ctrl_value); return status; } @@ -1809,13 +1614,11 @@ int cx231xx_tuner_pre_channel_change(struct cx231xx *dev) u32 dwval; /* Set the RF and IF k_agc values to 3 */ - status = cx231xx_read_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, - DIF_AGC_IF_REF, 2, &dwval, 4); + status = vid_blk_read_word(dev, DIF_AGC_IF_REF, &dwval); dwval &= ~(FLD_DIF_K_AGC_RF | FLD_DIF_K_AGC_IF); dwval |= 0x33000000; - status = cx231xx_write_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, - DIF_AGC_IF_REF, 2, dwval, 4); + status = vid_blk_write_word(dev, DIF_AGC_IF_REF, dwval); return status; } @@ -1827,8 +1630,7 @@ int cx231xx_tuner_post_channel_change(struct cx231xx *dev) /* Set the RF and IF k_agc values to 4 for PAL/NTSC and 8 for * SECAM L/B/D standards */ - status = cx231xx_read_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, - DIF_AGC_IF_REF, 2, &dwval, 4); + status = vid_blk_read_word(dev, DIF_AGC_IF_REF, &dwval); dwval &= ~(FLD_DIF_K_AGC_RF | FLD_DIF_K_AGC_IF); if (dev->norm & (V4L2_STD_SECAM_L | V4L2_STD_SECAM_B | @@ -1837,63 +1639,62 @@ int cx231xx_tuner_post_channel_change(struct cx231xx *dev) else dwval |= 0x44000000; - status = cx231xx_write_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, - DIF_AGC_IF_REF, 2, dwval, 4); + status = vid_blk_write_word(dev, DIF_AGC_IF_REF, dwval); return status; } /****************************************************************************** - * F L A T I R O N - B L O C K C O N T R O L functions * + * I 2 S - B L O C K C O N T R O L functions * ******************************************************************************/ -int cx231xx_flatiron_initialize(struct cx231xx *dev) +int cx231xx_i2s_blk_initialize(struct cx231xx *dev) { int status = 0; u32 value; - status = cx231xx_read_i2c_data(dev, Flatrion_DEVICE_ADDRESS, + status = cx231xx_read_i2c_data(dev, I2S_BLK_DEVICE_ADDRESS, CH_PWR_CTRL1, 1, &value, 1); /* enables clock to delta-sigma and decimation filter */ value |= 0x80; - status = cx231xx_write_i2c_data(dev, Flatrion_DEVICE_ADDRESS, + status = cx231xx_write_i2c_data(dev, I2S_BLK_DEVICE_ADDRESS, CH_PWR_CTRL1, 1, value, 1); /* power up all channel */ - status = cx231xx_write_i2c_data(dev, Flatrion_DEVICE_ADDRESS, + status = cx231xx_write_i2c_data(dev, I2S_BLK_DEVICE_ADDRESS, CH_PWR_CTRL2, 1, 0x00, 1); return status; } -int cx231xx_flatiron_update_power_control(struct cx231xx *dev, +int cx231xx_i2s_blk_update_power_control(struct cx231xx *dev, enum AV_MODE avmode) { int status = 0; u32 value = 0; if (avmode != POLARIS_AVMODE_ENXTERNAL_AV) { - status = cx231xx_read_i2c_data(dev, Flatrion_DEVICE_ADDRESS, + status = cx231xx_read_i2c_data(dev, I2S_BLK_DEVICE_ADDRESS, CH_PWR_CTRL2, 1, &value, 1); value |= 0xfe; - status = cx231xx_write_i2c_data(dev, Flatrion_DEVICE_ADDRESS, + status = cx231xx_write_i2c_data(dev, I2S_BLK_DEVICE_ADDRESS, CH_PWR_CTRL2, 1, value, 1); } else { - status = cx231xx_write_i2c_data(dev, Flatrion_DEVICE_ADDRESS, + status = cx231xx_write_i2c_data(dev, I2S_BLK_DEVICE_ADDRESS, CH_PWR_CTRL2, 1, 0x00, 1); } return status; } -/* set flatiron for audio input types */ -int cx231xx_flatiron_set_audio_input(struct cx231xx *dev, u8 audio_input) +/* set i2s_blk for audio input types */ +int cx231xx_i2s_blk_set_audio_input(struct cx231xx *dev, u8 audio_input) { int status = 0; switch (audio_input) { case CX231XX_AMUX_LINE_IN: - status = cx231xx_write_i2c_data(dev, Flatrion_DEVICE_ADDRESS, + status = cx231xx_write_i2c_data(dev, I2S_BLK_DEVICE_ADDRESS, CH_PWR_CTRL2, 1, 0x00, 1); - status = cx231xx_write_i2c_data(dev, Flatrion_DEVICE_ADDRESS, + status = cx231xx_write_i2c_data(dev, I2S_BLK_DEVICE_ADDRESS, CH_PWR_CTRL1, 1, 0x80, 1); break; case CX231XX_AMUX_VIDEO: @@ -2114,11 +1915,11 @@ int cx231xx_set_power_mode(struct cx231xx *dev, enum AV_MODE mode) msleep(PWR_SLEEP_INTERVAL); } - /* update power control for colibri */ - status = cx231xx_colibri_update_power_control(dev, mode); + /* update power control for afe */ + status = cx231xx_afe_update_power_control(dev, mode); - /* update power control for flatiron */ - status = cx231xx_flatiron_update_power_control(dev, mode); + /* update power control for i2s_blk */ + status = cx231xx_i2s_blk_update_power_control(dev, mode); status = cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER, PWR_CTL_EN, value, 4); diff --git a/linux/drivers/media/video/cx231xx/cx231xx-cards.c b/linux/drivers/media/video/cx231xx/cx231xx-cards.c index bc8e375ca..d1872988a 100644 --- a/linux/drivers/media/video/cx231xx/cx231xx-cards.c +++ b/linux/drivers/media/video/cx231xx/cx231xx-cards.c @@ -169,11 +169,11 @@ const unsigned int cx231xx_bcount = ARRAY_SIZE(cx231xx_boards); /* table of devices that work with this driver */ struct usb_device_id cx231xx_id_table[] = { - {USB_DEVICE(0x0572, 0x58A0), + {USB_DEVICE(0x0572, 0x5A3C), .driver_info = CX231XX_BOARD_UNKNOWN}, {USB_DEVICE(0x0572, 0x58A2), .driver_info = CX231XX_BOARD_CNXT_RDE_250}, - {USB_DEVICE(0x0572, 0x5A3C), + {USB_DEVICE(0x0572, 0x58A1), .driver_info = CX231XX_BOARD_CNXT_RDU_250}, {}, }; @@ -225,7 +225,6 @@ void cx231xx_pre_card_setup(struct cx231xx *dev) cx231xx_info("Identified as %s (card=%d)\n", dev->board.name, dev->model); - cx231xx_info("Precard: Board is %s\n", dev->board.name); /* set the direction for GPIO pins */ cx231xx_set_gpio_direction(dev, dev->board.tuner_gpio->bit, 1); cx231xx_set_gpio_value(dev, dev->board.tuner_gpio->bit, 1); @@ -244,8 +243,6 @@ void cx231xx_pre_card_setup(struct cx231xx *dev) } -#if 0 /* Keep */ - static void cx231xx_config_tuner(struct cx231xx *dev) { struct tuner_setup tun_setup; @@ -259,8 +256,8 @@ static void cx231xx_config_tuner(struct cx231xx *dev) tun_setup.addr = dev->tuner_addr; tun_setup.tuner_callback = cx231xx_tuner_callback; - cx231xx_i2c_call_clients(&dev->i2c_bus[1], TUNER_SET_TYPE_ADDR, - &tun_setup); + tuner_call(dev, tuner, s_type_addr, &tun_setup); + #if 0 /* Keep */ if (tun_setup.type == TUNER_XC5000) { static struct xc2028_ctrl ctrl = { @@ -272,20 +269,17 @@ static void cx231xx_config_tuner(struct cx231xx *dev) .tuner = dev->tuner_type, .priv = &ctrl, }; - cx231xx_i2c_call_clients(&dev->i2c_bus[1], TUNER_SET_CONFIG, - &cfg); + tuner_call(dev, tuner, s_config, &cfg); } #endif - /* configure tuner */ f.tuner = 0; f.type = V4L2_TUNER_ANALOG_TV; f.frequency = 9076; /* just a magic number */ dev->ctl_freq = f.frequency; - cx231xx_i2c_call_clients(&dev->i2c_bus[1], VIDIOC_S_FREQUENCY, &f); -} + call_all(dev, tuner, s_frequency, &f); -#endif +} /* ----------------------------------------------------------------------- */ void cx231xx_set_ir(struct cx231xx *dev, struct IR_i2c *ir) @@ -309,40 +303,37 @@ void cx231xx_set_ir(struct cx231xx *dev, struct IR_i2c *ir) void cx231xx_card_setup(struct cx231xx *dev) { + cx231xx_set_model(dev); dev->tuner_type = cx231xx_boards[dev->model].tuner_type; if (cx231xx_boards[dev->model].tuner_addr) dev->tuner_addr = cx231xx_boards[dev->model].tuner_addr; - cx231xx_info(": tuner type %d, tuner address %d \n", - dev->tuner_type, dev->tuner_addr); - - /* Do card specific if any */ - switch (dev->model) { - case CX231XX_BOARD_CNXT_RDE_250: - /* do card specific GPIO settings if required */ - cx231xx_info("Board is Conexnat RDE 250\n"); - break; - case CX231XX_BOARD_CNXT_RDU_250: - /* do card specific GPIO settings if required */ - cx231xx_info("Board is Conexnat RDU 250\n"); - break; - } - /* request some modules */ if (dev->board.decoder == CX231XX_AVDECODER) { - cx231xx_info(": Requesting cx25840 module\n"); - request_module("cx25840"); + dev->sd_cx25840 = + v4l2_i2c_new_subdev(&dev->i2c_bus[0].i2c_adap, + "cx25840", "cx25840", 0x88 >> 1); + if (dev->sd_cx25840 == NULL) + cx231xx_info("cx25840 subdev registration failure\n"); + cx25840_call(dev, core, init, 0); + } -#if 0 /* Keep */ + if (dev->board.tuner_type != TUNER_ABSENT) { - cx231xx_info(": Requesting Tuner module\n"); - request_module("tuner"); + dev->sd_tuner = + v4l2_i2c_new_subdev(&dev->i2c_bus[1].i2c_adap, + "tuner", "tuner", 0xc2 >> 1); + if (dev->sd_tuner == NULL) + cx231xx_info("tuner subdev registration failure\n"); + + cx231xx_config_tuner(dev); } cx231xx_config_tuner(dev); +#if 0 /* Keep */ /* TBD IR will be added later */ cx231xx_ir_init(dev); #endif @@ -372,7 +363,7 @@ void cx231xx_config_i2c(struct cx231xx *dev) route.input = INPUT(dev->video_input)->vmux; route.output = 0; - cx231xx_i2c_call_clients(&dev->i2c_bus[0], VIDIOC_STREAMON, NULL); + call_all(dev, video, s_stream, 1); } /* @@ -560,16 +551,16 @@ static int cx231xx_usb_probe(struct usb_interface *interface, udev = usb_get_dev(interface_to_usbdev(interface)); ifnum = interface->altsetting[0].desc.bInterfaceNumber; - cx231xx_info(": Interface Number %d\n", ifnum); - - /* Interface number 0 - IR interface */ - if (ifnum == 0) { + if (!ifnum) { + /* + * Interface number 0 - IR interface + */ /* Check to see next free device and mark as used */ nr = find_first_zero_bit(&cx231xx_devused, CX231XX_MAXBOARDS); cx231xx_devused |= 1 << nr; if (nr >= CX231XX_MAXBOARDS) { - cx231xx_info(": Supports only %i cx231xx boards.\n", + cx231xx_err(DRIVER_NAME ": Supports only %i cx231xx boards.\n", CX231XX_MAXBOARDS); cx231xx_devused &= ~(1 << nr); return -ENOMEM; @@ -602,42 +593,46 @@ static int cx231xx_usb_probe(struct usb_interface *interface, /* get maximum no.of IAD interfaces */ assoc_desc = udev->actconfig->intf_assoc[0]; dev->max_iad_interface_count = assoc_desc->bInterfaceCount; - cx231xx_info("Found IAD interface count %d\n", - dev->max_iad_interface_count); /* init CIR module TBD */ /* store the current interface */ lif = interface; - } else if (ifnum == 1) { - - /* Get dev structure first */ - dev = usb_get_intfdata(udev->actconfig->interface[0]); - if (dev == NULL) { - cx231xx_err(DRIVER_NAME ": out of first interface!\n"); - return -ENODEV; + switch (udev->speed) { + case USB_SPEED_LOW: + speed = "1.5"; + break; + case USB_SPEED_UNKNOWN: + case USB_SPEED_FULL: + speed = "12"; + break; + case USB_SPEED_HIGH: + speed = "480"; + break; + default: + speed = "unknown"; } - /* store the interface 0 back */ - lif = udev->actconfig->interface[0]; - - /* increment interface count */ - dev->interface_count++; - - /* get device number */ - nr = dev->devno; + if (udev->manufacturer) + strlcpy(descr, udev->manufacturer, sizeof(descr)); - assoc_desc = udev->actconfig->intf_assoc[0]; - if (assoc_desc->bFirstInterface == ifnum) { - cx231xx_info - ("Found IAD interface match: AV Desc Start!! \n"); - } else { - cx231xx_err(" Not found matching interface\n"); - return -ENODEV; + if (udev->product) { + if (*descr) + strlcat(descr, " ", sizeof(descr)); + strlcat(descr, udev->product, sizeof(descr)); } + if (*descr) + strlcat(descr, " ", sizeof(descr)); - } else if (ifnum >= 2) { + cx231xx_info("New device %s@ %s Mbps " + "(%04x:%04x) with %d interfaces\n", + descr, + speed, + le16_to_cpu(udev->descriptor.idVendor), + le16_to_cpu(udev->descriptor.idProduct), + dev->max_iad_interface_count); + } else { /* Get dev structure first */ dev = usb_get_intfdata(udev->actconfig->interface[0]); if (dev == NULL) { @@ -654,220 +649,196 @@ static int cx231xx_usb_probe(struct usb_interface *interface, /* get device number */ nr = dev->devno; - /* set skip interface */ - if ((dev->interface_count - 1) != dev->max_iad_interface_count) - skip_interface = 1; /* set skipping */ - else { - cx231xx_info - ("Found IAD interface no. match with AV Device no.!\n"); + /* + * set skip interface, for all interfaces but + * interface 1 and the last one + */ + if ((ifnum != 1) && ((dev->interface_count - 1) + != dev->max_iad_interface_count)) + skip_interface = 1; + + if (ifnum == 1) { + assoc_desc = udev->actconfig->intf_assoc[0]; + if (assoc_desc->bFirstInterface != ifnum) { + cx231xx_err(DRIVER_NAME ": Not found " + "matching IAD interface\n"); + return -ENODEV; + } } } - switch (udev->speed) { - case USB_SPEED_LOW: - speed = "1.5"; - break; - case USB_SPEED_UNKNOWN: - case USB_SPEED_FULL: - speed = "12"; - break; - case USB_SPEED_HIGH: - speed = "480"; - break; - default: - speed = "unknown"; - } + if (skip_interface) + return -ENODEV; - if (udev->manufacturer) - strlcpy(descr, udev->manufacturer, sizeof(descr)); + cx231xx_info("registering interface %d\n", ifnum); - if (udev->product) { - if (*descr) - strlcat(descr, " ", sizeof(descr)); - strlcat(descr, udev->product, sizeof(descr)); - } - if (*descr) - strlcat(descr, " ", sizeof(descr)); + /* save our data pointer in this interface device */ + usb_set_intfdata(lif, dev); - cx231xx_info("New device %s@ %s Mbps " - "(%04x:%04x, interface %d, class %d)\n", - descr, - speed, - le16_to_cpu(udev->descriptor.idVendor), - le16_to_cpu(udev->descriptor.idProduct), - ifnum, interface->altsetting->desc.bInterfaceNumber); - - /* AV device initialization */ - if ((dev->interface_count - 1) == dev->max_iad_interface_count) { - cx231xx_info(" Calling init_dev\n"); - /* allocate device struct */ - retval = cx231xx_init_dev(&dev, udev, nr); - if (retval) { - cx231xx_devused &= ~(1 << dev->devno); - kfree(dev); + if ((dev->interface_count - 1) != dev->max_iad_interface_count) + return 0; - return retval; - } + /* + * AV device initialization - only done at the last interface + */ - /* compute alternate max packet sizes for video */ - uif = - udev->actconfig->interface[dev->current_pcb_config. - hs_config_info[0].interface_info. - video_index + 1]; + /* Create v4l2 device */ + snprintf(dev->v4l2_dev.name, sizeof(dev->v4l2_dev.name), + "%s-%03d", "cx231xx", nr); + retval = v4l2_device_register(&udev->dev, &dev->v4l2_dev); + if (retval) { + cx231xx_errdev("v4l2_device_register failed\n"); + cx231xx_devused &= ~(1 << nr); + kfree(dev); + return -EIO; + } - dev->video_mode.end_point_addr = - le16_to_cpu(uif->altsetting[0].endpoint[isoc_pipe].desc. - bEndpointAddress); + /* allocate device struct */ + retval = cx231xx_init_dev(&dev, udev, nr); + if (retval) { + cx231xx_devused &= ~(1 << dev->devno); + v4l2_device_unregister(&dev->v4l2_dev); + kfree(dev); + return retval; + } - dev->video_mode.num_alt = uif->num_altsetting; - cx231xx_info(": EndPoint Addr 0x%x, Alternate settings: %i\n", - dev->video_mode.end_point_addr, - dev->video_mode.num_alt); - dev->video_mode.alt_max_pkt_size = - kmalloc(32 * dev->video_mode.num_alt, GFP_KERNEL); + /* compute alternate max packet sizes for video */ + uif = udev->actconfig->interface[dev->current_pcb_config. + hs_config_info[0].interface_info.video_index + 1]; - if (dev->video_mode.alt_max_pkt_size == NULL) { - cx231xx_errdev("out of memory!\n"); - cx231xx_devused &= ~(1 << nr); - kfree(dev); - return -ENOMEM; - } + dev->video_mode.end_point_addr = le16_to_cpu(uif->altsetting[0]. + endpoint[isoc_pipe].desc.bEndpointAddress); - for (i = 0; i < dev->video_mode.num_alt; i++) { - u16 tmp = - le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe]. - desc.wMaxPacketSize); - dev->video_mode.alt_max_pkt_size[i] = - (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1); - cx231xx_info("Alternate setting %i, max size= %i\n", i, - dev->video_mode.alt_max_pkt_size[i]); - } + dev->video_mode.num_alt = uif->num_altsetting; + cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n", + dev->video_mode.end_point_addr, + dev->video_mode.num_alt); + dev->video_mode.alt_max_pkt_size = + kmalloc(32 * dev->video_mode.num_alt, GFP_KERNEL); - /* compute alternate max packet sizes for vbi */ - uif = - udev->actconfig->interface[dev->current_pcb_config. - hs_config_info[0].interface_info. - vanc_index + 1]; + if (dev->video_mode.alt_max_pkt_size == NULL) { + cx231xx_errdev("out of memory!\n"); + cx231xx_devused &= ~(1 << nr); + v4l2_device_unregister(&dev->v4l2_dev); + kfree(dev); + return -ENOMEM; + } - dev->vbi_mode.end_point_addr = - le16_to_cpu(uif->altsetting[0].endpoint[isoc_pipe].desc. - bEndpointAddress); + for (i = 0; i < dev->video_mode.num_alt; i++) { + u16 tmp = le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe]. + desc.wMaxPacketSize); + dev->video_mode.alt_max_pkt_size[i] = + (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1); + cx231xx_info("Alternate setting %i, max size= %i\n", i, + dev->video_mode.alt_max_pkt_size[i]); + } - dev->vbi_mode.num_alt = uif->num_altsetting; - cx231xx_info(": EndPoint Addr 0x%x, Alternate settings: %i\n", - dev->vbi_mode.end_point_addr, - dev->vbi_mode.num_alt); - dev->vbi_mode.alt_max_pkt_size = - kmalloc(32 * dev->vbi_mode.num_alt, GFP_KERNEL); + /* compute alternate max packet sizes for vbi */ + uif = udev->actconfig->interface[dev->current_pcb_config. + hs_config_info[0].interface_info. + vanc_index + 1]; + + dev->vbi_mode.end_point_addr = + le16_to_cpu(uif->altsetting[0].endpoint[isoc_pipe].desc. + bEndpointAddress); + + dev->vbi_mode.num_alt = uif->num_altsetting; + cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n", + dev->vbi_mode.end_point_addr, + dev->vbi_mode.num_alt); + dev->vbi_mode.alt_max_pkt_size = + kmalloc(32 * dev->vbi_mode.num_alt, GFP_KERNEL); + + if (dev->vbi_mode.alt_max_pkt_size == NULL) { + cx231xx_errdev("out of memory!\n"); + cx231xx_devused &= ~(1 << nr); + v4l2_device_unregister(&dev->v4l2_dev); + kfree(dev); + return -ENOMEM; + } - if (dev->vbi_mode.alt_max_pkt_size == NULL) { - cx231xx_errdev("out of memory!\n"); - cx231xx_devused &= ~(1 << nr); - kfree(dev); - return -ENOMEM; - } + for (i = 0; i < dev->vbi_mode.num_alt; i++) { + u16 tmp = + le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe]. + desc.wMaxPacketSize); + dev->vbi_mode.alt_max_pkt_size[i] = + (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1); + cx231xx_info("Alternate setting %i, max size= %i\n", i, + dev->vbi_mode.alt_max_pkt_size[i]); + } - for (i = 0; i < dev->vbi_mode.num_alt; i++) { - u16 tmp = - le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe]. - desc.wMaxPacketSize); - dev->vbi_mode.alt_max_pkt_size[i] = - (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1); - cx231xx_info("Alternate setting %i, max size= %i\n", i, - dev->vbi_mode.alt_max_pkt_size[i]); - } + /* compute alternate max packet sizes for sliced CC */ + uif = udev->actconfig->interface[dev->current_pcb_config. + hs_config_info[0].interface_info. + hanc_index + 1]; + + dev->sliced_cc_mode.end_point_addr = + le16_to_cpu(uif->altsetting[0].endpoint[isoc_pipe].desc. + bEndpointAddress); + + dev->sliced_cc_mode.num_alt = uif->num_altsetting; + cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n", + dev->sliced_cc_mode.end_point_addr, + dev->sliced_cc_mode.num_alt); + dev->sliced_cc_mode.alt_max_pkt_size = + kmalloc(32 * dev->sliced_cc_mode.num_alt, GFP_KERNEL); + + if (dev->sliced_cc_mode.alt_max_pkt_size == NULL) { + cx231xx_errdev("out of memory!\n"); + cx231xx_devused &= ~(1 << nr); + v4l2_device_unregister(&dev->v4l2_dev); + kfree(dev); + return -ENOMEM; + } + + for (i = 0; i < dev->sliced_cc_mode.num_alt; i++) { + u16 tmp = le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe]. + desc.wMaxPacketSize); + dev->sliced_cc_mode.alt_max_pkt_size[i] = + (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1); + cx231xx_info("Alternate setting %i, max size= %i\n", i, + dev->sliced_cc_mode.alt_max_pkt_size[i]); + } - /* compute alternate max packet sizes for sliced CC */ - uif = - udev->actconfig->interface[dev->current_pcb_config. - hs_config_info[0].interface_info. - hanc_index + 1]; + if (dev->current_pcb_config.ts1_source != 0xff) { + /* compute alternate max packet sizes for TS1 */ + uif = udev->actconfig->interface[dev->current_pcb_config. + hs_config_info[0]. + interface_info. + ts1_index + 1]; - dev->sliced_cc_mode.end_point_addr = - le16_to_cpu(uif->altsetting[0].endpoint[isoc_pipe].desc. - bEndpointAddress); + dev->ts1_mode.end_point_addr = + le16_to_cpu(uif->altsetting[0].endpoint[isoc_pipe]. + desc.bEndpointAddress); - dev->sliced_cc_mode.num_alt = uif->num_altsetting; - cx231xx_info(": EndPoint Addr 0x%x, Alternate settings: %i\n", - dev->sliced_cc_mode.end_point_addr, - dev->sliced_cc_mode.num_alt); - dev->sliced_cc_mode.alt_max_pkt_size = - kmalloc(32 * dev->sliced_cc_mode.num_alt, GFP_KERNEL); + dev->ts1_mode.num_alt = uif->num_altsetting; + cx231xx_info("EndPoint Addr 0x%x, Alternate settings: %i\n", + dev->ts1_mode.end_point_addr, + dev->ts1_mode.num_alt); + dev->ts1_mode.alt_max_pkt_size = + kmalloc(32 * dev->ts1_mode.num_alt, GFP_KERNEL); - if (dev->sliced_cc_mode.alt_max_pkt_size == NULL) { + if (dev->ts1_mode.alt_max_pkt_size == NULL) { cx231xx_errdev("out of memory!\n"); cx231xx_devused &= ~(1 << nr); + v4l2_device_unregister(&dev->v4l2_dev); kfree(dev); return -ENOMEM; } - for (i = 0; i < dev->sliced_cc_mode.num_alt; i++) { - u16 tmp = - le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe]. - desc.wMaxPacketSize); - dev->sliced_cc_mode.alt_max_pkt_size[i] = - (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1); - cx231xx_info("Alternate setting %i, max size= %i\n", i, - dev->sliced_cc_mode.alt_max_pkt_size[i]); - } - - if (dev->current_pcb_config.ts1_source != 0xff) { - - /* compute alternate max packet sizes for TS1 */ - uif = - udev->actconfig->interface[dev->current_pcb_config. - hs_config_info[0]. - interface_info. - ts1_index + 1]; - - dev->ts1_mode.end_point_addr = - le16_to_cpu(uif->altsetting[0].endpoint[isoc_pipe]. - desc.bEndpointAddress); - - dev->ts1_mode.num_alt = uif->num_altsetting; - cx231xx_info - (": EndPoint Addr 0x%x, Alternate settings: %i\n", - dev->ts1_mode.end_point_addr, - dev->ts1_mode.num_alt); - dev->ts1_mode.alt_max_pkt_size = - kmalloc(32 * dev->ts1_mode.num_alt, GFP_KERNEL); - - if (dev->ts1_mode.alt_max_pkt_size == NULL) { - cx231xx_errdev("out of memory!\n"); - cx231xx_devused &= ~(1 << nr); - kfree(dev); - return -ENOMEM; - } - - for (i = 0; i < dev->ts1_mode.num_alt; i++) { - u16 tmp = - le16_to_cpu(uif->altsetting[i]. + for (i = 0; i < dev->ts1_mode.num_alt; i++) { + u16 tmp = le16_to_cpu(uif->altsetting[i]. endpoint[isoc_pipe].desc. wMaxPacketSize); - dev->ts1_mode.alt_max_pkt_size[i] = - (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + - 1); - cx231xx_info - ("Alternate setting %i, max size= %i\n", i, + dev->ts1_mode.alt_max_pkt_size[i] = + (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1); + cx231xx_info("Alternate setting %i, max size= %i\n", i, dev->ts1_mode.alt_max_pkt_size[i]); - } } - } - /* save our data pointer in this interface device */ - usb_set_intfdata(lif, dev); - /* load other modules required */ - if ((dev->interface_count - 1) == dev->max_iad_interface_count) { - cx231xx_info("Calling request modules\n"); - request_modules(dev); - } - - if (skip_interface) { - cx231xx_info("Skipping the interface\n"); - return -ENODEV; - } + request_modules(dev); return 0; } @@ -887,6 +858,12 @@ static void cx231xx_usb_disconnect(struct usb_interface *interface) if (!dev) return; + if (!dev->udev) + return; + + /* delete v4l2 device */ + v4l2_device_unregister(&dev->v4l2_dev); + /* wait until all current v4l2 io is finished then deallocate resources */ mutex_lock(&dev->lock); @@ -932,9 +909,7 @@ static int __init cx231xx_module_init(void) { int result; - printk(KERN_INFO DRIVER_NAME " v4l2 driver version %d.%d.%d loaded\n", - (CX231XX_VERSION_CODE >> 16) & 0xff, - (CX231XX_VERSION_CODE >> 8) & 0xff, CX231XX_VERSION_CODE & 0xff); + printk(KERN_INFO DRIVER_NAME " v4l2 driver loaded.\n"); /* register this driver with the USB subsystem */ result = usb_register(&cx231xx_usb_driver); diff --git a/linux/drivers/media/video/cx231xx/cx231xx-core.c b/linux/drivers/media/video/cx231xx/cx231xx-core.c index 2aec3a842..70478aa8b 100644 --- a/linux/drivers/media/video/cx231xx/cx231xx-core.c +++ b/linux/drivers/media/video/cx231xx/cx231xx-core.c @@ -125,7 +125,7 @@ int cx231xx_register_extension(struct cx231xx_ops *ops) if (dev) ops->init(dev); } - cx231xx_info("Cx231xx: Initialized (%s) extension\n", ops->name); + printk(KERN_INFO DRIVER_NAME ": %s initialized\n", ops->name); mutex_unlock(&cx231xx_extension_devlist_lock); mutex_unlock(&cx231xx_devlist_mutex); return 0; @@ -143,7 +143,7 @@ void cx231xx_unregister_extension(struct cx231xx_ops *ops) } mutex_lock(&cx231xx_extension_devlist_lock); - cx231xx_info("Cx231xx: Removed (%s) extension\n", ops->name); + printk(KERN_INFO DRIVER_NAME ": %s removed\n", ops->name); list_del(&ops->next); mutex_unlock(&cx231xx_extension_devlist_lock); mutex_unlock(&cx231xx_devlist_mutex); @@ -906,7 +906,7 @@ int cx231xx_dev_init(struct cx231xx *dev) /* init hardware */ /* Note : with out calling set power mode function, - colibri can not be set up correctly */ + afe can not be set up correctly */ errCode = cx231xx_set_power_mode(dev, POLARIS_AVMODE_ANALOGT_TV); if (errCode < 0) { cx231xx_errdev @@ -916,17 +916,17 @@ int cx231xx_dev_init(struct cx231xx *dev) } /* initialize Colibri block */ - errCode = cx231xx_colibri_init_super_block(dev, 0x23c); + errCode = cx231xx_afe_init_super_block(dev, 0x23c); if (errCode < 0) { cx231xx_errdev - ("%s: cx231xx_colibri init super block - errCode [%d]!\n", + ("%s: cx231xx_afe init super block - errCode [%d]!\n", __func__, errCode); return errCode; } - errCode = cx231xx_colibri_init_channels(dev); + errCode = cx231xx_afe_init_channels(dev); if (errCode < 0) { cx231xx_errdev - ("%s: cx231xx_colibri init channels - errCode [%d]!\n", + ("%s: cx231xx_afe init channels - errCode [%d]!\n", __func__, errCode); return errCode; } @@ -940,11 +940,11 @@ int cx231xx_dev_init(struct cx231xx *dev) return errCode; } - /* flatiron related functions */ - errCode = cx231xx_flatiron_initialize(dev); + /* I2S block related functions */ + errCode = cx231xx_i2s_blk_initialize(dev); if (errCode < 0) { cx231xx_errdev - ("%s: cx231xx_flatiron initialize - errCode [%d]!\n", + ("%s: cx231xx_i2s block initialize - errCode [%d]!\n", __func__, errCode); return errCode; } diff --git a/linux/drivers/media/video/cx231xx/cx231xx-i2c.c b/linux/drivers/media/video/cx231xx/cx231xx-i2c.c index 87dbd4e4e..d196fe666 100644 --- a/linux/drivers/media/video/cx231xx/cx231xx-i2c.c +++ b/linux/drivers/media/video/cx231xx/cx231xx-i2c.c @@ -435,18 +435,6 @@ static int attach_inform(struct i2c_client *client) struct cx231xx *dev = bus->dev; switch (client->addr << 1) { - case 0x32: - dprintk1(1, "attach_inform: Geminit III detected.\n"); - break; - case 0x02: - dprintk1(1, "attach_inform: Acquarius detected.\n"); - break; - case 0xa0: - dprintk1(1, "attach_inform: eeprom detected.\n"); - break; - case 0x60: - dprintk1(1, "attach_inform: Colibri detected.\n"); - break; case 0x8e: { struct IR_i2c *ir = i2c_get_clientdata(client); @@ -455,28 +443,15 @@ static int attach_inform(struct i2c_client *client) cx231xx_set_ir(dev, ir); break; } - case 0x80: - case 0x88: - dprintk1(1, "attach_inform: Hammerhead detected.\n"); break; default: - if (!dev->tuner_addr) - dev->tuner_addr = client->addr; - - dprintk1(1, "attach inform: detected I2C address %x\n", - client->addr << 1); + break; } return 0; } -static int detach_inform(struct i2c_client *client) -{ - dprintk1(1, "i2c detach [client=%s]\n", client->name); - return 0; -} - static struct i2c_algorithm cx231xx_algo = { .master_xfer = cx231xx_i2c_xfer, .functionality = functionality, @@ -487,12 +462,10 @@ static struct i2c_algorithm cx231xx_algo = { static struct i2c_adapter cx231xx_adap_template = { .owner = THIS_MODULE, - .class = I2C_CLASS_TV_ANALOG, .name = "cx231xx", .id = I2C_HW_B_CX231XX, .algo = &cx231xx_algo, .client_register = attach_inform, - .client_unregister = detach_inform, }; static struct i2c_client cx231xx_client_template = { @@ -539,19 +512,6 @@ void cx231xx_do_i2c_scan(struct cx231xx *dev, struct i2c_client *c) } /* - * cx231xx_i2c_call_clients() - * send commands to all attached i2c devices - */ -void cx231xx_i2c_call_clients(struct cx231xx_i2c *bus, unsigned int cmd, - void *arg) -{ - /* struct cx231xx *dev = bus->dev; */ - - BUG_ON(NULL == bus->i2c_adap.algo_data); - i2c_clients_command(&bus->i2c_adap, cmd, arg); -} - -/* * cx231xx_i2c_register() * register i2c bus */ @@ -561,8 +521,6 @@ int cx231xx_i2c_register(struct cx231xx_i2c *bus) BUG_ON(!dev->cx231xx_send_usb_command); - cx231xx_info("%s(bus = %d)\n", __func__, bus->nr); - memcpy(&bus->i2c_adap, &cx231xx_adap_template, sizeof(bus->i2c_adap)); memcpy(&bus->i2c_algo, &cx231xx_algo, sizeof(bus->i2c_algo)); memcpy(&bus->i2c_client, &cx231xx_client_template, @@ -574,13 +532,12 @@ int cx231xx_i2c_register(struct cx231xx_i2c *bus) bus->i2c_algo.data = bus; bus->i2c_adap.algo_data = bus; - i2c_set_adapdata(&bus->i2c_adap, bus); + i2c_set_adapdata(&bus->i2c_adap, &dev->v4l2_dev); i2c_add_adapter(&bus->i2c_adap); bus->i2c_client.adapter = &bus->i2c_adap; if (0 == bus->i2c_rc) { - cx231xx_info("%s: i2c bus %d registered\n", dev->name, bus->nr); if (i2c_scan) cx231xx_do_i2c_scan(dev, &bus->i2c_client); } else diff --git a/linux/drivers/media/video/cx231xx/cx231xx-pcb-cfg.c b/linux/drivers/media/video/cx231xx/cx231xx-pcb-cfg.c index c00f51eae..7473c33e8 100644 --- a/linux/drivers/media/video/cx231xx/cx231xx-pcb-cfg.c +++ b/linux/drivers/media/video/cx231xx/cx231xx-pcb-cfg.c @@ -22,6 +22,10 @@ #include "cx231xx.h" #include "cx231xx-conf-reg.h" +static unsigned int pcb_debug; +module_param(pcb_debug, int, 0644); +MODULE_PARM_DESC(pcb_debug, "enable pcb config debug messages [video]"); + /******************************************************************************/ struct pcb_config cx231xx_Scenario[] = { @@ -659,11 +663,8 @@ u32 initialize_cx231xx(struct cx231xx *dev) u32 ts1_source = 0; u32 ts2_source = 0; u32 analog_source = 0; - u8 tmp = 0; u8 _current_scenario_idx = 0xff; - cx231xx_info("PcbConfig::initialize \n"); - ts1_source = SOURCE_TS_BDA; ts2_source = SOURCE_TS_BDA; @@ -672,7 +673,6 @@ u32 initialize_cx231xx(struct cx231xx *dev) cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER, BOARD_CFG_STAT, data, 4); config_info = *((u32 *) data); - cx231xx_info("SC(0x00) register = 0x%x\n", config_info); usb_speed = (u8) (config_info & 0x1); /* Verify this device belongs to Bus power or Self power device */ @@ -776,18 +776,20 @@ u32 initialize_cx231xx(struct cx231xx *dev) memcpy(&dev->current_pcb_config, p_pcb_info, sizeof(struct pcb_config)); - /*******************************************************************/ - tmp = (dev->current_pcb_config.index) + 1; - - cx231xx_info("scenario %d\n", tmp); - cx231xx_info("type=%x\n", dev->current_pcb_config.type); - cx231xx_info("mode=%x\n", dev->current_pcb_config.mode); - cx231xx_info("speed=%x\n", dev->current_pcb_config.speed); - cx231xx_info("ts1_source=%x\n", dev->current_pcb_config.ts1_source); - cx231xx_info("ts2_source=%x\n", dev->current_pcb_config.ts2_source); - cx231xx_info("analog_source=%x\n", - dev->current_pcb_config.analog_source); - /*******************************************************************/ + if (pcb_debug) { + cx231xx_info("SC(0x00) register = 0x%x\n", config_info); + cx231xx_info("scenario %d\n", + (dev->current_pcb_config.index) + 1); + cx231xx_info("type=%x\n", dev->current_pcb_config.type); + cx231xx_info("mode=%x\n", dev->current_pcb_config.mode); + cx231xx_info("speed=%x\n", dev->current_pcb_config.speed); + cx231xx_info("ts1_source=%x\n", + dev->current_pcb_config.ts1_source); + cx231xx_info("ts2_source=%x\n", + dev->current_pcb_config.ts2_source); + cx231xx_info("analog_source=%x\n", + dev->current_pcb_config.analog_source); + } return 0; } diff --git a/linux/drivers/media/video/cx231xx/cx231xx-pcb-cfg.h b/linux/drivers/media/video/cx231xx/cx231xx-pcb-cfg.h index 86fec113f..f5e46e89f 100644 --- a/linux/drivers/media/video/cx231xx/cx231xx-pcb-cfg.h +++ b/linux/drivers/media/video/cx231xx/cx231xx-pcb-cfg.h @@ -91,10 +91,10 @@ enum TS_PORT{ #define EAVP_MASK 0x8 enum EAV_PRESENT{ NO_EXTERNAL_AV = 0x0, /* 0: No External A/V inputs - (no need for Flatiron), + (no need for i2s blcok), Analog Tuner must be present */ EXTERNAL_AV = 0x8 /* 1: External A/V inputs - present (requires Flatiron) */ + present (requires i2s blk) */ }; #define ATM_MASK 0x30 @@ -123,10 +123,6 @@ enum AVDEC_STATUS{ }; #define BO_1_MASK 0x100 -enum HAMMERHEAD__STATUS{ - HAMMERHEAD_ONLY = 0x0, /* 0:Hammerhead Only */ - HAMMERHEAD_SC = 0x100 /* 1:Hammerhead and SC */ -}; #define BUSPOWER_MASK 0xC4 /* for Polaris spec 0.8 */ #define SELFPOWER_MASK 0x86 diff --git a/linux/drivers/media/video/cx231xx/cx231xx-vbi.c b/linux/drivers/media/video/cx231xx/cx231xx-vbi.c index 9080d1755..020aa13b8 100644 --- a/linux/drivers/media/video/cx231xx/cx231xx-vbi.c +++ b/linux/drivers/media/video/cx231xx/cx231xx-vbi.c @@ -187,10 +187,6 @@ vbi_buffer_setup(struct videobuf_queue *vq, unsigned int *count, if (*count < CX231XX_MIN_BUF) *count = CX231XX_MIN_BUF; - /* call VBI setup if required */ - /* cx231xx_i2c_call_clients(&dev->i2c_bus[1], VIDIOC_S_FREQUENCY, &f); - */ - return 0; } diff --git a/linux/drivers/media/video/cx231xx/cx231xx-video.c b/linux/drivers/media/video/cx231xx/cx231xx-video.c index 2dbe65b83..d53ddcb6a 100644 --- a/linux/drivers/media/video/cx231xx/cx231xx-video.c +++ b/linux/drivers/media/video/cx231xx/cx231xx-video.c @@ -44,6 +44,8 @@ #include "cx231xx.h" #include "cx231xx-vbi.h" +#define CX231XX_VERSION_CODE KERNEL_VERSION(0, 0, 1) + #define DRIVER_AUTHOR "Srinivasa Deevi <srinivasa.deevi@conexant.com>" #define DRIVER_DESC "Conexant cx231xx based USB video device driver" @@ -702,7 +704,7 @@ buffer_setup(struct videobuf_queue *vq, unsigned int *count, unsigned int *size) f.frequency = dev->ctl_freq; f.type = fh->radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV; - cx231xx_i2c_call_clients(&dev->i2c_bus[1], VIDIOC_S_FREQUENCY, &f); + call_all(dev, tuner, s_frequency, &f); return 0; } @@ -828,8 +830,7 @@ void video_mux(struct cx231xx *dev, int index) cx231xx_set_video_input_mux(dev, index); - cx231xx_i2c_call_clients(&dev->i2c_bus[0], VIDIOC_INT_S_VIDEO_ROUTING, - &route); + cx25840_call(dev, video, s_routing, &route); cx231xx_set_audio_input(dev, dev->ctl_ainput); @@ -1043,7 +1044,7 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, dev->format = fmt; get_scale(dev, dev->width, dev->height, &dev->hscale, &dev->vscale); - cx231xx_i2c_call_clients(&dev->i2c_bus[0], VIDIOC_S_FMT, f); + call_all(dev, video, s_fmt, f); /* Set the correct alternate setting for this resolution */ cx231xx_resolution_set(dev); @@ -1062,7 +1063,7 @@ static int vidioc_g_std(struct file *file, void *priv, v4l2_std_id * id) return 0; } -static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id * norm) +static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *norm) { struct cx231xx_fh *fh = priv; struct cx231xx *dev = fh->dev; @@ -1088,7 +1089,7 @@ static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id * norm) dev->height = f.fmt.pix.height; get_scale(dev, dev->width, dev->height, &dev->hscale, &dev->vscale); - cx231xx_i2c_call_clients(&dev->i2c_bus[0], VIDIOC_S_STD, &dev->norm); + call_all(dev, tuner, s_std, dev->norm); mutex_unlock(&dev->lock); @@ -1242,7 +1243,7 @@ static int vidioc_queryctrl(struct file *file, void *priv, *qc = cx231xx_ctls[i].v; mutex_lock(&dev->lock); - cx231xx_i2c_call_clients(&dev->i2c_bus[0], VIDIOC_QUERYCTRL, qc); + call_all(dev, core, queryctrl, qc); mutex_unlock(&dev->lock); if (qc->type) @@ -1263,9 +1264,7 @@ static int vidioc_g_ctrl(struct file *file, void *priv, return rc; mutex_lock(&dev->lock); - - cx231xx_i2c_call_clients(&dev->i2c_bus[0], VIDIOC_G_CTRL, ctrl); - + call_all(dev, core, g_ctrl, ctrl); mutex_unlock(&dev->lock); return rc; } @@ -1282,9 +1281,7 @@ static int vidioc_s_ctrl(struct file *file, void *priv, return rc; mutex_lock(&dev->lock); - - cx231xx_i2c_call_clients(&dev->i2c_bus[0], VIDIOC_S_CTRL, ctrl); - + call_all(dev, core, s_ctrl, ctrl); mutex_unlock(&dev->lock); return rc; } @@ -1326,9 +1323,7 @@ static int vidioc_s_tuner(struct file *file, void *priv, struct v4l2_tuner *t) return -EINVAL; #if 0 /* Keep */ mutex_lock(&dev->lock); - - cx231xx_i2c_call_clients(&dev->i2c_bus[1], VIDIOC_S_TUNER, t); - + call_all(dev, tuner, s_tuner, t); mutex_unlock(&dev->lock); #endif return 0; @@ -1344,7 +1339,7 @@ static int vidioc_g_frequency(struct file *file, void *priv, f->type = fh->radio ? V4L2_TUNER_RADIO : V4L2_TUNER_ANALOG_TV; f->frequency = dev->ctl_freq; - cx231xx_i2c_call_clients(&dev->i2c_bus[1], VIDIOC_G_FREQUENCY, f); + call_all(dev, tuner, g_frequency, f); mutex_unlock(&dev->lock); @@ -1380,10 +1375,8 @@ static int vidioc_s_frequency(struct file *file, void *priv, if (dev->tuner_type == TUNER_XC5000) { if (dev->cx231xx_set_analog_freq != NULL) dev->cx231xx_set_analog_freq(dev, f->frequency); - } else { - cx231xx_i2c_call_clients(&dev->i2c_bus[1], - VIDIOC_S_FREQUENCY, f); - } + } else + call_all(dev, tuner, s_frequency, f); mutex_unlock(&dev->lock); @@ -1428,36 +1421,36 @@ static int vidioc_g_register(struct file *file, void *priv, reg->val = value[0] | value[1] << 8 | value[2] << 16 | value[3] << 24; break; - case 1: /* Colibri - read byte */ - ret = cx231xx_read_i2c_data(dev, Colibri_DEVICE_ADDRESS, + case 1: /* AFE - read byte */ + ret = cx231xx_read_i2c_data(dev, AFE_DEVICE_ADDRESS, (u16)reg->reg, 2, &data, 1); reg->val = le32_to_cpu(data & 0xff); break; - case 14: /* Colibri - read dword */ - ret = cx231xx_read_i2c_data(dev, Colibri_DEVICE_ADDRESS, + case 14: /* AFE - read dword */ + ret = cx231xx_read_i2c_data(dev, AFE_DEVICE_ADDRESS, (u16)reg->reg, 2, &data, 4); reg->val = le32_to_cpu(data); break; - case 2: /* Hammerhead - read byte */ - ret = cx231xx_read_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, + case 2: /* Video Block - read byte */ + ret = cx231xx_read_i2c_data(dev, VID_BLK_I2C_ADDRESS, (u16)reg->reg, 2, &data, 1); reg->val = le32_to_cpu(data & 0xff); break; - case 24: /* Hammerhead - read dword */ - ret = cx231xx_read_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, + case 24: /* Video Block - read dword */ + ret = cx231xx_read_i2c_data(dev, VID_BLK_I2C_ADDRESS, (u16)reg->reg, 2, &data, 4); reg->val = le32_to_cpu(data); break; - case 3: /* flatiron - read byte */ + case 3: /* I2S block - read byte */ ret = cx231xx_read_i2c_data(dev, - Flatrion_DEVICE_ADDRESS, + I2S_BLK_DEVICE_ADDRESS, (u16)reg->reg, 1, &data, 1); reg->val = le32_to_cpu(data & 0xff); break; - case 34: /* flatiron - read dword */ + case 34: /* I2S Block - read dword */ ret = - cx231xx_read_i2c_data(dev, Flatrion_DEVICE_ADDRESS, + cx231xx_read_i2c_data(dev, I2S_BLK_DEVICE_ADDRESS, (u16)reg->reg, 1, &data, 4); reg->val = le32_to_cpu(data); break; @@ -1465,8 +1458,7 @@ static int vidioc_g_register(struct file *file, void *priv, return ret < 0 ? ret : 0; case V4L2_CHIP_MATCH_I2C_DRIVER: - cx231xx_i2c_call_clients(&dev->i2c_bus[0], - VIDIOC_DBG_G_REGISTER, reg); + call_all(dev, core, g_register, reg); return 0; case V4L2_CHIP_MATCH_I2C_ADDR: /* Not supported yet */ @@ -1477,7 +1469,7 @@ static int vidioc_g_register(struct file *file, void *priv, } mutex_lock(&dev->lock); - cx231xx_i2c_call_clients(&dev->i2c_bus[0], VIDIOC_DBG_G_REGISTER, reg); + call_all(dev, core, g_register, reg); mutex_unlock(&dev->lock); return ret; @@ -1511,43 +1503,43 @@ static int vidioc_s_register(struct file *file, void *priv, (u16)reg->reg, data, 4); break; - case 1: /* Colibri - read byte */ + case 1: /* AFE - read byte */ ret = cx231xx_write_i2c_data(dev, - Colibri_DEVICE_ADDRESS, + AFE_DEVICE_ADDRESS, (u16)reg->reg, 2, value, 1); break; - case 14: /* Colibri - read dword */ + case 14: /* AFE - read dword */ ret = cx231xx_write_i2c_data(dev, - Colibri_DEVICE_ADDRESS, + AFE_DEVICE_ADDRESS, (u16)reg->reg, 2, value, 4); break; - case 2: /* Hammerhead - read byte */ + case 2: /* Video Block - read byte */ ret = cx231xx_write_i2c_data(dev, - HAMMERHEAD_I2C_ADDRESS, + VID_BLK_I2C_ADDRESS, (u16)reg->reg, 2, value, 1); break; - case 24: /* Hammerhead - read dword */ + case 24: /* Video Block - read dword */ ret = cx231xx_write_i2c_data(dev, - HAMMERHEAD_I2C_ADDRESS, + VID_BLK_I2C_ADDRESS, (u16)reg->reg, 2, value, 4); break; - case 3: /* flatiron - read byte */ + case 3: /* I2S block - read byte */ ret = cx231xx_write_i2c_data(dev, - Flatrion_DEVICE_ADDRESS, + I2S_BLK_DEVICE_ADDRESS, (u16)reg->reg, 1, value, 1); break; - case 34: /* flatiron - read dword */ + case 34: /* I2S block - read dword */ ret = cx231xx_write_i2c_data(dev, - Flatrion_DEVICE_ADDRESS, + I2S_BLK_DEVICE_ADDRESS, (u16)reg->reg, 1, value, 4); break; @@ -1560,9 +1552,7 @@ static int vidioc_s_register(struct file *file, void *priv, } mutex_lock(&dev->lock); - - cx231xx_i2c_call_clients(&dev->i2c_bus[0], VIDIOC_DBG_S_REGISTER, reg); - + call_all(dev, core, s_register, reg); mutex_unlock(&dev->lock); return ret; @@ -1606,6 +1596,8 @@ static int vidioc_streamon(struct file *file, void *priv, if (likely(rc >= 0)) rc = videobuf_streamon(&fh->vb_vidq); + call_all(dev, video, s_stream, 1); + mutex_unlock(&dev->lock); return rc; @@ -1622,7 +1614,7 @@ static int vidioc_streamoff(struct file *file, void *priv, if (rc < 0) return rc; - if ((fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) || + if ((fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) && (fh->type != V4L2_BUF_TYPE_VBI_CAPTURE)) return -EINVAL; if (type != fh->type) @@ -1630,6 +1622,8 @@ static int vidioc_streamoff(struct file *file, void *priv, mutex_lock(&dev->lock); + cx25840_call(dev, video, s_stream, 0); + videobuf_streamoff(&fh->vb_vidq); res_free(fh); @@ -1646,8 +1640,7 @@ static int vidioc_querycap(struct file *file, void *priv, strlcpy(cap->driver, "cx231xx", sizeof(cap->driver)); strlcpy(cap->card, cx231xx_boards[dev->model].name, sizeof(cap->card)); - strlcpy(cap->bus_info, dev_name(&dev->udev->dev), - sizeof(cap->bus_info)); + usb_make_path(dev->udev, cap->bus_info, sizeof(cap->bus_info)); cap->version = CX231XX_VERSION_CODE; @@ -1694,7 +1687,7 @@ static int vidioc_g_fmt_sliced_vbi_cap(struct file *file, void *priv, f->fmt.sliced.service_set = 0; - cx231xx_i2c_call_clients(&dev->i2c_bus[0], VIDIOC_G_FMT, f); + call_all(dev, video, g_fmt, f); if (f->fmt.sliced.service_set == 0) rc = -EINVAL; @@ -1715,7 +1708,7 @@ static int vidioc_try_set_sliced_vbi_cap(struct file *file, void *priv, return rc; mutex_lock(&dev->lock); - cx231xx_i2c_call_clients(&dev->i2c_bus[0], VIDIOC_G_FMT, f); + call_all(dev, video, g_fmt, f); mutex_unlock(&dev->lock); if (f->fmt.sliced.service_set == 0) @@ -1870,7 +1863,7 @@ static int radio_g_tuner(struct file *file, void *priv, struct v4l2_tuner *t) t->type = V4L2_TUNER_RADIO; mutex_lock(&dev->lock); - cx231xx_i2c_call_clients(&dev->i2c_bus[1], VIDIOC_G_TUNER, t); + call_all(dev, tuner, s_tuner, t); mutex_unlock(&dev->lock); return 0; @@ -1903,7 +1896,7 @@ static int radio_s_tuner(struct file *file, void *priv, struct v4l2_tuner *t) return -EINVAL; mutex_lock(&dev->lock); - cx231xx_i2c_call_clients(&dev->i2c_bus[1], VIDIOC_S_TUNER, t); + call_all(dev, tuner, s_tuner, t); mutex_unlock(&dev->lock); return 0; @@ -2009,8 +2002,7 @@ static int cx231xx_v4l2_open(struct file *filp) /* cx231xx_start_radio(dev); */ - cx231xx_i2c_call_clients(&dev->i2c_bus[1], AUDC_SET_RADIO, - NULL); + call_all(dev, tuner, s_radio); } dev->users++; @@ -2133,8 +2125,7 @@ static int cx231xx_v4l2_close(struct file *filp) } /* Save some power by putting tuner to sleep */ - cx231xx_i2c_call_clients(&dev->i2c_bus[1], TUNER_SET_STANDBY, - NULL); + call_all(dev, core, s_standby, 0); /* do this before setting alternate! */ cx231xx_uninit_isoc(dev); @@ -2348,7 +2339,7 @@ static struct video_device *cx231xx_vdev_init(struct cx231xx *dev, *vfd = *template; vfd->minor = -1; - vfd->parent = &dev->udev->dev; + vfd->v4l2_dev = &dev->v4l2_dev; vfd->release = video_device_release; vfd->debug = video_debug; @@ -2361,8 +2352,6 @@ int cx231xx_register_analog_devices(struct cx231xx *dev) { int ret; - cx231xx_info("%s()\n", __func__); - cx231xx_info("%s: v4l2 driver version %d.%d.%d\n", dev->name, (CX231XX_VERSION_CODE >> 16) & 0xff, diff --git a/linux/drivers/media/video/cx231xx/cx231xx.h b/linux/drivers/media/video/cx231xx/cx231xx.h index 4606f27b4..21b4023dd 100644 --- a/linux/drivers/media/video/cx231xx/cx231xx.h +++ b/linux/drivers/media/video/cx231xx/cx231xx.h @@ -22,13 +22,17 @@ #ifndef _CX231XX_H #define _CX231XX_H -#include "compat.h" #include <linux/videodev2.h> -#include <media/videobuf-vmalloc.h> - +#include <linux/types.h> +#include <linux/ioctl.h> #include <linux/i2c.h> #include <linux/i2c-algo-bit.h> #include <linux/mutex.h> + +#include "compat.h" + +#include <media/videobuf-vmalloc.h> +#include <media/v4l2-device.h> #include <media/ir-kbd-i2c.h> #if defined(CONFIG_VIDEO_CX231XX_DVB) || \ defined(CONFIG_VIDEO_CX231XX_DVB_MODULE) @@ -39,14 +43,13 @@ #include "cx231xx-pcb-cfg.h" #include "cx231xx-conf-reg.h" -#define CX231XX_VERSION_CODE KERNEL_VERSION(0, 1, 0) #define DRIVER_NAME "cx231xx" #define PWR_SLEEP_INTERVAL 5 /* I2C addresses for control block in Cx231xx */ -#define Colibri_DEVICE_ADDRESS 0x60 -#define Flatrion_DEVICE_ADDRESS 0x98 -#define HAMMERHEAD_I2C_ADDRESS 0x88 +#define AFE_DEVICE_ADDRESS 0x60 +#define I2S_BLK_DEVICE_ADDRESS 0x98 +#define VID_BLK_I2C_ADDRESS 0x88 #define DIF_USE_BASEBAND 0xFFFFFFFF /* Boards supported by driver */ @@ -457,6 +460,10 @@ struct cx231xx { struct cx231xx_fmt *format; + struct v4l2_device v4l2_dev; + struct v4l2_subdev *sd_cx25840; + struct v4l2_subdev *sd_tuner; + struct cx231xx_IR *ir; struct list_head devlist; @@ -542,9 +549,9 @@ struct cx231xx { /* Power Modes */ int power_mode; - /* colibri parameters */ - enum AFE_MODE colibri_mode; - u32 colibri_ref_count; + /* afe parameters */ + enum AFE_MODE afe_mode; + u32 afe_ref_count; /* video related parameters */ u32 video_input; @@ -554,6 +561,13 @@ struct cx231xx { }; +#define cx25840_call(cx231xx, o, f, args...) \ + v4l2_subdev_call(cx231xx->sd_cx25840, o, f, ##args) +#define tuner_call(cx231xx, o, f, args...) \ + v4l2_subdev_call(cx231xx->sd_tuner, o, f, ##args) +#define call_all(dev, o, f, args...) \ + v4l2_device_call_until_err(&dev->v4l2_dev, 0, o, f, ##args) + struct cx231xx_ops { struct list_head next; char *name; @@ -567,8 +581,6 @@ int cx231xx_set_analog_freq(struct cx231xx *dev, u32 freq); int cx231xx_reset_analog_tuner(struct cx231xx *dev); /* Provided by cx231xx-i2c.c */ -void cx231xx_i2c_call_clients(struct cx231xx_i2c *bus, unsigned int cmd, - void *arg); void cx231xx_do_i2c_scan(struct cx231xx *dev, struct i2c_client *c); int cx231xx_i2c_register(struct cx231xx_i2c *bus); int cx231xx_i2c_unregister(struct cx231xx_i2c *bus); @@ -585,21 +597,21 @@ int cx231xx_read_modify_write_i2c_dword(struct cx231xx *dev, u8 dev_addr, u16 saddr, u32 mask, u32 value); u32 cx231xx_set_field(u32 field_mask, u32 data); -/* Colibri related functions */ -int cx231xx_colibri_init_super_block(struct cx231xx *dev, u32 ref_count); -int cx231xx_colibri_init_channels(struct cx231xx *dev); -int cx231xx_colibri_setup_AFE_for_baseband(struct cx231xx *dev); -int cx231xx_colibri_set_input_mux(struct cx231xx *dev, u32 input_mux); -int cx231xx_colibri_set_mode(struct cx231xx *dev, enum AFE_MODE mode); -int cx231xx_colibri_update_power_control(struct cx231xx *dev, +/* afe related functions */ +int cx231xx_afe_init_super_block(struct cx231xx *dev, u32 ref_count); +int cx231xx_afe_init_channels(struct cx231xx *dev); +int cx231xx_afe_setup_AFE_for_baseband(struct cx231xx *dev); +int cx231xx_afe_set_input_mux(struct cx231xx *dev, u32 input_mux); +int cx231xx_afe_set_mode(struct cx231xx *dev, enum AFE_MODE mode); +int cx231xx_afe_update_power_control(struct cx231xx *dev, enum AV_MODE avmode); -int cx231xx_colibri_adjust_ref_count(struct cx231xx *dev, u32 video_input); +int cx231xx_afe_adjust_ref_count(struct cx231xx *dev, u32 video_input); -/* flatiron related functions */ -int cx231xx_flatiron_initialize(struct cx231xx *dev); -int cx231xx_flatiron_update_power_control(struct cx231xx *dev, +/* i2s block related functions */ +int cx231xx_i2s_blk_initialize(struct cx231xx *dev); +int cx231xx_i2s_blk_update_power_control(struct cx231xx *dev, enum AV_MODE avmode); -int cx231xx_flatiron_set_audio_input(struct cx231xx *dev, u8 audio_input); +int cx231xx_i2s_blk_set_audio_input(struct cx231xx *dev, u8 audio_input); /* DIF related functions */ int cx231xx_dif_configure_C2HH_for_low_IF(struct cx231xx *dev, u32 mode, diff --git a/linux/drivers/media/video/cx23885/Kconfig b/linux/drivers/media/video/cx23885/Kconfig index e603ceb28..fd3fc3e31 100644 --- a/linux/drivers/media/video/cx23885/Kconfig +++ b/linux/drivers/media/video/cx23885/Kconfig @@ -19,11 +19,11 @@ config VIDEO_CX23885 select DVB_LNBP21 if !DVB_FE_CUSTOMISE select DVB_STV6110 if !DVB_FE_CUSTOMISE select DVB_STV0900 if !DVB_FE_CUSTOMISE - select MEDIA_TUNER_MT2131 if !MEDIA_TUNER_CUSTOMIZE - select MEDIA_TUNER_XC2028 if !MEDIA_TUNER_CUSTOMIZE - select MEDIA_TUNER_TDA8290 if !MEDIA_TUNER_CUSTOMIZE - select MEDIA_TUNER_TDA18271 if !MEDIA_TUNER_CUSTOMIZE - select MEDIA_TUNER_XC5000 if !MEDIA_TUNER_CUSTOMIZE + select MEDIA_TUNER_MT2131 if !MEDIA_TUNER_CUSTOMISE + select MEDIA_TUNER_XC2028 if !MEDIA_TUNER_CUSTOMISE + select MEDIA_TUNER_TDA8290 if !MEDIA_TUNER_CUSTOMISE + select MEDIA_TUNER_TDA18271 if !MEDIA_TUNER_CUSTOMISE + select MEDIA_TUNER_XC5000 if !MEDIA_TUNER_CUSTOMISE ---help--- This is a video4linux driver for Conexant 23885 based TV cards. diff --git a/linux/drivers/media/video/cx23885/cimax2.c b/linux/drivers/media/video/cx23885/cimax2.c index 193d9b4cc..0e29f97f3 100644 --- a/linux/drivers/media/video/cx23885/cimax2.c +++ b/linux/drivers/media/video/cx23885/cimax2.c @@ -157,7 +157,7 @@ int netup_ci_get_mem(struct cx23885_dev *dev) } int netup_ci_op_cam(struct dvb_ca_en50221 *en50221, int slot, - u8 flag, u8 read, u8 addr, u8 data) + u8 flag, u8 read, int addr, u8 data) { struct netup_ci_state *state = en50221->data; struct cx23885_tsport *port = state->priv; diff --git a/linux/drivers/media/video/cx23885/cx23885-core.c b/linux/drivers/media/video/cx23885/cx23885-core.c index 6ae7ee247..d894d4900 100644 --- a/linux/drivers/media/video/cx23885/cx23885-core.c +++ b/linux/drivers/media/video/cx23885/cx23885-core.c @@ -1710,7 +1710,8 @@ static irqreturn_t cx23885_irq(int irq, void *dev_id) PCI_MSK_GPIO1); } - if ((pci_status & PCI_MSK_GPIO0) || (pci_status & PCI_MSK_GPIO1)) + if (cx23885_boards[dev->board].cimax > 0 && + ((pci_status & PCI_MSK_GPIO0) || (pci_status & PCI_MSK_GPIO1))) /* handled += cx23885_irq_gpio(dev, pci_status); */ handled += netup_ci_slot_status(dev, pci_status); @@ -1786,7 +1787,12 @@ static int __devinit cx23885_initdev(struct pci_dev *pci_dev, } pci_set_drvdata(pci_dev, dev); - cx_set(PCI_INT_MSK, 0x01800000); /* for NetUP */ + + switch (dev->board) { + case CX23885_BOARD_NETUP_DUAL_DVBS2_CI: + cx_set(PCI_INT_MSK, 0x01800000); /* for NetUP */ + break; + } return 0; diff --git a/linux/drivers/media/video/cx23885/cx23885-dvb.c b/linux/drivers/media/video/cx23885/cx23885-dvb.c index 5529dcf6a..364543987 100644 --- a/linux/drivers/media/video/cx23885/cx23885-dvb.c +++ b/linux/drivers/media/video/cx23885/cx23885-dvb.c @@ -779,7 +779,11 @@ int cx23885_dvb_unregister(struct cx23885_tsport *port) if (fe0->dvb.frontend) videobuf_dvb_unregister_bus(&port->frontends); - netup_ci_exit(port); + switch (port->dev->board) { + case CX23885_BOARD_NETUP_DUAL_DVBS2_CI: + netup_ci_exit(port); + break; + } return 0; } diff --git a/linux/drivers/media/video/cx25840/cx25840-core.c b/linux/drivers/media/video/cx25840/cx25840-core.c index b10f2bb8b..5387a846f 100644 --- a/linux/drivers/media/video/cx25840/cx25840-core.c +++ b/linux/drivers/media/video/cx25840/cx25840-core.c @@ -1594,9 +1594,9 @@ static int cx25840_probe(struct i2c_client *client, } else if ((device_id & 0xff00) == 0x8400) { id = V4L2_IDENT_CX25840 + ((device_id >> 4) & 0xf); - } /* else if (device_id == 0x0000) { + } else if (device_id == 0x0000) { id = V4L2_IDENT_CX25836 + ((device_id >> 4) & 0xf) - 6; - } */ else if (device_id == 0x1313) { + } else if (device_id == 0x1313) { id = V4L2_IDENT_CX25836 + ((device_id >> 4) & 0xf) - 6; } else if ((device_id & 0xfff0) == 0x5A30) { id = V4L2_IDENT_CX25840 + ((device_id >> 4) & 0xf); diff --git a/linux/drivers/media/video/cx88/Kconfig b/linux/drivers/media/video/cx88/Kconfig index 2d250a2a7..49952980d 100644 --- a/linux/drivers/media/video/cx88/Kconfig +++ b/linux/drivers/media/video/cx88/Kconfig @@ -61,7 +61,7 @@ config VIDEO_CX88_DVB select DVB_STV0299 if !DVB_FE_CUSTOMISE select DVB_STV0288 if !DVB_FE_CUSTOMISE select DVB_STB6000 if !DVB_FE_CUSTOMISE - select MEDIA_TUNER_SIMPLE if !MEDIA_TUNER_CUSTOMIZE + select MEDIA_TUNER_SIMPLE if !MEDIA_TUNER_CUSTOMISE ---help--- This adds support for DVB/ATSC cards based on the Conexant 2388x chip. diff --git a/linux/drivers/media/video/cx88/cx88-cards.c b/linux/drivers/media/video/cx88/cx88-cards.c index b3d966ad5..2f30d34be 100644 --- a/linux/drivers/media/video/cx88/cx88-cards.c +++ b/linux/drivers/media/video/cx88/cx88-cards.c @@ -3160,6 +3160,8 @@ struct cx88_core *cx88_core_create(struct pci_dev *pci, int nr) int i; core = kzalloc(sizeof(*core), GFP_KERNEL); + if (core == NULL) + return NULL; atomic_inc(&core->refcount); core->pci_bus = pci->bus->number; @@ -3171,7 +3173,15 @@ struct cx88_core *cx88_core_create(struct pci_dev *pci, int nr) core->nr = nr; sprintf(core->name, "cx88[%d]", core->nr); + + strcpy(core->v4l2_dev.name, core->name); + if (v4l2_device_register(NULL, &core->v4l2_dev)) { + kfree(core); + return NULL; + } + if (0 != cx88_get_resources(core, pci)) { + v4l2_device_unregister(&core->v4l2_dev); kfree(core); return NULL; } @@ -3182,6 +3192,11 @@ struct cx88_core *cx88_core_create(struct pci_dev *pci, int nr) pci_resource_len(pci, 0)); core->bmmio = (u8 __iomem *)core->lmmio; + if (core->lmmio == NULL) { + kfree(core); + return NULL; + } + /* board config */ core->boardnr = UNSET; if (card[core->nr] < ARRAY_SIZE(cx88_boards)) diff --git a/linux/drivers/media/video/cx88/cx88-core.c b/linux/drivers/media/video/cx88/cx88-core.c index c9de13b56..ca36a48fa 100644 --- a/linux/drivers/media/video/cx88/cx88-core.c +++ b/linux/drivers/media/video/cx88/cx88-core.c @@ -1040,7 +1040,8 @@ struct video_device *cx88_vdev_init(struct cx88_core *core, return NULL; *vfd = *template; vfd->minor = -1; - vfd->parent = &pci->dev; + vfd->v4l2_dev = &core->v4l2_dev; + vfd->parent = &pci->dev; vfd->release = video_device_release; snprintf(vfd->name, sizeof(vfd->name), "%s %s (%s)", core->name, type, core->board.name); @@ -1093,6 +1094,7 @@ void cx88_core_put(struct cx88_core *core, struct pci_dev *pci) iounmap(core->lmmio); cx88_devcount--; mutex_unlock(&devlist); + v4l2_device_unregister(&core->v4l2_dev); kfree(core); } diff --git a/linux/drivers/media/video/cx88/cx88-i2c.c b/linux/drivers/media/video/cx88/cx88-i2c.c index c0ff2305d..4a17a7579 100644 --- a/linux/drivers/media/video/cx88/cx88-i2c.c +++ b/linux/drivers/media/video/cx88/cx88-i2c.c @@ -99,7 +99,8 @@ static int cx8800_bit_getsda(void *data) static int attach_inform(struct i2c_client *client) { - struct cx88_core *core = i2c_get_adapdata(client->adapter); + struct v4l2_device *v4l2_dev = i2c_get_adapdata(client->adapter); + struct cx88_core *core = to_core(v4l2_dev); dprintk(1, "%s i2c attach [addr=0x%x,client=%s]\n", client->driver->driver.name, client->addr, client->name); @@ -108,7 +109,8 @@ static int attach_inform(struct i2c_client *client) static int detach_inform(struct i2c_client *client) { - struct cx88_core *core = i2c_get_adapdata(client->adapter); + struct v4l2_device *v4l2_dev = i2c_get_adapdata(client->adapter); + struct cx88_core *core = to_core(v4l2_dev); dprintk(1, "i2c detach [client=%s]\n", client->name); return 0; @@ -186,7 +188,7 @@ int cx88_i2c_init(struct cx88_core *core, struct pci_dev *pci) core->i2c_adap.client_unregister = detach_inform; core->i2c_algo.udelay = i2c_udelay; core->i2c_algo.data = core; - i2c_set_adapdata(&core->i2c_adap,core); + i2c_set_adapdata(&core->i2c_adap, &core->v4l2_dev); core->i2c_adap.algo_data = &core->i2c_algo; core->i2c_client.adapter = &core->i2c_adap; strlcpy(core->i2c_client.name, "cx88xx internal", I2C_NAME_SIZE); diff --git a/linux/drivers/media/video/cx88/cx88.h b/linux/drivers/media/video/cx88/cx88.h index 1372d2b7b..d70e26000 100644 --- a/linux/drivers/media/video/cx88/cx88.h +++ b/linux/drivers/media/video/cx88/cx88.h @@ -25,7 +25,7 @@ #include <linux/videodev2.h> #include <linux/kdev_t.h> -#include <media/v4l2-common.h> +#include <media/v4l2-device.h> #include <media/tuner.h> #include <media/tveeprom.h> #include <media/videobuf-dma-sg.h> @@ -331,6 +331,7 @@ struct cx88_core { u32 i2c_state, i2c_rc; /* config info -- analog */ + struct v4l2_device v4l2_dev; unsigned int boardnr; struct cx88_board board; @@ -369,6 +370,11 @@ struct cx88_core { int active_fe_id; }; +static inline struct cx88_core *to_core(struct v4l2_device *v4l2_dev) +{ + return container_of(v4l2_dev, struct cx88_core, v4l2_dev); +} + struct cx8800_dev; struct cx8802_dev; diff --git a/linux/drivers/media/video/dabusb.c b/linux/drivers/media/video/dabusb.c index b399f18c1..5585f46dd 100644 --- a/linux/drivers/media/video/dabusb.c +++ b/linux/drivers/media/video/dabusb.c @@ -351,7 +351,7 @@ static int dabusb_loadmem (pdabusb_t s, const char *fname) PINTEL_HEX_RECORD ptr = firmware; #else const struct ihex_binrec *rec; - const struct firmware *fw; + const struct firmware *uninitialized_var(fw); #endif dbg("Enter dabusb_loadmem (internal)"); @@ -734,8 +734,9 @@ static int dabusb_release (struct inode *inode, struct file *file) return 0; } -static int dabusb_ioctl (struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg) +static long dabusb_ioctl (struct file *file, unsigned int cmd, unsigned long arg) { + lock_kernel(); pdabusb_t s = (pdabusb_t) file->private_data; pbulk_transfer_t pbulk; int ret = 0; @@ -743,13 +744,16 @@ static int dabusb_ioctl (struct inode *inode, struct file *file, unsigned int cm dbg("dabusb_ioctl"); - if (s->remove_pending) + if (s->remove_pending) { + unlock_kernel(); return -EIO; + } mutex_lock(&s->mutex); if (!s->usbdev) { mutex_unlock(&s->mutex); + unlock_kernel(); return -EIO; } @@ -790,6 +794,7 @@ static int dabusb_ioctl (struct inode *inode, struct file *file, unsigned int cm break; } mutex_unlock(&s->mutex); + unlock_kernel(); return ret; } @@ -802,7 +807,7 @@ static struct file_operations dabusb_fops = .owner = THIS_MODULE, .llseek = no_llseek, .read = dabusb_read, - .ioctl = dabusb_ioctl, + .unlocked_ioctl = dabusb_ioctl, .open = dabusb_open, .release = dabusb_release, }; diff --git a/linux/drivers/media/video/em28xx/em28xx-cards.c b/linux/drivers/media/video/em28xx/em28xx-cards.c index fcb8131e6..6b4a204a9 100644 --- a/linux/drivers/media/video/em28xx/em28xx-cards.c +++ b/linux/drivers/media/video/em28xx/em28xx-cards.c @@ -652,6 +652,7 @@ struct em28xx_board em28xx_boards[] = { .mts_firmware = 1, .has_dvb = 1, .dvb_gpio = hauppauge_wintv_hvr_900_digital, + .ir_codes = ir_codes_hauppauge_new, .decoder = EM28XX_TVP5150, .input = { { .type = EM28XX_VMUX_TELEVISION, @@ -676,6 +677,7 @@ struct em28xx_board em28xx_boards[] = { .tuner_type = TUNER_XC2028, .tuner_gpio = default_tuner_gpio, .mts_firmware = 1, + .ir_codes = ir_codes_hauppauge_new, .decoder = EM28XX_TVP5150, #if 0 /* FIXME: add an entry at em28xx-dvb */ .has_dvb = 1, diff --git a/linux/drivers/media/video/em28xx/em28xx-core.c b/linux/drivers/media/video/em28xx/em28xx-core.c index 0d4c9fcc2..4edd3870e 100644 --- a/linux/drivers/media/video/em28xx/em28xx-core.c +++ b/linux/drivers/media/video/em28xx/em28xx-core.c @@ -991,7 +991,7 @@ int em28xx_init_isoc(struct em28xx *dev, int max_packets, em28xx_irq_callback, dma_q, 1); urb->number_of_packets = max_packets; - urb->transfer_flags = URB_ISO_ASAP; + urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP; k = 0; for (j = 0; j < max_packets; j++) { diff --git a/linux/drivers/media/video/gspca/Kconfig b/linux/drivers/media/video/gspca/Kconfig index a0f05ef5c..578dc4ffc 100644 --- a/linux/drivers/media/video/gspca/Kconfig +++ b/linux/drivers/media/video/gspca/Kconfig @@ -185,6 +185,15 @@ config USB_GSPCA_SQ905 To compile this driver as a module, choose M here: the module will be called gspca_sq905. +config USB_GSPCA_SQ905C + tristate "SQ Technologies SQ905C based USB Camera Driver" + depends on VIDEO_V4L2 && USB_GSPCA + help + Say Y here if you want support for cameras based on the SQ905C chip. + + To compile this driver as a module, choose M here: the + module will be called gspca_sq905c. + config USB_GSPCA_STK014 tristate "Syntek DV4000 (STK014) USB Camera Driver" depends on VIDEO_V4L2 && USB_GSPCA diff --git a/linux/drivers/media/video/gspca/Makefile b/linux/drivers/media/video/gspca/Makefile index b6ec61185..8a6643e8e 100644 --- a/linux/drivers/media/video/gspca/Makefile +++ b/linux/drivers/media/video/gspca/Makefile @@ -17,6 +17,7 @@ obj-$(CONFIG_USB_GSPCA_SPCA506) += gspca_spca506.o obj-$(CONFIG_USB_GSPCA_SPCA508) += gspca_spca508.o obj-$(CONFIG_USB_GSPCA_SPCA561) += gspca_spca561.o obj-$(CONFIG_USB_GSPCA_SQ905) += gspca_sq905.o +obj-$(CONFIG_USB_GSPCA_SQ905C) += gspca_sq905c.o obj-$(CONFIG_USB_GSPCA_SUNPLUS) += gspca_sunplus.o obj-$(CONFIG_USB_GSPCA_STK014) += gspca_stk014.o obj-$(CONFIG_USB_GSPCA_T613) += gspca_t613.o @@ -43,6 +44,7 @@ gspca_spca506-objs := spca506.o gspca_spca508-objs := spca508.o gspca_spca561-objs := spca561.o gspca_sq905-objs := sq905.o +gspca_sq905c-objs := sq905c.o gspca_stk014-objs := stk014.o gspca_sunplus-objs := sunplus.o gspca_t613-objs := t613.o diff --git a/linux/drivers/media/video/gspca/conex.c b/linux/drivers/media/video/gspca/conex.c index de2e608bf..219cfa6fb 100644 --- a/linux/drivers/media/video/gspca/conex.c +++ b/linux/drivers/media/video/gspca/conex.c @@ -23,7 +23,6 @@ #include "gspca.h" #define CONEX_CAM 1 /* special JPEG header */ -#define QUANT_VAL 0 /* quantization table */ #include "jpeg.h" MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>"); @@ -37,6 +36,12 @@ struct sd { unsigned char brightness; unsigned char contrast; unsigned char colors; + u8 quality; +#define QUALITY_MIN 30 +#define QUALITY_MAX 60 +#define QUALITY_DEF 40 + + u8 *jpeg_hdr; }; /* V4L2 controls supported by the driver */ @@ -820,6 +825,7 @@ static int sd_config(struct gspca_dev *gspca_dev, sd->brightness = BRIGHTNESS_DEF; sd->contrast = CONTRAST_DEF; sd->colors = COLOR_DEF; + sd->quality = QUALITY_DEF; return 0; } @@ -836,6 +842,14 @@ static int sd_init(struct gspca_dev *gspca_dev) static int sd_start(struct gspca_dev *gspca_dev) { + struct sd *sd = (struct sd *) gspca_dev; + + /* create the JPEG header */ + sd->jpeg_hdr = kmalloc(JPEG_HDR_SZ, GFP_KERNEL); + jpeg_define(sd->jpeg_hdr, gspca_dev->height, gspca_dev->width, + 0x22); /* JPEG 411 */ + jpeg_set_qual(sd->jpeg_hdr, sd->quality); + cx11646_initsize(gspca_dev); cx11646_fw(gspca_dev); cx_sensor(gspca_dev); @@ -846,8 +860,11 @@ static int sd_start(struct gspca_dev *gspca_dev) /* called on streamoff with alt 0 and on disconnect */ static void sd_stop0(struct gspca_dev *gspca_dev) { + struct sd *sd = (struct sd *) gspca_dev; int retry = 50; + kfree(sd->jpeg_hdr); + if (!gspca_dev->present) return; reg_w_val(gspca_dev, 0x0000, 0x00); @@ -873,6 +890,8 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev, __u8 *data, /* isoc packet */ int len) /* iso packet length */ { + struct sd *sd = (struct sd *) gspca_dev; + if (data[0] == 0xff && data[1] == 0xd8) { /* start of frame */ @@ -880,7 +899,8 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev, data, 0); /* put the JPEG header in the new frame */ - jpeg_put_header(gspca_dev, frame, 0x22); + gspca_frame_add(gspca_dev, FIRST_PACKET, frame, + sd->jpeg_hdr, JPEG_HDR_SZ); data += 2; len -= 2; } @@ -983,6 +1003,34 @@ static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val) return 0; } +static int sd_set_jcomp(struct gspca_dev *gspca_dev, + struct v4l2_jpegcompression *jcomp) +{ + struct sd *sd = (struct sd *) gspca_dev; + + if (jcomp->quality < QUALITY_MIN) + sd->quality = QUALITY_MIN; + else if (jcomp->quality > QUALITY_MAX) + sd->quality = QUALITY_MAX; + else + sd->quality = jcomp->quality; + if (gspca_dev->streaming) + jpeg_set_qual(sd->jpeg_hdr, sd->quality); + return 0; +} + +static int sd_get_jcomp(struct gspca_dev *gspca_dev, + struct v4l2_jpegcompression *jcomp) +{ + struct sd *sd = (struct sd *) gspca_dev; + + memset(jcomp, 0, sizeof *jcomp); + jcomp->quality = sd->quality; + jcomp->jpeg_markers = V4L2_JPEG_MARKER_DHT + | V4L2_JPEG_MARKER_DQT; + return 0; +} + /* sub-driver description */ static struct sd_desc sd_desc = { .name = MODULE_NAME, @@ -993,6 +1041,8 @@ static struct sd_desc sd_desc = { .start = sd_start, .stop0 = sd_stop0, .pkt_scan = sd_pkt_scan, + .get_jcomp = sd_get_jcomp, + .set_jcomp = sd_set_jcomp, }; /* -- module initialisation -- */ diff --git a/linux/drivers/media/video/gspca/finepix.c b/linux/drivers/media/video/gspca/finepix.c index dc65c363a..00e6863ed 100644 --- a/linux/drivers/media/video/gspca/finepix.c +++ b/linux/drivers/media/video/gspca/finepix.c @@ -27,7 +27,7 @@ MODULE_DESCRIPTION("Fujifilm FinePix USB V4L2 driver"); MODULE_LICENSE("GPL"); /* Default timeout, in ms */ -#define FPIX_TIMEOUT (HZ / 10) +#define FPIX_TIMEOUT 250 /* Maximum transfer size to use. The windows driver reads by chunks of * 0x2000 bytes, so do the same. Note: reading more seems to work @@ -38,38 +38,15 @@ MODULE_LICENSE("GPL"); struct usb_fpix { struct gspca_dev gspca_dev; /* !! must be the first item */ - /* - * USB stuff - */ - struct usb_ctrlrequest ctrlreq; - struct urb *control_urb; - struct timer_list bulk_timer; - - enum { - FPIX_NOP, /* inactive, else streaming */ - FPIX_RESET, /* must reset */ - FPIX_REQ_FRAME, /* requesting a frame */ - FPIX_READ_FRAME, /* reading frame */ - } state; - - /* - * Driver stuff - */ - struct delayed_work wqe; - struct completion can_close; - int streaming; + struct work_struct work_struct; + struct workqueue_struct *work_thread; }; /* Delay after which claim the next frame. If the delay is too small, * the camera will return old frames. On the 4800Z, 20ms is bad, 25ms - * will fail every 4 or 5 frames, but 30ms is perfect. */ -#define NEXT_FRAME_DELAY (((HZ * 30) + 999) / 1000) - -#define dev_new_state(new_state) { \ - PDEBUG(D_STREAM, "new state from %d to %d at %s:%d", \ - dev->state, new_state, __func__, __LINE__); \ - dev->state = new_state; \ -} + * will fail every 4 or 5 frames, but 30ms is perfect. On the A210, + * 30ms is bad while 35ms is perfect. */ +#define NEXT_FRAME_DELAY 35 /* These cameras only support 320x200. */ static const struct v4l2_pix_format fpix_mode[1] = { @@ -80,314 +57,183 @@ static const struct v4l2_pix_format fpix_mode[1] = { .priv = 0} }; -/* Reads part of a frame */ -static void read_frame_part(struct usb_fpix *dev) +/* send a command to the webcam */ +static int command(struct gspca_dev *gspca_dev, + int order) /* 0: reset, 1: frame request */ { - int ret; + static u8 order_values[2][12] = { + {0xc6, 0, 0, 0, 0, 0, 0, 0, 0x20, 0, 0, 0}, /* reset */ + {0xd3, 0, 0, 0, 0, 0, 0, 0x01, 0, 0, 0, 0}, /* fr req */ + }; - PDEBUG(D_STREAM, "read_frame_part"); - - /* Reads part of a frame */ - ret = usb_submit_urb(dev->gspca_dev.urb[0], GFP_ATOMIC); - if (ret) { - dev_new_state(FPIX_RESET); - schedule_delayed_work(&dev->wqe, 1); - PDEBUG(D_STREAM, "usb_submit_urb failed with %d", - ret); - } else { - /* Sometimes we never get a callback, so use a timer. - * Is this masking a bug somewhere else? */ - dev->bulk_timer.expires = jiffies + msecs_to_jiffies(150); - add_timer(&dev->bulk_timer); - } + memcpy(gspca_dev->usb_buf, order_values[order], 12); + return usb_control_msg(gspca_dev->dev, + usb_sndctrlpipe(gspca_dev->dev, 0), + USB_REQ_GET_STATUS, + USB_DIR_OUT | USB_TYPE_CLASS | + USB_RECIP_INTERFACE, 0, 0, gspca_dev->usb_buf, + 12, FPIX_TIMEOUT); } -/* Callback for URBs. */ -static void urb_callback(struct urb *urb) +/* workqueue */ +static void dostream(struct work_struct *work) { - struct gspca_dev *gspca_dev = urb->context; - struct usb_fpix *dev = (struct usb_fpix *) gspca_dev; - - PDEBUG(D_PACK, - "enter urb_callback - status=%d, length=%d", - urb->status, urb->actual_length); - - if (dev->state == FPIX_READ_FRAME) - del_timer(&dev->bulk_timer); - - if (urb->status != 0) { - /* We kill a stuck urb every 50 frames on average, so don't - * display a log message for that. */ - if (urb->status != -ECONNRESET) - PDEBUG(D_STREAM, "bad URB status %d", urb->status); - dev_new_state(FPIX_RESET); - schedule_delayed_work(&dev->wqe, 1); - } - - switch (dev->state) { - case FPIX_REQ_FRAME: - dev_new_state(FPIX_READ_FRAME); - read_frame_part(dev); - break; - - case FPIX_READ_FRAME: { - unsigned char *data = urb->transfer_buffer; - struct gspca_frame *frame; - - frame = gspca_get_i_frame(&dev->gspca_dev); - if (frame == NULL) - gspca_dev->last_packet_type = DISCARD_PACKET; - if (urb->actual_length < FPIX_MAX_TRANSFER || - (data[urb->actual_length-2] == 0xff && - data[urb->actual_length-1] == 0xd9)) { - - /* If the result is less than what was asked - * for, then it's the end of the - * frame. Sometime the jpeg is not complete, - * but there's nothing we can do. We also end - * here if the the jpeg ends right at the end - * of the frame. */ - if (frame) - gspca_frame_add(gspca_dev, LAST_PACKET, - frame, - data, urb->actual_length); - dev_new_state(FPIX_REQ_FRAME); - schedule_delayed_work(&dev->wqe, NEXT_FRAME_DELAY); - } else { + struct usb_fpix *dev = container_of(work, struct usb_fpix, work_struct); + struct gspca_dev *gspca_dev = &dev->gspca_dev; + struct urb *urb = gspca_dev->urb[0]; + u8 *data = urb->transfer_buffer; + struct gspca_frame *frame; + int ret = 0; + int len; + + /* synchronize with the main driver */ + mutex_lock(&gspca_dev->usb_lock); + mutex_unlock(&gspca_dev->usb_lock); + PDEBUG(D_STREAM, "dostream started"); + + /* loop reading a frame */ +again: + while (gspca_dev->present && gspca_dev->streaming) { + + /* request a frame */ + mutex_lock(&gspca_dev->usb_lock); + ret = command(gspca_dev, 1); + mutex_unlock(&gspca_dev->usb_lock); + if (ret < 0) + break; + if (!gspca_dev->present || !gspca_dev->streaming) + break; + + /* the frame comes in parts */ + for (;;) { + ret = usb_bulk_msg(gspca_dev->dev, + urb->pipe, + data, + FPIX_MAX_TRANSFER, + &len, FPIX_TIMEOUT); + if (ret < 0) { + /* Most of the time we get a timeout + * error. Just restart. */ + goto again; + } + if (!gspca_dev->present || !gspca_dev->streaming) + goto out; + frame = gspca_get_i_frame(&dev->gspca_dev); + if (frame == NULL) + gspca_dev->last_packet_type = DISCARD_PACKET; + + if (len < FPIX_MAX_TRANSFER || + (data[len - 2] == 0xff && + data[len - 1] == 0xd9)) { + + /* If the result is less than what was asked + * for, then it's the end of the + * frame. Sometimes the jpeg is not complete, + * but there's nothing we can do. We also end + * here if the the jpeg ends right at the end + * of the frame. */ + if (frame) + frame = gspca_frame_add(gspca_dev, + LAST_PACKET, + frame, + data, len); + break; + } /* got a partial image */ if (frame) gspca_frame_add(gspca_dev, gspca_dev->last_packet_type - == LAST_PACKET + == LAST_PACKET ? FIRST_PACKET : INTER_PACKET, - frame, - data, urb->actual_length); - read_frame_part(dev); + frame, data, len); } - break; - } - - case FPIX_NOP: - case FPIX_RESET: - PDEBUG(D_STREAM, "invalid state %d", dev->state); - break; - } -} - -/* Request a new frame */ -static void request_frame(struct usb_fpix *dev) -{ - int ret; - struct gspca_dev *gspca_dev = &dev->gspca_dev; - /* Setup command packet */ - memset(gspca_dev->usb_buf, 0, 12); - gspca_dev->usb_buf[0] = 0xd3; - gspca_dev->usb_buf[7] = 0x01; - - /* Request a frame */ - dev->ctrlreq.bRequestType = - USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE; - dev->ctrlreq.bRequest = USB_REQ_GET_STATUS; - dev->ctrlreq.wValue = 0; - dev->ctrlreq.wIndex = 0; - dev->ctrlreq.wLength = cpu_to_le16(12); - - usb_fill_control_urb(dev->control_urb, - gspca_dev->dev, - usb_sndctrlpipe(gspca_dev->dev, 0), - (unsigned char *) &dev->ctrlreq, - gspca_dev->usb_buf, - 12, urb_callback, gspca_dev); - - ret = usb_submit_urb(dev->control_urb, GFP_ATOMIC); - if (ret) { - dev_new_state(FPIX_RESET); - schedule_delayed_work(&dev->wqe, 1); - PDEBUG(D_STREAM, "usb_submit_urb failed with %d", ret); + /* We must wait before trying reading the next + * frame. If we don't, or if the delay is too short, + * the camera will disconnect. */ + msleep(NEXT_FRAME_DELAY); } -} - -/*--------------------------------------------------------------------------*/ -/* State machine. */ -static void fpix_sm(struct work_struct *work) -{ - struct usb_fpix *dev = container_of(work, struct usb_fpix, wqe.work); - - PDEBUG(D_STREAM, "fpix_sm state %d", dev->state); - - /* verify that the device wasn't unplugged */ - if (!dev->gspca_dev.present) { - PDEBUG(D_STREAM, "device is gone"); - dev_new_state(FPIX_NOP); - complete(&dev->can_close); - return; - } - - if (!dev->streaming) { - PDEBUG(D_STREAM, "stopping state machine"); - dev_new_state(FPIX_NOP); - complete(&dev->can_close); - return; - } - - switch (dev->state) { - case FPIX_RESET: - dev_new_state(FPIX_REQ_FRAME); - schedule_delayed_work(&dev->wqe, HZ / 10); - break; - - case FPIX_REQ_FRAME: - /* get an image */ - request_frame(dev); - break; - - case FPIX_NOP: - case FPIX_READ_FRAME: - PDEBUG(D_STREAM, "invalid state %d", dev->state); - break; - } +out: + PDEBUG(D_STREAM, "dostream stopped"); } /* this function is called at probe time */ static int sd_config(struct gspca_dev *gspca_dev, const struct usb_device_id *id) { + struct usb_fpix *dev = (struct usb_fpix *) gspca_dev; struct cam *cam = &gspca_dev->cam; cam->cam_mode = fpix_mode; cam->nmodes = 1; cam->bulk_size = FPIX_MAX_TRANSFER; -/* gspca_dev->nbalt = 1; * use bulk transfer */ - return 0; -} - -/* Stop streaming and free the ressources allocated by sd_start. */ -static void sd_stopN(struct gspca_dev *gspca_dev) -{ - struct usb_fpix *dev = (struct usb_fpix *) gspca_dev; + INIT_WORK(&dev->work_struct, dostream); - dev->streaming = 0; - - /* Stop the state machine */ - if (dev->state != FPIX_NOP) - wait_for_completion(&dev->can_close); -} - -/* called on streamoff with alt 0 and disconnect */ -static void sd_stop0(struct gspca_dev *gspca_dev) -{ - struct usb_fpix *dev = (struct usb_fpix *) gspca_dev; - - usb_free_urb(dev->control_urb); - dev->control_urb = NULL; -} - -/* Kill an URB that hasn't completed. */ -static void timeout_kill(unsigned long data) -{ - struct urb *urb = (struct urb *) data; - - usb_unlink_urb(urb); + return 0; } /* this function is called at probe and resume time */ static int sd_init(struct gspca_dev *gspca_dev) { - struct usb_fpix *dev = (struct usb_fpix *) gspca_dev; - - INIT_DELAYED_WORK(&dev->wqe, fpix_sm); - - init_timer(&dev->bulk_timer); - dev->bulk_timer.function = timeout_kill; - return 0; } +/* start the camera */ static int sd_start(struct gspca_dev *gspca_dev) { struct usb_fpix *dev = (struct usb_fpix *) gspca_dev; - int ret; - int size_ret; + int ret, len; /* Init the device */ - memset(gspca_dev->usb_buf, 0, 12); - gspca_dev->usb_buf[0] = 0xc6; - gspca_dev->usb_buf[8] = 0x20; - - ret = usb_control_msg(gspca_dev->dev, - usb_sndctrlpipe(gspca_dev->dev, 0), - USB_REQ_GET_STATUS, - USB_DIR_OUT | USB_TYPE_CLASS | - USB_RECIP_INTERFACE, 0, 0, gspca_dev->usb_buf, - 12, FPIX_TIMEOUT); - - if (ret != 12) { - PDEBUG(D_STREAM, "usb_control_msg failed (%d)", ret); - ret = -EIO; - goto error; + ret = command(gspca_dev, 0); + if (ret < 0) { + PDEBUG(D_STREAM, "init failed %d", ret); + return ret; } /* Read the result of the command. Ignore the result, for it * varies with the device. */ ret = usb_bulk_msg(gspca_dev->dev, gspca_dev->urb[0]->pipe, - gspca_dev->usb_buf, FPIX_MAX_TRANSFER, &size_ret, + gspca_dev->urb[0]->transfer_buffer, + FPIX_MAX_TRANSFER, &len, FPIX_TIMEOUT); - if (ret != 0) { - PDEBUG(D_STREAM, "usb_bulk_msg failed (%d)", ret); - ret = -EIO; - goto error; + if (ret < 0) { + PDEBUG(D_STREAM, "usb_bulk_msg failed %d", ret); + return ret; } /* Request a frame, but don't read it */ - memset(gspca_dev->usb_buf, 0, 12); - gspca_dev->usb_buf[0] = 0xd3; - gspca_dev->usb_buf[7] = 0x01; - - ret = usb_control_msg(gspca_dev->dev, - usb_sndctrlpipe(gspca_dev->dev, 0), - USB_REQ_GET_STATUS, - USB_DIR_OUT | USB_TYPE_CLASS | - USB_RECIP_INTERFACE, 0, 0, gspca_dev->usb_buf, - 12, FPIX_TIMEOUT); - if (ret != 12) { - PDEBUG(D_STREAM, "usb_control_msg failed (%d)", ret); - ret = -EIO; - goto error; + ret = command(gspca_dev, 1); + if (ret < 0) { + PDEBUG(D_STREAM, "frame request failed %d", ret); + return ret; } /* Again, reset bulk in endpoint */ usb_clear_halt(gspca_dev->dev, gspca_dev->urb[0]->pipe); - /* Allocate a control URB */ - dev->control_urb = usb_alloc_urb(0, GFP_KERNEL); - if (!dev->control_urb) { - PDEBUG(D_STREAM, "No free urbs available"); - ret = -EIO; - goto error; - } - - /* Various initializations. */ - init_completion(&dev->can_close); - dev->bulk_timer.data = (unsigned long)dev->gspca_dev.urb[0]; - dev->gspca_dev.urb[0]->complete = urb_callback; - dev->streaming = 1; - - /* Schedule a frame request. */ - dev_new_state(FPIX_REQ_FRAME); - schedule_delayed_work(&dev->wqe, 1); + /* Start the workqueue function to do the streaming */ + dev->work_thread = create_singlethread_workqueue(MODULE_NAME); + queue_work(dev->work_thread, &dev->work_struct); return 0; +} + +/* called on streamoff with alt==0 and on disconnect */ +/* the usb_lock is held at entry - restore on exit */ +static void sd_stop0(struct gspca_dev *gspca_dev) +{ + struct usb_fpix *dev = (struct usb_fpix *) gspca_dev; -error: - /* Free the ressources */ - sd_stopN(gspca_dev); - sd_stop0(gspca_dev); - return ret; + /* wait for the work queue to terminate */ + mutex_unlock(&gspca_dev->usb_lock); + destroy_workqueue(dev->work_thread); + mutex_lock(&gspca_dev->usb_lock); + dev->work_thread = NULL; } /* Table of supported USB devices */ @@ -422,12 +268,11 @@ MODULE_DEVICE_TABLE(usb, device_table); /* sub-driver description */ static const struct sd_desc sd_desc = { - .name = MODULE_NAME, + .name = MODULE_NAME, .config = sd_config, - .init = sd_init, - .start = sd_start, - .stopN = sd_stopN, - .stop0 = sd_stop0, + .init = sd_init, + .start = sd_start, + .stop0 = sd_stop0, }; /* -- device connect -- */ @@ -441,13 +286,13 @@ static int sd_probe(struct usb_interface *intf, } static struct usb_driver sd_driver = { - .name = MODULE_NAME, - .id_table = device_table, - .probe = sd_probe, + .name = MODULE_NAME, + .id_table = device_table, + .probe = sd_probe, .disconnect = gspca_disconnect, #ifdef CONFIG_PM .suspend = gspca_suspend, - .resume = gspca_resume, + .resume = gspca_resume, #endif }; @@ -455,12 +300,14 @@ static struct usb_driver sd_driver = { static int __init sd_mod_init(void) { int ret; + ret = usb_register(&sd_driver); if (ret < 0) return ret; PDEBUG(D_PROBE, "registered"); return 0; } + static void __exit sd_mod_exit(void) { usb_deregister(&sd_driver); diff --git a/linux/drivers/media/video/gspca/gspca.c b/linux/drivers/media/video/gspca/gspca.c index d629ce1dc..88de8b865 100644 --- a/linux/drivers/media/video/gspca/gspca.c +++ b/linux/drivers/media/video/gspca/gspca.c @@ -486,14 +486,14 @@ static struct usb_host_endpoint *get_ep(struct gspca_dev *gspca_dev) i = gspca_dev->alt; /* previous alt setting */ /* try isoc */ - while (--i > 0) { /* alt 0 is unusable */ + while (--i >= 0) { ep = alt_xfer(&intf->altsetting[i], USB_ENDPOINT_XFER_ISOC); if (ep) break; } - /* if no isoc, try bulk */ + /* if no isoc, try bulk (alt 0 only) */ if (ep == NULL) { ep = alt_xfer(&intf->altsetting[0], USB_ENDPOINT_XFER_BULK); @@ -501,6 +501,8 @@ static struct usb_host_endpoint *get_ep(struct gspca_dev *gspca_dev) err("no transfer endpoint found"); return NULL; } + i = 0; + gspca_dev->bulk = 1; } PDEBUG(D_STREAM, "use alt %d ep 0x%02x", i, ep->desc.bEndpointAddress); @@ -527,7 +529,7 @@ static int create_urbs(struct gspca_dev *gspca_dev, /* calculate the packet size and the number of packets */ psize = le16_to_cpu(ep->desc.wMaxPacketSize); - if (gspca_dev->alt != 0) { /* isoc */ + if (!gspca_dev->bulk) { /* isoc */ /* See paragraph 5.9 / table 5-11 of the usb 2.0 spec. */ psize = (psize & 0x07ff) * (1 + ((psize >> 11) & 3)); @@ -627,7 +629,7 @@ static int gspca_init_transfer(struct gspca_dev *gspca_dev) goto out; /* clear the bulk endpoint */ - if (gspca_dev->alt == 0) /* if bulk transfer */ + if (gspca_dev->bulk) usb_clear_halt(gspca_dev->dev, gspca_dev->urb[0]->pipe); @@ -640,7 +642,7 @@ static int gspca_init_transfer(struct gspca_dev *gspca_dev) gspca_dev->streaming = 1; /* some bulk transfers are started by the subdriver */ - if (gspca_dev->alt == 0 && gspca_dev->cam.bulk_nurbs == 0) + if (gspca_dev->bulk && gspca_dev->cam.bulk_nurbs == 0) break; /* submit the URBs */ diff --git a/linux/drivers/media/video/gspca/gspca.h b/linux/drivers/media/video/gspca/gspca.h index 6f172e9e5..e4d4cf6ce 100644 --- a/linux/drivers/media/video/gspca/gspca.h +++ b/linux/drivers/media/video/gspca/gspca.h @@ -167,6 +167,7 @@ struct gspca_dev { __u8 iface; /* USB interface number */ __u8 alt; /* USB alternate setting */ __u8 nbalt; /* number of USB alternate settings */ + u8 bulk; /* image transfer by 0:isoc / 1:bulk */ }; int gspca_dev_probe(struct usb_interface *intf, diff --git a/linux/drivers/media/video/gspca/jpeg.h b/linux/drivers/media/video/gspca/jpeg.h index 7d2df9720..de63c3680 100644 --- a/linux/drivers/media/video/gspca/jpeg.h +++ b/linux/drivers/media/video/gspca/jpeg.h @@ -27,42 +27,16 @@ /* * generation options * CONEX_CAM Conexant if present - * QUANT_VAL quantization table (0..8) */ -/* - * JPEG header: - * - start of jpeg frame - * - quantization table - * - huffman table - * - start of SOF0 - */ +/* JPEG header */ static const u8 jpeg_head[] = { 0xff, 0xd8, /* jpeg */ + +/* quantization table quality 50% */ 0xff, 0xdb, 0x00, 0x84, /* DQT */ -#if QUANT_VAL == 0 -/* index 0 - Q40*/ -0, /* quantization table part 1 */ - 0x14, 0x0e, 0x0f, 0x12, 0x0f, 0x0d, 0x14, 0x12, - 0x10, 0x12, 0x17, 0x15, 0x14, 0x18, 0x1e, 0x32, - 0x21, 0x1e, 0x1c, 0x1c, 0x1e, 0x3d, 0x2c, 0x2e, - 0x24, 0x32, 0x49, 0x40, 0x4c, 0x4b, 0x47, 0x40, - 0x46, 0x45, 0x50, 0x5a, 0x73, 0x62, 0x50, 0x55, - 0x6d, 0x56, 0x45, 0x46, 0x64, 0x88, 0x65, 0x6d, - 0x77, 0x7b, 0x81, 0x82, 0x81, 0x4e, 0x60, 0x8d, - 0x97, 0x8c, 0x7d, 0x96, 0x73, 0x7e, 0x81, 0x7c, -1, /* quantization table part 2 */ - 0x15, 0x17, 0x17, 0x1e, 0x1a, 0x1e, 0x3b, 0x21, - 0x21, 0x3b, 0x7c, 0x53, 0x46, 0x53, 0x7c, 0x0c, - 0x7c, 0x7c, 0x7c, 0x7c, 0x7c, 0x7c, 0x7c, 0x7c, - 0x7c, 0x7c, 0x7c, 0x7c, 0x7c, 0x7c, 0x7c, 0x7c, - 0x7c, 0x7c, 0x7c, 0x7c, 0x7c, 0x7c, 0x7c, 0x7c, - 0x7c, 0x7c, 0x7c, 0x7c, 0x7c, 0x7c, 0x7c, 0x7c, - 0x7c, 0x7c, 0x7c, 0x7c, 0x7c, 0x7c, 0x7c, 0x7c, - 0x7c, 0x7c, 0x7c, 0x7c, 0x7c, 0x7c, 0x7c, 0x7c, -#elif QUANT_VAL == 1 -/* index 1 - Q50 */ 0, +#define JPEG_QT0_OFFSET 7 0x10, 0x0b, 0x0c, 0x0e, 0x0c, 0x0a, 0x10, 0x0e, 0x0d, 0x0e, 0x12, 0x11, 0x10, 0x13, 0x18, 0x28, 0x1a, 0x18, 0x16, 0x16, 0x18, 0x31, 0x23, 0x25, @@ -72,6 +46,7 @@ static const u8 jpeg_head[] = { 0x5f, 0x62, 0x67, 0x68, 0x67, 0x3e, 0x4d, 0x71, 0x79, 0x70, 0x64, 0x78, 0x5c, 0x65, 0x67, 0x63, 1, +#define JPEG_QT1_OFFSET 72 0x11, 0x12, 0x12, 0x18, 0x15, 0x18, 0x2f, 0x1a, 0x1a, 0x2f, 0x63, 0x42, 0x38, 0x42, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, @@ -80,149 +55,6 @@ static const u8 jpeg_head[] = { 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, -#elif QUANT_VAL == 2 -/* index 2 Q60 */ -0, - 0x0d, 0x09, 0x0a, 0x0b, 0x0a, 0x08, 0x0d, 0x0b, - 0x0a, 0x0b, 0x0e, 0x0e, 0x0d, 0x0f, 0x13, 0x20, - 0x15, 0x13, 0x12, 0x12, 0x13, 0x27, 0x1c, 0x1e, - 0x17, 0x20, 0x2e, 0x29, 0x31, 0x30, 0x2e, 0x29, - 0x2d, 0x2c, 0x33, 0x3a, 0x4a, 0x3e, 0x33, 0x36, - 0x46, 0x37, 0x2c, 0x2d, 0x40, 0x57, 0x41, 0x46, - 0x4c, 0x4e, 0x52, 0x53, 0x52, 0x32, 0x3e, 0x5a, - 0x61, 0x5a, 0x50, 0x60, 0x4a, 0x51, 0x52, 0x4f, -1, - 0x0e, 0x0e, 0x0e, 0x13, 0x11, 0x13, 0x26, 0x15, - 0x15, 0x26, 0x4f, 0x35, 0x2d, 0x35, 0x4f, 0x4f, - 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, - 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, - 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, - 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, - 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, - 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, 0x4f, -#elif QUANT_VAL == 3 -/* index 3 - Q70 */ -0, - 0x0a, 0x07, 0x07, 0x08, 0x07, 0x06, 0x0a, 0x08, - 0x08, 0x08, 0x0b, 0x0a, 0x0a, 0x0b, 0x0e, 0x18, - 0x10, 0x0e, 0x0d, 0x0d, 0x0e, 0x1d, 0x15, 0x16, - 0x11, 0x18, 0x23, 0x1f, 0x25, 0x24, 0x22, 0x1f, - 0x22, 0x21, 0x26, 0x2b, 0x37, 0x2f, 0x26, 0x29, - 0x34, 0x29, 0x21, 0x22, 0x30, 0x41, 0x31, 0x34, - 0x39, 0x3b, 0x3e, 0x3e, 0x3e, 0x25, 0x2e, 0x44, - 0x49, 0x43, 0x3c, 0x48, 0x37, 0x3d, 0x3e, 0x3b, -1, - 0x0a, 0x0b, 0x0b, 0x0e, 0x0d, 0x0e, 0x1c, 0x10, - 0x10, 0x1c, 0x3b, 0x28, 0x22, 0x28, 0x3b, 0x3b, - 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, - 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, - 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, - 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, - 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, - 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, 0x3b, -#elif QUANT_VAL == 4 -/* index 4 - Q80 */ -0, - 0x06, 0x04, 0x05, 0x06, 0x05, 0x04, 0x06, 0x06, - 0x05, 0x06, 0x07, 0x07, 0x06, 0x08, 0x0a, 0x10, - 0x0a, 0x0a, 0x09, 0x09, 0x0a, 0x14, 0x0e, 0x0f, - 0x0c, 0x10, 0x17, 0x14, 0x18, 0x18, 0x17, 0x14, - 0x16, 0x16, 0x1a, 0x1d, 0x25, 0x1f, 0x1a, 0x1b, - 0x23, 0x1c, 0x16, 0x16, 0x20, 0x2c, 0x20, 0x23, - 0x26, 0x27, 0x29, 0x2a, 0x29, 0x19, 0x1f, 0x2d, - 0x30, 0x2d, 0x28, 0x30, 0x25, 0x28, 0x29, 0x28, -1, - 0x07, 0x07, 0x07, 0x0a, 0x08, 0x0a, 0x13, 0x0a, - 0x0a, 0x13, 0x28, 0x1a, 0x16, 0x1a, 0x28, 0x28, - 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, - 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, - 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, - 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, - 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, - 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, -#elif QUANT_VAL == 5 -/* index 5 - Q85 */ -0, - 0x05, 0x03, 0x04, 0x04, 0x04, 0x03, 0x05, 0x04, - 0x04, 0x04, 0x05, 0x05, 0x05, 0x06, 0x07, 0x0c, - 0x08, 0x07, 0x07, 0x07, 0x07, 0x0f, 0x0b, 0x0b, - 0x09, 0x0c, 0x11, 0x0f, 0x12, 0x12, 0x11, 0x0f, - 0x11, 0x11, 0x13, 0x16, 0x1c, 0x17, 0x13, 0x14, - 0x1a, 0x15, 0x11, 0x11, 0x18, 0x21, 0x18, 0x1a, - 0x1d, 0x1d, 0x1f, 0x1f, 0x1f, 0x13, 0x17, 0x22, - 0x24, 0x22, 0x1e, 0x24, 0x1c, 0x1e, 0x1f, 0x1e, -1, - 0x05, 0x05, 0x05, 0x07, 0x06, 0x07, 0x0e, 0x08, - 0x08, 0x0e, 0x1e, 0x14, 0x11, 0x14, 0x1e, 0x1e, - 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, - 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, - 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, - 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, - 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, - 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, -#elif QUANT_VAL == 6 -/* index 6 - 86 */ -0, - 0x04, 0x03, 0x03, 0x04, 0x03, 0x03, 0x04, 0x04, - 0x04, 0x04, 0x05, 0x05, 0x04, 0x05, 0x07, 0x0B, - 0x07, 0x07, 0x06, 0x06, 0x07, 0x0e, 0x0a, 0x0a, - 0x08, 0x0B, 0x10, 0x0e, 0x11, 0x11, 0x10, 0x0e, - 0x10, 0x0f, 0x12, 0x14, 0x1a, 0x16, 0x12, 0x13, - 0x18, 0x13, 0x0f, 0x10, 0x16, 0x1f, 0x17, 0x18, - 0x1b, 0x1b, 0x1d, 0x1d, 0x1d, 0x11, 0x16, 0x20, - 0x22, 0x1f, 0x1c, 0x22, 0x1a, 0x1c, 0x1d, 0x1c, -1, - 0x05, 0x05, 0x05, 0x07, 0x06, 0x07, 0x0D, 0x07, - 0x07, 0x0D, 0x1c, 0x12, 0x10, 0x12, 0x1c, 0x1c, - 0x1c, 0x1c, 0x1c, 0x1c, 0x1c, 0x1c, 0x1c, 0x1c, - 0x1c, 0x1c, 0x1c, 0x1c, 0x1c, 0x1c, 0x1c, 0x1c, - 0x1c, 0x1c, 0x1c, 0x1c, 0x1c, 0x1c, 0x1c, 0x1c, - 0x1c, 0x1c, 0x1c, 0x1c, 0x1c, 0x1c, 0x1c, 0x1c, - 0x1c, 0x1c, 0x1c, 0x1c, 0x1c, 0x1c, 0x1c, 0x1c, - 0x1c, 0x1c, 0x1c, 0x1c, 0x1c, 0x1c, 0x1c, 0x1c, -#elif QUANT_VAL == 7 -/* index 7 - 88 */ -0, - 0x04, 0x03, 0x03, 0x03, 0x03, 0x02, 0x04, 0x03, - 0x03, 0x03, 0x04, 0x04, 0x04, 0x05, 0x06, 0x0a, - 0x06, 0x06, 0x05, 0x05, 0x06, 0x0C, 0x08, 0x09, - 0x07, 0x0a, 0x0e, 0x0c, 0x0f, 0x0e, 0x0e, 0x0c, - 0x0d, 0x0d, 0x0f, 0x11, 0x16, 0x13, 0x0f, 0x10, - 0x15, 0x11, 0x0d, 0x0d, 0x13, 0x1a, 0x13, 0x15, - 0x17, 0x18, 0x19, 0x19, 0x19, 0x0f, 0x12, 0x1b, - 0x1d, 0x1b, 0x18, 0x1d, 0x16, 0x18, 0x19, 0x18, -1, - 0x04, 0x04, 0x04, 0x06, 0x05, 0x06, 0x0B, 0x06, - 0x06, 0x0B, 0x18, 0x10, 0x0d, 0x10, 0x18, 0x18, - 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, - 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, - 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, - 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, - 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, - 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, -#elif QUANT_VAL == 8 -/* index 8 - ?? */ -0, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, - 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x05, - 0x03, 0x03, 0x03, 0x03, 0x03, 0x06, 0x04, 0x05, - 0x04, 0x05, 0x07, 0x06, 0x08, 0x08, 0x07, 0x06, - 0x07, 0x07, 0x08, 0x09, 0x0c, 0x0a, 0x08, 0x09, - 0x0B, 0x09, 0x07, 0x07, 0x0a, 0x0e, 0x0a, 0x0b, - 0x0c, 0x0c, 0x0d, 0x0d, 0x0d, 0x08, 0x0a, 0x0e, - 0x0f, 0x0e, 0x0d, 0x0f, 0x0c, 0x0d, 0x0d, 0x0c, -1, - 0x02, 0x02, 0x02, 0x03, 0x03, 0x03, 0x06, 0x03, - 0x03, 0x06, 0x0c, 0x08, 0x07, 0x08, 0x0c, 0x0c, - 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, - 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, - 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, - 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, - 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, - 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, -#else -#error "Invalid quantization table" -#endif /* huffman table */ 0xff, 0xc4, 0x01, 0xa2, @@ -280,55 +112,57 @@ static const u8 jpeg_head[] = { 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, #ifdef CONEX_CAM /* the Conexant frames start with SOF0 */ +#define JPEG_HDR_SZ 556 #else 0xff, 0xc0, 0x00, 0x11, /* SOF0 (start of frame 0 */ 0x08, /* data precision */ -#endif -}; - -#ifndef CONEX_CAM -/* variable part: - * 0x01, 0xe0, height - * 0x02, 0x80, width - * 0x03, component number - * 0x01, - * 0x21, samples Y - */ - -/* end of header */ -static u8 eoh[] = { +#define JPEG_HEIGHT_OFFSET 561 + 0x01, 0xe0, /* height */ + 0x02, 0x80, /* width */ + 0x03, /* component number */ + 0x01, + 0x21, /* samples Y */ 0x00, /* quant Y */ 0x02, 0x11, 0x01, /* samples CbCr - quant CbCr */ 0x03, 0x11, 0x01, 0xff, 0xda, 0x00, 0x0c, /* SOS (start of scan) */ 0x03, 0x01, 0x00, 0x02, 0x11, 0x03, 0x11, 0x00, 0x3f, 0x00 -}; +#define JPEG_HDR_SZ 589 #endif +}; -/* -- output the JPEG header -- */ -static void jpeg_put_header(struct gspca_dev *gspca_dev, - struct gspca_frame *frame, - int samplesY) +/* define the JPEG header */ +static void jpeg_define(u8 *jpeg_hdr, + int height, + int width, + int samplesY) { + memcpy(jpeg_hdr, jpeg_head, sizeof jpeg_head); #ifndef CONEX_CAM - u8 tmpbuf[8]; + jpeg_hdr[JPEG_HEIGHT_OFFSET + 0] = height >> 8; + jpeg_hdr[JPEG_HEIGHT_OFFSET + 1] = height & 0xff; + jpeg_hdr[JPEG_HEIGHT_OFFSET + 2] = width >> 8; + jpeg_hdr[JPEG_HEIGHT_OFFSET + 3] = width & 0xff; + jpeg_hdr[JPEG_HEIGHT_OFFSET + 6] = samplesY; #endif +} - gspca_frame_add(gspca_dev, FIRST_PACKET, frame, - jpeg_head, sizeof jpeg_head); -#ifndef CONEX_CAM - tmpbuf[0] = gspca_dev->height >> 8; - tmpbuf[1] = gspca_dev->height & 0xff; - tmpbuf[2] = gspca_dev->width >> 8; - tmpbuf[3] = gspca_dev->width & 0xff; - tmpbuf[4] = 0x03; /* component number */ - tmpbuf[5] = 0x01; /* first component */ - tmpbuf[6] = samplesY; - gspca_frame_add(gspca_dev, INTER_PACKET, frame, - tmpbuf, 7); - gspca_frame_add(gspca_dev, INTER_PACKET, frame, - eoh, sizeof eoh); -#endif +/* set the JPEG quality */ +static void jpeg_set_qual(u8 *jpeg_hdr, + int quality) +{ + int i, sc; + + if (quality < 50) + sc = 5000 / quality; + else + sc = 200 - quality * 2; + for (i = 0; i < 64; i++) { + jpeg_hdr[JPEG_QT0_OFFSET + i] = + (jpeg_head[JPEG_QT0_OFFSET + i] * sc + 50) / 100; + jpeg_hdr[JPEG_QT1_OFFSET + i] = + (jpeg_head[JPEG_QT1_OFFSET + i] * sc + 50) / 100; + } } #endif diff --git a/linux/drivers/media/video/gspca/mars.c b/linux/drivers/media/video/gspca/mars.c index 5d54893eb..789fd178a 100644 --- a/linux/drivers/media/video/gspca/mars.c +++ b/linux/drivers/media/video/gspca/mars.c @@ -22,7 +22,6 @@ #define MODULE_NAME "mars" #include "gspca.h" -#define QUANT_VAL 1 /* quantization table */ #include "jpeg.h" MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>"); @@ -37,6 +36,12 @@ struct sd { u8 colors; u8 gamma; u8 sharpness; + u8 quality; +#define QUALITY_MIN 40 +#define QUALITY_MAX 70 +#define QUALITY_DEF 50 + + u8 *jpeg_hdr; }; /* V4L2 controls supported by the driver */ @@ -176,6 +181,7 @@ static int sd_config(struct gspca_dev *gspca_dev, sd->colors = COLOR_DEF; sd->gamma = GAMMA_DEF; sd->sharpness = SHARPNESS_DEF; + sd->quality = QUALITY_DEF; gspca_dev->nbalt = 9; /* use the altsetting 08 */ return 0; } @@ -193,6 +199,12 @@ static int sd_start(struct gspca_dev *gspca_dev) u8 *data; int i; + /* create the JPEG header */ + sd->jpeg_hdr = kmalloc(JPEG_HDR_SZ, GFP_KERNEL); + jpeg_define(sd->jpeg_hdr, gspca_dev->height, gspca_dev->width, + 0x21); /* JPEG 422 */ + jpeg_set_qual(sd->jpeg_hdr, sd->quality); + data = gspca_dev->usb_buf; data[0] = 0x01; /* address */ @@ -341,11 +353,19 @@ static void sd_stopN(struct gspca_dev *gspca_dev) PDEBUG(D_ERR, "Camera Stop failed"); } +static void sd_stop0(struct gspca_dev *gspca_dev) +{ + struct sd *sd = (struct sd *) gspca_dev; + + kfree(sd->jpeg_hdr); +} + static void sd_pkt_scan(struct gspca_dev *gspca_dev, struct gspca_frame *frame, /* target */ __u8 *data, /* isoc packet */ int len) /* iso packet length */ { + struct sd *sd = (struct sd *) gspca_dev; int p; if (len < 6) { @@ -368,7 +388,8 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev, frame, data, p); /* put the JPEG header */ - jpeg_put_header(gspca_dev, frame, 0x21); + gspca_frame_add(gspca_dev, FIRST_PACKET, frame, + sd->jpeg_hdr, JPEG_HDR_SZ); data += p + 16; len -= p + 16; break; @@ -465,6 +486,34 @@ static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val) return 0; } +static int sd_set_jcomp(struct gspca_dev *gspca_dev, + struct v4l2_jpegcompression *jcomp) +{ + struct sd *sd = (struct sd *) gspca_dev; + + if (jcomp->quality < QUALITY_MIN) + sd->quality = QUALITY_MIN; + else if (jcomp->quality > QUALITY_MAX) + sd->quality = QUALITY_MAX; + else + sd->quality = jcomp->quality; + if (gspca_dev->streaming) + jpeg_set_qual(sd->jpeg_hdr, sd->quality); + return 0; +} + +static int sd_get_jcomp(struct gspca_dev *gspca_dev, + struct v4l2_jpegcompression *jcomp) +{ + struct sd *sd = (struct sd *) gspca_dev; + + memset(jcomp, 0, sizeof *jcomp); + jcomp->quality = sd->quality; + jcomp->jpeg_markers = V4L2_JPEG_MARKER_DHT + | V4L2_JPEG_MARKER_DQT; + return 0; +} + /* sub-driver description */ static const struct sd_desc sd_desc = { .name = MODULE_NAME, @@ -474,7 +523,10 @@ static const struct sd_desc sd_desc = { .init = sd_init, .start = sd_start, .stopN = sd_stopN, + .stop0 = sd_stop0, .pkt_scan = sd_pkt_scan, + .get_jcomp = sd_get_jcomp, + .set_jcomp = sd_set_jcomp, }; /* -- module initialisation -- */ diff --git a/linux/drivers/media/video/gspca/mr97310a.c b/linux/drivers/media/video/gspca/mr97310a.c index 5ec5ce6e3..2a901a4a6 100644 --- a/linux/drivers/media/video/gspca/mr97310a.c +++ b/linux/drivers/media/video/gspca/mr97310a.c @@ -29,9 +29,7 @@ MODULE_LICENSE("GPL"); /* specific webcam descriptor */ struct sd { struct gspca_dev gspca_dev; /* !! must be the first item */ - u8 sof_read; - u8 header_read; }; /* V4L2 controls supported by the driver */ @@ -285,7 +283,6 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev, __u8 *data, /* isoc packet */ int len) /* iso packet length */ { - struct sd *sd = (struct sd *) gspca_dev; unsigned char *sof; sof = pac_find_sof(gspca_dev, data, len); @@ -300,25 +297,12 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev, n = 0; frame = gspca_frame_add(gspca_dev, LAST_PACKET, frame, data, n); - sd->header_read = 0; - gspca_frame_add(gspca_dev, FIRST_PACKET, frame, NULL, 0); + /* Start next frame. */ + gspca_frame_add(gspca_dev, FIRST_PACKET, frame, + pac_sof_marker, sizeof pac_sof_marker); len -= sof - data; data = sof; } - if (sd->header_read < 7) { - int needed; - - /* skip the rest of the header */ - needed = 7 - sd->header_read; - if (len <= needed) { - sd->header_read += len; - return; - } - data += needed; - len -= needed; - sd->header_read = 7; - } - gspca_frame_add(gspca_dev, INTER_PACKET, frame, data, len); } diff --git a/linux/drivers/media/video/gspca/ov534.c b/linux/drivers/media/video/gspca/ov534.c index de0ab8e06..0f5ec9317 100644 --- a/linux/drivers/media/video/gspca/ov534.c +++ b/linux/drivers/media/video/gspca/ov534.c @@ -1,7 +1,8 @@ /* - * ov534/ov772x gspca driver + * ov534 gspca driver * Copyright (C) 2008 Antonio Ospite <ospite@studenti.unina.it> * Copyright (C) 2008 Jim Paris <jim@jtan.com> + * Copyright (C) 2009 Jean-Francois Moine http://moinejf.free.fr * * Based on a prototype written by Mark Ferrell <majortrips@gmail.com> * USB protocol reverse engineered by Jim Paris <jim@jtan.com> @@ -26,7 +27,7 @@ #include "gspca.h" -#define OV534_REG_ADDRESS 0xf1 /* ? */ +#define OV534_REG_ADDRESS 0xf1 /* sensor address */ #define OV534_REG_SUBADDR 0xf2 #define OV534_REG_WRITE 0xf3 #define OV534_REG_READ 0xf4 @@ -46,9 +47,13 @@ MODULE_LICENSE("GPL"); /* specific webcam descriptor */ struct sd { struct gspca_dev gspca_dev; /* !! must be the first item */ - __u32 last_fid; __u32 last_pts; - int frame_rate; + u16 last_fid; + u8 frame_rate; + + u8 sensor; +#define SENSOR_OV772X 0 +#define SENSOR_OV965X 1 }; /* V4L2 controls supported by the driver */ @@ -63,114 +68,7 @@ static const struct v4l2_pix_format vga_mode[] = { .priv = 0}, }; -static void ov534_reg_write(struct gspca_dev *gspca_dev, u16 reg, u8 val) -{ - struct usb_device *udev = gspca_dev->dev; - int ret; - - PDEBUG(D_USBO, "reg=0x%04x, val=0%02x", reg, val); - gspca_dev->usb_buf[0] = val; - ret = usb_control_msg(udev, - usb_sndctrlpipe(udev, 0), - 0x1, - USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, - 0x0, reg, gspca_dev->usb_buf, 1, CTRL_TIMEOUT); - if (ret < 0) - PDEBUG(D_ERR, "write failed"); -} - -static u8 ov534_reg_read(struct gspca_dev *gspca_dev, u16 reg) -{ - struct usb_device *udev = gspca_dev->dev; - int ret; - - ret = usb_control_msg(udev, - usb_rcvctrlpipe(udev, 0), - 0x1, - USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, - 0x0, reg, gspca_dev->usb_buf, 1, CTRL_TIMEOUT); - PDEBUG(D_USBI, "reg=0x%04x, data=0x%02x", reg, gspca_dev->usb_buf[0]); - if (ret < 0) - PDEBUG(D_ERR, "read failed"); - return gspca_dev->usb_buf[0]; -} - -/* Two bits control LED: 0x21 bit 7 and 0x23 bit 7. - * (direction and output)? */ -static void ov534_set_led(struct gspca_dev *gspca_dev, int status) -{ - u8 data; - - PDEBUG(D_CONF, "led status: %d", status); - - data = ov534_reg_read(gspca_dev, 0x21); - data |= 0x80; - ov534_reg_write(gspca_dev, 0x21, data); - - data = ov534_reg_read(gspca_dev, 0x23); - if (status) - data |= 0x80; - else - data &= ~(0x80); - - ov534_reg_write(gspca_dev, 0x23, data); -} - -static int sccb_check_status(struct gspca_dev *gspca_dev) -{ - u8 data; - int i; - - for (i = 0; i < 5; i++) { - data = ov534_reg_read(gspca_dev, OV534_REG_STATUS); - - switch (data) { - case 0x00: - return 1; - case 0x04: - return 0; - case 0x03: - break; - default: - PDEBUG(D_ERR, "sccb status 0x%02x, attempt %d/5", - data, i + 1); - } - } - return 0; -} - -static void sccb_reg_write(struct gspca_dev *gspca_dev, u16 reg, u8 val) -{ - PDEBUG(D_USBO, "reg: 0x%04x, val: 0x%02x", reg, val); - ov534_reg_write(gspca_dev, OV534_REG_SUBADDR, reg); - ov534_reg_write(gspca_dev, OV534_REG_WRITE, val); - ov534_reg_write(gspca_dev, OV534_REG_OPERATION, OV534_OP_WRITE_3); - - if (!sccb_check_status(gspca_dev)) - PDEBUG(D_ERR, "sccb_reg_write failed"); -} - -#ifdef GSPCA_DEBUG -static u8 sccb_reg_read(struct gspca_dev *gspca_dev, u16 reg) -{ - ov534_reg_write(gspca_dev, OV534_REG_SUBADDR, reg); - ov534_reg_write(gspca_dev, OV534_REG_OPERATION, OV534_OP_WRITE_2); - if (!sccb_check_status(gspca_dev)) - PDEBUG(D_ERR, "sccb_reg_read failed 1"); - - ov534_reg_write(gspca_dev, OV534_REG_OPERATION, OV534_OP_READ_2); - if (!sccb_check_status(gspca_dev)) - PDEBUG(D_ERR, "sccb_reg_read failed 2"); - - return ov534_reg_read(gspca_dev, OV534_REG_READ); -} -#endif - -static const __u8 ov534_reg_initdata[][2] = { - { 0xe7, 0x3a }, - - { OV534_REG_ADDRESS, 0x42 }, /* select OV772x sensor */ - +static const u8 bridge_init_ov722x[][2] = { { 0xc2, 0x0c }, { 0x88, 0xf8 }, { 0xc3, 0x69 }, @@ -228,7 +126,7 @@ static const __u8 ov534_reg_initdata[][2] = { { 0xc2, 0x0c }, }; -static const __u8 ov772x_reg_initdata[][2] = { +static const u8 sensor_init_ov722x[][2] = { { 0x12, 0x80 }, { 0x11, 0x01 }, @@ -311,6 +209,475 @@ static const __u8 ov772x_reg_initdata[][2] = { { 0x0c, 0xd0 } }; +static const u8 bridge_init_ov965x[][2] = { + {0x88, 0xf8}, + {0x89, 0xff}, + {0x76, 0x03}, + {0x92, 0x03}, + {0x95, 0x10}, + {0xe2, 0x00}, + {0xe7, 0x3e}, + {0x8d, 0x1c}, + {0x8e, 0x00}, + {0x8f, 0x00}, + {0x1f, 0x00}, + {0xc3, 0xf9}, + {0x89, 0xff}, + {0x88, 0xf8}, + {0x76, 0x03}, + {0x92, 0x01}, + {0x93, 0x18}, + {0x1c, 0x0a}, + {0x1d, 0x48}, + {0xc0, 0x50}, + {0xc1, 0x3c}, + {0x34, 0x05}, + {0xc2, 0x0c}, + {0xc3, 0xf9}, + {0x34, 0x05}, + {0xe7, 0x2e}, + {0x31, 0xf9}, + {0x35, 0x02}, + {0xd9, 0x10}, + {0x25, 0x42}, + {0x94, 0x11}, +}; + +static const u8 sensor_init_ov965x[][2] = { + {0x12, 0x80}, /* com7 - reset */ + {0x00, 0x00}, /* gain */ + {0x01, 0x80}, /* blue */ + {0x02, 0x80}, /* red */ + {0x03, 0x1b}, /* vref */ + {0x04, 0x03}, /* com1 - exposure low bits */ + {0x0b, 0x57}, /* ver */ + {0x0e, 0x61}, /* com5 */ + {0x0f, 0x42}, /* com6 */ + {0x11, 0x00}, /* clkrc */ + {0x12, 0x02}, /* com7 */ + {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */ + {0x14, 0x28}, /* com9 */ + {0x16, 0x24}, /* rsvd16 */ + {0x17, 0x1d}, /* hstart*/ + {0x18, 0xbd}, /* hstop */ + {0x19, 0x01}, /* vstrt */ + {0x1a, 0x81}, /* vstop*/ + {0x1e, 0x04}, /* mvfp */ + {0x24, 0x3c}, /* aew */ + {0x25, 0x36}, /* aeb */ + {0x26, 0x71}, /* vpt */ + {0x27, 0x08}, /* bbias */ + {0x28, 0x08}, /* gbbias */ + {0x29, 0x15}, /* gr com */ + {0x2a, 0x00}, + {0x2b, 0x00}, + {0x2c, 0x08}, /* rbias */ + {0x32, 0xff}, /* href */ + {0x33, 0x00}, /* chlf */ + {0x34, 0x3f}, /* arblm */ + {0x35, 0x00}, /* rsvd35 */ + {0x36, 0xf8}, /* rsvd36 */ + {0x38, 0x72}, /* acom38 */ + {0x39, 0x57}, /* ofon */ + {0x3a, 0x80}, /* tslb */ + {0x3b, 0xc4}, + {0x3d, 0x99}, /* com13 */ + {0x3f, 0xc1}, + {0x40, 0xc0}, /* com15 */ + {0x41, 0x40}, /* com16 */ + {0x42, 0xc0}, + {0x43, 0x0a}, + {0x44, 0xf0}, + {0x45, 0x46}, + {0x46, 0x62}, + {0x47, 0x2a}, + {0x48, 0x3c}, + {0x4a, 0xfc}, + {0x4b, 0xfc}, + {0x4c, 0x7f}, + {0x4d, 0x7f}, + {0x4e, 0x7f}, + {0x4f, 0x98}, + {0x50, 0x98}, + {0x51, 0x00}, + {0x52, 0x28}, + {0x53, 0x70}, + {0x54, 0x98}, + {0x58, 0x1a}, + {0x59, 0x85}, + {0x5a, 0xa9}, + {0x5b, 0x64}, + {0x5c, 0x84}, + {0x5d, 0x53}, + {0x5e, 0x0e}, + {0x5f, 0xf0}, + {0x60, 0xf0}, + {0x61, 0xf0}, + {0x62, 0x00}, /* lcc1 */ + {0x63, 0x00}, /* lcc2 */ + {0x64, 0x02}, /* lcc3 */ + {0x65, 0x16}, /* lcc4 */ + {0x66, 0x01}, /* lcc5 */ + {0x69, 0x02}, /* hv */ + {0x6b, 0x5a}, /* dbvl */ + {0x6c, 0x04}, + {0x6d, 0x55}, + {0x6e, 0x00}, + {0x6f, 0x9d}, + {0x70, 0x21}, + {0x71, 0x78}, + {0x72, 0x00}, + {0x73, 0x01}, + {0x74, 0x3a}, + {0x75, 0x35}, + {0x76, 0x01}, + {0x77, 0x02}, + {0x7a, 0x12}, + {0x7b, 0x08}, + {0x7c, 0x16}, + {0x7d, 0x30}, + {0x7e, 0x5e}, + {0x7f, 0x72}, + {0x80, 0x82}, + {0x81, 0x8e}, + {0x82, 0x9a}, + {0x83, 0xa4}, + {0x84, 0xac}, + {0x85, 0xb8}, + {0x86, 0xc3}, + {0x87, 0xd6}, + {0x88, 0xe6}, + {0x89, 0xf2}, + {0x8a, 0x03}, + {0x8c, 0x89}, + {0x14, 0x28}, /* com9 */ + {0x90, 0x7d}, + {0x91, 0x7b}, + {0x9d, 0x03}, + {0x9e, 0x04}, + {0x9f, 0x7a}, + {0xa0, 0x79}, + {0xa1, 0x40}, /* aechm */ + {0xa4, 0x50}, + {0xa5, 0x68}, /* com26 */ + {0xa6, 0x4a}, + {0xa8, 0xc1}, /* acoma8 */ + {0xa9, 0xef}, /* acoma9 */ + {0xaa, 0x92}, + {0xab, 0x04}, + {0xac, 0x80}, + {0xad, 0x80}, + {0xae, 0x80}, + {0xaf, 0x80}, + {0xb2, 0xf2}, + {0xb3, 0x20}, + {0xb4, 0x20}, + {0xb5, 0x00}, + {0xb6, 0xaf}, + {0xbb, 0xae}, + {0xbc, 0x7f}, + {0xdb, 0x7f}, + {0xbe, 0x7f}, + {0xbf, 0x7f}, + {0xc0, 0xe2}, + {0xc1, 0xc0}, + {0xc2, 0x01}, + {0xc3, 0x4e}, + {0xc6, 0x85}, + {0xc7, 0x80}, + {0xc9, 0xe0}, + {0xca, 0xe8}, + {0xcb, 0xf0}, + {0xcc, 0xd8}, + {0xcd, 0xf1}, + {0x4f, 0x98}, + {0x50, 0x98}, + {0x51, 0x00}, + {0x52, 0x28}, + {0x53, 0x70}, + {0x54, 0x98}, + {0x58, 0x1a}, + {0xff, 0x41}, /* read 41, write ff 00 */ + {0x41, 0x40}, /* com16 */ + {0xc5, 0x03}, + {0x6a, 0x02}, + + {0x12, 0x62}, /* com7 - VGA + CIF */ + {0x36, 0xfa}, /* rsvd36 */ + {0x69, 0x0a}, /* hv */ + {0x8c, 0x89}, /* com22 */ + {0x14, 0x28}, /* com9 */ + {0x3e, 0x0c}, + {0x41, 0x40}, /* com16 */ + {0x72, 0x00}, + {0x73, 0x00}, + {0x74, 0x3a}, + {0x75, 0x35}, + {0x76, 0x01}, + {0xc7, 0x80}, + {0x03, 0x12}, /* vref */ + {0x17, 0x16}, /* hstart */ + {0x18, 0x02}, /* hstop */ + {0x19, 0x01}, /* vstrt */ + {0x1a, 0x3d}, /* vstop */ + {0x32, 0xff}, /* href */ + {0xc0, 0xaa}, +}; + +static const u8 bridge_init_ov965x_2[][2] = { + {0x94, 0xaa}, + {0xf1, 0x60}, + {0xe5, 0x04}, + {0xc0, 0x50}, + {0xc1, 0x3c}, + {0x8c, 0x00}, + {0x8d, 0x1c}, + {0x34, 0x05}, + + {0xc2, 0x0c}, + {0xc3, 0xf9}, + {0xda, 0x01}, + {0x50, 0x00}, + {0x51, 0xa0}, + {0x52, 0x3c}, + {0x53, 0x00}, + {0x54, 0x00}, + {0x55, 0x00}, + {0x57, 0x00}, + {0x5c, 0x00}, + {0x5a, 0xa0}, + {0x5b, 0x78}, + {0x35, 0x02}, + {0xd9, 0x10}, + {0x94, 0x11}, +}; + +static const u8 sensor_init_ov965x_2[][2] = { + {0x3b, 0xc4}, + {0x1e, 0x04}, /* mvfp */ + {0x13, 0xe0}, /* com8 */ + {0x00, 0x00}, /* gain */ + {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */ + {0x11, 0x03}, /* clkrc */ + {0x6b, 0x5a}, /* dblv */ + {0x6a, 0x05}, + {0xc5, 0x07}, + {0xa2, 0x4b}, + {0xa3, 0x3e}, + {0x2d, 0x00}, + {0xff, 0x42}, /* read 42, write ff 00 */ + {0x42, 0xc0}, + {0x2d, 0x00}, + {0xff, 0x42}, /* read 42, write ff 00 */ + {0x42, 0xc1}, + {0x3f, 0x01}, + {0xff, 0x42}, /* read 42, write ff 00 */ + {0x42, 0xc1}, + {0x4f, 0x98}, + {0x50, 0x98}, + {0x51, 0x00}, + {0x52, 0x28}, + {0x53, 0x70}, + {0x54, 0x98}, + {0x58, 0x1a}, + {0xff, 0x41}, /* read 41, write ff 00 */ + {0x41, 0x40}, /* com16 */ + {0x56, 0x40}, + {0x55, 0x8f}, + {0x10, 0x25}, /* aech - exposure high bits */ + {0xff, 0x13}, /* read 13, write ff 00 */ + {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */ +}; + +static const u8 bridge_start_ov965x[][2] = { +#if 0 + {0x94, 0xaa}, + {0xf1, 0x60}, + {0xe5, 0x04}, + {0xc0, 0x50}, + {0xc1, 0x3c}, + {0x8c, 0x00}, + {0x8d, 0x1c}, + {0x34, 0x05}, +#endif + {0xc2, 0x4c}, + {0xc3, 0xf9}, + {0x50, 0x00}, + {0x51, 0xa0}, + {0x52, 0x78}, + {0x53, 0x00}, + {0x54, 0x00}, + {0x55, 0x00}, + {0x57, 0x00}, + {0x5c, 0x00}, + {0x5a, 0x28}, + {0x5b, 0x1e}, + {0x35, 0x00}, + {0xd9, 0x21}, + {0x94, 0x11}, +}; + +static const u8 sensor_start_ov965x[][2] = { + {0x3b, 0xe4}, + {0x1e, 0x04}, /* mvfp */ + {0x13, 0xe0}, /* com8 */ + {0x00, 0x00}, + {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */ + {0x11, 0x01}, /* clkrc */ + {0x6b, 0x5a}, /* dblv */ + {0x6a, 0x02}, + {0xc5, 0x03}, + {0xa2, 0x96}, + {0xa3, 0x7d}, + {0xff, 0x13}, /* read 13, write ff 00 */ + {0x13, 0xe7}, + {0x3a, 0x80}, + {0xff, 0x42}, /* read 42, write ff 00 */ + {0x42, 0xc1}, +}; + +#if 0 +static const u8 sensor_start_ov965x_2[][2] = { + {0xff, 0x13}, /* read 13, write ff 00 */ + {0x13, 0xe7}, + {0x3a, 0x80}, + {0xff, 0x42}, /* read 42, write ff 00 */ + {0x42, 0xc1}, +}; +#endif + +static void ov534_reg_write(struct gspca_dev *gspca_dev, u16 reg, u8 val) +{ + struct usb_device *udev = gspca_dev->dev; + int ret; + + PDEBUG(D_USBO, "reg=0x%04x, val=0%02x", reg, val); + gspca_dev->usb_buf[0] = val; + ret = usb_control_msg(udev, + usb_sndctrlpipe(udev, 0), + 0x01, + USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, + 0x00, reg, gspca_dev->usb_buf, 1, CTRL_TIMEOUT); + if (ret < 0) + PDEBUG(D_ERR, "write failed"); +} + +static u8 ov534_reg_read(struct gspca_dev *gspca_dev, u16 reg) +{ + struct usb_device *udev = gspca_dev->dev; + int ret; + + ret = usb_control_msg(udev, + usb_rcvctrlpipe(udev, 0), + 0x01, + USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, + 0x00, reg, gspca_dev->usb_buf, 1, CTRL_TIMEOUT); + PDEBUG(D_USBI, "reg=0x%04x, data=0x%02x", reg, gspca_dev->usb_buf[0]); + if (ret < 0) + PDEBUG(D_ERR, "read failed"); + return gspca_dev->usb_buf[0]; +} + +/* Two bits control LED: 0x21 bit 7 and 0x23 bit 7. + * (direction and output)? */ +static void ov534_set_led(struct gspca_dev *gspca_dev, int status) +{ + u8 data; + + PDEBUG(D_CONF, "led status: %d", status); + + data = ov534_reg_read(gspca_dev, 0x21); + data |= 0x80; + ov534_reg_write(gspca_dev, 0x21, data); + + data = ov534_reg_read(gspca_dev, 0x23); + if (status) + data |= 0x80; + else + data &= ~0x80; + + ov534_reg_write(gspca_dev, 0x23, data); + + if (!status) { + data = ov534_reg_read(gspca_dev, 0x21); + data &= ~0x80; + ov534_reg_write(gspca_dev, 0x21, data); + } +} + +static int sccb_check_status(struct gspca_dev *gspca_dev) +{ + u8 data; + int i; + + for (i = 0; i < 5; i++) { + data = ov534_reg_read(gspca_dev, OV534_REG_STATUS); + + switch (data) { + case 0x00: + return 1; + case 0x04: + return 0; + case 0x03: + break; + default: + PDEBUG(D_ERR, "sccb status 0x%02x, attempt %d/5", + data, i + 1); + } + } + return 0; +} + +static void sccb_reg_write(struct gspca_dev *gspca_dev, u8 reg, u8 val) +{ + PDEBUG(D_USBO, "reg: 0x%02x, val: 0x%02x", reg, val); + ov534_reg_write(gspca_dev, OV534_REG_SUBADDR, reg); + ov534_reg_write(gspca_dev, OV534_REG_WRITE, val); + ov534_reg_write(gspca_dev, OV534_REG_OPERATION, OV534_OP_WRITE_3); + + if (!sccb_check_status(gspca_dev)) + PDEBUG(D_ERR, "sccb_reg_write failed"); +} + +static u8 sccb_reg_read(struct gspca_dev *gspca_dev, u16 reg) +{ + ov534_reg_write(gspca_dev, OV534_REG_SUBADDR, reg); + ov534_reg_write(gspca_dev, OV534_REG_OPERATION, OV534_OP_WRITE_2); + if (!sccb_check_status(gspca_dev)) + PDEBUG(D_ERR, "sccb_reg_read failed 1"); + + ov534_reg_write(gspca_dev, OV534_REG_OPERATION, OV534_OP_READ_2); + if (!sccb_check_status(gspca_dev)) + PDEBUG(D_ERR, "sccb_reg_read failed 2"); + + return ov534_reg_read(gspca_dev, OV534_REG_READ); +} + +/* output a bridge sequence (reg - val) */ +static void reg_w_array(struct gspca_dev *gspca_dev, + const u8 (*data)[2], int len) +{ + while (--len >= 0) { + ov534_reg_write(gspca_dev, (*data)[0], (*data)[1]); + data++; + } +} + +/* output a sensor sequence (reg - val) */ +static void sccb_w_array(struct gspca_dev *gspca_dev, + const u8 (*data)[2], int len) +{ + while (--len >= 0) { + if ((*data)[0] != 0xff) { + sccb_reg_write(gspca_dev, (*data)[0], (*data)[1]); + } else { + sccb_reg_read(gspca_dev, (*data)[1]); + sccb_reg_write(gspca_dev, 0xff, 0x00); + } + data++; + } +} + /* set framerate */ static void ov534_set_frame_rate(struct gspca_dev *gspca_dev) { @@ -346,37 +713,15 @@ static void ov534_set_frame_rate(struct gspca_dev *gspca_dev) PDEBUG(D_PROBE, "frame_rate: %d", fr); } -/* setup method */ -static void ov534_setup(struct gspca_dev *gspca_dev) -{ - int i; - - /* Initialize bridge chip */ - for (i = 0; i < ARRAY_SIZE(ov534_reg_initdata); i++) - ov534_reg_write(gspca_dev, ov534_reg_initdata[i][0], - ov534_reg_initdata[i][1]); - - PDEBUG(D_PROBE, "sensor is ov%02x%02x", - sccb_reg_read(gspca_dev, 0x0a), - sccb_reg_read(gspca_dev, 0x0b)); - - ov534_set_led(gspca_dev, 1); - - /* Initialize sensor */ - for (i = 0; i < ARRAY_SIZE(ov772x_reg_initdata); i++) - sccb_reg_write(gspca_dev, ov772x_reg_initdata[i][0], - ov772x_reg_initdata[i][1]); - - ov534_reg_write(gspca_dev, 0xe0, 0x09); - ov534_set_led(gspca_dev, 0); -} - /* this function is called at probe time */ static int sd_config(struct gspca_dev *gspca_dev, const struct usb_device_id *id) { + struct sd *sd = (struct sd *) gspca_dev; struct cam *cam; + sd->sensor = id->driver_info; + cam = &gspca_dev->cam; cam->cam_mode = vga_mode; @@ -391,26 +736,106 @@ static int sd_config(struct gspca_dev *gspca_dev, /* this function is called at probe and resume time */ static int sd_init(struct gspca_dev *gspca_dev) { - ov534_setup(gspca_dev); - ov534_set_frame_rate(gspca_dev); + struct sd *sd = (struct sd *) gspca_dev; + u16 sensor_id; + static const u8 sensor_addr[2] = { + 0x42, /* 0 SENSOR_OV772X */ + 0x60, /* 1 SENSOR_OV965X */ + }; + + /* reset bridge */ + ov534_reg_write(gspca_dev, 0xe7, 0x3a); + ov534_reg_write(gspca_dev, 0xe0, 0x08); + msleep(100); + + /* initialize the sensor address */ + ov534_reg_write(gspca_dev, OV534_REG_ADDRESS, + sensor_addr[sd->sensor]); + + /* reset sensor */ + sccb_reg_write(gspca_dev, 0x12, 0x80); + msleep(10); + + /* probe the sensor */ + sccb_reg_read(gspca_dev, 0x0a); + sensor_id = sccb_reg_read(gspca_dev, 0x0a) << 8; + sccb_reg_read(gspca_dev, 0x0b); + sensor_id |= sccb_reg_read(gspca_dev, 0x0b); + PDEBUG(D_PROBE, "Sensor ID: %04x", sensor_id); + + /* initialize */ + switch (sd->sensor) { + case SENSOR_OV772X: + reg_w_array(gspca_dev, bridge_init_ov722x, + ARRAY_SIZE(bridge_init_ov722x)); + ov534_set_led(gspca_dev, 1); + sccb_w_array(gspca_dev, sensor_init_ov722x, + ARRAY_SIZE(sensor_init_ov722x)); + ov534_reg_write(gspca_dev, 0xe0, 0x09); + ov534_set_led(gspca_dev, 0); + ov534_set_frame_rate(gspca_dev); + break; + default: +/* case SENSOR_OV965X: */ + reg_w_array(gspca_dev, bridge_init_ov965x, + ARRAY_SIZE(bridge_init_ov965x)); + sccb_w_array(gspca_dev, sensor_init_ov965x, + ARRAY_SIZE(sensor_init_ov965x)); + reg_w_array(gspca_dev, bridge_init_ov965x_2, + ARRAY_SIZE(bridge_init_ov965x_2)); + sccb_w_array(gspca_dev, sensor_init_ov965x_2, + ARRAY_SIZE(sensor_init_ov965x_2)); + ov534_reg_write(gspca_dev, 0xe0, 0x00); + ov534_reg_write(gspca_dev, 0xe0, 0x01); + ov534_set_led(gspca_dev, 0); + ov534_reg_write(gspca_dev, 0xe0, 0x00); + } return 0; } static int sd_start(struct gspca_dev *gspca_dev) { - /* start streaming data */ - ov534_set_led(gspca_dev, 1); - ov534_reg_write(gspca_dev, 0xe0, 0x00); + struct sd *sd = (struct sd *) gspca_dev; + switch (sd->sensor) { + case SENSOR_OV772X: + ov534_set_led(gspca_dev, 1); + ov534_reg_write(gspca_dev, 0xe0, 0x00); + break; + default: +/* case SENSOR_OV965X: */ +#if 0 + sccb_w_array(gspca_dev, sensor_init_ov965x, + ARRAY_SIZE(sensor_init_ov965x)); +#endif + reg_w_array(gspca_dev, bridge_start_ov965x, + ARRAY_SIZE(bridge_start_ov965x)); + sccb_w_array(gspca_dev, sensor_start_ov965x, + ARRAY_SIZE(sensor_start_ov965x)); + ov534_reg_write(gspca_dev, 0xe0, 0x00); + ov534_set_led(gspca_dev, 1); +/*fixme: other sensor start omitted*/ + } return 0; } static void sd_stopN(struct gspca_dev *gspca_dev) { - /* stop streaming data */ - ov534_reg_write(gspca_dev, 0xe0, 0x09); - ov534_set_led(gspca_dev, 0); + struct sd *sd = (struct sd *) gspca_dev; + + switch (sd->sensor) { + case SENSOR_OV772X: + ov534_reg_write(gspca_dev, 0xe0, 0x09); + ov534_set_led(gspca_dev, 0); + break; + default: +/* case SENSOR_OV965X: */ + ov534_reg_write(gspca_dev, 0xe0, 0x01); + ov534_set_led(gspca_dev, 0); + ov534_reg_write(gspca_dev, 0xe0, 0x00); + break; + } } /* Values for bmHeaderInfo (Video and Still Image Payload Headers, 2.4.3.3) */ @@ -428,75 +853,75 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev, struct gspca_frame *frame, { struct sd *sd = (struct sd *) gspca_dev; __u32 this_pts; - int this_fid; + u16 this_fid; int remaining_len = len; - __u8 *next_data = data; -scan_next: - if (remaining_len <= 0) - return; - - data = next_data; - len = min(remaining_len, 2048); - remaining_len -= len; - next_data += len; - - /* Payloads are prefixed with a UVC-style header. We - consider a frame to start when the FID toggles, or the PTS - changes. A frame ends when EOF is set, and we've received - the correct number of bytes. */ - - /* Verify UVC header. Header length is always 12 */ - if (data[0] != 12 || len < 12) { - PDEBUG(D_PACK, "bad header"); - goto discard; - } + do { + len = min(remaining_len, 2040); /*fixme: was 2048*/ - /* Check errors */ - if (data[1] & UVC_STREAM_ERR) { - PDEBUG(D_PACK, "payload error"); - goto discard; - } - - /* Extract PTS and FID */ - if (!(data[1] & UVC_STREAM_PTS)) { - PDEBUG(D_PACK, "PTS not present"); - goto discard; - } - this_pts = (data[5] << 24) | (data[4] << 16) | (data[3] << 8) | data[2]; - this_fid = (data[1] & UVC_STREAM_FID) ? 1 : 0; - - /* If PTS or FID has changed, start a new frame. */ - if (this_pts != sd->last_pts || this_fid != sd->last_fid) { - gspca_frame_add(gspca_dev, FIRST_PACKET, frame, NULL, 0); - sd->last_pts = this_pts; - sd->last_fid = this_fid; - } + /* Payloads are prefixed with a UVC-style header. We + consider a frame to start when the FID toggles, or the PTS + changes. A frame ends when EOF is set, and we've received + the correct number of bytes. */ - /* Add the data from this payload */ - gspca_frame_add(gspca_dev, INTER_PACKET, frame, - data + 12, len - 12); + /* Verify UVC header. Header length is always 12 */ + if (data[0] != 12 || len < 12) { + PDEBUG(D_PACK, "bad header"); + goto discard; + } - /* If this packet is marked as EOF, end the frame */ - if (data[1] & UVC_STREAM_EOF) { - sd->last_pts = 0; + /* Check errors */ + if (data[1] & UVC_STREAM_ERR) { + PDEBUG(D_PACK, "payload error"); + goto discard; + } - if ((frame->data_end - frame->data) != - (gspca_dev->width * gspca_dev->height * 2)) { - PDEBUG(D_PACK, "short frame"); + /* Extract PTS and FID */ + if (!(data[1] & UVC_STREAM_PTS)) { + PDEBUG(D_PACK, "PTS not present"); goto discard; } + this_pts = (data[5] << 24) | (data[4] << 16) + | (data[3] << 8) | data[2]; + this_fid = (data[1] & UVC_STREAM_FID) ? 1 : 0; + + /* If PTS or FID has changed, start a new frame. */ + if (this_pts != sd->last_pts || this_fid != sd->last_fid) { + gspca_frame_add(gspca_dev, FIRST_PACKET, frame, + NULL, 0); + sd->last_pts = this_pts; + sd->last_fid = this_fid; + } - gspca_frame_add(gspca_dev, LAST_PACKET, frame, NULL, 0); - } + /* Add the data from this payload */ + gspca_frame_add(gspca_dev, INTER_PACKET, frame, + data + 12, len - 12); + + /* If this packet is marked as EOF, end the frame */ + if (data[1] & UVC_STREAM_EOF) { + sd->last_pts = 0; + + if (frame->data_end - frame->data != + gspca_dev->width * gspca_dev->height * 2) { + PDEBUG(D_PACK, "short frame"); + goto discard; + } - /* Done this payload */ - goto scan_next; + frame = gspca_frame_add(gspca_dev, LAST_PACKET, frame, + NULL, 0); + } + + /* Done this payload */ + goto scan_next; discard: - /* Discard data until a new frame starts. */ - gspca_frame_add(gspca_dev, DISCARD_PACKET, frame, NULL, 0); - goto scan_next; + /* Discard data until a new frame starts. */ + gspca_frame_add(gspca_dev, DISCARD_PACKET, frame, NULL, 0); + +scan_next: + remaining_len -= len; + data += len; + } while (remaining_len > 0); } /* get stream parameters (framerate) */ @@ -556,11 +981,11 @@ static const struct sd_desc sd_desc = { /* -- module initialisation -- */ static const __devinitdata struct usb_device_id device_table[] = { #if 0 - /* these two are not supported yet, different sensors */ - {USB_DEVICE(0x06f8, 0x3002)}, /* Hercules Blog Webcam */ - {USB_DEVICE(0x06f8, 0x3003)}, /* Hercules Dualpix HD Weblog */ + /* not supported yet */ + {USB_DEVICE(0x06f8, 0x3002), .driver_info = SENSOR_unknown}, #endif - {USB_DEVICE(0x1415, 0x2000)}, /* Sony HD Eye for PS3 (SLEH 00201) */ + {USB_DEVICE(0x06f8, 0x3003), .driver_info = SENSOR_OV965X}, + {USB_DEVICE(0x1415, 0x2000), .driver_info = SENSOR_OV772X}, {} }; diff --git a/linux/drivers/media/video/gspca/sonixj.c b/linux/drivers/media/video/gspca/sonixj.c index 36d6f50be..c3959f00a 100644 --- a/linux/drivers/media/video/gspca/sonixj.c +++ b/linux/drivers/media/video/gspca/sonixj.c @@ -22,7 +22,6 @@ #define MODULE_NAME "sonixj" #include "gspca.h" -#define QUANT_VAL 4 /* quantization table */ #include "jpeg.h" #define V4L2_CID_INFRARED (V4L2_CID_PRIVATE_BASE + 0) @@ -47,6 +46,13 @@ struct sd { u8 gamma; u8 vflip; /* ov7630/ov7648 only */ u8 infrared; /* mt9v111 only */ + u8 quality; /* image quality */ +#define QUALITY_MIN 60 +#define QUALITY_MAX 95 +#define QUALITY_DEF 80 + u8 jpegqual; /* webcam quality */ + + u8 reg18; s8 ag_cnt; #define AG_CNT_START 13 @@ -68,6 +74,8 @@ struct sd { #define SENSOR_OV7660 7 #define SENSOR_SP80708 8 u8 i2c_base; + + u8 *jpeg_hdr; }; /* V4L2 controls supported by the driver */ @@ -867,25 +875,6 @@ static const u8 sp80708_sensor_init[][8] = { {} }; -static const u8 qtable4[] = { - 0x06, 0x04, 0x04, 0x06, 0x04, 0x04, 0x06, 0x06, - 0x06, 0x06, 0x08, 0x06, 0x06, 0x08, 0x0a, 0x11, - 0x0a, 0x0a, 0x08, 0x08, 0x0a, 0x15, 0x0f, 0x0f, - 0x0c, 0x11, 0x19, 0x15, 0x19, 0x19, 0x17, 0x15, - 0x17, 0x17, 0x1b, 0x1d, 0x25, 0x21, 0x1b, 0x1d, - 0x23, 0x1d, 0x17, 0x17, 0x21, 0x2e, 0x21, 0x23, - 0x27, 0x29, 0x2c, 0x2c, 0x2c, 0x19, 0x1f, 0x30, - 0x32, 0x2e, 0x29, 0x32, 0x25, 0x29, 0x2c, 0x29, - 0x06, 0x08, 0x08, 0x0a, 0x08, 0x0a, 0x13, 0x0a, - 0x0a, 0x13, 0x29, 0x1b, 0x17, 0x1b, 0x29, 0x29, - 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, - 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, - 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, - 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, - 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, - 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29, 0x29 -}; - /* read <len> bytes to gspca_dev->usb_buf */ static void reg_r(struct gspca_dev *gspca_dev, u16 value, int len) @@ -1325,6 +1314,8 @@ static int sd_config(struct gspca_dev *gspca_dev, else sd->vflip = 1; sd->infrared = INFRARED_DEF; + sd->quality = QUALITY_DEF; + sd->jpegqual = 80; gspca_dev->ctrl_dis = ctrl_dis[sd->sensor]; return 0; @@ -1642,12 +1633,49 @@ static void setinfrared(struct sd *sd) #endif } +static void setjpegqual(struct gspca_dev *gspca_dev) +{ + struct sd *sd = (struct sd *) gspca_dev; + int i, sc; + + if (sd->jpegqual < 50) + sc = 5000 / sd->jpegqual; + else + sc = 200 - sd->jpegqual * 2; +#if USB_BUF_SZ < 64 +#error "No room enough in usb_buf for quantization table" +#endif + for (i = 0; i < 64; i++) + gspca_dev->usb_buf[i] = + (jpeg_head[JPEG_QT0_OFFSET + i] * sc + 50) / 100; + usb_control_msg(gspca_dev->dev, + usb_sndctrlpipe(gspca_dev->dev, 0), + 0x08, + USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE, + 0x0100, 0, + gspca_dev->usb_buf, 64, + 500); + for (i = 0; i < 64; i++) + gspca_dev->usb_buf[i] = + (jpeg_head[JPEG_QT1_OFFSET + i] * sc + 50) / 100; + usb_control_msg(gspca_dev->dev, + usb_sndctrlpipe(gspca_dev->dev, 0), + 0x08, + USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE, + 0x0140, 0, + gspca_dev->usb_buf, 64, + 500); + + sd->reg18 ^= 0x40; + reg_w1(gspca_dev, 0x18, sd->reg18); +} + /* -- start the camera -- */ static int sd_start(struct gspca_dev *gspca_dev) { struct sd *sd = (struct sd *) gspca_dev; int i; - u8 reg1, reg17, reg18; + u8 reg1, reg17; const u8 *sn9c1xx; int mode; static const u8 C0[] = { 0x2d, 0x2d, 0x3a, 0x05, 0x04, 0x3f }; @@ -1656,6 +1684,12 @@ static int sd_start(struct gspca_dev *gspca_dev) static const u8 CE_ov76xx[] = { 0x32, 0xdd, 0x32, 0xdd }; + /* create the JPEG header */ + sd->jpeg_hdr = kmalloc(JPEG_HDR_SZ, GFP_KERNEL); + jpeg_define(sd->jpeg_hdr, gspca_dev->height, gspca_dev->width, + 0x21); /* JPEG 422 */ + jpeg_set_qual(sd->jpeg_hdr, sd->quality); + sn9c1xx = sn_tb[(int) sd->sensor]; configure_gpio(gspca_dev, sn9c1xx); @@ -1816,13 +1850,9 @@ static int sd_start(struct gspca_dev *gspca_dev) } /* here change size mode 0 -> VGA; 1 -> CIF */ - reg18 = sn9c1xx[0x18] | (mode << 4); - reg_w1(gspca_dev, 0x18, reg18 | 0x40); - - reg_w(gspca_dev, 0x0100, qtable4, 0x40); - reg_w(gspca_dev, 0x0140, qtable4 + 0x40, 0x40); - - reg_w1(gspca_dev, 0x18, reg18); + sd->reg18 = sn9c1xx[0x18] | (mode << 4) | 0x40; + reg_w1(gspca_dev, 0x18, sd->reg18); + setjpegqual(gspca_dev); reg_w1(gspca_dev, 0x17, reg17); reg_w1(gspca_dev, 0x01, reg1); @@ -1884,6 +1914,13 @@ static void sd_stopN(struct gspca_dev *gspca_dev) reg_w1(gspca_dev, 0xf1, 0x00); } +static void sd_stop0(struct gspca_dev *gspca_dev) +{ + struct sd *sd = (struct sd *) gspca_dev; + + kfree(sd->jpeg_hdr); +} + static void do_autogain(struct gspca_dev *gspca_dev) { struct sd *sd = (struct sd *) gspca_dev; @@ -1967,7 +2004,8 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev, if (gspca_dev->last_packet_type == LAST_PACKET) { /* put the JPEG 422 header */ - jpeg_put_header(gspca_dev, frame, 0x21); + gspca_frame_add(gspca_dev, FIRST_PACKET, frame, + sd->jpeg_hdr, JPEG_HDR_SZ); } gspca_frame_add(gspca_dev, INTER_PACKET, frame, data, len); } @@ -2134,6 +2172,34 @@ static int sd_getinfrared(struct gspca_dev *gspca_dev, __s32 *val) return 0; } +static int sd_set_jcomp(struct gspca_dev *gspca_dev, + struct v4l2_jpegcompression *jcomp) +{ + struct sd *sd = (struct sd *) gspca_dev; + + if (jcomp->quality < QUALITY_MIN) + sd->quality = QUALITY_MIN; + else if (jcomp->quality > QUALITY_MAX) + sd->quality = QUALITY_MAX; + else + sd->quality = jcomp->quality; + if (gspca_dev->streaming) + jpeg_set_qual(sd->jpeg_hdr, sd->quality); + return 0; +} + +static int sd_get_jcomp(struct gspca_dev *gspca_dev, + struct v4l2_jpegcompression *jcomp) +{ + struct sd *sd = (struct sd *) gspca_dev; + + memset(jcomp, 0, sizeof *jcomp); + jcomp->quality = sd->quality; + jcomp->jpeg_markers = V4L2_JPEG_MARKER_DHT + | V4L2_JPEG_MARKER_DQT; + return 0; +} + /* sub-driver description */ static const struct sd_desc sd_desc = { .name = MODULE_NAME, @@ -2143,8 +2209,11 @@ static const struct sd_desc sd_desc = { .init = sd_init, .start = sd_start, .stopN = sd_stopN, + .stop0 = sd_stop0, .pkt_scan = sd_pkt_scan, .dq_callback = do_autogain, + .get_jcomp = sd_get_jcomp, + .set_jcomp = sd_set_jcomp, }; /* -- module initialisation -- */ @@ -2159,9 +2228,7 @@ static const __devinitdata struct usb_device_id device_table[] = { #endif {USB_DEVICE(0x045e, 0x00f5), BSI(SN9C105, OV7660, 0x21)}, {USB_DEVICE(0x045e, 0x00f7), BSI(SN9C105, OV7660, 0x21)}, -#if !defined CONFIG_USB_SN9C102 && !defined CONFIG_USB_SN9C102_MODULE {USB_DEVICE(0x0471, 0x0327), BSI(SN9C105, MI0360, 0x5d)}, -#endif {USB_DEVICE(0x0471, 0x0328), BSI(SN9C105, MI0360, 0x5d)}, {USB_DEVICE(0x0471, 0x0330), BSI(SN9C105, MI0360, 0x5d)}, {USB_DEVICE(0x06f8, 0x3004), BSI(SN9C105, OV7660, 0x21)}, diff --git a/linux/drivers/media/video/gspca/spca500.c b/linux/drivers/media/video/gspca/spca500.c index 94caba63b..8cfb7cad9 100644 --- a/linux/drivers/media/video/gspca/spca500.c +++ b/linux/drivers/media/video/gspca/spca500.c @@ -22,7 +22,6 @@ #define MODULE_NAME "spca500" #include "gspca.h" -#define QUANT_VAL 5 /* quantization table */ #include "jpeg.h" MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>"); @@ -39,6 +38,10 @@ struct sd { unsigned char brightness; unsigned char contrast; unsigned char colors; + u8 quality; +#define QUALITY_MIN 70 +#define QUALITY_MAX 95 +#define QUALITY_DEF 85 char subtype; #define AgfaCl20 0 @@ -56,6 +59,8 @@ struct sd { #define Optimedia 12 #define PalmPixDC85 13 #define ToptroIndus 14 + + u8 *jpeg_hdr; }; /* V4L2 controls supported by the driver */ @@ -657,6 +662,7 @@ static int sd_config(struct gspca_dev *gspca_dev, sd->brightness = BRIGHTNESS_DEF; sd->contrast = CONTRAST_DEF; sd->colors = COLOR_DEF; + sd->quality = QUALITY_DEF; return 0; } @@ -682,6 +688,12 @@ static int sd_start(struct gspca_dev *gspca_dev) __u8 Data; __u8 xmult, ymult; + /* create the JPEG header */ + sd->jpeg_hdr = kmalloc(JPEG_HDR_SZ, GFP_KERNEL); + jpeg_define(sd->jpeg_hdr, gspca_dev->height, gspca_dev->width, + 0x22); /* JPEG 411 */ + jpeg_set_qual(sd->jpeg_hdr, sd->quality); + if (sd->subtype == LogitechClickSmart310) { xmult = 0x16; ymult = 0x12; @@ -897,6 +909,13 @@ static void sd_stopN(struct gspca_dev *gspca_dev) gspca_dev->usb_buf[0]); } +static void sd_stop0(struct gspca_dev *gspca_dev) +{ + struct sd *sd = (struct sd *) gspca_dev; + + kfree(sd->jpeg_hdr); +} + static void sd_pkt_scan(struct gspca_dev *gspca_dev, struct gspca_frame *frame, /* target */ __u8 *data, /* isoc packet */ @@ -917,7 +936,8 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev, ffd9, 2); /* put the JPEG header in the new frame */ - jpeg_put_header(gspca_dev, frame, 0x22); + gspca_frame_add(gspca_dev, FIRST_PACKET, frame, + sd->jpeg_hdr, JPEG_HDR_SZ); data += SPCA500_OFFSET_DATA; len -= SPCA500_OFFSET_DATA; @@ -1021,6 +1041,34 @@ static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val) return 0; } +static int sd_set_jcomp(struct gspca_dev *gspca_dev, + struct v4l2_jpegcompression *jcomp) +{ + struct sd *sd = (struct sd *) gspca_dev; + + if (jcomp->quality < QUALITY_MIN) + sd->quality = QUALITY_MIN; + else if (jcomp->quality > QUALITY_MAX) + sd->quality = QUALITY_MAX; + else + sd->quality = jcomp->quality; + if (gspca_dev->streaming) + jpeg_set_qual(sd->jpeg_hdr, sd->quality); + return 0; +} + +static int sd_get_jcomp(struct gspca_dev *gspca_dev, + struct v4l2_jpegcompression *jcomp) +{ + struct sd *sd = (struct sd *) gspca_dev; + + memset(jcomp, 0, sizeof *jcomp); + jcomp->quality = sd->quality; + jcomp->jpeg_markers = V4L2_JPEG_MARKER_DHT + | V4L2_JPEG_MARKER_DQT; + return 0; +} + /* sub-driver description */ static struct sd_desc sd_desc = { .name = MODULE_NAME, @@ -1030,7 +1078,10 @@ static struct sd_desc sd_desc = { .init = sd_init, .start = sd_start, .stopN = sd_stopN, + .stop0 = sd_stop0, .pkt_scan = sd_pkt_scan, + .get_jcomp = sd_get_jcomp, + .set_jcomp = sd_set_jcomp, }; /* -- module initialisation -- */ diff --git a/linux/drivers/media/video/gspca/sq905.c b/linux/drivers/media/video/gspca/sq905.c index da60eea51..04e3ae57a 100644 --- a/linux/drivers/media/video/gspca/sq905.c +++ b/linux/drivers/media/video/gspca/sq905.c @@ -82,8 +82,6 @@ MODULE_LICENSE("GPL"); struct sd { struct gspca_dev gspca_dev; /* !! must be the first item */ - const struct v4l2_pix_format *cap_mode; - /* * Driver stuff */ @@ -218,6 +216,7 @@ static void sq905_dostream(struct work_struct *work) int header_read; /* true if we have already read the frame header. */ int discarding; /* true if we failed to get space for frame. */ int packet_type; + int frame_sz; int ret; u8 *data; u8 *buffer; @@ -229,6 +228,9 @@ static void sq905_dostream(struct work_struct *work) goto quit_stream; } + frame_sz = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].sizeimage + + FRAME_HEADER_LEN; + while (gspca_dev->present && gspca_dev->streaming) { /* Need a short delay to ensure streaming flag was set by * gspca and to make sure gspca can grab the mutex. */ @@ -237,7 +239,7 @@ static void sq905_dostream(struct work_struct *work) /* request some data and then read it until we have * a complete frame. */ - bytes_left = dev->cap_mode->sizeimage + FRAME_HEADER_LEN; + bytes_left = frame_sz; header_read = 0; discarding = 0; @@ -270,13 +272,14 @@ static void sq905_dostream(struct work_struct *work) } frame = gspca_get_i_frame(gspca_dev); if (frame && !discarding) { - gspca_frame_add(gspca_dev, packet_type, + frame = gspca_frame_add(gspca_dev, packet_type, frame, data, data_len); /* If entire frame fits in one packet we still need to add a LAST_PACKET */ - if ((packet_type == FIRST_PACKET) && - (bytes_left == 0)) - gspca_frame_add(gspca_dev, LAST_PACKET, + if (packet_type == FIRST_PACKET && + bytes_left == 0) + frame = gspca_frame_add(gspca_dev, + LAST_PACKET, frame, data, 0); } else { discarding = 1; @@ -366,21 +369,18 @@ static int sd_start(struct gspca_dev *gspca_dev) struct sd *dev = (struct sd *) gspca_dev; int ret; - /* Set capture mode based on selected resolution. */ - dev->cap_mode = gspca_dev->cam.cam_mode; /* "Open the shutter" and set size, to start capture */ - switch (gspca_dev->width) { - case 640: + switch (gspca_dev->curr_mode) { + default: +/* case 2: */ PDEBUG(D_STREAM, "Start streaming at high resolution"); - dev->cap_mode += 2; ret = sq905_command(&dev->gspca_dev, SQ905_CAPTURE_HIGH); break; - case 320: + case 1: PDEBUG(D_STREAM, "Start streaming at medium resolution"); - dev->cap_mode++; ret = sq905_command(&dev->gspca_dev, SQ905_CAPTURE_MED); break; - default: + case 0: PDEBUG(D_STREAM, "Start streaming at low resolution"); ret = sq905_command(&dev->gspca_dev, SQ905_CAPTURE_LOW); } diff --git a/linux/drivers/media/video/gspca/sq905c.c b/linux/drivers/media/video/gspca/sq905c.c new file mode 100644 index 000000000..0bcb74a1b --- /dev/null +++ b/linux/drivers/media/video/gspca/sq905c.c @@ -0,0 +1,328 @@ +/* + * SQ905C subdriver + * + * Copyright (C) 2009 Theodore Kilgore + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* + * + * This driver uses work done in + * libgphoto2/camlibs/digigr8, Copyright (C) Theodore Kilgore. + * + * This driver has also used as a base the sq905c driver + * and may contain code fragments from it. + */ + +#define MODULE_NAME "sq905c" + +#include <linux/workqueue.h> +#include "gspca.h" + +MODULE_AUTHOR("Theodore Kilgore <kilgota@auburn.edu>"); +MODULE_DESCRIPTION("GSPCA/SQ905C USB Camera Driver"); +MODULE_LICENSE("GPL"); + +/* Default timeouts, in ms */ +#define SQ905C_CMD_TIMEOUT 500 +#define SQ905C_DATA_TIMEOUT 1000 + +/* Maximum transfer size to use. */ +#define SQ905C_MAX_TRANSFER 0x8000 + +#define FRAME_HEADER_LEN 0x50 + +/* Commands. These go in the "value" slot. */ +#define SQ905C_CLEAR 0xa0 /* clear everything */ +#define SQ905C_CAPTURE_LOW 0xa040 /* Starts capture at 160x120 */ +#define SQ905C_CAPTURE_MED 0x1440 /* Starts capture at 320x240 */ +#define SQ905C_CAPTURE_HI 0x2840 /* Starts capture at 320x240 */ + +/* For capture, this must go in the "index" slot. */ +#define SQ905C_CAPTURE_INDEX 0x110f + +/* Structure to hold all of our device specific stuff */ +struct sd { + struct gspca_dev gspca_dev; /* !! must be the first item */ + const struct v4l2_pix_format *cap_mode; + /* Driver stuff */ + struct work_struct work_struct; + struct workqueue_struct *work_thread; +}; + +/* + * Most of these cameras will do 640x480 and 320x240. 160x120 works + * in theory but gives very poor output. Therefore, not supported. + * The 0x2770:0x9050 cameras have max resolution of 320x240. + */ +static struct v4l2_pix_format sq905c_mode[] = { + { 320, 240, V4L2_PIX_FMT_SQ905C, V4L2_FIELD_NONE, + .bytesperline = 320, + .sizeimage = 320 * 240, + .colorspace = V4L2_COLORSPACE_SRGB, + .priv = 0}, + { 640, 480, V4L2_PIX_FMT_SQ905C, V4L2_FIELD_NONE, + .bytesperline = 640, + .sizeimage = 640 * 480, + .colorspace = V4L2_COLORSPACE_SRGB, + .priv = 0} +}; + +/* Send a command to the camera. */ +static int sq905c_command(struct gspca_dev *gspca_dev, u16 command, u16 index) +{ + int ret; + + ret = usb_control_msg(gspca_dev->dev, + usb_sndctrlpipe(gspca_dev->dev, 0), + USB_REQ_SYNCH_FRAME, /* request */ + USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, + command, index, NULL, 0, + SQ905C_CMD_TIMEOUT); + if (ret < 0) { + PDEBUG(D_ERR, "%s: usb_control_msg failed (%d)", + __func__, ret); + return ret; + } + + return 0; +} + +/* This function is called as a workqueue function and runs whenever the camera + * is streaming data. Because it is a workqueue function it is allowed to sleep + * so we can use synchronous USB calls. To avoid possible collisions with other + * threads attempting to use the camera's USB interface the gspca usb_lock is + * used when performing the one USB control operation inside the workqueue, + * which tells the camera to close the stream. In practice the only thing + * which needs to be protected against is the usb_set_interface call that + * gspca makes during stream_off. Otherwise the camera doesn't provide any + * controls that the user could try to change. + */ +static void sq905c_dostream(struct work_struct *work) +{ + struct sd *dev = container_of(work, struct sd, work_struct); + struct gspca_dev *gspca_dev = &dev->gspca_dev; + struct gspca_frame *frame; + int bytes_left; /* bytes remaining in current frame. */ + int data_len; /* size to use for the next read. */ + int act_len; + int discarding = 0; /* true if we failed to get space for frame. */ + int packet_type; + int ret; + u8 *buffer; + + buffer = kmalloc(SQ905C_MAX_TRANSFER, GFP_KERNEL | GFP_DMA); + if (!buffer) { + PDEBUG(D_ERR, "Couldn't allocate USB buffer"); + goto quit_stream; + } + + while (gspca_dev->present && gspca_dev->streaming) { + if (!gspca_dev->present) + goto quit_stream; + /* Request the header, which tells the size to download */ + ret = usb_bulk_msg(gspca_dev->dev, + usb_rcvbulkpipe(gspca_dev->dev, 0x81), + buffer, FRAME_HEADER_LEN, &act_len, + SQ905C_DATA_TIMEOUT); + PDEBUG(D_STREAM, + "Got %d bytes out of %d for header", + act_len, FRAME_HEADER_LEN); + if (ret < 0 || act_len < FRAME_HEADER_LEN) + goto quit_stream; + /* size is read from 4 bytes starting 0x40, little endian */ + bytes_left = buffer[0x40]|(buffer[0x41]<<8)|(buffer[0x42]<<16) + |(buffer[0x43]<<24); + PDEBUG(D_STREAM, "bytes_left = 0x%x", bytes_left); + /* We keep the header. It has other information, too. */ + packet_type = FIRST_PACKET; + frame = gspca_get_i_frame(gspca_dev); + if (frame && !discarding) { + gspca_frame_add(gspca_dev, packet_type, + frame, buffer, FRAME_HEADER_LEN); + } else + discarding = 1; + while (bytes_left > 0) { + data_len = bytes_left > SQ905C_MAX_TRANSFER ? + SQ905C_MAX_TRANSFER : bytes_left; + if (!gspca_dev->present) + goto quit_stream; + ret = usb_bulk_msg(gspca_dev->dev, + usb_rcvbulkpipe(gspca_dev->dev, 0x81), + buffer, data_len, &act_len, + SQ905C_DATA_TIMEOUT); + if (ret < 0 || act_len < data_len) + goto quit_stream; + PDEBUG(D_STREAM, + "Got %d bytes out of %d for frame", + data_len, bytes_left); + bytes_left -= data_len; + if (bytes_left == 0) + packet_type = LAST_PACKET; + else + packet_type = INTER_PACKET; + frame = gspca_get_i_frame(gspca_dev); + if (frame && !discarding) + gspca_frame_add(gspca_dev, packet_type, + frame, buffer, data_len); + else + discarding = 1; + } + } +quit_stream: + mutex_lock(&gspca_dev->usb_lock); + if (gspca_dev->present) + sq905c_command(gspca_dev, SQ905C_CLEAR, 0); + mutex_unlock(&gspca_dev->usb_lock); + kfree(buffer); +} + +/* This function is called at probe time just before sd_init */ +static int sd_config(struct gspca_dev *gspca_dev, + const struct usb_device_id *id) +{ + struct cam *cam = &gspca_dev->cam; + struct sd *dev = (struct sd *) gspca_dev; + + PDEBUG(D_PROBE, + "SQ9050 camera detected" + " (vid/pid 0x%04X:0x%04X)", id->idVendor, id->idProduct); + cam->cam_mode = sq905c_mode; + cam->nmodes = 2; + if (id->idProduct == 0x9050) + cam->nmodes = 1; + /* We don't use the buffer gspca allocates so make it small. */ + cam->bulk_size = 32; + INIT_WORK(&dev->work_struct, sq905c_dostream); + return 0; +} + +/* called on streamoff with alt==0 and on disconnect */ +/* the usb_lock is held at entry - restore on exit */ +static void sd_stop0(struct gspca_dev *gspca_dev) +{ + struct sd *dev = (struct sd *) gspca_dev; + + /* wait for the work queue to terminate */ + mutex_unlock(&gspca_dev->usb_lock); + /* This waits for sq905c_dostream to finish */ + destroy_workqueue(dev->work_thread); + dev->work_thread = NULL; + mutex_lock(&gspca_dev->usb_lock); +} + +/* this function is called at probe and resume time */ +static int sd_init(struct gspca_dev *gspca_dev) +{ + int ret; + + /* connect to the camera and reset it. */ + ret = sq905c_command(gspca_dev, SQ905C_CLEAR, 0); + return ret; +} + +/* Set up for getting frames. */ +static int sd_start(struct gspca_dev *gspca_dev) +{ + struct sd *dev = (struct sd *) gspca_dev; + int ret; + + dev->cap_mode = gspca_dev->cam.cam_mode; + /* "Open the shutter" and set size, to start capture */ + switch (gspca_dev->width) { + case 640: + PDEBUG(D_STREAM, "Start streaming at high resolution"); + dev->cap_mode++; + ret = sq905c_command(gspca_dev, SQ905C_CAPTURE_HI, + SQ905C_CAPTURE_INDEX); + break; + default: /* 320 */ + PDEBUG(D_STREAM, "Start streaming at medium resolution"); + ret = sq905c_command(gspca_dev, SQ905C_CAPTURE_MED, + SQ905C_CAPTURE_INDEX); + } + + if (ret < 0) { + PDEBUG(D_ERR, "Start streaming command failed"); + return ret; + } + /* Start the workqueue function to do the streaming */ + dev->work_thread = create_singlethread_workqueue(MODULE_NAME); + queue_work(dev->work_thread, &dev->work_struct); + + return 0; +} + +/* Table of supported USB devices */ +static const __devinitdata struct usb_device_id device_table[] = { + {USB_DEVICE(0x2770, 0x905c)}, + {USB_DEVICE(0x2770, 0x9050)}, + {USB_DEVICE(0x2770, 0x913d)}, + {} +}; + +MODULE_DEVICE_TABLE(usb, device_table); + +/* sub-driver description */ +static const struct sd_desc sd_desc = { + .name = MODULE_NAME, + .config = sd_config, + .init = sd_init, + .start = sd_start, + .stop0 = sd_stop0, +}; + +/* -- device connect -- */ +static int sd_probe(struct usb_interface *intf, + const struct usb_device_id *id) +{ + return gspca_dev_probe(intf, id, + &sd_desc, + sizeof(struct sd), + THIS_MODULE); +} + +static struct usb_driver sd_driver = { + .name = MODULE_NAME, + .id_table = device_table, + .probe = sd_probe, + .disconnect = gspca_disconnect, +#ifdef CONFIG_PM + .suspend = gspca_suspend, + .resume = gspca_resume, +#endif +}; + +/* -- module insert / remove -- */ +static int __init sd_mod_init(void) +{ + int ret; + + ret = usb_register(&sd_driver); + if (ret < 0) + return ret; + PDEBUG(D_PROBE, "registered"); + return 0; +} + +static void __exit sd_mod_exit(void) +{ + usb_deregister(&sd_driver); + PDEBUG(D_PROBE, "deregistered"); +} + +module_init(sd_mod_init); +module_exit(sd_mod_exit); diff --git a/linux/drivers/media/video/gspca/stk014.c b/linux/drivers/media/video/gspca/stk014.c index d1d54edd8..f25be20cf 100644 --- a/linux/drivers/media/video/gspca/stk014.c +++ b/linux/drivers/media/video/gspca/stk014.c @@ -21,8 +21,6 @@ #define MODULE_NAME "stk014" #include "gspca.h" -#define QUANT_VAL 7 /* quantization table */ - /* <= 4 KO - 7: good (enough!) */ #include "jpeg.h" MODULE_AUTHOR("Jean-Francois Moine <http://moinejf.free.fr>"); @@ -37,6 +35,12 @@ struct sd { unsigned char contrast; unsigned char colors; unsigned char lightfreq; + u8 quality; +#define QUALITY_MIN 60 +#define QUALITY_MAX 95 +#define QUALITY_DEF 80 + + u8 *jpeg_hdr; }; /* V4L2 controls supported by the driver */ @@ -300,6 +304,7 @@ static int sd_config(struct gspca_dev *gspca_dev, sd->contrast = CONTRAST_DEF; sd->colors = COLOR_DEF; sd->lightfreq = FREQ_DEF; + sd->quality = QUALITY_DEF; return 0; } @@ -323,8 +328,15 @@ static int sd_init(struct gspca_dev *gspca_dev) /* -- start the camera -- */ static int sd_start(struct gspca_dev *gspca_dev) { + struct sd *sd = (struct sd *) gspca_dev; int ret, value; + /* create the JPEG header */ + sd->jpeg_hdr = kmalloc(JPEG_HDR_SZ, GFP_KERNEL); + jpeg_define(sd->jpeg_hdr, gspca_dev->height, gspca_dev->width, + 0x22); /* JPEG 411 */ + jpeg_set_qual(sd->jpeg_hdr, sd->quality); + /* work on alternate 1 */ usb_set_interface(gspca_dev->dev, gspca_dev->iface, 1); @@ -396,11 +408,19 @@ static void sd_stopN(struct gspca_dev *gspca_dev) PDEBUG(D_STREAM, "camera stopped"); } +static void sd_stop0(struct gspca_dev *gspca_dev) +{ + struct sd *sd = (struct sd *) gspca_dev; + + kfree(sd->jpeg_hdr); +} + static void sd_pkt_scan(struct gspca_dev *gspca_dev, struct gspca_frame *frame, /* target */ __u8 *data, /* isoc packet */ int len) /* iso packet length */ { + struct sd *sd = (struct sd *) gspca_dev; static unsigned char ffd9[] = {0xff, 0xd9}; /* a frame starts with: @@ -417,7 +437,8 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev, ffd9, 2); /* put the JPEG 411 header */ - jpeg_put_header(gspca_dev, frame, 0x22); + gspca_frame_add(gspca_dev, FIRST_PACKET, frame, + sd->jpeg_hdr, JPEG_HDR_SZ); /* beginning of the frame */ #define STKHDRSZ 12 @@ -517,6 +538,34 @@ static int sd_querymenu(struct gspca_dev *gspca_dev, return -EINVAL; } +static int sd_set_jcomp(struct gspca_dev *gspca_dev, + struct v4l2_jpegcompression *jcomp) +{ + struct sd *sd = (struct sd *) gspca_dev; + + if (jcomp->quality < QUALITY_MIN) + sd->quality = QUALITY_MIN; + else if (jcomp->quality > QUALITY_MAX) + sd->quality = QUALITY_MAX; + else + sd->quality = jcomp->quality; + if (gspca_dev->streaming) + jpeg_set_qual(sd->jpeg_hdr, sd->quality); + return 0; +} + +static int sd_get_jcomp(struct gspca_dev *gspca_dev, + struct v4l2_jpegcompression *jcomp) +{ + struct sd *sd = (struct sd *) gspca_dev; + + memset(jcomp, 0, sizeof *jcomp); + jcomp->quality = sd->quality; + jcomp->jpeg_markers = V4L2_JPEG_MARKER_DHT + | V4L2_JPEG_MARKER_DQT; + return 0; +} + /* sub-driver description */ static const struct sd_desc sd_desc = { .name = MODULE_NAME, @@ -526,8 +575,11 @@ static const struct sd_desc sd_desc = { .init = sd_init, .start = sd_start, .stopN = sd_stopN, + .stop0 = sd_stop0, .pkt_scan = sd_pkt_scan, .querymenu = sd_querymenu, + .get_jcomp = sd_get_jcomp, + .set_jcomp = sd_set_jcomp, }; /* -- module initialisation -- */ diff --git a/linux/drivers/media/video/gspca/sunplus.c b/linux/drivers/media/video/gspca/sunplus.c index fba6f98d1..428b1e2b7 100644 --- a/linux/drivers/media/video/gspca/sunplus.c +++ b/linux/drivers/media/video/gspca/sunplus.c @@ -22,7 +22,6 @@ #define MODULE_NAME "sunplus" #include "gspca.h" -#define QUANT_VAL 5 /* quantization table */ #include "jpeg.h" MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>"); @@ -40,6 +39,10 @@ struct sd { unsigned char contrast; unsigned char colors; unsigned char autogain; + u8 quality; +#define QUALITY_MIN 70 +#define QUALITY_MAX 95 +#define QUALITY_DEF 85 char bridge; #define BRIDGE_SPCA504 0 @@ -52,6 +55,8 @@ struct sd { #define LogitechClickSmart420 2 #define LogitechClickSmart820 3 #define MegapixV4 4 + + u8 *jpeg_hdr; }; /* V4L2 controls supported by the driver */ @@ -883,6 +888,7 @@ static int sd_config(struct gspca_dev *gspca_dev, sd->brightness = sd_ctrls[SD_BRIGHTNESS].qctrl.default_value; sd->contrast = sd_ctrls[SD_CONTRAST].qctrl.default_value; sd->colors = sd_ctrls[SD_COLOR].qctrl.default_value; + sd->quality = QUALITY_DEF; return 0; } @@ -999,6 +1005,12 @@ static int sd_start(struct gspca_dev *gspca_dev) __u8 i; __u8 info[6]; + /* create the JPEG header */ + sd->jpeg_hdr = kmalloc(JPEG_HDR_SZ, GFP_KERNEL); + jpeg_define(sd->jpeg_hdr, gspca_dev->height, gspca_dev->width, + 0x22); /* JPEG 411 */ + jpeg_set_qual(sd->jpeg_hdr, sd->quality); + if (sd->bridge == BRIDGE_SPCA504B) spca504B_setQtable(gspca_dev); spca504B_SetSizeType(gspca_dev); @@ -1108,6 +1120,13 @@ static void sd_stopN(struct gspca_dev *gspca_dev) } } +static void sd_stop0(struct gspca_dev *gspca_dev) +{ + struct sd *sd = (struct sd *) gspca_dev; + + kfree(sd->jpeg_hdr); +} + static void sd_pkt_scan(struct gspca_dev *gspca_dev, struct gspca_frame *frame, /* target */ __u8 *data, /* isoc packet */ @@ -1184,7 +1203,8 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev, ffd9, 2); /* put the JPEG header in the new frame */ - jpeg_put_header(gspca_dev, frame, 0x22); + gspca_frame_add(gspca_dev, FIRST_PACKET, frame, + sd->jpeg_hdr, JPEG_HDR_SZ); } /* add 0x00 after 0xff */ @@ -1333,6 +1353,34 @@ static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val) return 0; } +static int sd_set_jcomp(struct gspca_dev *gspca_dev, + struct v4l2_jpegcompression *jcomp) +{ + struct sd *sd = (struct sd *) gspca_dev; + + if (jcomp->quality < QUALITY_MIN) + sd->quality = QUALITY_MIN; + else if (jcomp->quality > QUALITY_MAX) + sd->quality = QUALITY_MAX; + else + sd->quality = jcomp->quality; + if (gspca_dev->streaming) + jpeg_set_qual(sd->jpeg_hdr, sd->quality); + return 0; +} + +static int sd_get_jcomp(struct gspca_dev *gspca_dev, + struct v4l2_jpegcompression *jcomp) +{ + struct sd *sd = (struct sd *) gspca_dev; + + memset(jcomp, 0, sizeof *jcomp); + jcomp->quality = sd->quality; + jcomp->jpeg_markers = V4L2_JPEG_MARKER_DHT + | V4L2_JPEG_MARKER_DQT; + return 0; +} + /* sub-driver description */ static const struct sd_desc sd_desc = { .name = MODULE_NAME, @@ -1342,7 +1390,10 @@ static const struct sd_desc sd_desc = { .init = sd_init, .start = sd_start, .stopN = sd_stopN, + .stop0 = sd_stop0, .pkt_scan = sd_pkt_scan, + .get_jcomp = sd_get_jcomp, + .set_jcomp = sd_set_jcomp, }; /* -- module initialisation -- */ diff --git a/linux/drivers/media/video/gspca/t613.c b/linux/drivers/media/video/gspca/t613.c index f60a4c21a..f6ff3e1ea 100644 --- a/linux/drivers/media/video/gspca/t613.c +++ b/linux/drivers/media/video/gspca/t613.c @@ -495,7 +495,7 @@ static void om6802_sensor_init(struct gspca_dev *gspca_dev) }; reg_w_buf(gspca_dev, sensor_reset, sizeof sensor_reset); - msleep(5); + msleep(100); i = 4; while (--i > 0) { byte = reg_r(gspca_dev, 0x0060); @@ -639,7 +639,7 @@ static int sd_init(struct gspca_dev *gspca_dev) u16 reg80, reg8e; static const u8 read_indexs[] = - { 0x06, 0x07, 0x0a, 0x0b, 0x66, 0x80, 0x81, 0x8e, 0x8f, 0xa5, + { 0x0a, 0x0b, 0x66, 0x80, 0x81, 0x8e, 0x8f, 0xa5, 0xa6, 0xa8, 0xbb, 0xbc, 0xc6, 0x00 }; static const u8 n1[] = {0x08, 0x03, 0x09, 0x03, 0x12, 0x04}; @@ -679,7 +679,7 @@ static int sd_init(struct gspca_dev *gspca_dev) sensor_id = (reg_r(gspca_dev, 0x06) << 8) | reg_r(gspca_dev, 0x07); - switch (sensor_id) { + switch (sensor_id & 0xff0f) { case 0x0801: PDEBUG(D_PROBE, "sensor tas5130a"); sd->sensor = SENSOR_TAS5130A; diff --git a/linux/drivers/media/video/gspca/vc032x.c b/linux/drivers/media/video/gspca/vc032x.c index f1c149476..772d18e70 100644 --- a/linux/drivers/media/video/gspca/vc032x.c +++ b/linux/drivers/media/video/gspca/vc032x.c @@ -37,18 +37,21 @@ struct sd { __u8 lightfreq; __u8 sharpness; + u8 image_offset; + char bridge; #define BRIDGE_VC0321 0 #define BRIDGE_VC0323 1 char sensor; #define SENSOR_HV7131R 0 #define SENSOR_MI0360 1 -#define SENSOR_MI1320 2 -#define SENSOR_MI1310_SOC 3 -#define SENSOR_OV7660 4 -#define SENSOR_OV7670 5 -#define SENSOR_PO1200 6 -#define SENSOR_PO3130NC 7 +#define SENSOR_MI1310_SOC 2 +#define SENSOR_MI1320 3 +#define SENSOR_MI1320_SOC 4 +#define SENSOR_OV7660 5 +#define SENSOR_OV7670 6 +#define SENSOR_PO1200 7 +#define SENSOR_PO3130NC 8 }; /* V4L2 controls supported by the driver */ @@ -149,13 +152,50 @@ static const struct v4l2_pix_format vc0323_mode[] = { .sizeimage = 640 * 480 * 3 / 8 + 590, .colorspace = V4L2_COLORSPACE_JPEG, .priv = 0}, - {1280, 1024, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE, /* mi1310_soc only */ + {1280, 1024, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE, /* mi13x0_soc only */ .bytesperline = 1280, .sizeimage = 1280 * 1024 * 1 / 4 + 590, .colorspace = V4L2_COLORSPACE_JPEG, .priv = 2}, }; - +static const struct v4l2_pix_format bi_mode[] = { +/*fixme: jeg does not work + {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE, + .bytesperline = 320, + .sizeimage = 320 * 240 * 3 / 8 + 590, + .colorspace = V4L2_COLORSPACE_JPEG, + .priv = 5}, +*/ + {320, 240, V4L2_PIX_FMT_YVYU, V4L2_FIELD_NONE, + .bytesperline = 320, + .sizeimage = 320 * 240 * 2, + .colorspace = V4L2_COLORSPACE_SRGB, + .priv = 4}, +/* + {640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE, + .bytesperline = 640, + .sizeimage = 640 * 480 * 3 / 8 + 590, + .colorspace = V4L2_COLORSPACE_JPEG, + .priv = 3}, +*/ + {640, 480, V4L2_PIX_FMT_YVYU, V4L2_FIELD_NONE, + .bytesperline = 640, + .sizeimage = 640 * 480 * 2, + .colorspace = V4L2_COLORSPACE_SRGB, + .priv = 2}, +/* + {1280, 1024, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE, + .bytesperline = 1280, + .sizeimage = 1280 * 1024 * 1 / 4 + 590, + .colorspace = V4L2_COLORSPACE_JPEG, + .priv = 1}, +*/ + {1280, 1024, V4L2_PIX_FMT_YVYU, V4L2_FIELD_NONE, + .bytesperline = 1280, + .sizeimage = 1280 * 1024 * 2, + .colorspace = V4L2_COLORSPACE_SRGB, + .priv = 0}, +}; static const struct v4l2_pix_format svga_mode[] = { {800, 600, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE, .bytesperline = 800, @@ -891,6 +931,722 @@ static const __u8 mi1320_initQVGA_data[][4] = { {} }; +static const u8 mi1320_soc_InitVGA[][4] = { + {0xb3, 0x01, 0x01, 0xcc}, + {0xb0, 0x03, 0x19, 0xcc}, + {0xb0, 0x04, 0x02, 0xcc}, + {0x00, 0x00, 0x30, 0xdd}, + {0xb3, 0x00, 0x64, 0xcc}, + {0xb3, 0x00, 0x67, 0xcc}, + {0xb3, 0x05, 0x01, 0xcc}, + {0xb3, 0x06, 0x01, 0xcc}, + {0xb3, 0x08, 0x01, 0xcc}, + {0xb3, 0x09, 0x0c, 0xcc}, + {0xb3, 0x34, 0x02, 0xcc}, + {0xb3, 0x35, 0xc8, 0xcc}, + {0xb3, 0x02, 0x00, 0xcc}, + {0xb3, 0x03, 0x0a, 0xcc}, + {0xb3, 0x04, 0x05, 0xcc}, + {0xb3, 0x20, 0x00, 0xcc}, + {0xb3, 0x21, 0x00, 0xcc}, + {0xb3, 0x22, 0x01, 0xcc}, + {0xb3, 0x23, 0xe0, 0xcc}, + {0xb3, 0x14, 0x00, 0xcc}, + {0xb3, 0x15, 0x00, 0xcc}, + {0xb3, 0x16, 0x02, 0xcc}, + {0xb3, 0x17, 0x7f, 0xcc}, + {0xb3, 0x00, 0x67, 0xcc}, + {0xb8, 0x00, 0x00, 0xcc}, + {0xbc, 0x00, 0x71, 0xcc}, + {0xbc, 0x01, 0x01, 0xcc}, + {0xb3, 0x5c, 0x01, 0xcc}, + {0xf0, 0x00, 0x02, 0xbb}, + {0x00, 0x00, 0x10, 0xdd}, + {0xc8, 0x00, 0x00, 0xbb}, + {0x00, 0x00, 0x30, 0xdd}, + {0xf0, 0x00, 0x00, 0xbb}, + {0x00, 0x00, 0x10, 0xdd}, + {0x07, 0x00, 0xe0, 0xbb}, + {0x08, 0x00, 0x0b, 0xbb}, + {0x21, 0x00, 0x0c, 0xbb}, + {0x20, 0x01, 0x03, 0xbb}, + {0xbf, 0xc0, 0x26, 0xcc}, + {0xbf, 0xc1, 0x02, 0xcc}, + {0xbf, 0xcc, 0x04, 0xcc}, + {0xb3, 0x01, 0x41, 0xcc}, + {0xf0, 0x00, 0x00, 0xbb}, + {0x05, 0x01, 0x78, 0xbb}, + {0x06, 0x00, 0x11, 0xbb}, + {0x07, 0x01, 0x42, 0xbb}, + {0x08, 0x00, 0x11, 0xbb}, + {0x20, 0x01, 0x03, 0xbb}, + {0x21, 0x80, 0x00, 0xbb}, + {0x22, 0x0d, 0x0f, 0xbb}, + {0x24, 0x80, 0x00, 0xbb}, + {0x59, 0x00, 0xff, 0xbb}, + {0xf0, 0x00, 0x02, 0xbb}, + {0x39, 0x03, 0xca, 0xbb}, + {0x3a, 0x06, 0x80, 0xbb}, + {0x3b, 0x01, 0x52, 0xbb}, + {0x3c, 0x05, 0x40, 0xbb}, + {0x57, 0x01, 0x9c, 0xbb}, + {0x58, 0x01, 0xee, 0xbb}, + {0x59, 0x00, 0xf0, 0xbb}, + {0x5a, 0x01, 0x20, 0xbb}, + {0x5c, 0x1d, 0x17, 0xbb}, + {0x5d, 0x22, 0x1c, 0xbb}, + {0x64, 0x1e, 0x1c, 0xbb}, + {0x5b, 0x00, 0x00, 0xbb}, + {0xf0, 0x00, 0x02, 0xbb}, + {0x22, 0xa0, 0x78, 0xbb}, + {0x23, 0xa0, 0x78, 0xbb}, + {0x24, 0x7f, 0x00, 0xbb}, + {0x28, 0xea, 0x02, 0xbb}, + {0x29, 0x86, 0x7a, 0xbb}, + {0x5e, 0x52, 0x4c, 0xbb}, + {0x5f, 0x20, 0x24, 0xbb}, + {0x60, 0x00, 0x02, 0xbb}, + {0x02, 0x00, 0xee, 0xbb}, + {0x03, 0x39, 0x23, 0xbb}, + {0x04, 0x07, 0x24, 0xbb}, + {0x09, 0x00, 0xc0, 0xbb}, + {0x0a, 0x00, 0x79, 0xbb}, + {0x0b, 0x00, 0x04, 0xbb}, + {0x0c, 0x00, 0x5c, 0xbb}, + {0x0d, 0x00, 0xd9, 0xbb}, + {0x0e, 0x00, 0x53, 0xbb}, + {0x0f, 0x00, 0x21, 0xbb}, + {0x10, 0x00, 0xa4, 0xbb}, + {0x11, 0x00, 0xe5, 0xbb}, + {0x15, 0x00, 0x00, 0xbb}, + {0x16, 0x00, 0x00, 0xbb}, + {0x17, 0x00, 0x00, 0xbb}, + {0x18, 0x00, 0x00, 0xbb}, + {0x19, 0x00, 0x00, 0xbb}, + {0x1a, 0x00, 0x00, 0xbb}, + {0x1b, 0x00, 0x00, 0xbb}, + {0x1c, 0x00, 0x00, 0xbb}, + {0x1d, 0x00, 0x00, 0xbb}, + {0x1e, 0x00, 0x00, 0xbb}, + {0xf0, 0x00, 0x01, 0xbb}, + {0x06, 0xe0, 0x0e, 0xbb}, + {0x06, 0x60, 0x0e, 0xbb}, + {0xb3, 0x5c, 0x01, 0xcc}, + {} +}; +static const u8 mi1320_soc_InitVGA_JPG[][4] = { + {0xb3, 0x01, 0x01, 0xcc}, + {0xb0, 0x03, 0x19, 0xcc}, + {0xb0, 0x04, 0x02, 0xcc}, + {0x00, 0x00, 0x30, 0xdd}, + {0xb3, 0x00, 0x64, 0xcc}, + {0xb3, 0x00, 0x67, 0xcc}, + {0xb3, 0x05, 0x01, 0xcc}, + {0xb3, 0x06, 0x01, 0xcc}, + {0xb3, 0x08, 0x01, 0xcc}, + {0xb3, 0x09, 0x0c, 0xcc}, + {0xb3, 0x34, 0x02, 0xcc}, + {0xb3, 0x35, 0xc8, 0xcc}, + {0xb3, 0x02, 0x00, 0xcc}, + {0xb3, 0x03, 0x0a, 0xcc}, + {0xb3, 0x04, 0x05, 0xcc}, + {0xb3, 0x20, 0x00, 0xcc}, + {0xb3, 0x21, 0x00, 0xcc}, + {0xb3, 0x22, 0x01, 0xcc}, + {0xb3, 0x23, 0xe0, 0xcc}, + {0xb3, 0x14, 0x00, 0xcc}, + {0xb3, 0x15, 0x00, 0xcc}, + {0xb3, 0x16, 0x02, 0xcc}, + {0xb3, 0x17, 0x7f, 0xcc}, + {0xb3, 0x00, 0x67, 0xcc}, + {0xb8, 0x00, 0x00, 0xcc}, + {0xbc, 0x00, 0x71, 0xcc}, + {0xbc, 0x01, 0x01, 0xcc}, + {0xb3, 0x5c, 0x01, 0xcc}, + {0xf0, 0x00, 0x02, 0xbb}, + {0x00, 0x00, 0x10, 0xdd}, + {0xc8, 0x00, 0x00, 0xbb}, + {0x00, 0x00, 0x30, 0xdd}, + {0xf0, 0x00, 0x00, 0xbb}, + {0x00, 0x00, 0x10, 0xdd}, + {0x07, 0x00, 0xe0, 0xbb}, + {0x08, 0x00, 0x0b, 0xbb}, + {0x21, 0x00, 0x0c, 0xbb}, + {0x20, 0x01, 0x03, 0xbb}, + {0xb6, 0x00, 0x00, 0xcc}, + {0xb6, 0x03, 0x02, 0xcc}, + {0xb6, 0x02, 0x80, 0xcc}, + {0xb6, 0x05, 0x01, 0xcc}, + {0xb6, 0x04, 0xe0, 0xcc}, + {0xb6, 0x12, 0xf8, 0xcc}, + {0xb6, 0x13, 0x05, 0xcc}, + {0xb6, 0x18, 0x02, 0xcc}, + {0xb6, 0x17, 0x58, 0xcc}, + {0xb6, 0x16, 0x00, 0xcc}, + {0xb6, 0x22, 0x12, 0xcc}, + {0xb6, 0x23, 0x0b, 0xcc}, + {0xbf, 0xc0, 0x39, 0xcc}, + {0xbf, 0xc1, 0x04, 0xcc}, + {0xbf, 0xcc, 0x00, 0xcc}, + {0xb3, 0x01, 0x41, 0xcc}, + {0xf0, 0x00, 0x00, 0xbb}, + {0x05, 0x01, 0x78, 0xbb}, + {0x06, 0x00, 0x11, 0xbb}, + {0x07, 0x01, 0x42, 0xbb}, + {0x08, 0x00, 0x11, 0xbb}, + {0x20, 0x01, 0x03, 0xbb}, + {0x21, 0x80, 0x00, 0xbb}, + {0x22, 0x0d, 0x0f, 0xbb}, + {0x24, 0x80, 0x00, 0xbb}, + {0x59, 0x00, 0xff, 0xbb}, + {0xf0, 0x00, 0x02, 0xbb}, + {0x39, 0x03, 0xca, 0xbb}, + {0x3a, 0x06, 0x80, 0xbb}, + {0x3b, 0x01, 0x52, 0xbb}, + {0x3c, 0x05, 0x40, 0xbb}, + {0x57, 0x01, 0x9c, 0xbb}, + {0x58, 0x01, 0xee, 0xbb}, + {0x59, 0x00, 0xf0, 0xbb}, + {0x5a, 0x01, 0x20, 0xbb}, + {0x5c, 0x1d, 0x17, 0xbb}, + {0x5d, 0x22, 0x1c, 0xbb}, + {0x64, 0x1e, 0x1c, 0xbb}, + {0x5b, 0x00, 0x00, 0xbb}, + {0xf0, 0x00, 0x02, 0xbb}, + {0x22, 0xa0, 0x78, 0xbb}, + {0x23, 0xa0, 0x78, 0xbb}, + {0x24, 0x7f, 0x00, 0xbb}, + {0x28, 0xea, 0x02, 0xbb}, + {0x29, 0x86, 0x7a, 0xbb}, + {0x5e, 0x52, 0x4c, 0xbb}, + {0x5f, 0x20, 0x24, 0xbb}, + {0x60, 0x00, 0x02, 0xbb}, + {0x02, 0x00, 0xee, 0xbb}, + {0x03, 0x39, 0x23, 0xbb}, + {0x04, 0x07, 0x24, 0xbb}, + {0x09, 0x00, 0xc0, 0xbb}, + {0x0a, 0x00, 0x79, 0xbb}, + {0x0b, 0x00, 0x04, 0xbb}, + {0x0c, 0x00, 0x5c, 0xbb}, + {0x0d, 0x00, 0xd9, 0xbb}, + {0x0e, 0x00, 0x53, 0xbb}, + {0x0f, 0x00, 0x21, 0xbb}, + {0x10, 0x00, 0xa4, 0xbb}, + {0x11, 0x00, 0xe5, 0xbb}, + {0x15, 0x00, 0x00, 0xbb}, + {0x16, 0x00, 0x00, 0xbb}, + {0x17, 0x00, 0x00, 0xbb}, + {0x18, 0x00, 0x00, 0xbb}, + {0x19, 0x00, 0x00, 0xbb}, + {0x1a, 0x00, 0x00, 0xbb}, + {0x1b, 0x00, 0x00, 0xbb}, + {0x1c, 0x00, 0x00, 0xbb}, + {0x1d, 0x00, 0x00, 0xbb}, + {0x1e, 0x00, 0x00, 0xbb}, + {0xf0, 0x00, 0x01, 0xbb}, + {0x06, 0xe0, 0x0e, 0xbb}, + {0x06, 0x60, 0x0e, 0xbb}, + {0xb3, 0x5c, 0x01, 0xcc}, + {} +}; +static const u8 mi1320_soc_InitQVGA[][4] = { + {0xb3, 0x01, 0x01, 0xcc}, + {0xb0, 0x03, 0x19, 0xcc}, + {0xb0, 0x04, 0x02, 0xcc}, + {0x00, 0x00, 0x30, 0xdd}, + {0xb3, 0x00, 0x64, 0xcc}, + {0xb3, 0x00, 0x67, 0xcc}, + {0xb3, 0x05, 0x01, 0xcc}, + {0xb3, 0x06, 0x01, 0xcc}, + {0xb3, 0x08, 0x01, 0xcc}, + {0xb3, 0x09, 0x0c, 0xcc}, + {0xb3, 0x34, 0x02, 0xcc}, + {0xb3, 0x35, 0xc8, 0xcc}, + {0xb3, 0x02, 0x00, 0xcc}, + {0xb3, 0x03, 0x0a, 0xcc}, + {0xb3, 0x04, 0x05, 0xcc}, + {0xb3, 0x20, 0x00, 0xcc}, + {0xb3, 0x21, 0x00, 0xcc}, + {0xb3, 0x22, 0x01, 0xcc}, + {0xb3, 0x23, 0xe0, 0xcc}, + {0xb3, 0x14, 0x00, 0xcc}, + {0xb3, 0x15, 0x00, 0xcc}, + {0xb3, 0x16, 0x02, 0xcc}, + {0xb3, 0x17, 0x7f, 0xcc}, + {0xb3, 0x00, 0x67, 0xcc}, + {0xb8, 0x00, 0x00, 0xcc}, + {0xbc, 0x00, 0xd1, 0xcc}, + {0xbc, 0x01, 0x01, 0xcc}, + {0xb3, 0x5c, 0x01, 0xcc}, + {0xf0, 0x00, 0x02, 0xbb}, + {0x00, 0x00, 0x10, 0xdd}, + {0xc8, 0x00, 0x00, 0xbb}, + {0x00, 0x00, 0x30, 0xdd}, + {0xf0, 0x00, 0x00, 0xbb}, + {0x00, 0x00, 0x10, 0xdd}, + {0x07, 0x00, 0xe0, 0xbb}, + {0x08, 0x00, 0x0b, 0xbb}, + {0x21, 0x00, 0x0c, 0xbb}, + {0x20, 0x01, 0x03, 0xbb}, + {0xbf, 0xc0, 0x26, 0xcc}, + {0xbf, 0xc1, 0x02, 0xcc}, + {0xbf, 0xcc, 0x04, 0xcc}, + {0xbc, 0x02, 0x18, 0xcc}, + {0xbc, 0x03, 0x50, 0xcc}, + {0xbc, 0x04, 0x18, 0xcc}, + {0xbc, 0x05, 0x00, 0xcc}, + {0xbc, 0x06, 0x00, 0xcc}, + {0xbc, 0x08, 0x30, 0xcc}, + {0xbc, 0x09, 0x40, 0xcc}, + {0xbc, 0x0a, 0x10, 0xcc}, + {0xbc, 0x0b, 0x00, 0xcc}, + {0xbc, 0x0c, 0x00, 0xcc}, + {0xb3, 0x01, 0x41, 0xcc}, + {0xf0, 0x00, 0x00, 0xbb}, + {0x05, 0x01, 0x78, 0xbb}, + {0x06, 0x00, 0x11, 0xbb}, + {0x07, 0x01, 0x42, 0xbb}, + {0x08, 0x00, 0x11, 0xbb}, + {0x20, 0x01, 0x03, 0xbb}, + {0x21, 0x80, 0x00, 0xbb}, + {0x22, 0x0d, 0x0f, 0xbb}, + {0x24, 0x80, 0x00, 0xbb}, + {0x59, 0x00, 0xff, 0xbb}, + {0xf0, 0x00, 0x02, 0xbb}, + {0x39, 0x03, 0xca, 0xbb}, + {0x3a, 0x06, 0x80, 0xbb}, + {0x3b, 0x01, 0x52, 0xbb}, + {0x3c, 0x05, 0x40, 0xbb}, + {0x57, 0x01, 0x9c, 0xbb}, + {0x58, 0x01, 0xee, 0xbb}, + {0x59, 0x00, 0xf0, 0xbb}, + {0x5a, 0x01, 0x20, 0xbb}, + {0x5c, 0x1d, 0x17, 0xbb}, + {0x5d, 0x22, 0x1c, 0xbb}, + {0x64, 0x1e, 0x1c, 0xbb}, + {0x5b, 0x00, 0x00, 0xbb}, + {0xf0, 0x00, 0x02, 0xbb}, + {0x22, 0xa0, 0x78, 0xbb}, + {0x23, 0xa0, 0x78, 0xbb}, + {0x24, 0x7f, 0x00, 0xbb}, + {0x28, 0xea, 0x02, 0xbb}, + {0x29, 0x86, 0x7a, 0xbb}, + {0x5e, 0x52, 0x4c, 0xbb}, + {0x5f, 0x20, 0x24, 0xbb}, + {0x60, 0x00, 0x02, 0xbb}, + {0x02, 0x00, 0xee, 0xbb}, + {0x03, 0x39, 0x23, 0xbb}, + {0x04, 0x07, 0x24, 0xbb}, + {0x09, 0x00, 0xc0, 0xbb}, + {0x0a, 0x00, 0x79, 0xbb}, + {0x0b, 0x00, 0x04, 0xbb}, + {0x0c, 0x00, 0x5c, 0xbb}, + {0x0d, 0x00, 0xd9, 0xbb}, + {0x0e, 0x00, 0x53, 0xbb}, + {0x0f, 0x00, 0x21, 0xbb}, + {0x10, 0x00, 0xa4, 0xbb}, + {0x11, 0x00, 0xe5, 0xbb}, + {0x15, 0x00, 0x00, 0xbb}, + {0x16, 0x00, 0x00, 0xbb}, + {0x17, 0x00, 0x00, 0xbb}, + {0x18, 0x00, 0x00, 0xbb}, + {0x19, 0x00, 0x00, 0xbb}, + {0x1a, 0x00, 0x00, 0xbb}, + {0x1b, 0x00, 0x00, 0xbb}, + {0x1c, 0x00, 0x00, 0xbb}, + {0x1d, 0x00, 0x00, 0xbb}, + {0x1e, 0x00, 0x00, 0xbb}, + {0xf0, 0x00, 0x01, 0xbb}, + {0x06, 0xe0, 0x0e, 0xbb}, + {0x06, 0x60, 0x0e, 0xbb}, + {0xb3, 0x5c, 0x01, 0xcc}, + {} +}; +static const u8 mi1320_soc_InitQVGA_JPG[][4] = { + {0xb3, 0x01, 0x01, 0xcc}, + {0xb0, 0x03, 0x19, 0xcc}, + {0xb0, 0x04, 0x02, 0xcc}, + {0x00, 0x00, 0x30, 0xdd}, + {0xb3, 0x00, 0x64, 0xcc}, + {0xb3, 0x00, 0x67, 0xcc}, + {0xb3, 0x05, 0x01, 0xcc}, + {0xb3, 0x06, 0x01, 0xcc}, + {0xb3, 0x08, 0x01, 0xcc}, + {0xb3, 0x09, 0x0c, 0xcc}, + {0xb3, 0x34, 0x02, 0xcc}, + {0xb3, 0x35, 0xc8, 0xcc}, + {0xb3, 0x02, 0x00, 0xcc}, + {0xb3, 0x03, 0x0a, 0xcc}, + {0xb3, 0x04, 0x05, 0xcc}, + {0xb3, 0x20, 0x00, 0xcc}, + {0xb3, 0x21, 0x00, 0xcc}, + {0xb3, 0x22, 0x01, 0xcc}, + {0xb3, 0x23, 0xe0, 0xcc}, + {0xb3, 0x14, 0x00, 0xcc}, + {0xb3, 0x15, 0x00, 0xcc}, + {0xb3, 0x16, 0x02, 0xcc}, + {0xb3, 0x17, 0x7f, 0xcc}, + {0xb3, 0x00, 0x67, 0xcc}, + {0xb8, 0x00, 0x00, 0xcc}, + {0xbc, 0x00, 0xd1, 0xcc}, + {0xbc, 0x01, 0x01, 0xcc}, + {0xb3, 0x5c, 0x01, 0xcc}, + {0xf0, 0x00, 0x02, 0xbb}, + {0x00, 0x00, 0x10, 0xdd}, + {0xc8, 0x00, 0x00, 0xbb}, + {0x00, 0x00, 0x30, 0xdd}, + {0xf0, 0x00, 0x00, 0xbb}, + {0x00, 0x00, 0x10, 0xdd}, + {0x07, 0x00, 0xe0, 0xbb}, + {0x08, 0x00, 0x0b, 0xbb}, + {0x21, 0x00, 0x0c, 0xbb}, + {0x20, 0x01, 0x03, 0xbb}, + {0xb6, 0x00, 0x00, 0xcc}, + {0xb6, 0x03, 0x01, 0xcc}, + {0xb6, 0x02, 0x40, 0xcc}, + {0xb6, 0x05, 0x00, 0xcc}, + {0xb6, 0x04, 0xf0, 0xcc}, + {0xb6, 0x12, 0xf8, 0xcc}, + {0xb6, 0x13, 0x05, 0xcc}, + {0xb6, 0x18, 0x00, 0xcc}, + {0xb6, 0x17, 0x96, 0xcc}, + {0xb6, 0x16, 0x00, 0xcc}, + {0xb6, 0x22, 0x12, 0xcc}, + {0xb6, 0x23, 0x0b, 0xcc}, + {0xbf, 0xc0, 0x39, 0xcc}, + {0xbf, 0xc1, 0x04, 0xcc}, + {0xbf, 0xcc, 0x00, 0xcc}, + {0xbc, 0x02, 0x18, 0xcc}, + {0xbc, 0x03, 0x50, 0xcc}, + {0xbc, 0x04, 0x18, 0xcc}, + {0xbc, 0x05, 0x00, 0xcc}, + {0xbc, 0x06, 0x00, 0xcc}, + {0xbc, 0x08, 0x30, 0xcc}, + {0xbc, 0x09, 0x40, 0xcc}, + {0xbc, 0x0a, 0x10, 0xcc}, + {0xbc, 0x0b, 0x00, 0xcc}, + {0xbc, 0x0c, 0x00, 0xcc}, + {0xb3, 0x01, 0x41, 0xcc}, + {0xf0, 0x00, 0x00, 0xbb}, + {0x05, 0x01, 0x78, 0xbb}, + {0x06, 0x00, 0x11, 0xbb}, + {0x07, 0x01, 0x42, 0xbb}, + {0x08, 0x00, 0x11, 0xbb}, + {0x20, 0x01, 0x03, 0xbb}, + {0x21, 0x80, 0x00, 0xbb}, + {0x22, 0x0d, 0x0f, 0xbb}, + {0x24, 0x80, 0x00, 0xbb}, + {0x59, 0x00, 0xff, 0xbb}, + {0xf0, 0x00, 0x02, 0xbb}, + {0x39, 0x03, 0xca, 0xbb}, + {0x3a, 0x06, 0x80, 0xbb}, + {0x3b, 0x01, 0x52, 0xbb}, + {0x3c, 0x05, 0x40, 0xbb}, + {0x57, 0x01, 0x9c, 0xbb}, + {0x58, 0x01, 0xee, 0xbb}, + {0x59, 0x00, 0xf0, 0xbb}, + {0x5a, 0x01, 0x20, 0xbb}, + {0x5c, 0x1d, 0x17, 0xbb}, + {0x5d, 0x22, 0x1c, 0xbb}, + {0x64, 0x1e, 0x1c, 0xbb}, + {0x5b, 0x00, 0x00, 0xbb}, + {0xf0, 0x00, 0x02, 0xbb}, + {0x22, 0xa0, 0x78, 0xbb}, + {0x23, 0xa0, 0x78, 0xbb}, + {0x24, 0x7f, 0x00, 0xbb}, + {0x28, 0xea, 0x02, 0xbb}, + {0x29, 0x86, 0x7a, 0xbb}, + {0x5e, 0x52, 0x4c, 0xbb}, + {0x5f, 0x20, 0x24, 0xbb}, + {0x60, 0x00, 0x02, 0xbb}, + {0x02, 0x00, 0xee, 0xbb}, + {0x03, 0x39, 0x23, 0xbb}, + {0x04, 0x07, 0x24, 0xbb}, + {0x09, 0x00, 0xc0, 0xbb}, + {0x0a, 0x00, 0x79, 0xbb}, + {0x0b, 0x00, 0x04, 0xbb}, + {0x0c, 0x00, 0x5c, 0xbb}, + {0x0d, 0x00, 0xd9, 0xbb}, + {0x0e, 0x00, 0x53, 0xbb}, + {0x0f, 0x00, 0x21, 0xbb}, + {0x10, 0x00, 0xa4, 0xbb}, + {0x11, 0x00, 0xe5, 0xbb}, + {0x15, 0x00, 0x00, 0xbb}, + {0x16, 0x00, 0x00, 0xbb}, + {0x17, 0x00, 0x00, 0xbb}, + {0x18, 0x00, 0x00, 0xbb}, + {0x19, 0x00, 0x00, 0xbb}, + {0x1a, 0x00, 0x00, 0xbb}, + {0x1b, 0x00, 0x00, 0xbb}, + {0x1c, 0x00, 0x00, 0xbb}, + {0x1d, 0x00, 0x00, 0xbb}, + {0x1e, 0x00, 0x00, 0xbb}, + {0xf0, 0x00, 0x01, 0xbb}, + {0x06, 0xe0, 0x0e, 0xbb}, + {0x06, 0x60, 0x0e, 0xbb}, + {0xb3, 0x5c, 0x01, 0xcc}, + {} +}; +static const u8 mi1320_soc_InitSXGA_JPG[][4] = { + {0xb3, 0x01, 0x01, 0xcc}, + {0xb0, 0x03, 0x19, 0xcc}, + {0xb0, 0x04, 0x02, 0xcc}, + {0x00, 0x00, 0x33, 0xdd}, + {0xb3, 0x00, 0x64, 0xcc}, + {0xb3, 0x00, 0x67, 0xcc}, + {0xb3, 0x05, 0x00, 0xcc}, + {0xb3, 0x06, 0x00, 0xcc}, + {0xb3, 0x08, 0x01, 0xcc}, + {0xb3, 0x09, 0x0c, 0xcc}, + {0xb3, 0x34, 0x02, 0xcc}, + {0xb3, 0x35, 0xc8, 0xcc}, + {0xb3, 0x02, 0x00, 0xcc}, + {0xb3, 0x03, 0x0a, 0xcc}, + {0xb3, 0x04, 0x05, 0xcc}, + {0xb3, 0x20, 0x00, 0xcc}, + {0xb3, 0x21, 0x00, 0xcc}, + {0xb3, 0x22, 0x04, 0xcc}, + {0xb3, 0x23, 0x00, 0xcc}, + {0xb3, 0x14, 0x00, 0xcc}, + {0xb3, 0x15, 0x00, 0xcc}, + {0xb3, 0x16, 0x04, 0xcc}, + {0xb3, 0x17, 0xff, 0xcc}, + {0xb3, 0x00, 0x67, 0xcc}, + {0xbc, 0x00, 0x71, 0xcc}, + {0xbc, 0x01, 0x01, 0xcc}, + {0xf0, 0x00, 0x02, 0xbb}, + {0x00, 0x00, 0x30, 0xdd}, + {0xc8, 0x9f, 0x0b, 0xbb}, + {0x00, 0x00, 0x20, 0xdd}, + {0x5b, 0x00, 0x01, 0xbb}, + {0x00, 0x00, 0x20, 0xdd}, + {0xf0, 0x00, 0x00, 0xbb}, + {0x00, 0x00, 0x30, 0xdd}, + {0x20, 0x01, 0x03, 0xbb}, + {0x00, 0x00, 0x20, 0xdd}, + {0xb6, 0x00, 0x00, 0xcc}, + {0xb6, 0x03, 0x05, 0xcc}, + {0xb6, 0x02, 0x00, 0xcc}, + {0xb6, 0x05, 0x04, 0xcc}, + {0xb6, 0x04, 0x00, 0xcc}, + {0xb6, 0x12, 0xf8, 0xcc}, + {0xb6, 0x13, 0x29, 0xcc}, + {0xb6, 0x18, 0x0a, 0xcc}, + {0xb6, 0x17, 0x00, 0xcc}, + {0xb6, 0x16, 0x00, 0xcc}, + {0xb6, 0x22, 0x12, 0xcc}, + {0xb6, 0x23, 0x0b, 0xcc}, + {0xbf, 0xc0, 0x39, 0xcc}, + {0xbf, 0xc1, 0x04, 0xcc}, + {0xbf, 0xcc, 0x00, 0xcc}, + {0xb3, 0x5c, 0x01, 0xcc}, + {0xb3, 0x01, 0x41, 0xcc}, + {0xf0, 0x00, 0x00, 0xbb}, + {0x05, 0x01, 0x78, 0xbb}, + {0x06, 0x00, 0x11, 0xbb}, + {0x07, 0x01, 0x42, 0xbb}, + {0x08, 0x00, 0x11, 0xbb}, + {0x20, 0x01, 0x03, 0xbb}, + {0x21, 0x80, 0x00, 0xbb}, + {0x22, 0x0d, 0x0f, 0xbb}, + {0x24, 0x80, 0x00, 0xbb}, + {0x59, 0x00, 0xff, 0xbb}, + {0xf0, 0x00, 0x02, 0xbb}, + {0x39, 0x03, 0xca, 0xbb}, + {0x3a, 0x06, 0x80, 0xbb}, + {0x3b, 0x01, 0x52, 0xbb}, + {0x3c, 0x05, 0x40, 0xbb}, + {0x57, 0x01, 0x9c, 0xbb}, + {0x58, 0x01, 0xee, 0xbb}, + {0x59, 0x00, 0xf0, 0xbb}, + {0x5a, 0x01, 0x20, 0xbb}, + {0x5c, 0x1d, 0x17, 0xbb}, + {0x5d, 0x22, 0x1c, 0xbb}, + {0x64, 0x1e, 0x1c, 0xbb}, + {0x5b, 0x00, 0x00, 0xbb}, + {0xf0, 0x00, 0x02, 0xbb}, + {0x22, 0xa0, 0x78, 0xbb}, + {0x23, 0xa0, 0x78, 0xbb}, + {0x24, 0x7f, 0x00, 0xbb}, + {0x28, 0xea, 0x02, 0xbb}, + {0x29, 0x86, 0x7a, 0xbb}, + {0x5e, 0x52, 0x4c, 0xbb}, + {0x5f, 0x20, 0x24, 0xbb}, + {0x60, 0x00, 0x02, 0xbb}, + {0x02, 0x00, 0xee, 0xbb}, + {0x03, 0x39, 0x23, 0xbb}, + {0x04, 0x07, 0x24, 0xbb}, + {0x09, 0x00, 0xc0, 0xbb}, + {0x0a, 0x00, 0x79, 0xbb}, + {0x0b, 0x00, 0x04, 0xbb}, + {0x0c, 0x00, 0x5c, 0xbb}, + {0x0d, 0x00, 0xd9, 0xbb}, + {0x0e, 0x00, 0x53, 0xbb}, + {0x0f, 0x00, 0x21, 0xbb}, + {0x10, 0x00, 0xa4, 0xbb}, + {0x11, 0x00, 0xe5, 0xbb}, + {0x15, 0x00, 0x00, 0xbb}, + {0x16, 0x00, 0x00, 0xbb}, + {0x17, 0x00, 0x00, 0xbb}, + {0x18, 0x00, 0x00, 0xbb}, + {0x19, 0x00, 0x00, 0xbb}, + {0x1a, 0x00, 0x00, 0xbb}, + {0x1b, 0x00, 0x00, 0xbb}, + {0x1c, 0x00, 0x00, 0xbb}, + {0x1d, 0x00, 0x00, 0xbb}, + {0x1e, 0x00, 0x00, 0xbb}, + {0xf0, 0x00, 0x01, 0xbb}, + {0x06, 0xe0, 0x0e, 0xbb}, + {0x06, 0x60, 0x0e, 0xbb}, + {0xb3, 0x5c, 0x01, 0xcc}, + {0xf0, 0x00, 0x00, 0xbb}, + {0x05, 0x01, 0x13, 0xbb}, + {0x06, 0x00, 0x11, 0xbb}, + {0x07, 0x00, 0x85, 0xbb}, + {0x08, 0x00, 0x27, 0xbb}, + {0x20, 0x01, 0x03, 0xbb}, + {0x21, 0x80, 0x00, 0xbb}, + {0x22, 0x0d, 0x0f, 0xbb}, + {0x24, 0x80, 0x00, 0xbb}, + {0x59, 0x00, 0xff, 0xbb}, + {0xf0, 0x00, 0x02, 0xbb}, + {0x39, 0x03, 0x0d, 0xbb}, + {0x3a, 0x06, 0x1b, 0xbb}, + {0x3b, 0x00, 0x95, 0xbb}, + {0x3c, 0x04, 0xdb, 0xbb}, + {0x57, 0x02, 0x00, 0xbb}, + {0x58, 0x02, 0x66, 0xbb}, + {0x59, 0x00, 0xff, 0xbb}, + {0x5a, 0x01, 0x33, 0xbb}, + {0x5c, 0x12, 0x0d, 0xbb}, + {0x5d, 0x16, 0x11, 0xbb}, + {0x64, 0x5e, 0x1c, 0xbb}, + {0x2f, 0x90, 0x00, 0xbb}, + {} +}; +static const u8 mi1320_soc_InitSXGA[][4] = { + {0xb3, 0x01, 0x01, 0xcc}, + {0xb0, 0x03, 0x19, 0xcc}, + {0x00, 0x00, 0x30, 0xdd}, + {0xb3, 0x00, 0x64, 0xcc}, + {0xb3, 0x00, 0x67, 0xcc}, + {0xb3, 0x05, 0x01, 0xcc}, + {0xb3, 0x06, 0x01, 0xcc}, + {0xb3, 0x08, 0x01, 0xcc}, + {0xb3, 0x09, 0x0c, 0xcc}, + {0xb3, 0x34, 0x02, 0xcc}, + {0xb3, 0x35, 0xc8, 0xcc}, + {0xb3, 0x02, 0x00, 0xcc}, + {0xb3, 0x03, 0x0a, 0xcc}, + {0xb3, 0x04, 0x05, 0xcc}, + {0xb3, 0x20, 0x00, 0xcc}, + {0xb3, 0x21, 0x00, 0xcc}, + {0xb3, 0x22, 0x04, 0xcc}, + {0xb3, 0x23, 0x00, 0xcc}, + {0xb3, 0x14, 0x00, 0xcc}, + {0xb3, 0x15, 0x00, 0xcc}, + {0xb3, 0x16, 0x04, 0xcc}, + {0xb3, 0x17, 0xff, 0xcc}, + {0xb3, 0x00, 0x67, 0xcc}, + {0xbc, 0x00, 0x71, 0xcc}, + {0xbc, 0x01, 0x01, 0xcc}, + {0xb3, 0x5c, 0x01, 0xcc}, + {0xf0, 0x00, 0x02, 0xbb}, + {0x00, 0x00, 0x30, 0xdd}, + {0xc8, 0x9f, 0x0b, 0xbb}, + {0x00, 0x00, 0x20, 0xdd}, + {0x5b, 0x00, 0x01, 0xbb}, + {0x00, 0x00, 0x20, 0xdd}, + {0xf0, 0x00, 0x00, 0xbb}, + {0x00, 0x00, 0x30, 0xdd}, + {0x20, 0x01, 0x03, 0xbb}, + {0x00, 0x00, 0x20, 0xdd}, + {0xbf, 0xc0, 0x26, 0xcc}, + {0xbf, 0xc1, 0x02, 0xcc}, + {0xbf, 0xcc, 0x04, 0xcc}, + {0xb3, 0x01, 0x41, 0xcc}, + {0xf0, 0x00, 0x00, 0xbb}, + {0x05, 0x01, 0x78, 0xbb}, + {0x06, 0x00, 0x11, 0xbb}, + {0x07, 0x01, 0x42, 0xbb}, + {0x08, 0x00, 0x11, 0xbb}, + {0x20, 0x01, 0x03, 0xbb}, + {0x21, 0x80, 0x00, 0xbb}, + {0x22, 0x0d, 0x0f, 0xbb}, + {0x24, 0x80, 0x00, 0xbb}, + {0x59, 0x00, 0xff, 0xbb}, + {0xf0, 0x00, 0x02, 0xbb}, + {0x39, 0x03, 0xca, 0xbb}, + {0x3a, 0x06, 0x80, 0xbb}, + {0x3b, 0x01, 0x52, 0xbb}, + {0x3c, 0x05, 0x40, 0xbb}, + {0x57, 0x01, 0x9c, 0xbb}, + {0x58, 0x01, 0xee, 0xbb}, + {0x59, 0x00, 0xf0, 0xbb}, + {0x5a, 0x01, 0x20, 0xbb}, + {0x5c, 0x1d, 0x17, 0xbb}, + {0x5d, 0x22, 0x1c, 0xbb}, + {0x64, 0x1e, 0x1c, 0xbb}, + {0x5b, 0x00, 0x00, 0xbb}, + {0xf0, 0x00, 0x02, 0xbb}, + {0x22, 0xa0, 0x78, 0xbb}, + {0x23, 0xa0, 0x78, 0xbb}, + {0x24, 0x7f, 0x00, 0xbb}, + {0x28, 0xea, 0x02, 0xbb}, + {0x29, 0x86, 0x7a, 0xbb}, + {0x5e, 0x52, 0x4c, 0xbb}, + {0x5f, 0x20, 0x24, 0xbb}, + {0x60, 0x00, 0x02, 0xbb}, + {0x02, 0x00, 0xee, 0xbb}, + {0x03, 0x39, 0x23, 0xbb}, + {0x04, 0x07, 0x24, 0xbb}, + {0x09, 0x00, 0xc0, 0xbb}, + {0x0a, 0x00, 0x79, 0xbb}, + {0x0b, 0x00, 0x04, 0xbb}, + {0x0c, 0x00, 0x5c, 0xbb}, + {0x0d, 0x00, 0xd9, 0xbb}, + {0x0e, 0x00, 0x53, 0xbb}, + {0x0f, 0x00, 0x21, 0xbb}, + {0x10, 0x00, 0xa4, 0xbb}, + {0x11, 0x00, 0xe5, 0xbb}, + {0x15, 0x00, 0x00, 0xbb}, + {0x16, 0x00, 0x00, 0xbb}, + {0x17, 0x00, 0x00, 0xbb}, + {0x18, 0x00, 0x00, 0xbb}, + {0x19, 0x00, 0x00, 0xbb}, + {0x1a, 0x00, 0x00, 0xbb}, + {0x1b, 0x00, 0x00, 0xbb}, + {0x1c, 0x00, 0x00, 0xbb}, + {0x1d, 0x00, 0x00, 0xbb}, + {0x1e, 0x00, 0x00, 0xbb}, + {0xf0, 0x00, 0x01, 0xbb}, + {0x06, 0xe0, 0x0e, 0xbb}, + {0x06, 0x60, 0x0e, 0xbb}, + {0xb3, 0x5c, 0x01, 0xcc}, + {0xf0, 0x00, 0x00, 0xbb}, + {0x05, 0x01, 0x13, 0xbb}, + {0x06, 0x00, 0x11, 0xbb}, + {0x07, 0x00, 0x85, 0xbb}, + {0x08, 0x00, 0x27, 0xbb}, + {0x20, 0x01, 0x03, 0xbb}, + {0x21, 0x80, 0x00, 0xbb}, + {0x22, 0x0d, 0x0f, 0xbb}, + {0x24, 0x80, 0x00, 0xbb}, + {0x59, 0x00, 0xff, 0xbb}, + {0xf0, 0x00, 0x02, 0xbb}, + {0x39, 0x03, 0x0d, 0xbb}, + {0x3a, 0x06, 0x1b, 0xbb}, + {0x3b, 0x00, 0x95, 0xbb}, + {0x3c, 0x04, 0xdb, 0xbb}, + {0x57, 0x02, 0x00, 0xbb}, + {0x58, 0x02, 0x66, 0xbb}, + {0x59, 0x00, 0xff, 0xbb}, + {0x5a, 0x01, 0x33, 0xbb}, + {0x5c, 0x12, 0x0d, 0xbb}, + {0x5d, 0x16, 0x11, 0xbb}, + {0x64, 0x5e, 0x1c, 0xbb}, + {} +}; static const __u8 po3130_gamma[17] = { 0x00, 0x13, 0x38, 0x59, 0x79, 0x92, 0xa7, 0xb9, 0xc8, 0xd4, 0xdf, 0xe7, 0xee, 0xf4, 0xf9, 0xfc, 0xff @@ -1903,26 +2659,55 @@ static const __u8 po1200_initVGA_data[][4] = { }; struct sensor_info { - int sensorId; - __u8 I2cAdd; - __u8 IdAdd; - __u16 VpId; - __u8 m1; - __u8 m2; - __u8 op; - }; + s8 sensorId; + u8 I2cAdd; + u8 IdAdd; + u16 VpId; + u8 m1; + u8 m2; + u8 op; +}; static const struct sensor_info sensor_info_data[] = { /* sensorId, I2cAdd, IdAdd, VpId, m1, m2, op */ +#if 1 + {-1, 0x80 | 0x30, 0x0a, 0x0000, 0x25, 0x24, 0x05}, + {-1, 0x80 | 0x20, 0x82, 0x0000, 0x24, 0x25, 0x01}, +/* (tested in vc032x_probe_sensor) */ +/* {-1, 0x80 | 0x20, 0x83, 0x0000, 0x24, 0x25, 0x01}, */ + {SENSOR_PO3130NC, 0x80 | 0x76, 0x00, 0x3130, 0x24, 0x25, 0x01}, + {SENSOR_MI1310_SOC, 0x80 | 0x5d, 0x00, 0x143a, 0x24, 0x25, 0x01}, +/* (tested in vc032x_probe_sensor) */ +/* {SENSOR_MI0360, 0x80 | 0x5d, 0x00, 0x8243, 0x24, 0x25, 0x01}, */ + {SENSOR_HV7131R, 0x80 | 0x11, 0x00, 0x0209, 0x24, 0x25, 0x01}, + {-1, 0x80 | 0x21, 0x0a, 0x0000, 0x21, 0x20, 0x05}, + {-1, 0x80 | 0x40, 0x00, 0x0000, 0x20, 0x22, 0x05}, + {SENSOR_OV7660, 0x80 | 0x21, 0x0a, 0x7660, 0x26, 0x26, 0x05}, +/* {SENSOR_PO3130NC, 0x80 | 0x76, 0x00, 0x0000, 0x24, 0x25, 0x01}, */ + {-1, 0x80 | 0x6e, 0x00, 0x0000, 0x24, 0x25, 0x01}, +/* {SENSOR_MI1310_SOC, 0x80 | 0x5d, 0x00, 0x0000, 0x24, 0x25, 0x01}, */ +/* {-1, 0x80 | 0x30, 0x0a, 0x0000, 0x25, 0x24, 0x05}, */ + {-1, 0x80 | 0x11, 0x39, 0x0000, 0x24, 0x25, 0x01}, + {SENSOR_PO1200, 0x80 | 0x5c, 0x00, 0x1200, 0x67, 0x67, 0x01}, + {-1, 0x80 | 0x2d, 0x00, 0x0000, 0x65, 0x67, 0x01}, + {-1, 0x80 | 0x6e, 0x00, 0x0000, 0x24, 0x25, 0x01}, + {-1, 0x80 | 0x56, 0x01, 0x0000, 0x64, 0x67, 0x01}, + {SENSOR_MI1320_SOC, 0x80 | 0x48, 0x00, 0x148c, 0x64, 0x67, 0x01}, +/*fixme: previously detected?*/ + {SENSOR_MI1320, 0x80 | 0x48, 0x00, 0x148c, 0x64, 0x65, 0x01}, +/*fixme: not in the ms-win probe - may be found before?*/ + {SENSOR_OV7670, 0x80 | 0x21, 0x0a, 0x7673, 0x66, 0x67, 0x05}, +#else {SENSOR_HV7131R, 0x80 | 0x11, 0x00, 0x0209, 0x24, 0x25, 0x01}, {SENSOR_OV7660, 0x80 | 0x21, 0x0a, 0x7660, 0x26, 0x26, 0x05}, {SENSOR_PO3130NC, 0x80 | 0x76, 0x00, 0x3130, 0x24, 0x25, 0x01}, - {SENSOR_MI1320, 0x80 | 0xc8, 0x00, 0x148c, 0x64, 0x65, 0x01}, + {SENSOR_MI1320, 0x80 | 0x48, 0x00, 0x148c, 0x64, 0x65, 0x01}, {SENSOR_OV7670, 0x80 | 0x21, 0x0a, 0x7673, 0x66, 0x67, 0x05}, {SENSOR_MI1310_SOC, 0x80 | 0x5d, 0x00, 0x143a, 0x24, 0x25, 0x01}, /* (tested in vc032x_probe_sensor) */ /* {SENSOR_MI0360, 0x80 | 0x5d, 0x00, 0x8243, 0x24, 0x25, 0x01}, */ {SENSOR_PO1200, 0x80 | 0x5c, 0x00, 0x1200, 0x67, 0x67, 0x01}, +#endif }; /* read 'len' bytes in gspca_dev->usb_buf */ @@ -1957,7 +2742,7 @@ static u16 read_sensor_register(struct gspca_dev *gspca_dev, u16 address) { struct usb_device *dev = gspca_dev->dev; - __u8 ldata, mdata, hdata; + u8 ldata, mdata, hdata; int retry = 50; reg_r(gspca_dev, 0xa1, 0xb33f, 1); @@ -1970,9 +2755,11 @@ static u16 read_sensor_register(struct gspca_dev *gspca_dev, reg_w(dev, 0xa0, 0x02, 0xb339); do { - msleep(8); reg_r(gspca_dev, 0xa1, 0xb33b, 1); - } while (retry-- && gspca_dev->usb_buf[0]); + if (gspca_dev->usb_buf[0] == 0x00) + break; + msleep(40); + } while (--retry >= 0); reg_r(gspca_dev, 0xa1, 0xb33e, 1); ldata = gspca_dev->usb_buf[0]; @@ -1993,7 +2780,7 @@ static int vc032x_probe_sensor(struct gspca_dev *gspca_dev) { struct usb_device *dev = gspca_dev->dev; int i; - __u16 value; + u16 value; const struct sensor_info *ptsensor_info; reg_r(gspca_dev, 0xa1, 0xbfcf, 1); @@ -2008,45 +2795,40 @@ static int vc032x_probe_sensor(struct gspca_dev *gspca_dev) reg_w(dev, 0xa0, ptsensor_info->I2cAdd, 0xb335); reg_w(dev, 0xa0, ptsensor_info->op, 0xb301); value = read_sensor_register(gspca_dev, ptsensor_info->IdAdd); - if (value == ptsensor_info->VpId) - return ptsensor_info->sensorId; - - /* special case for MI0360 */ - if (ptsensor_info->sensorId == SENSOR_MI1310_SOC - && value == 0x8243) - return SENSOR_MI0360; + if (value == 0 && ptsensor_info->IdAdd == 0x82) + value = read_sensor_register(gspca_dev, 0x83); + if (value != 0) { + PDEBUG(D_ERR|D_PROBE, "Sensor ID %04x (%d)", + value, i); + if (value == ptsensor_info->VpId) + return ptsensor_info->sensorId; + + switch (value) { + case 0x7673: + return SENSOR_OV7670; + case 0x8243: + return SENSOR_MI0360; + } +/*fixme: should return here*/ + } } return -1; } static void i2c_write(struct gspca_dev *gspca_dev, - __u8 reg, const __u8 *val, __u8 size) + u8 reg, const u8 *val, + u8 size) /* 1 or 2 */ { struct usb_device *dev = gspca_dev->dev; int retry; -#ifdef GSPCA_DEBUG - if (size > 3 || size < 1) - return; -#endif reg_r(gspca_dev, 0xa1, 0xb33f, 1); +/*fixme:should check if (!(gspca_dev->usb_buf[0] & 0x02)) error*/ reg_w(dev, 0xa0, size, 0xb334); reg_w(dev, 0xa0, reg, 0xb33a); - switch (size) { - case 1: - reg_w(dev, 0xa0, val[0], 0xb336); - break; - case 2: - reg_w(dev, 0xa0, val[0], 0xb336); + reg_w(dev, 0xa0, val[0], 0xb336); + if (size > 1) reg_w(dev, 0xa0, val[1], 0xb337); - break; - default: -/* case 3: */ - reg_w(dev, 0xa0, val[0], 0xb336); - reg_w(dev, 0xa0, val[1], 0xb337); - reg_w(dev, 0xa0, val[2], 0xb338); - break; - } reg_w(dev, 0xa0, 0x01, 0xb339); retry = 4; do { @@ -2141,6 +2923,9 @@ static int sd_config(struct gspca_dev *gspca_dev, case SENSOR_MI1320: PDEBUG(D_PROBE, "Find Sensor MI1320"); break; + case SENSOR_MI1320_SOC: + PDEBUG(D_PROBE, "Find Sensor MI1320_SOC"); + break; case SENSOR_OV7660: PDEBUG(D_PROBE, "Find Sensor OV7660"); break; @@ -2160,15 +2945,23 @@ static int sd_config(struct gspca_dev *gspca_dev, cam->cam_mode = vc0321_mode; cam->nmodes = ARRAY_SIZE(vc0321_mode); } else { - if (sensor != SENSOR_PO1200) { - cam->cam_mode = vc0323_mode; - if (sd->sensor != SENSOR_MI1310_SOC) - cam->nmodes = ARRAY_SIZE(vc0323_mode); - else /* no SXGA */ - cam->nmodes = ARRAY_SIZE(vc0323_mode) - 1; - } else { + switch (sensor) { + case SENSOR_PO1200: cam->cam_mode = svga_mode; cam->nmodes = ARRAY_SIZE(svga_mode); + break; + case SENSOR_MI1310_SOC: + cam->cam_mode = vc0323_mode; + cam->nmodes = ARRAY_SIZE(vc0323_mode); + break; + case SENSOR_MI1320_SOC: + cam->cam_mode = bi_mode; + cam->nmodes = ARRAY_SIZE(bi_mode); + break; + default: + cam->cam_mode = vc0323_mode; + cam->nmodes = ARRAY_SIZE(vc0323_mode) - 1; + break; } } @@ -2271,6 +3064,14 @@ static int sd_start(struct gspca_dev *gspca_dev) const __u8 *GammaT = NULL; const __u8 *MatrixT = NULL; int mode; + static const u8 (*mi1320_soc_init[])[4] = { + mi1320_soc_InitSXGA, + mi1320_soc_InitSXGA_JPG, + mi1320_soc_InitVGA, + mi1320_soc_InitVGA_JPG, + mi1320_soc_InitQVGA, + mi1320_soc_InitQVGA_JPG + }; /* Assume start use the good resolution from gspca_dev->mode */ if (sd->bridge == BRIDGE_VC0321) { @@ -2278,6 +3079,13 @@ static int sd_start(struct gspca_dev *gspca_dev) reg_w(gspca_dev->dev, 0xa0, 0xff, 0xbfed); reg_w(gspca_dev->dev, 0xa0, 0xff, 0xbfee); reg_w(gspca_dev->dev, 0xa0, 0xff, 0xbfef); + sd->image_offset = 46; + } else { + if (gspca_dev->cam.cam_mode[gspca_dev->curr_mode].pixelformat + == V4L2_PIX_FMT_JPEG) + sd->image_offset = 0; + else + sd->image_offset = 32; } mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv; @@ -2325,7 +3133,7 @@ static int sd_start(struct gspca_dev *gspca_dev) init = mi1310_socinitVGA_JPG; /* 640x480 */ break; default: - init = mi1310_soc_InitSXGA_JPG; /* 1280xq024 */ + init = mi1310_soc_InitSXGA_JPG; /* 1280x1024 */ break; } break; @@ -2337,6 +3145,11 @@ static int sd_start(struct gspca_dev *gspca_dev) else init = mi1320_initVGA_data; /* 640x480 */ break; + case SENSOR_MI1320_SOC: + GammaT = mi1320_gamma; + MatrixT = mi1320_matrix; + init = mi1320_soc_init[mode]; + break; case SENSOR_PO3130NC: GammaT = po3130_gamma; MatrixT = po3130_matrix; @@ -2407,12 +3220,8 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev, "vc032x header packet found len %d", len); frame = gspca_frame_add(gspca_dev, LAST_PACKET, frame, data, 0); - if (sd->bridge == BRIDGE_VC0321) { -#define VCHDRSZ 46 - data += VCHDRSZ; - len -= VCHDRSZ; -#undef VCHDRSZ - } + data += sd->image_offset; + len -= sd->image_offset; gspca_frame_add(gspca_dev, FIRST_PACKET, frame, data, len); return; @@ -2545,6 +3354,7 @@ static const __devinitdata struct usb_device_id device_table[] = { {USB_DEVICE(0x0ac8, 0x0328), .driver_info = BRIDGE_VC0321}, {USB_DEVICE(0x0ac8, 0xc001), .driver_info = BRIDGE_VC0321}, {USB_DEVICE(0x0ac8, 0xc002), .driver_info = BRIDGE_VC0321}, + {USB_DEVICE(0x15b8, 0x6001), .driver_info = BRIDGE_VC0323}, {USB_DEVICE(0x15b8, 0x6002), .driver_info = BRIDGE_VC0323}, {USB_DEVICE(0x17ef, 0x4802), .driver_info = BRIDGE_VC0323}, {} diff --git a/linux/drivers/media/video/gspca/zc3xx.c b/linux/drivers/media/video/gspca/zc3xx.c index ad385b9a0..a90b3b0d4 100644 --- a/linux/drivers/media/video/gspca/zc3xx.c +++ b/linux/drivers/media/video/gspca/zc3xx.c @@ -23,6 +23,7 @@ #define MODULE_NAME "zc3xx" #include "gspca.h" +#include "jpeg.h" MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>, " "Serge A. Suchkov <Serge.A.S@tochka.ru>"); @@ -32,7 +33,6 @@ MODULE_LICENSE("GPL"); static int force_sensor = -1; #define QUANT_VAL 1 /* quantization table */ -#include "jpeg.h" #include "zc3xx-reg.h" /* specific webcam descriptor */ @@ -45,6 +45,10 @@ struct sd { __u8 autogain; __u8 lightfreq; __u8 sharpness; + u8 quality; /* image quality */ +#define QUALITY_MIN 40 +#define QUALITY_MAX 60 +#define QUALITY_DEF 50 signed char sensor; /* Type of image sensor chip */ /* !! values used in different tables */ @@ -69,6 +73,8 @@ struct sd { #define SENSOR_TAS5130C_VF0250 17 #define SENSOR_MAX 18 unsigned short chip_revision; + + u8 *jpeg_hdr; }; /* V4L2 controls supported by the driver */ @@ -7206,6 +7212,7 @@ static int sd_config(struct gspca_dev *gspca_dev, sd->gamma = gamma[(int) sd->sensor]; sd->autogain = sd_ctrls[SD_AUTOGAIN].qctrl.default_value; sd->lightfreq = sd_ctrls[SD_FREQ].qctrl.default_value; + sd->quality = QUALITY_DEF; switch (sd->sensor) { case SENSOR_GC0305: @@ -7261,6 +7268,12 @@ static int sd_start(struct gspca_dev *gspca_dev) /* 17 */ }; + /* create the JPEG header */ + sd->jpeg_hdr = kmalloc(JPEG_HDR_SZ, GFP_KERNEL); + jpeg_define(sd->jpeg_hdr, gspca_dev->height, gspca_dev->width, + 0x21); /* JPEG 422 */ + jpeg_set_qual(sd->jpeg_hdr, sd->quality); + mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv; zc3_init = init_tb[(int) sd->sensor][mode]; switch (sd->sensor) { @@ -7398,6 +7411,7 @@ static void sd_stop0(struct gspca_dev *gspca_dev) { struct sd *sd = (struct sd *) gspca_dev; + kfree(sd->jpeg_hdr); if (!gspca_dev->present) return; send_unknown(gspca_dev->dev, sd->sensor); @@ -7408,12 +7422,15 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev, __u8 *data, int len) { + struct sd *sd = (struct sd *) gspca_dev; if (data[0] == 0xff && data[1] == 0xd8) { /* start of frame */ frame = gspca_frame_add(gspca_dev, LAST_PACKET, frame, data, 0); /* put the JPEG header in the new frame */ - jpeg_put_header(gspca_dev, frame, 0x21); + gspca_frame_add(gspca_dev, FIRST_PACKET, frame, + sd->jpeg_hdr, JPEG_HDR_SZ); + /* remove the webcam's header: * ff d8 ff fe 00 0e 00 00 ss ss 00 01 ww ww hh hh pp pp * - 'ss ss' is the frame sequence number (BE) @@ -7555,6 +7572,34 @@ static int sd_querymenu(struct gspca_dev *gspca_dev, return -EINVAL; } +static int sd_set_jcomp(struct gspca_dev *gspca_dev, + struct v4l2_jpegcompression *jcomp) +{ + struct sd *sd = (struct sd *) gspca_dev; + + if (jcomp->quality < QUALITY_MIN) + sd->quality = QUALITY_MIN; + else if (jcomp->quality > QUALITY_MAX) + sd->quality = QUALITY_MAX; + else + sd->quality = jcomp->quality; + if (gspca_dev->streaming) + jpeg_set_qual(sd->jpeg_hdr, sd->quality); + return 0; +} + +static int sd_get_jcomp(struct gspca_dev *gspca_dev, + struct v4l2_jpegcompression *jcomp) +{ + struct sd *sd = (struct sd *) gspca_dev; + + memset(jcomp, 0, sizeof *jcomp); + jcomp->quality = sd->quality; + jcomp->jpeg_markers = V4L2_JPEG_MARKER_DHT + | V4L2_JPEG_MARKER_DQT; + return 0; +} + static const struct sd_desc sd_desc = { .name = MODULE_NAME, .ctrls = sd_ctrls, @@ -7565,6 +7610,8 @@ static const struct sd_desc sd_desc = { .stop0 = sd_stop0, .pkt_scan = sd_pkt_scan, .querymenu = sd_querymenu, + .get_jcomp = sd_get_jcomp, + .set_jcomp = sd_set_jcomp, }; static const __devinitdata struct usb_device_id device_table[] = { @@ -7615,7 +7662,7 @@ static const __devinitdata struct usb_device_id device_table[] = { {USB_DEVICE(0x055f, 0xd004)}, {USB_DEVICE(0x0698, 0x2003)}, {USB_DEVICE(0x0ac8, 0x0301), .driver_info = SENSOR_PAS106}, - {USB_DEVICE(0x0ac8, 0x0302)}, + {USB_DEVICE(0x0ac8, 0x0302), .driver_info = SENSOR_PAS106}, {USB_DEVICE(0x0ac8, 0x301b)}, {USB_DEVICE(0x0ac8, 0x303b)}, {USB_DEVICE(0x0ac8, 0x305b), .driver_info = SENSOR_TAS5130C_VF0250}, diff --git a/linux/drivers/media/video/hdpvr/Kconfig b/linux/drivers/media/video/hdpvr/Kconfig new file mode 100644 index 000000000..de247f3c7 --- /dev/null +++ b/linux/drivers/media/video/hdpvr/Kconfig @@ -0,0 +1,10 @@ + +config VIDEO_HDPVR + tristate "Hauppauge HD PVR support" + depends on VIDEO_DEV + ---help--- + This is a video4linux driver for Hauppauge's HD PVR USB device. + + To compile this driver as a module, choose M here: the + module will be called hdpvr + diff --git a/linux/drivers/media/video/hdpvr/Makefile b/linux/drivers/media/video/hdpvr/Makefile new file mode 100644 index 000000000..e0230fcb2 --- /dev/null +++ b/linux/drivers/media/video/hdpvr/Makefile @@ -0,0 +1,9 @@ +hdpvr-objs := hdpvr-control.o hdpvr-core.o hdpvr-video.o + +hdpvr-$(CONFIG_I2C) += hdpvr-i2c.o + +obj-$(CONFIG_VIDEO_HDPVR) += hdpvr.o + +EXTRA_CFLAGS += -Idrivers/media/video + +EXTRA_CFLAGS += $(extra-cflags-y) $(extra-cflags-m) diff --git a/linux/drivers/media/video/hdpvr/hdpvr-control.c b/linux/drivers/media/video/hdpvr/hdpvr-control.c new file mode 100644 index 000000000..06791749d --- /dev/null +++ b/linux/drivers/media/video/hdpvr/hdpvr-control.c @@ -0,0 +1,201 @@ +/* + * Hauppauge HD PVR USB driver - video 4 linux 2 interface + * + * Copyright (C) 2008 Janne Grunau (j@jannau.net) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, version 2. + * + */ + +#include <linux/kernel.h> +#include <linux/errno.h> +#include <linux/init.h> +#include <linux/slab.h> +#include <linux/module.h> +#include <linux/usb.h> +#include <linux/mutex.h> + +#include <linux/videodev2.h> + +#include <media/v4l2-common.h> + +#include "hdpvr.h" + + +int hdpvr_config_call(struct hdpvr_device *dev, uint value, u8 valbuf) +{ + int ret; + char request_type = 0x38, snd_request = 0x01; + + msleep(10); + + mutex_lock(&dev->usbc_mutex); + dev->usbc_buf[0] = valbuf; + ret = usb_control_msg(dev->udev, + usb_sndctrlpipe(dev->udev, 0), + snd_request, 0x00 | request_type, + value, CTRL_DEFAULT_INDEX, + dev->usbc_buf, 1, 10000); + + mutex_unlock(&dev->usbc_mutex); + v4l2_dbg(MSG_INFO, hdpvr_debug, &dev->v4l2_dev, + "config call request for value 0x%x returned %d\n", value, + ret); + + return ret < 0 ? ret : 0; +} + +struct hdpvr_video_info *get_video_info(struct hdpvr_device *dev) +{ + struct hdpvr_video_info *vidinf = NULL; +#ifdef HDPVR_DEBUG + char print_buf[15]; +#endif + int ret; + + vidinf = kzalloc(sizeof(struct hdpvr_video_info), GFP_KERNEL); + if (!vidinf) { + v4l2_err(&dev->v4l2_dev, "out of memory\n"); + goto err; + } + + mutex_lock(&dev->usbc_mutex); + ret = usb_control_msg(dev->udev, + usb_rcvctrlpipe(dev->udev, 0), + 0x81, 0x80 | 0x38, + 0x1400, 0x0003, + dev->usbc_buf, 5, + 1000); + if (ret == 5) { + vidinf->width = dev->usbc_buf[1] << 8 | dev->usbc_buf[0]; + vidinf->height = dev->usbc_buf[3] << 8 | dev->usbc_buf[2]; + vidinf->fps = dev->usbc_buf[4]; + } + +#ifdef HDPVR_DEBUG + if (hdpvr_debug & MSG_INFO) { + hex_dump_to_buffer(dev->usbc_buf, 5, 16, 1, print_buf, + sizeof(print_buf), 0); + v4l2_dbg(MSG_INFO, hdpvr_debug, &dev->v4l2_dev, + "get video info returned: %d, %s\n", ret, print_buf); + } +#endif + mutex_unlock(&dev->usbc_mutex); + + if (!vidinf->width || !vidinf->height || !vidinf->fps) { + kfree(vidinf); + vidinf = NULL; + } +err: + return vidinf; +} + +int get_input_lines_info(struct hdpvr_device *dev) +{ +#ifdef HDPVR_DEBUG + char print_buf[9]; +#endif + int ret, lines; + + mutex_lock(&dev->usbc_mutex); + ret = usb_control_msg(dev->udev, + usb_rcvctrlpipe(dev->udev, 0), + 0x81, 0x80 | 0x38, + 0x1800, 0x0003, + dev->usbc_buf, 3, + 1000); + +#ifdef HDPVR_DEBUG + if (hdpvr_debug & MSG_INFO) { + hex_dump_to_buffer(dev->usbc_buf, 3, 16, 1, print_buf, + sizeof(print_buf), 0); + v4l2_dbg(MSG_INFO, hdpvr_debug, &dev->v4l2_dev, + "get input lines info returned: %d, %s\n", ret, + print_buf); + } +#endif + lines = dev->usbc_buf[1] << 8 | dev->usbc_buf[0]; + mutex_unlock(&dev->usbc_mutex); + return lines; +} + + +int hdpvr_set_bitrate(struct hdpvr_device *dev) +{ + int ret; + + mutex_lock(&dev->usbc_mutex); + memset(dev->usbc_buf, 0, 4); + dev->usbc_buf[0] = dev->options.bitrate; + dev->usbc_buf[2] = dev->options.peak_bitrate; + + ret = usb_control_msg(dev->udev, + usb_sndctrlpipe(dev->udev, 0), + 0x01, 0x38, CTRL_BITRATE_VALUE, + CTRL_DEFAULT_INDEX, dev->usbc_buf, 4, 1000); + mutex_unlock(&dev->usbc_mutex); + + return ret; +} + +int hdpvr_set_audio(struct hdpvr_device *dev, u8 input, + enum v4l2_mpeg_audio_encoding codec) +{ + int ret = 0; + + if (dev->flags & HDPVR_FLAG_AC3_CAP) { + mutex_lock(&dev->usbc_mutex); + memset(dev->usbc_buf, 0, 2); + dev->usbc_buf[0] = input; + if (codec == V4L2_MPEG_AUDIO_ENCODING_AAC) + dev->usbc_buf[1] = 0; + else if (codec == V4L2_MPEG_AUDIO_ENCODING_AC3) + dev->usbc_buf[1] = 1; + else { + mutex_unlock(&dev->usbc_mutex); + v4l2_err(&dev->v4l2_dev, "invalid audio codec %d\n", + codec); + ret = -EINVAL; + goto error; + } + + ret = usb_control_msg(dev->udev, + usb_sndctrlpipe(dev->udev, 0), + 0x01, 0x38, CTRL_AUDIO_INPUT_VALUE, + CTRL_DEFAULT_INDEX, dev->usbc_buf, 2, + 1000); + mutex_unlock(&dev->usbc_mutex); + if (ret == 2) + ret = 0; + } else + ret = hdpvr_config_call(dev, CTRL_AUDIO_INPUT_VALUE, + dev->options.audio_input+1); +error: + return ret; +} + +int hdpvr_set_options(struct hdpvr_device *dev) +{ + hdpvr_config_call(dev, CTRL_VIDEO_STD_TYPE, dev->options.video_std); + + hdpvr_config_call(dev, CTRL_VIDEO_INPUT_VALUE, + dev->options.video_input+1); + + hdpvr_set_audio(dev, dev->options.audio_input+1, + dev->options.audio_codec); + + hdpvr_set_bitrate(dev); + hdpvr_config_call(dev, CTRL_BITRATE_MODE_VALUE, + dev->options.bitrate_mode); + hdpvr_config_call(dev, CTRL_GOP_MODE_VALUE, dev->options.gop_mode); + + hdpvr_config_call(dev, CTRL_BRIGHTNESS, dev->options.brightness); + hdpvr_config_call(dev, CTRL_CONTRAST, dev->options.contrast); + hdpvr_config_call(dev, CTRL_HUE, dev->options.hue); + hdpvr_config_call(dev, CTRL_SATURATION, dev->options.saturation); + hdpvr_config_call(dev, CTRL_SHARPNESS, dev->options.sharpness); + + return 0; +} diff --git a/linux/drivers/media/video/hdpvr/hdpvr-core.c b/linux/drivers/media/video/hdpvr/hdpvr-core.c new file mode 100644 index 000000000..188bd5aea --- /dev/null +++ b/linux/drivers/media/video/hdpvr/hdpvr-core.c @@ -0,0 +1,466 @@ +/* + * Hauppauge HD PVR USB driver + * + * Copyright (C) 2001-2004 Greg Kroah-Hartman (greg@kroah.com) + * Copyright (C) 2008 Janne Grunau (j@jannau.net) + * Copyright (C) 2008 John Poet + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, version 2. + * + */ + +#include <linux/kernel.h> +#include <linux/errno.h> +#include <linux/init.h> +#include <linux/slab.h> +#include <linux/module.h> +#include <linux/uaccess.h> +#include <asm/atomic.h> +#include <linux/usb.h> +#include <linux/mutex.h> +#include <linux/i2c.h> + +#include <linux/videodev2.h> +#include <media/v4l2-dev.h> +#include <media/v4l2-common.h> + +#include "hdpvr.h" + +static int video_nr[HDPVR_MAX] = {[0 ... (HDPVR_MAX - 1)] = UNSET}; +module_param_array(video_nr, int, NULL, 0); +MODULE_PARM_DESC(video_nr, "video device number (-1=Auto)"); + +/* holds the number of currently registered devices */ +static atomic_t dev_nr = ATOMIC_INIT(-1); + +int hdpvr_debug; +module_param(hdpvr_debug, int, S_IRUGO|S_IWUSR); +MODULE_PARM_DESC(hdpvr_debug, "enable debugging output"); + +uint default_video_input = HDPVR_VIDEO_INPUTS; +module_param(default_video_input, uint, S_IRUGO|S_IWUSR); +MODULE_PARM_DESC(default_video_input, "default video input: 0=Component / " + "1=S-Video / 2=Composite"); + +uint default_audio_input = HDPVR_AUDIO_INPUTS; +module_param(default_audio_input, uint, S_IRUGO|S_IWUSR); +MODULE_PARM_DESC(default_audio_input, "default audio input: 0=RCA back / " + "1=RCA front / 2=S/PDIF"); + +static int boost_audio; +module_param(boost_audio, bool, S_IRUGO|S_IWUSR); +MODULE_PARM_DESC(boost_audio, "boost the audio signal"); + + +/* table of devices that work with this driver */ +static struct usb_device_id hdpvr_table[] = { + { USB_DEVICE(HD_PVR_VENDOR_ID, HD_PVR_PRODUCT_ID) }, + { USB_DEVICE(HD_PVR_VENDOR_ID, HD_PVR_PRODUCT_ID1) }, + { USB_DEVICE(HD_PVR_VENDOR_ID, HD_PVR_PRODUCT_ID2) }, + { } /* Terminating entry */ +}; +MODULE_DEVICE_TABLE(usb, hdpvr_table); + + +void hdpvr_delete(struct hdpvr_device *dev) +{ + hdpvr_free_buffers(dev); + + if (dev->video_dev) + video_device_release(dev->video_dev); + + usb_put_dev(dev->udev); +} + +static void challenge(u8 *bytes) +{ + u64 *i64P, tmp64; + uint i, idx; + + for (idx = 0; idx < 32; ++idx) { + + if (idx & 0x3) + bytes[(idx >> 3) + 3] = bytes[(idx >> 2) & 0x3]; + + switch (idx & 0x3) { + case 0x3: + bytes[2] += bytes[3] * 4 + bytes[4] + bytes[5]; + bytes[4] += bytes[(idx & 0x1) * 2] * 9 + 9; + break; + case 0x1: + bytes[0] *= 8; + bytes[0] += 7*idx + 4; + bytes[6] += bytes[3] * 3; + break; + case 0x0: + bytes[3 - (idx >> 3)] = bytes[idx >> 2]; + bytes[5] += bytes[6] * 3; + for (i = 0; i < 3; i++) + bytes[3] *= bytes[3] + 1; + break; + case 0x2: + for (i = 0; i < 3; i++) + bytes[1] *= bytes[6] + 1; + for (i = 0; i < 3; i++) { + i64P = (u64 *)bytes; + tmp64 = le64_to_cpup(i64P); + tmp64 <<= bytes[7] & 0x0f; + *i64P += cpu_to_le64(tmp64); + } + break; + } + } +} + +/* try to init the device like the windows driver */ +static int device_authorization(struct hdpvr_device *dev) +{ + + int ret, retval = -ENOMEM; + char request_type = 0x38, rcv_request = 0x81; + char *response; +#ifdef HDPVR_DEBUG + size_t buf_size = 46; + char *print_buf = kzalloc(5*buf_size+1, GFP_KERNEL); + if (!print_buf) { + v4l2_err(&dev->v4l2_dev, "Out of memory\n"); + goto error; + } +#endif + + mutex_lock(&dev->usbc_mutex); + ret = usb_control_msg(dev->udev, + usb_rcvctrlpipe(dev->udev, 0), + rcv_request, 0x80 | request_type, + 0x0400, 0x0003, + dev->usbc_buf, 46, + 10000); + if (ret != 46) { + v4l2_err(&dev->v4l2_dev, + "unexpected answer of status request, len %d\n", ret); + goto error; + } +#ifdef HDPVR_DEBUG + else { + hex_dump_to_buffer(dev->usbc_buf, 46, 16, 1, print_buf, + sizeof(print_buf), 0); + v4l2_dbg(MSG_INFO, hdpvr_debug, &dev->v4l2_dev, + "Status request returned, len %d: %s\n", + ret, print_buf); + } +#endif + if (dev->usbc_buf[1] == HDPVR_FIRMWARE_VERSION) { + dev->flags &= ~HDPVR_FLAG_AC3_CAP; + } else if (dev->usbc_buf[1] == HDPVR_FIRMWARE_VERSION_AC3) { + dev->flags |= HDPVR_FLAG_AC3_CAP; + } else if (dev->usbc_buf[1] > HDPVR_FIRMWARE_VERSION_AC3) { + v4l2_info(&dev->v4l2_dev, "untested firmware version 0x%x, " + "the driver might not work\n", dev->usbc_buf[1]); + dev->flags |= HDPVR_FLAG_AC3_CAP; + } else { + v4l2_err(&dev->v4l2_dev, "unknown firmware version 0x%x\n", + dev->usbc_buf[1]); + ret = -EINVAL; + goto error; + } + + response = dev->usbc_buf+38; +#ifdef HDPVR_DEBUG + hex_dump_to_buffer(response, 8, 16, 1, print_buf, sizeof(print_buf), 0); + v4l2_dbg(MSG_INFO, hdpvr_debug, &dev->v4l2_dev, "challenge: %s\n", + print_buf); +#endif + challenge(response); +#ifdef HDPVR_DEBUG + hex_dump_to_buffer(response, 8, 16, 1, print_buf, sizeof(print_buf), 0); + v4l2_dbg(MSG_INFO, hdpvr_debug, &dev->v4l2_dev, " response: %s\n", + print_buf); +#endif + + msleep(100); + ret = usb_control_msg(dev->udev, + usb_sndctrlpipe(dev->udev, 0), + 0xd1, 0x00 | request_type, + 0x0000, 0x0000, + response, 8, + 10000); + v4l2_dbg(MSG_INFO, hdpvr_debug, &dev->v4l2_dev, + "magic request returned %d\n", ret); + mutex_unlock(&dev->usbc_mutex); + + retval = ret != 8; +error: + return retval; +} + +static int hdpvr_device_init(struct hdpvr_device *dev) +{ + int ret; + u8 *buf; + struct hdpvr_video_info *vidinf; + + if (device_authorization(dev)) + return -EACCES; + + /* default options for init */ + hdpvr_set_options(dev); + + /* set filter options */ + mutex_lock(&dev->usbc_mutex); + buf = dev->usbc_buf; + buf[0] = 0x03; buf[1] = 0x03; buf[2] = 0x00; buf[3] = 0x00; + ret = usb_control_msg(dev->udev, + usb_sndctrlpipe(dev->udev, 0), + 0x01, 0x38, + CTRL_LOW_PASS_FILTER_VALUE, CTRL_DEFAULT_INDEX, + buf, 4, + 1000); + v4l2_dbg(MSG_INFO, hdpvr_debug, &dev->v4l2_dev, + "control request returned %d\n", ret); + mutex_unlock(&dev->usbc_mutex); + + vidinf = get_video_info(dev); + if (!vidinf) + v4l2_dbg(MSG_INFO, hdpvr_debug, &dev->v4l2_dev, + "no valid video signal or device init failed\n"); + else + kfree(vidinf); + + /* enable fan and bling leds */ + mutex_lock(&dev->usbc_mutex); + buf[0] = 0x1; + ret = usb_control_msg(dev->udev, + usb_sndctrlpipe(dev->udev, 0), + 0xd4, 0x38, 0, 0, buf, 1, + 1000); + v4l2_dbg(MSG_INFO, hdpvr_debug, &dev->v4l2_dev, + "control request returned %d\n", ret); + + /* boost analog audio */ + buf[0] = boost_audio; + ret = usb_control_msg(dev->udev, + usb_sndctrlpipe(dev->udev, 0), + 0xd5, 0x38, 0, 0, buf, 1, + 1000); + v4l2_dbg(MSG_INFO, hdpvr_debug, &dev->v4l2_dev, + "control request returned %d\n", ret); + mutex_unlock(&dev->usbc_mutex); + + dev->status = STATUS_IDLE; + return 0; +} + +static const struct hdpvr_options hdpvr_default_options = { + .video_std = HDPVR_60HZ, + .video_input = HDPVR_COMPONENT, + .audio_input = HDPVR_RCA_BACK, + .bitrate = 65, /* 6 mbps */ + .peak_bitrate = 90, /* 9 mbps */ + .bitrate_mode = HDPVR_CONSTANT, + .gop_mode = HDPVR_SIMPLE_IDR_GOP, + .audio_codec = V4L2_MPEG_AUDIO_ENCODING_AAC, + .brightness = 0x86, + .contrast = 0x80, + .hue = 0x80, + .saturation = 0x80, + .sharpness = 0x80, +}; + +static int hdpvr_probe(struct usb_interface *interface, + const struct usb_device_id *id) +{ + struct hdpvr_device *dev; + struct usb_host_interface *iface_desc; + struct usb_endpoint_descriptor *endpoint; + size_t buffer_size; + int i; + int retval = -ENOMEM; + + /* allocate memory for our device state and initialize it */ + dev = kzalloc(sizeof(*dev), GFP_KERNEL); + if (!dev) { + err("Out of memory"); + goto error; + } + + /* register v4l2_device early so it can be used for printks */ + if (v4l2_device_register(&interface->dev, &dev->v4l2_dev)) { + err("v4l2_device_register failed"); + goto error; + } + + mutex_init(&dev->io_mutex); + mutex_init(&dev->i2c_mutex); + mutex_init(&dev->usbc_mutex); + dev->usbc_buf = kmalloc(64, GFP_KERNEL); + if (!dev->usbc_buf) { + v4l2_err(&dev->v4l2_dev, "Out of memory\n"); + goto error; + } + + init_waitqueue_head(&dev->wait_buffer); + init_waitqueue_head(&dev->wait_data); + + dev->workqueue = create_singlethread_workqueue("hdpvr_buffer"); + if (!dev->workqueue) + goto error; + + /* init video transfer queues */ + INIT_LIST_HEAD(&dev->free_buff_list); + INIT_LIST_HEAD(&dev->rec_buff_list); + + dev->options = hdpvr_default_options; + + if (default_video_input < HDPVR_VIDEO_INPUTS) + dev->options.video_input = default_video_input; + + if (default_audio_input < HDPVR_AUDIO_INPUTS) + dev->options.audio_input = default_audio_input; + + dev->udev = usb_get_dev(interface_to_usbdev(interface)); + + /* set up the endpoint information */ + /* use only the first bulk-in and bulk-out endpoints */ + iface_desc = interface->cur_altsetting; + for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) { + endpoint = &iface_desc->endpoint[i].desc; + + if (!dev->bulk_in_endpointAddr && + usb_endpoint_is_bulk_in(endpoint)) { + /* USB interface description is buggy, reported max + * packet size is 512 bytes, windows driver uses 8192 */ + buffer_size = 8192; + dev->bulk_in_size = buffer_size; + dev->bulk_in_endpointAddr = endpoint->bEndpointAddress; + } + + } + if (!dev->bulk_in_endpointAddr) { + v4l2_err(&dev->v4l2_dev, "Could not find bulk-in endpoint\n"); + goto error; + } + + /* init the device */ + if (hdpvr_device_init(dev)) { + v4l2_err(&dev->v4l2_dev, "device init failed\n"); + goto error; + } + + mutex_lock(&dev->io_mutex); + if (hdpvr_alloc_buffers(dev, NUM_BUFFERS)) { + v4l2_err(&dev->v4l2_dev, + "allocating transfer buffers failed\n"); + goto error; + } + mutex_unlock(&dev->io_mutex); + + if (hdpvr_register_videodev(dev, &interface->dev, + video_nr[atomic_inc_return(&dev_nr)])) { + v4l2_err(&dev->v4l2_dev, "registering videodev failed\n"); + goto error; + } + +#ifdef CONFIG_I2C + /* until i2c is working properly */ + retval = 0; /* hdpvr_register_i2c_adapter(dev); */ + if (retval < 0) { + v4l2_err(&dev->v4l2_dev, "registering i2c adapter failed\n"); + goto error; + } +#endif /* CONFIG_I2C */ + + /* save our data pointer in this interface device */ + usb_set_intfdata(interface, dev); + + /* let the user know what node this device is now attached to */ + v4l2_info(&dev->v4l2_dev, "device now attached to /dev/video%d\n", + dev->video_dev->minor); + return 0; + +error: + if (dev) { + mutex_unlock(&dev->io_mutex); + /* this frees allocated memory */ + hdpvr_delete(dev); + } + return retval; +} + +static void hdpvr_disconnect(struct usb_interface *interface) +{ + struct hdpvr_device *dev; + int minor; + + dev = usb_get_intfdata(interface); + usb_set_intfdata(interface, NULL); + + minor = dev->video_dev->minor; + + /* prevent more I/O from starting and stop any ongoing */ + mutex_lock(&dev->io_mutex); + dev->status = STATUS_DISCONNECTED; + v4l2_device_disconnect(&dev->v4l2_dev); + video_unregister_device(dev->video_dev); + wake_up_interruptible(&dev->wait_data); + wake_up_interruptible(&dev->wait_buffer); + mutex_unlock(&dev->io_mutex); + msleep(100); + flush_workqueue(dev->workqueue); + mutex_lock(&dev->io_mutex); + hdpvr_cancel_queue(dev); + destroy_workqueue(dev->workqueue); + mutex_unlock(&dev->io_mutex); + + /* deregister I2C adapter */ +#ifdef CONFIG_I2C + mutex_lock(&dev->i2c_mutex); + if (dev->i2c_adapter) + i2c_del_adapter(dev->i2c_adapter); + kfree(dev->i2c_adapter); + dev->i2c_adapter = NULL; + mutex_unlock(&dev->i2c_mutex); +#endif /* CONFIG_I2C */ + + atomic_dec(&dev_nr); + + v4l2_info(&dev->v4l2_dev, "device /dev/video%d disconnected\n", minor); + + v4l2_device_unregister(&dev->v4l2_dev); + kfree(dev->usbc_buf); + kfree(dev); +} + + +static struct usb_driver hdpvr_usb_driver = { + .name = "hdpvr", + .probe = hdpvr_probe, + .disconnect = hdpvr_disconnect, + .id_table = hdpvr_table, +}; + +static int __init hdpvr_init(void) +{ + int result; + + /* register this driver with the USB subsystem */ + result = usb_register(&hdpvr_usb_driver); + if (result) + err("usb_register failed. Error number %d", result); + + return result; +} + +static void __exit hdpvr_exit(void) +{ + /* deregister this driver with the USB subsystem */ + usb_deregister(&hdpvr_usb_driver); +} + +module_init(hdpvr_init); +module_exit(hdpvr_exit); + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Janne Grunau"); +MODULE_DESCRIPTION("Hauppauge HD PVR driver"); diff --git a/linux/drivers/media/video/hdpvr/hdpvr-i2c.c b/linux/drivers/media/video/hdpvr/hdpvr-i2c.c new file mode 100644 index 000000000..c4b5d1515 --- /dev/null +++ b/linux/drivers/media/video/hdpvr/hdpvr-i2c.c @@ -0,0 +1,145 @@ + +/* + * Hauppauge HD PVR USB driver + * + * Copyright (C) 2008 Janne Grunau (j@jannau.net) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, version 2. + * + */ + +#include <linux/i2c.h> + +#include "hdpvr.h" + +#define CTRL_READ_REQUEST 0xb8 +#define CTRL_WRITE_REQUEST 0x38 + +#define REQTYPE_I2C_READ 0xb1 +#define REQTYPE_I2C_WRITE 0xb0 +#define REQTYPE_I2C_WRITE_STATT 0xd0 + +static int hdpvr_i2c_read(struct hdpvr_device *dev, unsigned char addr, + char *data, int len) +{ + int ret; + char *buf = kmalloc(len, GFP_KERNEL); + if (!buf) + return -ENOMEM; + + ret = usb_control_msg(dev->udev, + usb_rcvctrlpipe(dev->udev, 0), + REQTYPE_I2C_READ, CTRL_READ_REQUEST, + 0x100|addr, 0, buf, len, 1000); + + if (ret == len) { + memcpy(data, buf, len); + ret = 0; + } else if (ret >= 0) + ret = -EIO; + + kfree(buf); + + return ret; +} + +static int hdpvr_i2c_write(struct hdpvr_device *dev, unsigned char addr, + char *data, int len) +{ + int ret; + char *buf = kmalloc(len, GFP_KERNEL); + if (!buf) + return -ENOMEM; + + memcpy(buf, data, len); + ret = usb_control_msg(dev->udev, + usb_sndctrlpipe(dev->udev, 0), + REQTYPE_I2C_WRITE, CTRL_WRITE_REQUEST, + 0x100|addr, 0, buf, len, 1000); + + if (ret < 0) + goto error; + + ret = usb_control_msg(dev->udev, + usb_rcvctrlpipe(dev->udev, 0), + REQTYPE_I2C_WRITE_STATT, CTRL_READ_REQUEST, + 0, 0, buf, 2, 1000); + + if (ret == 2) + ret = 0; + else if (ret >= 0) + ret = -EIO; + +error: + kfree(buf); + return ret; +} + +static int hdpvr_transfer(struct i2c_adapter *i2c_adapter, struct i2c_msg *msgs, + int num) +{ + struct hdpvr_device *dev = i2c_get_adapdata(i2c_adapter); + int retval = 0, i, addr; + + if (num <= 0) + return 0; + + mutex_lock(&dev->i2c_mutex); + + for (i = 0; i < num && !retval; i++) { + addr = msgs[i].addr << 1; + + if (msgs[i].flags & I2C_M_RD) + retval = hdpvr_i2c_read(dev, addr, msgs[i].buf, + msgs[i].len); + else + retval = hdpvr_i2c_write(dev, addr, msgs[i].buf, + msgs[i].len); + } + + mutex_unlock(&dev->i2c_mutex); + + return retval ? retval : num; +} + +static u32 hdpvr_functionality(struct i2c_adapter *adapter) +{ + return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL; +} + +static struct i2c_algorithm hdpvr_algo = { + .master_xfer = hdpvr_transfer, + .functionality = hdpvr_functionality, +}; + +int hdpvr_register_i2c_adapter(struct hdpvr_device *dev) +{ + struct i2c_adapter *i2c_adap; + int retval = -ENOMEM; + + i2c_adap = kzalloc(sizeof(struct i2c_adapter), GFP_KERNEL); + if (i2c_adap == NULL) + goto error; + + strlcpy(i2c_adap->name, "Hauppauge HD PVR I2C", + sizeof(i2c_adap->name)); + i2c_adap->algo = &hdpvr_algo; + i2c_adap->class = I2C_CLASS_TV_ANALOG; + i2c_adap->id = I2C_HW_B_HDPVR; + i2c_adap->owner = THIS_MODULE; + i2c_adap->dev.parent = &dev->udev->dev; + + i2c_set_adapdata(i2c_adap, dev); + + retval = i2c_add_adapter(i2c_adap); + + if (!retval) + dev->i2c_adapter = i2c_adap; + else + kfree(i2c_adap); + +error: + return retval; +} diff --git a/linux/drivers/media/video/hdpvr/hdpvr-video.c b/linux/drivers/media/video/hdpvr/hdpvr-video.c new file mode 100644 index 000000000..3e6ffee8d --- /dev/null +++ b/linux/drivers/media/video/hdpvr/hdpvr-video.c @@ -0,0 +1,1248 @@ +/* + * Hauppauge HD PVR USB driver - video 4 linux 2 interface + * + * Copyright (C) 2008 Janne Grunau (j@jannau.net) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, version 2. + * + */ + +#include <linux/kernel.h> +#include <linux/errno.h> +#include <linux/init.h> +#include <linux/slab.h> +#include <linux/module.h> +#include <linux/uaccess.h> +#include <linux/usb.h> +#include <linux/mutex.h> +#include <linux/version.h> +#include <linux/workqueue.h> + +#include <linux/videodev2.h> +#include <media/v4l2-dev.h> +#include <media/v4l2-common.h> +#include <media/v4l2-ioctl.h> +#include "hdpvr.h" + +#define BULK_URB_TIMEOUT 1250 /* 1.25 seconds */ + +#define print_buffer_status() { \ + v4l2_dbg(MSG_BUFFER, hdpvr_debug, &dev->v4l2_dev, \ + "%s:%d buffer stat: %d free, %d proc\n", \ + __func__, __LINE__, \ + list_size(&dev->free_buff_list), \ + list_size(&dev->rec_buff_list)); } + +struct hdpvr_fh { + struct hdpvr_device *dev; +}; + +static uint list_size(struct list_head *list) +{ + struct list_head *tmp; + uint count = 0; + + list_for_each(tmp, list) { + count++; + } + + return count; +} + +/*=========================================================================*/ +/* urb callback */ +static void hdpvr_read_bulk_callback(struct urb *urb) +{ + struct hdpvr_buffer *buf = (struct hdpvr_buffer *)urb->context; + struct hdpvr_device *dev = buf->dev; + + /* marking buffer as received and wake waiting */ + buf->status = BUFSTAT_READY; + wake_up_interruptible(&dev->wait_data); +} + +/*=========================================================================*/ +/* bufffer bits */ + +/* function expects dev->io_mutex to be hold by caller */ +int hdpvr_cancel_queue(struct hdpvr_device *dev) +{ + struct hdpvr_buffer *buf; + + list_for_each_entry(buf, &dev->rec_buff_list, buff_list) { + usb_kill_urb(buf->urb); + buf->status = BUFSTAT_AVAILABLE; + } + + list_splice_init(&dev->rec_buff_list, dev->free_buff_list.prev); + + return 0; +} + +static int hdpvr_free_queue(struct list_head *q) +{ + struct list_head *tmp; + struct list_head *p; + struct hdpvr_buffer *buf; + struct urb *urb; + + for (p = q->next; p != q;) { + buf = list_entry(p, struct hdpvr_buffer, buff_list); + + urb = buf->urb; + usb_buffer_free(urb->dev, urb->transfer_buffer_length, + urb->transfer_buffer, urb->transfer_dma); + usb_free_urb(urb); + tmp = p->next; + list_del(p); + kfree(buf); + p = tmp; + } + + return 0; +} + +/* function expects dev->io_mutex to be hold by caller */ +int hdpvr_free_buffers(struct hdpvr_device *dev) +{ + hdpvr_cancel_queue(dev); + + hdpvr_free_queue(&dev->free_buff_list); + hdpvr_free_queue(&dev->rec_buff_list); + + return 0; +} + +/* function expects dev->io_mutex to be hold by caller */ +int hdpvr_alloc_buffers(struct hdpvr_device *dev, uint count) +{ + uint i; + int retval = -ENOMEM; + u8 *mem; + struct hdpvr_buffer *buf; + struct urb *urb; + + v4l2_dbg(MSG_INFO, hdpvr_debug, &dev->v4l2_dev, + "allocating %u buffers\n", count); + + for (i = 0; i < count; i++) { + + buf = kzalloc(sizeof(struct hdpvr_buffer), GFP_KERNEL); + if (!buf) { + v4l2_err(&dev->v4l2_dev, "cannot allocate buffer\n"); + goto exit; + } + buf->dev = dev; + + urb = usb_alloc_urb(0, GFP_KERNEL); + if (!urb) { + v4l2_err(&dev->v4l2_dev, "cannot allocate urb\n"); + goto exit; + } + buf->urb = urb; + + mem = usb_buffer_alloc(dev->udev, dev->bulk_in_size, GFP_KERNEL, + &urb->transfer_dma); + if (!mem) { + v4l2_err(&dev->v4l2_dev, + "cannot allocate usb transfer buffer\n"); + goto exit; + } + + usb_fill_bulk_urb(buf->urb, dev->udev, + usb_rcvbulkpipe(dev->udev, + dev->bulk_in_endpointAddr), + mem, dev->bulk_in_size, + hdpvr_read_bulk_callback, buf); + + buf->status = BUFSTAT_AVAILABLE; + list_add_tail(&buf->buff_list, &dev->free_buff_list); + } + return 0; +exit: + hdpvr_free_buffers(dev); + return retval; +} + +static int hdpvr_submit_buffers(struct hdpvr_device *dev) +{ + struct hdpvr_buffer *buf; + struct urb *urb; + int ret = 0, err_count = 0; + + mutex_lock(&dev->io_mutex); + + while (dev->status == STATUS_STREAMING && + !list_empty(&dev->free_buff_list)) { + + buf = list_entry(dev->free_buff_list.next, struct hdpvr_buffer, + buff_list); + if (buf->status != BUFSTAT_AVAILABLE) { + v4l2_err(&dev->v4l2_dev, + "buffer not marked as availbale\n"); + ret = -EFAULT; + goto err; + } + + urb = buf->urb; + urb->status = 0; + urb->actual_length = 0; + ret = usb_submit_urb(urb, GFP_KERNEL); + if (ret) { + v4l2_err(&dev->v4l2_dev, + "usb_submit_urb in %s returned %d\n", + __func__, ret); + if (++err_count > 2) + break; + continue; + } + buf->status = BUFSTAT_INPROGRESS; + list_move_tail(&buf->buff_list, &dev->rec_buff_list); + } +err: + print_buffer_status(); + mutex_unlock(&dev->io_mutex); + return ret; +} + +static struct hdpvr_buffer *hdpvr_get_next_buffer(struct hdpvr_device *dev) +{ + struct hdpvr_buffer *buf; + + mutex_lock(&dev->io_mutex); + + if (list_empty(&dev->rec_buff_list)) { + mutex_unlock(&dev->io_mutex); + return NULL; + } + + buf = list_entry(dev->rec_buff_list.next, struct hdpvr_buffer, + buff_list); + mutex_unlock(&dev->io_mutex); + + return buf; +} + +static void hdpvr_transmit_buffers(struct work_struct *work) +{ + struct hdpvr_device *dev = container_of(work, struct hdpvr_device, + worker); + + while (dev->status == STATUS_STREAMING) { + + if (hdpvr_submit_buffers(dev)) { + v4l2_err(&dev->v4l2_dev, "couldn't submit buffers\n"); + goto error; + } + if (wait_event_interruptible(dev->wait_buffer, + !list_empty(&dev->free_buff_list) || + dev->status != STATUS_STREAMING)) + goto error; + } + + v4l2_dbg(MSG_INFO, hdpvr_debug, &dev->v4l2_dev, + "transmit worker exited\n"); + return; +error: + v4l2_dbg(MSG_INFO, hdpvr_debug, &dev->v4l2_dev, + "transmit buffers errored\n"); + dev->status = STATUS_ERROR; +} + +/* function expects dev->io_mutex to be hold by caller */ +static int hdpvr_start_streaming(struct hdpvr_device *dev) +{ + int ret; + struct hdpvr_video_info *vidinf; + + if (dev->status == STATUS_STREAMING) + return 0; + else if (dev->status != STATUS_IDLE) + return -EAGAIN; + + vidinf = get_video_info(dev); + + if (vidinf) { + v4l2_dbg(MSG_BUFFER, hdpvr_debug, &dev->v4l2_dev, + "video signal: %dx%d@%dhz\n", vidinf->width, + vidinf->height, vidinf->fps); + kfree(vidinf); + + /* start streaming 2 request */ + ret = usb_control_msg(dev->udev, + usb_sndctrlpipe(dev->udev, 0), + 0xb8, 0x38, 0x1, 0, NULL, 0, 8000); + v4l2_dbg(MSG_BUFFER, hdpvr_debug, &dev->v4l2_dev, + "encoder start control request returned %d\n", ret); + + hdpvr_config_call(dev, CTRL_START_STREAMING_VALUE, 0x00); + + INIT_WORK(&dev->worker, hdpvr_transmit_buffers); + queue_work(dev->workqueue, &dev->worker); + + v4l2_dbg(MSG_BUFFER, hdpvr_debug, &dev->v4l2_dev, + "streaming started\n"); + dev->status = STATUS_STREAMING; + + return 0; + } + msleep(250); + v4l2_dbg(MSG_INFO, hdpvr_debug, &dev->v4l2_dev, + "no video signal at input %d\n", dev->options.video_input); + return -EAGAIN; +} + + +/* function expects dev->io_mutex to be hold by caller */ +static int hdpvr_stop_streaming(struct hdpvr_device *dev) +{ + uint actual_length, c = 0; + u8 *buf; + + if (dev->status == STATUS_IDLE) + return 0; + else if (dev->status != STATUS_STREAMING) + return -EAGAIN; + + buf = kmalloc(dev->bulk_in_size, GFP_KERNEL); + if (!buf) + v4l2_err(&dev->v4l2_dev, "failed to allocate temporary buffer " + "for emptying the internal device buffer. " + "Next capture start will be slow\n"); + + dev->status = STATUS_SHUTTING_DOWN; + hdpvr_config_call(dev, CTRL_STOP_STREAMING_VALUE, 0x00); + mutex_unlock(&dev->io_mutex); + + wake_up_interruptible(&dev->wait_buffer); + msleep(50); + + flush_workqueue(dev->workqueue); + + mutex_lock(&dev->io_mutex); + /* kill the still outstanding urbs */ + hdpvr_cancel_queue(dev); + + /* emptying the device buffer beforeshutting it down */ + while (buf && ++c < 500 && + !usb_bulk_msg(dev->udev, + usb_rcvbulkpipe(dev->udev, + dev->bulk_in_endpointAddr), + buf, dev->bulk_in_size, &actual_length, + BULK_URB_TIMEOUT)) { + /* wait */ + msleep(5); + v4l2_dbg(MSG_BUFFER, hdpvr_debug, &dev->v4l2_dev, + "%2d: got %d bytes\n", c, actual_length); + } + kfree(buf); + v4l2_dbg(MSG_BUFFER, hdpvr_debug, &dev->v4l2_dev, + "used %d urbs to empty device buffers\n", c-1); + msleep(10); + + dev->status = STATUS_IDLE; + + return 0; +} + + +/*=======================================================================*/ +/* + * video 4 linux 2 file operations + */ + +static int hdpvr_open(struct file *file) +{ + struct hdpvr_device *dev; + struct hdpvr_fh *fh; + int retval = -ENOMEM; + + dev = (struct hdpvr_device *)video_get_drvdata(video_devdata(file)); + if (!dev) { + v4l2_err(&dev->v4l2_dev, "open failing with with ENODEV\n"); + retval = -ENODEV; + goto err; + } + + fh = kzalloc(sizeof(struct hdpvr_fh), GFP_KERNEL); + if (!fh) { + v4l2_err(&dev->v4l2_dev, "Out of memory\n"); + goto err; + } + /* lock the device to allow correctly handling errors + * in resumption */ + mutex_lock(&dev->io_mutex); + dev->open_count++; + + fh->dev = dev; + + /* save our object in the file's private structure */ + file->private_data = fh; + + retval = 0; +err: + mutex_unlock(&dev->io_mutex); + return retval; +} + +static int hdpvr_release(struct file *file) +{ + struct hdpvr_fh *fh = (struct hdpvr_fh *)file->private_data; + struct hdpvr_device *dev = fh->dev; + + if (!dev) + return -ENODEV; + + mutex_lock(&dev->io_mutex); + if (!(--dev->open_count) && dev->status == STATUS_STREAMING) + hdpvr_stop_streaming(dev); + + mutex_unlock(&dev->io_mutex); + + return 0; +} + +/* + * hdpvr_v4l2_read() + * will allocate buffers when called for the first time + */ +static ssize_t hdpvr_read(struct file *file, char __user *buffer, size_t count, + loff_t *pos) +{ + struct hdpvr_fh *fh = file->private_data; + struct hdpvr_device *dev = fh->dev; + struct hdpvr_buffer *buf = NULL; + struct urb *urb; + unsigned int ret = 0; + int rem, cnt; + + if (*pos) + return -ESPIPE; + + if (!dev) + return -ENODEV; + + mutex_lock(&dev->io_mutex); + if (dev->status == STATUS_IDLE) { + if (hdpvr_start_streaming(dev)) { + v4l2_dbg(MSG_INFO, hdpvr_debug, &dev->v4l2_dev, + "start_streaming failed\n"); + ret = -EIO; + msleep(200); + dev->status = STATUS_IDLE; + mutex_unlock(&dev->io_mutex); + goto err; + } + print_buffer_status(); + } + mutex_unlock(&dev->io_mutex); + + /* wait for the first buffer */ + if (!(file->f_flags & O_NONBLOCK)) { + if (wait_event_interruptible(dev->wait_data, + hdpvr_get_next_buffer(dev))) + return -ERESTARTSYS; + } + + buf = hdpvr_get_next_buffer(dev); + + while (count > 0 && buf) { + + if (buf->status != BUFSTAT_READY && + dev->status != STATUS_DISCONNECTED) { + /* return nonblocking */ + if (file->f_flags & O_NONBLOCK) { + if (!ret) + ret = -EAGAIN; + goto err; + } + + if (wait_event_interruptible(dev->wait_data, + buf->status == BUFSTAT_READY)) { + ret = -ERESTARTSYS; + goto err; + } + } + + if (buf->status != BUFSTAT_READY) + break; + + /* set remaining bytes to copy */ + urb = buf->urb; + rem = urb->actual_length - buf->pos; + cnt = rem > count ? count : rem; + + if (copy_to_user(buffer, urb->transfer_buffer + buf->pos, + cnt)) { + v4l2_err(&dev->v4l2_dev, "read: copy_to_user failed\n"); + if (!ret) + ret = -EFAULT; + goto err; + } + + buf->pos += cnt; + count -= cnt; + buffer += cnt; + ret += cnt; + + /* finished, take next buffer */ + if (buf->pos == urb->actual_length) { + mutex_lock(&dev->io_mutex); + buf->pos = 0; + buf->status = BUFSTAT_AVAILABLE; + + list_move_tail(&buf->buff_list, &dev->free_buff_list); + + print_buffer_status(); + + mutex_unlock(&dev->io_mutex); + + wake_up_interruptible(&dev->wait_buffer); + + buf = hdpvr_get_next_buffer(dev); + } + } +err: + if (!ret && !buf) + ret = -EAGAIN; + return ret; +} + +static unsigned int hdpvr_poll(struct file *filp, poll_table *wait) +{ + struct hdpvr_buffer *buf = NULL; + struct hdpvr_fh *fh = (struct hdpvr_fh *)filp->private_data; + struct hdpvr_device *dev = fh->dev; + unsigned int mask = 0; + + mutex_lock(&dev->io_mutex); + + if (video_is_unregistered(dev->video_dev)) + return -EIO; + + if (dev->status == STATUS_IDLE) { + if (hdpvr_start_streaming(dev)) { + v4l2_dbg(MSG_BUFFER, hdpvr_debug, &dev->v4l2_dev, + "start_streaming failed\n"); + dev->status = STATUS_IDLE; + } + + print_buffer_status(); + } + mutex_unlock(&dev->io_mutex); + + buf = hdpvr_get_next_buffer(dev); + /* only wait if no data is available */ + if (!buf || buf->status != BUFSTAT_READY) { + poll_wait(filp, &dev->wait_data, wait); + buf = hdpvr_get_next_buffer(dev); + } + if (buf && buf->status == BUFSTAT_READY) + mask |= POLLIN | POLLRDNORM; + + return mask; +} + + +static const struct v4l2_file_operations hdpvr_fops = { + .owner = THIS_MODULE, + .open = hdpvr_open, + .release = hdpvr_release, + .read = hdpvr_read, + .poll = hdpvr_poll, + .unlocked_ioctl = video_ioctl2, +}; + +/*=======================================================================*/ +/* + * V4L2 ioctl handling + */ + +static int vidioc_querycap(struct file *file, void *priv, + struct v4l2_capability *cap) +{ + struct hdpvr_device *dev = video_drvdata(file); + + strcpy(cap->driver, "hdpvr"); + strcpy(cap->card, "Haupauge HD PVR"); + usb_make_path(dev->udev, cap->bus_info, sizeof(cap->bus_info)); + cap->version = HDPVR_VERSION; + cap->capabilities = V4L2_CAP_VIDEO_CAPTURE | + V4L2_CAP_AUDIO | + V4L2_CAP_READWRITE; + return 0; +} + +static int vidioc_s_std(struct file *file, void *private_data, + v4l2_std_id *std) +{ + struct hdpvr_fh *fh = file->private_data; + struct hdpvr_device *dev = fh->dev; + u8 std_type = 1; + + if (*std & (V4L2_STD_NTSC | V4L2_STD_PAL_60)) + std_type = 0; + + return hdpvr_config_call(dev, CTRL_VIDEO_STD_TYPE, std_type); +} + +static const char *iname[] = { + [HDPVR_COMPONENT] = "Component", + [HDPVR_SVIDEO] = "S-Video", + [HDPVR_COMPOSITE] = "Composite", +}; + +static int vidioc_enum_input(struct file *file, void *priv, + struct v4l2_input *i) +{ + struct hdpvr_fh *fh = file->private_data; + struct hdpvr_device *dev = fh->dev; + unsigned int n; + + n = i->index; + if (n >= HDPVR_VIDEO_INPUTS) + return -EINVAL; + + i->type = V4L2_INPUT_TYPE_CAMERA; + + strncpy(i->name, iname[n], sizeof(i->name) - 1); + i->name[sizeof(i->name) - 1] = '\0'; + + i->audioset = 1<<HDPVR_RCA_FRONT | 1<<HDPVR_RCA_BACK | 1<<HDPVR_SPDIF; + + i->std = dev->video_dev->tvnorms; + + return 0; +} + +static int vidioc_s_input(struct file *file, void *private_data, + unsigned int index) +{ + struct hdpvr_fh *fh = file->private_data; + struct hdpvr_device *dev = fh->dev; + int retval; + + if (index >= HDPVR_VIDEO_INPUTS) + return -EINVAL; + + if (dev->status != STATUS_IDLE) + return -EAGAIN; + + retval = hdpvr_config_call(dev, CTRL_VIDEO_INPUT_VALUE, index+1); + if (!retval) + dev->options.video_input = index; + + return retval; +} + +static int vidioc_g_input(struct file *file, void *private_data, + unsigned int *index) +{ + struct hdpvr_fh *fh = file->private_data; + struct hdpvr_device *dev = fh->dev; + + *index = dev->options.video_input; + return 0; +} + + +static const char *audio_iname[] = { + [HDPVR_RCA_FRONT] = "RCA front", + [HDPVR_RCA_BACK] = "RCA back", + [HDPVR_SPDIF] = "SPDIF", +}; + +static int vidioc_enumaudio(struct file *file, void *priv, + struct v4l2_audio *audio) +{ + unsigned int n; + + n = audio->index; + if (n >= HDPVR_AUDIO_INPUTS) + return -EINVAL; + + audio->capability = V4L2_AUDCAP_STEREO; + + strncpy(audio->name, audio_iname[n], sizeof(audio->name) - 1); + audio->name[sizeof(audio->name) - 1] = '\0'; + + return 0; +} + +static int vidioc_s_audio(struct file *file, void *private_data, + struct v4l2_audio *audio) +{ + struct hdpvr_fh *fh = file->private_data; + struct hdpvr_device *dev = fh->dev; + int retval; + + if (audio->index >= HDPVR_AUDIO_INPUTS) + return -EINVAL; + + if (dev->status != STATUS_IDLE) + return -EAGAIN; + + retval = hdpvr_set_audio(dev, audio->index+1, dev->options.audio_codec); + if (!retval) + dev->options.audio_input = audio->index; + + return retval; +} + +static int vidioc_g_audio(struct file *file, void *private_data, + struct v4l2_audio *audio) +{ + struct hdpvr_fh *fh = file->private_data; + struct hdpvr_device *dev = fh->dev; + + audio->index = dev->options.audio_input; + audio->capability = V4L2_AUDCAP_STEREO; + strncpy(audio->name, audio_iname[audio->index], sizeof(audio->name)); + audio->name[sizeof(audio->name) - 1] = '\0'; + return 0; +} + +static const s32 supported_v4l2_ctrls[] = { + V4L2_CID_BRIGHTNESS, + V4L2_CID_CONTRAST, + V4L2_CID_SATURATION, + V4L2_CID_HUE, + V4L2_CID_SHARPNESS, + V4L2_CID_MPEG_AUDIO_ENCODING, + V4L2_CID_MPEG_VIDEO_ENCODING, + V4L2_CID_MPEG_VIDEO_BITRATE_MODE, + V4L2_CID_MPEG_VIDEO_BITRATE, + V4L2_CID_MPEG_VIDEO_BITRATE_PEAK, +}; + +static int fill_queryctrl(struct hdpvr_options *opt, struct v4l2_queryctrl *qc, + int ac3) +{ + int err; + + switch (qc->id) { + case V4L2_CID_BRIGHTNESS: + return v4l2_ctrl_query_fill(qc, 0x0, 0xff, 1, 0x86); + case V4L2_CID_CONTRAST: + return v4l2_ctrl_query_fill(qc, 0x0, 0xff, 1, 0x80); + case V4L2_CID_SATURATION: + return v4l2_ctrl_query_fill(qc, 0x0, 0xff, 1, 0x80); + case V4L2_CID_HUE: + return v4l2_ctrl_query_fill(qc, 0x0, 0xff, 1, 0x80); + case V4L2_CID_SHARPNESS: + return v4l2_ctrl_query_fill(qc, 0x0, 0xff, 1, 0x80); + case V4L2_CID_MPEG_AUDIO_ENCODING: + return v4l2_ctrl_query_fill( + qc, V4L2_MPEG_AUDIO_ENCODING_AAC, + ac3 ? V4L2_MPEG_AUDIO_ENCODING_AC3 + : V4L2_MPEG_AUDIO_ENCODING_AAC, + 1, V4L2_MPEG_AUDIO_ENCODING_AAC); + case V4L2_CID_MPEG_VIDEO_ENCODING: + return v4l2_ctrl_query_fill( + qc, V4L2_MPEG_VIDEO_ENCODING_MPEG_4_AVC, + V4L2_MPEG_VIDEO_ENCODING_MPEG_4_AVC, 1, + V4L2_MPEG_VIDEO_ENCODING_MPEG_4_AVC); + +/* case V4L2_CID_MPEG_VIDEO_? maybe keyframe interval: */ +/* return v4l2_ctrl_query_fill(qc, 0, 128, 128, 0); */ + case V4L2_CID_MPEG_VIDEO_BITRATE_MODE: + return v4l2_ctrl_query_fill( + qc, V4L2_MPEG_VIDEO_BITRATE_MODE_VBR, + V4L2_MPEG_VIDEO_BITRATE_MODE_CBR, 1, + V4L2_MPEG_VIDEO_BITRATE_MODE_CBR); + + case V4L2_CID_MPEG_VIDEO_BITRATE: + return v4l2_ctrl_query_fill(qc, 1000000, 13500000, 100000, + 6500000); + case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK: + err = v4l2_ctrl_query_fill(qc, 1100000, 20200000, 100000, + 9000000); + if (!err && opt->bitrate_mode == HDPVR_CONSTANT) + qc->flags |= V4L2_CTRL_FLAG_INACTIVE; + return err; + default: + return -EINVAL; + } +} + +static int vidioc_queryctrl(struct file *file, void *private_data, + struct v4l2_queryctrl *qc) +{ + struct hdpvr_fh *fh = file->private_data; + struct hdpvr_device *dev = fh->dev; + int i, next; + u32 id = qc->id; + + memset(qc, 0, sizeof(*qc)); + + next = !!(id & V4L2_CTRL_FLAG_NEXT_CTRL); + qc->id = id & ~V4L2_CTRL_FLAG_NEXT_CTRL; + + for (i = 0; i < ARRAY_SIZE(supported_v4l2_ctrls); i++) { + if (next) { + if (qc->id < supported_v4l2_ctrls[i]) + qc->id = supported_v4l2_ctrls[i]; + else + continue; + } + + if (qc->id == supported_v4l2_ctrls[i]) + return fill_queryctrl(&dev->options, qc, + dev->flags & HDPVR_FLAG_AC3_CAP); + + if (qc->id < supported_v4l2_ctrls[i]) + break; + } + + return -EINVAL; +} + +static int vidioc_g_ctrl(struct file *file, void *private_data, + struct v4l2_control *ctrl) +{ + struct hdpvr_fh *fh = file->private_data; + struct hdpvr_device *dev = fh->dev; + + switch (ctrl->id) { + case V4L2_CID_BRIGHTNESS: + ctrl->value = dev->options.brightness; + break; + case V4L2_CID_CONTRAST: + ctrl->value = dev->options.contrast; + break; + case V4L2_CID_SATURATION: + ctrl->value = dev->options.saturation; + break; + case V4L2_CID_HUE: + ctrl->value = dev->options.hue; + break; + case V4L2_CID_SHARPNESS: + ctrl->value = dev->options.sharpness; + break; + default: + return -EINVAL; + } + return 0; +} + +static int vidioc_s_ctrl(struct file *file, void *private_data, + struct v4l2_control *ctrl) +{ + struct hdpvr_fh *fh = file->private_data; + struct hdpvr_device *dev = fh->dev; + int retval; + + switch (ctrl->id) { + case V4L2_CID_BRIGHTNESS: + retval = hdpvr_config_call(dev, CTRL_BRIGHTNESS, ctrl->value); + if (!retval) + dev->options.brightness = ctrl->value; + break; + case V4L2_CID_CONTRAST: + retval = hdpvr_config_call(dev, CTRL_CONTRAST, ctrl->value); + if (!retval) + dev->options.contrast = ctrl->value; + break; + case V4L2_CID_SATURATION: + retval = hdpvr_config_call(dev, CTRL_SATURATION, ctrl->value); + if (!retval) + dev->options.saturation = ctrl->value; + break; + case V4L2_CID_HUE: + retval = hdpvr_config_call(dev, CTRL_HUE, ctrl->value); + if (!retval) + dev->options.hue = ctrl->value; + break; + case V4L2_CID_SHARPNESS: + retval = hdpvr_config_call(dev, CTRL_SHARPNESS, ctrl->value); + if (!retval) + dev->options.sharpness = ctrl->value; + break; + default: + return -EINVAL; + } + + return retval; +} + + +static int hdpvr_get_ctrl(struct hdpvr_options *opt, + struct v4l2_ext_control *ctrl) +{ + switch (ctrl->id) { + case V4L2_CID_MPEG_AUDIO_ENCODING: + ctrl->value = opt->audio_codec; + break; + case V4L2_CID_MPEG_VIDEO_ENCODING: + ctrl->value = V4L2_MPEG_VIDEO_ENCODING_MPEG_4_AVC; + break; +/* case V4L2_CID_MPEG_VIDEO_B_FRAMES: */ +/* ctrl->value = (opt->gop_mode & 0x2) ? 0 : 128; */ +/* break; */ + case V4L2_CID_MPEG_VIDEO_BITRATE_MODE: + ctrl->value = opt->bitrate_mode == HDPVR_CONSTANT + ? V4L2_MPEG_VIDEO_BITRATE_MODE_CBR + : V4L2_MPEG_VIDEO_BITRATE_MODE_VBR; + break; + case V4L2_CID_MPEG_VIDEO_BITRATE: + ctrl->value = opt->bitrate * 100000; + break; + case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK: + ctrl->value = opt->peak_bitrate * 100000; + break; + case V4L2_CID_MPEG_STREAM_TYPE: + ctrl->value = V4L2_MPEG_STREAM_TYPE_MPEG2_TS; + break; + default: + return -EINVAL; + } + return 0; +} + +static int vidioc_g_ext_ctrls(struct file *file, void *priv, + struct v4l2_ext_controls *ctrls) +{ + struct hdpvr_fh *fh = file->private_data; + struct hdpvr_device *dev = fh->dev; + int i, err = 0; + + if (ctrls->ctrl_class == V4L2_CTRL_CLASS_MPEG) { + for (i = 0; i < ctrls->count; i++) { + struct v4l2_ext_control *ctrl = ctrls->controls + i; + + err = hdpvr_get_ctrl(&dev->options, ctrl); + if (err) { + ctrls->error_idx = i; + break; + } + } + return err; + + } + + return -EINVAL; +} + + +static int hdpvr_try_ctrl(struct v4l2_ext_control *ctrl, int ac3) +{ + int ret = -EINVAL; + + switch (ctrl->id) { + case V4L2_CID_MPEG_AUDIO_ENCODING: + if (ctrl->value == V4L2_MPEG_AUDIO_ENCODING_AAC || + (ac3 && ctrl->value == V4L2_MPEG_AUDIO_ENCODING_AC3)) + ret = 0; + break; + case V4L2_CID_MPEG_VIDEO_ENCODING: + if (ctrl->value == V4L2_MPEG_VIDEO_ENCODING_MPEG_4_AVC) + ret = 0; + break; +/* case V4L2_CID_MPEG_VIDEO_B_FRAMES: */ +/* if (ctrl->value == 0 || ctrl->value == 128) */ +/* ret = 0; */ +/* break; */ + case V4L2_CID_MPEG_VIDEO_BITRATE_MODE: + if (ctrl->value == V4L2_MPEG_VIDEO_BITRATE_MODE_CBR || + ctrl->value == V4L2_MPEG_VIDEO_BITRATE_MODE_VBR) + ret = 0; + break; + case V4L2_CID_MPEG_VIDEO_BITRATE: + { + uint bitrate = ctrl->value / 100000; + if (bitrate >= 10 && bitrate <= 135) + ret = 0; + break; + } + case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK: + { + uint peak_bitrate = ctrl->value / 100000; + if (peak_bitrate >= 10 && peak_bitrate <= 202) + ret = 0; + break; + } + case V4L2_CID_MPEG_STREAM_TYPE: + if (ctrl->value == V4L2_MPEG_STREAM_TYPE_MPEG2_TS) + ret = 0; + break; + default: + return -EINVAL; + } + return 0; +} + +static int vidioc_try_ext_ctrls(struct file *file, void *priv, + struct v4l2_ext_controls *ctrls) +{ + struct hdpvr_fh *fh = file->private_data; + struct hdpvr_device *dev = fh->dev; + int i, err = 0; + + if (ctrls->ctrl_class == V4L2_CTRL_CLASS_MPEG) { + for (i = 0; i < ctrls->count; i++) { + struct v4l2_ext_control *ctrl = ctrls->controls + i; + + err = hdpvr_try_ctrl(ctrl, + dev->flags & HDPVR_FLAG_AC3_CAP); + if (err) { + ctrls->error_idx = i; + break; + } + } + return err; + } + + return -EINVAL; +} + + +static int hdpvr_set_ctrl(struct hdpvr_device *dev, + struct v4l2_ext_control *ctrl) +{ + struct hdpvr_options *opt = &dev->options; + int ret = 0; + + switch (ctrl->id) { + case V4L2_CID_MPEG_AUDIO_ENCODING: + if (dev->flags & HDPVR_FLAG_AC3_CAP) { + opt->audio_codec = ctrl->value; + ret = hdpvr_set_audio(dev, opt->audio_input, + opt->audio_codec); + } + break; + case V4L2_CID_MPEG_VIDEO_ENCODING: + break; +/* case V4L2_CID_MPEG_VIDEO_B_FRAMES: */ +/* if (ctrl->value == 0 && !(opt->gop_mode & 0x2)) { */ +/* opt->gop_mode |= 0x2; */ +/* hdpvr_config_call(dev, CTRL_GOP_MODE_VALUE, */ +/* opt->gop_mode); */ +/* } */ +/* if (ctrl->value == 128 && opt->gop_mode & 0x2) { */ +/* opt->gop_mode &= ~0x2; */ +/* hdpvr_config_call(dev, CTRL_GOP_MODE_VALUE, */ +/* opt->gop_mode); */ +/* } */ +/* break; */ + case V4L2_CID_MPEG_VIDEO_BITRATE_MODE: + if (ctrl->value == V4L2_MPEG_VIDEO_BITRATE_MODE_CBR && + opt->bitrate_mode != HDPVR_CONSTANT) { + opt->bitrate_mode = HDPVR_CONSTANT; + hdpvr_config_call(dev, CTRL_BITRATE_MODE_VALUE, + opt->bitrate_mode); + } + if (ctrl->value == V4L2_MPEG_VIDEO_BITRATE_MODE_VBR && + opt->bitrate_mode == HDPVR_CONSTANT) { + opt->bitrate_mode = HDPVR_VARIABLE_AVERAGE; + hdpvr_config_call(dev, CTRL_BITRATE_MODE_VALUE, + opt->bitrate_mode); + } + break; + case V4L2_CID_MPEG_VIDEO_BITRATE: { + uint bitrate = ctrl->value / 100000; + + opt->bitrate = bitrate; + if (bitrate >= opt->peak_bitrate) + opt->peak_bitrate = bitrate+1; + + hdpvr_set_bitrate(dev); + break; + } + case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK: { + uint peak_bitrate = ctrl->value / 100000; + + if (opt->bitrate_mode == HDPVR_CONSTANT) + break; + + if (opt->bitrate < peak_bitrate) { + opt->peak_bitrate = peak_bitrate; + hdpvr_set_bitrate(dev); + } else + ret = -EINVAL; + break; + } + case V4L2_CID_MPEG_STREAM_TYPE: + break; + default: + return -EINVAL; + } + return ret; +} + +static int vidioc_s_ext_ctrls(struct file *file, void *priv, + struct v4l2_ext_controls *ctrls) +{ + struct hdpvr_fh *fh = file->private_data; + struct hdpvr_device *dev = fh->dev; + int i, err = 0; + + if (ctrls->ctrl_class == V4L2_CTRL_CLASS_MPEG) { + for (i = 0; i < ctrls->count; i++) { + struct v4l2_ext_control *ctrl = ctrls->controls + i; + + err = hdpvr_try_ctrl(ctrl, + dev->flags & HDPVR_FLAG_AC3_CAP); + if (err) { + ctrls->error_idx = i; + break; + } + err = hdpvr_set_ctrl(dev, ctrl); + if (err) { + ctrls->error_idx = i; + break; + } + } + return err; + + } + + return -EINVAL; +} + +static int vidioc_enum_fmt_vid_cap(struct file *file, void *private_data, + struct v4l2_fmtdesc *f) +{ + + if (f->index != 0 || f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) + return -EINVAL; + + f->flags = V4L2_FMT_FLAG_COMPRESSED; + strncpy(f->description, "MPEG2-TS with AVC/AAC streams", 32); + f->pixelformat = V4L2_PIX_FMT_MPEG; + + return 0; +} + +static int vidioc_g_fmt_vid_cap(struct file *file, void *private_data, + struct v4l2_format *f) +{ + struct hdpvr_fh *fh = file->private_data; + struct hdpvr_device *dev = fh->dev; + struct hdpvr_video_info *vid_info; + + if (!dev) + return -ENODEV; + + vid_info = get_video_info(dev); + if (!vid_info) + return -EFAULT; + + f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; + f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG; + f->fmt.pix.width = vid_info->width; + f->fmt.pix.height = vid_info->height; + f->fmt.pix.sizeimage = dev->bulk_in_size; + f->fmt.pix.colorspace = 0; + f->fmt.pix.bytesperline = 0; + f->fmt.pix.field = V4L2_FIELD_ANY; + + kfree(vid_info); + return 0; +} + +static int vidioc_encoder_cmd(struct file *filp, void *priv, + struct v4l2_encoder_cmd *a) +{ + struct hdpvr_fh *fh = filp->private_data; + struct hdpvr_device *dev = fh->dev; + int res; + + mutex_lock(&dev->io_mutex); + + memset(&a->raw, 0, sizeof(a->raw)); + switch (a->cmd) { + case V4L2_ENC_CMD_START: + a->flags = 0; + res = hdpvr_start_streaming(dev); + break; + case V4L2_ENC_CMD_STOP: + res = hdpvr_stop_streaming(dev); + break; + default: + v4l2_dbg(MSG_INFO, hdpvr_debug, &dev->v4l2_dev, + "Unsupported encoder cmd %d\n", a->cmd); + res = -EINVAL; + } + mutex_unlock(&dev->io_mutex); + return res; +} + +static int vidioc_try_encoder_cmd(struct file *filp, void *priv, + struct v4l2_encoder_cmd *a) +{ + switch (a->cmd) { + case V4L2_ENC_CMD_START: + case V4L2_ENC_CMD_STOP: + return 0; + default: + return -EINVAL; + } +} + +static const struct v4l2_ioctl_ops hdpvr_ioctl_ops = { + .vidioc_querycap = vidioc_querycap, + .vidioc_s_std = vidioc_s_std, + .vidioc_enum_input = vidioc_enum_input, + .vidioc_g_input = vidioc_g_input, + .vidioc_s_input = vidioc_s_input, + .vidioc_enumaudio = vidioc_enumaudio, + .vidioc_g_audio = vidioc_g_audio, + .vidioc_s_audio = vidioc_s_audio, + .vidioc_queryctrl = vidioc_queryctrl, + .vidioc_g_ctrl = vidioc_g_ctrl, + .vidioc_s_ctrl = vidioc_s_ctrl, + .vidioc_g_ext_ctrls = vidioc_g_ext_ctrls, + .vidioc_s_ext_ctrls = vidioc_s_ext_ctrls, + .vidioc_try_ext_ctrls = vidioc_try_ext_ctrls, + .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap, + .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap, + .vidioc_encoder_cmd = vidioc_encoder_cmd, + .vidioc_try_encoder_cmd = vidioc_try_encoder_cmd, +}; + +static void hdpvr_device_release(struct video_device *vdev) +{ + struct hdpvr_device *dev = video_get_drvdata(vdev); + + hdpvr_delete(dev); +} + +static const struct video_device hdpvr_video_template = { +/* .type = VFL_TYPE_GRABBER, */ +/* .type2 = VID_TYPE_CAPTURE | VID_TYPE_MPEG_ENCODER, */ + .fops = &hdpvr_fops, + .release = hdpvr_device_release, + .ioctl_ops = &hdpvr_ioctl_ops, + .tvnorms = + V4L2_STD_NTSC | V4L2_STD_SECAM | V4L2_STD_PAL_B | + V4L2_STD_PAL_G | V4L2_STD_PAL_H | V4L2_STD_PAL_I | + V4L2_STD_PAL_D | V4L2_STD_PAL_M | V4L2_STD_PAL_N | + V4L2_STD_PAL_60, +}; + +int hdpvr_register_videodev(struct hdpvr_device *dev, struct device *parent, + int devnum) +{ + /* setup and register video device */ + dev->video_dev = video_device_alloc(); + if (!dev->video_dev) { + v4l2_err(&dev->v4l2_dev, "video_device_alloc() failed\n"); + goto error; + } + + *(dev->video_dev) = hdpvr_video_template; + strcpy(dev->video_dev->name, "Hauppauge HD PVR"); + dev->video_dev->parent = parent; + video_set_drvdata(dev->video_dev, dev); + + if (video_register_device(dev->video_dev, VFL_TYPE_GRABBER, devnum)) { + v4l2_err(&dev->v4l2_dev, "video_device registration failed\n"); + goto error; + } + + return 0; +error: + return -ENOMEM; +} diff --git a/linux/drivers/media/video/hdpvr/hdpvr.h b/linux/drivers/media/video/hdpvr/hdpvr.h new file mode 100644 index 000000000..1edd87591 --- /dev/null +++ b/linux/drivers/media/video/hdpvr/hdpvr.h @@ -0,0 +1,303 @@ +/* + * Hauppauge HD PVR USB driver + * + * Copyright (C) 2008 Janne Grunau (j@jannau.net) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, version 2. + * + */ + +#include <linux/usb.h> +#include <linux/i2c.h> +#include <linux/mutex.h> +#include <linux/workqueue.h> +#include <linux/videodev2.h> + +#include <media/v4l2-device.h> + +#define HDPVR_MAJOR_VERSION 0 +#define HDPVR_MINOR_VERSION 2 +#define HDPVR_RELEASE 0 +#define HDPVR_VERSION \ + KERNEL_VERSION(HDPVR_MAJOR_VERSION, HDPVR_MINOR_VERSION, HDPVR_RELEASE) + +#define HDPVR_MAX 8 + +/* Define these values to match your devices */ +#define HD_PVR_VENDOR_ID 0x2040 +#define HD_PVR_PRODUCT_ID 0x4900 +#define HD_PVR_PRODUCT_ID1 0x4901 +#define HD_PVR_PRODUCT_ID2 0x4902 + +#define UNSET (-1U) + +#define NUM_BUFFERS 64 + +#define HDPVR_FIRMWARE_VERSION 0x8 +#define HDPVR_FIRMWARE_VERSION_AC3 0xd + +/* #define HDPVR_DEBUG */ + +extern int hdpvr_debug; + +#define MSG_INFO 1 +#define MSG_BUFFER 2 + +struct hdpvr_options { + u8 video_std; + u8 video_input; + u8 audio_input; + u8 bitrate; /* in 100kbps */ + u8 peak_bitrate; /* in 100kbps */ + u8 bitrate_mode; + u8 gop_mode; + enum v4l2_mpeg_audio_encoding audio_codec; + u8 brightness; + u8 contrast; + u8 hue; + u8 saturation; + u8 sharpness; +}; + +/* Structure to hold all of our device specific stuff */ +struct hdpvr_device { + /* the v4l device for this device */ + struct video_device *video_dev; + /* the usb device for this device */ + struct usb_device *udev; + /* v4l2-device unused */ + struct v4l2_device v4l2_dev; + + /* the max packet size of the bulk endpoint */ + size_t bulk_in_size; + /* the address of the bulk in endpoint */ + __u8 bulk_in_endpointAddr; + + /* holds the current device status */ + __u8 status; + /* count the number of openers */ + uint open_count; + + /* holds the cureent set options */ + struct hdpvr_options options; + + uint flags; + + /* synchronize I/O */ + struct mutex io_mutex; + /* available buffers */ + struct list_head free_buff_list; + /* in progress buffers */ + struct list_head rec_buff_list; + /* waitqueue for buffers */ + wait_queue_head_t wait_buffer; + /* waitqueue for data */ + wait_queue_head_t wait_data; + /**/ + struct workqueue_struct *workqueue; + /**/ + struct work_struct worker; + + /* I2C adapter */ + struct i2c_adapter *i2c_adapter; + /* I2C lock */ + struct mutex i2c_mutex; + + /* usb control transfer buffer and lock */ + struct mutex usbc_mutex; + u8 *usbc_buf; +}; + + +/* buffer one bulk urb of data */ +struct hdpvr_buffer { + struct list_head buff_list; + + struct urb *urb; + + struct hdpvr_device *dev; + + uint pos; + + __u8 status; +}; + +/* */ + +struct hdpvr_video_info { + u16 width; + u16 height; + u8 fps; +}; + +enum { + STATUS_UNINITIALIZED = 0, + STATUS_IDLE, + STATUS_STARTING, + STATUS_SHUTTING_DOWN, + STATUS_STREAMING, + STATUS_ERROR, + STATUS_DISCONNECTED, +}; + +enum { + HDPVR_FLAG_AC3_CAP = 1, +}; + +enum { + BUFSTAT_UNINITIALIZED = 0, + BUFSTAT_AVAILABLE, + BUFSTAT_INPROGRESS, + BUFSTAT_READY, +}; + +#define CTRL_START_STREAMING_VALUE 0x0700 +#define CTRL_STOP_STREAMING_VALUE 0x0800 +#define CTRL_BITRATE_VALUE 0x1000 +#define CTRL_BITRATE_MODE_VALUE 0x1200 +#define CTRL_GOP_MODE_VALUE 0x1300 +#define CTRL_VIDEO_INPUT_VALUE 0x1500 +#define CTRL_VIDEO_STD_TYPE 0x1700 +#define CTRL_AUDIO_INPUT_VALUE 0x2500 +#define CTRL_BRIGHTNESS 0x2900 +#define CTRL_CONTRAST 0x2a00 +#define CTRL_HUE 0x2b00 +#define CTRL_SATURATION 0x2c00 +#define CTRL_SHARPNESS 0x2d00 +#define CTRL_LOW_PASS_FILTER_VALUE 0x3100 + +#define CTRL_DEFAULT_INDEX 0x0003 + + + /* :0 s 38 01 1000 0003 0004 4 = 0a00ca00 + * BITRATE SETTING + * 1st and 2nd byte (little endian): average bitrate in 100 000 bit/s + * min: 1 mbit/s, max: 13.5 mbit/s + * 3rd and 4th byte (little endian): peak bitrate in 100 000 bit/s + * min: average + 100kbit/s, + * max: 20.2 mbit/s + */ + + /* :0 s 38 01 1200 0003 0001 1 = 02 + * BIT RATE MODE + * constant = 1, variable (peak) = 2, variable (average) = 3 + */ + + /* :0 s 38 01 1300 0003 0001 1 = 03 + * GOP MODE (2 bit) + * low bit 0/1: advanced/simple GOP + * high bit 0/1: IDR(4/32/128) / no IDR (4/32/0) + */ + + /* :0 s 38 01 1700 0003 0001 1 = 00 + * VIDEO STANDARD or FREQUNCY 0 = 60hz, 1 = 50hz + */ + + /* :0 s 38 01 3100 0003 0004 4 = 03030000 + * FILTER CONTROL + * 1st byte luma low pass filter strength, + * 2nd byte chroma low pass filter strength, + * 3rd byte MF enable chroma, min=0, max=1 + * 4th byte n + */ + + + /* :0 s 38 b9 0001 0000 0000 0 */ + + + +/* :0 s 38 d3 0000 0000 0001 1 = 00 */ +/* ret = usb_control_msg(dev->udev, */ +/* usb_sndctrlpipe(dev->udev, 0), */ +/* 0xd3, 0x38, */ +/* 0, 0, */ +/* "\0", 1, */ +/* 1000); */ + +/* info("control request returned %d", ret); */ +/* msleep(5000); */ + + + /* :0 s b8 81 1400 0003 0005 5 < + * :0 0 5 = d0024002 19 + * QUERY FRAME SIZE AND RATE + * 1st and 2nd byte (little endian): horizontal resolution + * 3rd and 4th byte (little endian): vertical resolution + * 5th byte: frame rate + */ + + /* :0 s b8 81 1800 0003 0003 3 < + * :0 0 3 = 030104 + * QUERY SIGNAL AND DETECTED LINES, maybe INPUT + */ + +enum hdpvr_video_std { + HDPVR_60HZ = 0, + HDPVR_50HZ, +}; + +enum hdpvr_video_input { + HDPVR_COMPONENT = 0, + HDPVR_SVIDEO, + HDPVR_COMPOSITE, + HDPVR_VIDEO_INPUTS +}; + +enum hdpvr_audio_inputs { + HDPVR_RCA_BACK = 0, + HDPVR_RCA_FRONT, + HDPVR_SPDIF, + HDPVR_AUDIO_INPUTS +}; + +enum hdpvr_bitrate_mode { + HDPVR_CONSTANT = 1, + HDPVR_VARIABLE_PEAK, + HDPVR_VARIABLE_AVERAGE, +}; + +enum hdpvr_gop_mode { + HDPVR_ADVANCED_IDR_GOP = 0, + HDPVR_SIMPLE_IDR_GOP, + HDPVR_ADVANCED_NOIDR_GOP, + HDPVR_SIMPLE_NOIDR_GOP, +}; + +void hdpvr_delete(struct hdpvr_device *dev); + +/*========================================================================*/ +/* hardware control functions */ +int hdpvr_set_options(struct hdpvr_device *dev); + +int hdpvr_set_bitrate(struct hdpvr_device *dev); + +int hdpvr_set_audio(struct hdpvr_device *dev, u8 input, + enum v4l2_mpeg_audio_encoding codec); + +int hdpvr_config_call(struct hdpvr_device *dev, uint value, + unsigned char valbuf); + +struct hdpvr_video_info *get_video_info(struct hdpvr_device *dev); + +/* :0 s b8 81 1800 0003 0003 3 < */ +/* :0 0 3 = 0301ff */ +int get_input_lines_info(struct hdpvr_device *dev); + + +/*========================================================================*/ +/* v4l2 registration */ +int hdpvr_register_videodev(struct hdpvr_device *dev, struct device *parent, + int devnumber); + +int hdpvr_cancel_queue(struct hdpvr_device *dev); + +/*========================================================================*/ +/* i2c adapter registration */ +int hdpvr_register_i2c_adapter(struct hdpvr_device *dev); + +/*========================================================================*/ +/* buffer management */ +int hdpvr_free_buffers(struct hdpvr_device *dev); +int hdpvr_alloc_buffers(struct hdpvr_device *dev, uint count); diff --git a/linux/drivers/media/video/ivtv/ivtv-vbi.c b/linux/drivers/media/video/ivtv/ivtv-vbi.c index 5c5d1c462..f420d31b9 100644 --- a/linux/drivers/media/video/ivtv/ivtv-vbi.c +++ b/linux/drivers/media/video/ivtv/ivtv-vbi.c @@ -185,6 +185,8 @@ static void copy_vbi_data(struct ivtv *itv, int lines, u32 pts_stamp) size = 4 + ((43 * line + 3) & ~3); } else { memcpy(dst + sd, "itv0", 4); + cpu_to_le32s(&linemask[0]); + cpu_to_le32s(&linemask[1]); memcpy(dst + sd + 4, &linemask[0], 8); size = 12 + ((43 * line + 3) & ~3); } diff --git a/linux/drivers/media/video/mt9m001.c b/linux/drivers/media/video/mt9m001.c index c2e52100a..e3dab2119 100644 --- a/linux/drivers/media/video/mt9m001.c +++ b/linux/drivers/media/video/mt9m001.c @@ -12,7 +12,6 @@ #include <linux/slab.h> #include <linux/i2c.h> #include <linux/log2.h> -#include <linux/gpio.h> #include <media/v4l2-common.h> #include <media/v4l2-chip-ident.h> @@ -73,9 +72,7 @@ struct mt9m001 { struct i2c_client *client; struct soc_camera_device icd; int model; /* V4L2_IDENT_MT9M001* codes from v4l2-chip-ident.h */ - int switch_gpio; unsigned char autoexposure; - unsigned char datawidth; }; static int reg_read(struct soc_camera_device *icd, const u8 reg) @@ -181,92 +178,28 @@ static int mt9m001_stop_capture(struct soc_camera_device *icd) return 0; } -static int bus_switch_request(struct mt9m001 *mt9m001, - struct soc_camera_link *icl) -{ -#ifdef CONFIG_MT9M001_PCA9536_SWITCH - int ret; - unsigned int gpio = icl->gpio; - - if (gpio_is_valid(gpio)) { - /* We have a data bus switch. */ - ret = gpio_request(gpio, "mt9m001"); - if (ret < 0) { - dev_err(&mt9m001->client->dev, "Cannot get GPIO %u\n", - gpio); - return ret; - } - - ret = gpio_direction_output(gpio, 0); - if (ret < 0) { - dev_err(&mt9m001->client->dev, - "Cannot set GPIO %u to output\n", gpio); - gpio_free(gpio); - return ret; - } - } - - mt9m001->switch_gpio = gpio; -#else - mt9m001->switch_gpio = -EINVAL; -#endif - return 0; -} - -static void bus_switch_release(struct mt9m001 *mt9m001) -{ -#ifdef CONFIG_MT9M001_PCA9536_SWITCH - if (gpio_is_valid(mt9m001->switch_gpio)) - gpio_free(mt9m001->switch_gpio); -#endif -} - -static int bus_switch_act(struct mt9m001 *mt9m001, int go8bit) -{ -#ifdef CONFIG_MT9M001_PCA9536_SWITCH - if (!gpio_is_valid(mt9m001->switch_gpio)) - return -ENODEV; - - gpio_set_value_cansleep(mt9m001->switch_gpio, go8bit); - return 0; -#else - return -ENODEV; -#endif -} - -static int bus_switch_possible(struct mt9m001 *mt9m001) -{ -#ifdef CONFIG_MT9M001_PCA9536_SWITCH - return gpio_is_valid(mt9m001->switch_gpio); -#else - return 0; -#endif -} - static int mt9m001_set_bus_param(struct soc_camera_device *icd, unsigned long flags) { struct mt9m001 *mt9m001 = container_of(icd, struct mt9m001, icd); - unsigned int width_flag = flags & SOCAM_DATAWIDTH_MASK; - int ret; + struct soc_camera_link *icl = mt9m001->client->dev.platform_data; + unsigned long width_flag = flags & SOCAM_DATAWIDTH_MASK; - /* Flags validity verified in test_bus_param */ + /* Only one width bit may be set */ + if (!is_power_of_2(width_flag)) + return -EINVAL; - if ((mt9m001->datawidth != 10 && (width_flag == SOCAM_DATAWIDTH_10)) || - (mt9m001->datawidth != 9 && (width_flag == SOCAM_DATAWIDTH_9)) || - (mt9m001->datawidth != 8 && (width_flag == SOCAM_DATAWIDTH_8))) { - /* Well, we actually only can do 10 or 8 bits... */ - if (width_flag == SOCAM_DATAWIDTH_9) - return -EINVAL; - ret = bus_switch_act(mt9m001, - width_flag == SOCAM_DATAWIDTH_8); - if (ret < 0) - return ret; + if (icl->set_bus_param) + return icl->set_bus_param(icl, width_flag); - mt9m001->datawidth = width_flag == SOCAM_DATAWIDTH_8 ? 8 : 10; - } + /* + * Without board specific bus width settings we only support the + * sensors native bus width + */ + if (width_flag == SOCAM_DATAWIDTH_10) + return 0; - return 0; + return -EINVAL; } static unsigned long mt9m001_query_bus_param(struct soc_camera_device *icd) @@ -274,18 +207,20 @@ static unsigned long mt9m001_query_bus_param(struct soc_camera_device *icd) struct mt9m001 *mt9m001 = container_of(icd, struct mt9m001, icd); struct soc_camera_link *icl = mt9m001->client->dev.platform_data; /* MT9M001 has all capture_format parameters fixed */ - unsigned long flags = SOCAM_DATAWIDTH_10 | SOCAM_PCLK_SAMPLE_RISING | + unsigned long flags = SOCAM_PCLK_SAMPLE_RISING | SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_HIGH | SOCAM_DATA_ACTIVE_HIGH | SOCAM_MASTER; - if (bus_switch_possible(mt9m001)) - flags |= SOCAM_DATAWIDTH_8; + if (icl->query_bus_param) + flags |= icl->query_bus_param(icl) & SOCAM_DATAWIDTH_MASK; + else + flags |= SOCAM_DATAWIDTH_10; return soc_camera_apply_sensor_flags(icl, flags); } -static int mt9m001_set_fmt(struct soc_camera_device *icd, - __u32 pixfmt, struct v4l2_rect *rect) +static int mt9m001_set_crop(struct soc_camera_device *icd, + struct v4l2_rect *rect) { struct mt9m001 *mt9m001 = container_of(icd, struct mt9m001, icd); int ret; @@ -324,6 +259,20 @@ static int mt9m001_set_fmt(struct soc_camera_device *icd, return ret; } +static int mt9m001_set_fmt(struct soc_camera_device *icd, + struct v4l2_format *f) +{ + struct v4l2_rect rect = { + .left = icd->x_current, + .top = icd->y_current, + .width = f->fmt.pix.width, + .height = f->fmt.pix.height, + }; + + /* No support for scaling so far, just crop. TODO: use skipping */ + return mt9m001_set_crop(icd, &rect); +} + static int mt9m001_try_fmt(struct soc_camera_device *icd, struct v4l2_format *f) { @@ -449,6 +398,7 @@ static struct soc_camera_ops mt9m001_ops = { .release = mt9m001_release, .start_capture = mt9m001_start_capture, .stop_capture = mt9m001_stop_capture, + .set_crop = mt9m001_set_crop, .set_fmt = mt9m001_set_fmt, .try_fmt = mt9m001_try_fmt, .set_bus_param = mt9m001_set_bus_param, @@ -583,6 +533,7 @@ static int mt9m001_video_probe(struct soc_camera_device *icd) struct soc_camera_link *icl = mt9m001->client->dev.platform_data; s32 data; int ret; + unsigned long flags; /* We must have a parent by now. And it cannot be a wrong one. * So this entire test is completely redundant. */ @@ -603,18 +554,10 @@ static int mt9m001_video_probe(struct soc_camera_device *icd) case 0x8421: mt9m001->model = V4L2_IDENT_MT9M001C12ST; icd->formats = mt9m001_colour_formats; - if (gpio_is_valid(icl->gpio)) - icd->num_formats = ARRAY_SIZE(mt9m001_colour_formats); - else - icd->num_formats = 1; break; case 0x8431: mt9m001->model = V4L2_IDENT_MT9M001C12STM; icd->formats = mt9m001_monochrome_formats; - if (gpio_is_valid(icl->gpio)) - icd->num_formats = ARRAY_SIZE(mt9m001_monochrome_formats); - else - icd->num_formats = 1; break; default: ret = -ENODEV; @@ -623,6 +566,26 @@ static int mt9m001_video_probe(struct soc_camera_device *icd) goto ei2c; } + icd->num_formats = 0; + + /* + * This is a 10bit sensor, so by default we only allow 10bit. + * The platform may support different bus widths due to + * different routing of the data lines. + */ + if (icl->query_bus_param) + flags = icl->query_bus_param(icl); + else + flags = SOCAM_DATAWIDTH_10; + + if (flags & SOCAM_DATAWIDTH_10) + icd->num_formats++; + else + icd->formats++; + + if (flags & SOCAM_DATAWIDTH_8) + icd->num_formats++; + dev_info(&icd->dev, "Detected a MT9M001 chip ID %x (%s)\n", data, data == 0x8431 ? "C12STM" : "C12ST"); @@ -692,18 +655,10 @@ static int mt9m001_probe(struct i2c_client *client) icd->height_max = 1024; icd->y_skip_top = 1; icd->iface = icl->bus_id; - /* Default datawidth - this is the only width this camera (normally) - * supports. It is only with extra logic that it can support - * other widths. Therefore it seems to be a sensible default. */ - mt9m001->datawidth = 10; /* Simulated autoexposure. If enabled, we calculate shutter width * ourselves in the driver based on vertical blanking and frame width */ mt9m001->autoexposure = 1; - ret = bus_switch_request(mt9m001, icl); - if (ret) - goto eswinit; - ret = soc_camera_device_register(icd); if (ret) goto eisdr; @@ -711,8 +666,6 @@ static int mt9m001_probe(struct i2c_client *client) return 0; eisdr: - bus_switch_release(mt9m001); -eswinit: kfree(mt9m001); return ret; } @@ -722,7 +675,6 @@ static int mt9m001_remove(struct i2c_client *client) struct mt9m001 *mt9m001 = i2c_get_clientdata(client); soc_camera_device_unregister(&mt9m001->icd); - bus_switch_release(mt9m001); kfree(mt9m001); return 0; diff --git a/linux/drivers/media/video/mt9m111.c b/linux/drivers/media/video/mt9m111.c index 3ae675a42..69498d519 100644 --- a/linux/drivers/media/video/mt9m111.c +++ b/linux/drivers/media/video/mt9m111.c @@ -152,7 +152,7 @@ struct mt9m111 { struct soc_camera_device icd; int model; /* V4L2_IDENT_MT9M11x* codes from v4l2-chip-ident.h */ enum mt9m111_context context; - unsigned int left, top, width, height; + struct v4l2_rect rect; u32 pixfmt; unsigned char autoexposure; unsigned char datawidth; @@ -249,12 +249,13 @@ static int mt9m111_set_context(struct soc_camera_device *icd, return reg_write(CONTEXT_CONTROL, valA); } -static int mt9m111_setup_rect(struct soc_camera_device *icd) +static int mt9m111_setup_rect(struct soc_camera_device *icd, + struct v4l2_rect *rect) { struct mt9m111 *mt9m111 = container_of(icd, struct mt9m111, icd); int ret, is_raw_format; - int width = mt9m111->width; - int height = mt9m111->height; + int width = rect->width; + int height = rect->height; if ((mt9m111->pixfmt == V4L2_PIX_FMT_SBGGR8) || (mt9m111->pixfmt == V4L2_PIX_FMT_SBGGR16)) @@ -262,9 +263,9 @@ static int mt9m111_setup_rect(struct soc_camera_device *icd) else is_raw_format = 0; - ret = reg_write(COLUMN_START, mt9m111->left); + ret = reg_write(COLUMN_START, rect->left); if (!ret) - ret = reg_write(ROW_START, mt9m111->top); + ret = reg_write(ROW_START, rect->top); if (is_raw_format) { if (!ret) @@ -436,6 +437,22 @@ static int mt9m111_set_bus_param(struct soc_camera_device *icd, unsigned long f) return 0; } +static int mt9m111_set_crop(struct soc_camera_device *icd, + struct v4l2_rect *rect) +{ + struct mt9m111 *mt9m111 = container_of(icd, struct mt9m111, icd); + int ret; + + dev_dbg(&icd->dev, "%s left=%d, top=%d, width=%d, height=%d\n", + __func__, rect->left, rect->top, rect->width, + rect->height); + + ret = mt9m111_setup_rect(icd, rect); + if (!ret) + mt9m111->rect = *rect; + return ret; +} + static int mt9m111_set_pixfmt(struct soc_camera_device *icd, u32 pixfmt) { struct mt9m111 *mt9m111 = container_of(icd, struct mt9m111, icd); @@ -486,23 +503,27 @@ static int mt9m111_set_pixfmt(struct soc_camera_device *icd, u32 pixfmt) } static int mt9m111_set_fmt(struct soc_camera_device *icd, - __u32 pixfmt, struct v4l2_rect *rect) + struct v4l2_format *f) { struct mt9m111 *mt9m111 = container_of(icd, struct mt9m111, icd); + struct v4l2_pix_format *pix = &f->fmt.pix; + struct v4l2_rect rect = { + .left = mt9m111->rect.left, + .top = mt9m111->rect.top, + .width = pix->width, + .height = pix->height, + }; int ret; - mt9m111->left = rect->left; - mt9m111->top = rect->top; - mt9m111->width = rect->width; - mt9m111->height = rect->height; - dev_dbg(&icd->dev, "%s fmt=%x left=%d, top=%d, width=%d, height=%d\n", - __func__, pixfmt, mt9m111->left, mt9m111->top, mt9m111->width, - mt9m111->height); + __func__, pix->pixelformat, rect.left, rect.top, rect.width, + rect.height); - ret = mt9m111_setup_rect(icd); + ret = mt9m111_setup_rect(icd, &rect); + if (!ret) + ret = mt9m111_set_pixfmt(icd, pix->pixelformat); if (!ret) - ret = mt9m111_set_pixfmt(icd, pixfmt); + mt9m111->rect = rect; return ret; } @@ -633,6 +654,7 @@ static struct soc_camera_ops mt9m111_ops = { .release = mt9m111_release, .start_capture = mt9m111_start_capture, .stop_capture = mt9m111_stop_capture, + .set_crop = mt9m111_set_crop, .set_fmt = mt9m111_set_fmt, .try_fmt = mt9m111_try_fmt, .query_bus_param = mt9m111_query_bus_param, @@ -817,7 +839,7 @@ static int mt9m111_restore_state(struct soc_camera_device *icd) mt9m111_set_context(icd, mt9m111->context); mt9m111_set_pixfmt(icd, mt9m111->pixfmt); - mt9m111_setup_rect(icd); + mt9m111_setup_rect(icd, &mt9m111->rect); mt9m111_set_flip(icd, mt9m111->hflip, MT9M111_RMB_MIRROR_COLS); mt9m111_set_flip(icd, mt9m111->vflip, MT9M111_RMB_MIRROR_ROWS); mt9m111_set_global_gain(icd, icd->gain); diff --git a/linux/drivers/media/video/mt9t031.c b/linux/drivers/media/video/mt9t031.c index aa0e8ec34..8a9ca0b27 100644 --- a/linux/drivers/media/video/mt9t031.c +++ b/linux/drivers/media/video/mt9t031.c @@ -144,8 +144,6 @@ static int mt9t031_init(struct soc_camera_device *icd) int ret; /* Disable chip output, synchronous option update */ - dev_dbg(icd->vdev->parent, "%s\n", __func__); - ret = reg_write(icd, MT9T031_RESET, 1); if (ret >= 0) ret = reg_write(icd, MT9T031_RESET, 0); @@ -186,9 +184,9 @@ static int mt9t031_set_bus_param(struct soc_camera_device *icd, return -EINVAL; if (flags & SOCAM_PCLK_SAMPLE_FALLING) - reg_set(icd, MT9T031_PIXEL_CLOCK_CONTROL, 0x8000); - else reg_clear(icd, MT9T031_PIXEL_CLOCK_CONTROL, 0x8000); + else + reg_set(icd, MT9T031_PIXEL_CLOCK_CONTROL, 0x8000); return 0; } @@ -213,36 +211,14 @@ static void recalculate_limits(struct soc_camera_device *icd, icd->height_max = MT9T031_MAX_HEIGHT / yskip; } -static int mt9t031_set_fmt(struct soc_camera_device *icd, - __u32 pixfmt, struct v4l2_rect *rect) +static int mt9t031_set_params(struct soc_camera_device *icd, + struct v4l2_rect *rect, u16 xskip, u16 yskip) { struct mt9t031 *mt9t031 = container_of(icd, struct mt9t031, icd); int ret; + u16 xbin, ybin, width, height, left, top; const u16 hblank = MT9T031_HORIZONTAL_BLANK, vblank = MT9T031_VERTICAL_BLANK; - u16 xbin, xskip, ybin, yskip, width, height, left, top; - - if (pixfmt) { - /* - * try_fmt has put rectangle within limits. - * S_FMT - use binning and skipping for scaling, recalculate - * limits, used for cropping - */ - /* Is this more optimal than just a division? */ - for (xskip = 8; xskip > 1; xskip--) - if (rect->width * xskip <= MT9T031_MAX_WIDTH) - break; - - for (yskip = 8; yskip > 1; yskip--) - if (rect->height * yskip <= MT9T031_MAX_HEIGHT) - break; - - recalculate_limits(icd, xskip, yskip); - } else { - /* CROP - no change in scaling, or in limits */ - xskip = mt9t031->xskip; - yskip = mt9t031->yskip; - } /* Make sure we don't exceed sensor limits */ if (rect->left + rect->width > icd->width_max) @@ -289,7 +265,7 @@ static int mt9t031_set_fmt(struct soc_camera_device *icd, if (ret >= 0) ret = reg_write(icd, MT9T031_VERTICAL_BLANKING, vblank); - if (pixfmt) { + if (yskip != mt9t031->yskip || xskip != mt9t031->xskip) { /* Binning, skipping */ if (ret >= 0) ret = reg_write(icd, MT9T031_COLUMN_ADDRESS_MODE, @@ -325,15 +301,58 @@ static int mt9t031_set_fmt(struct soc_camera_device *icd, } } - if (!ret && pixfmt) { + /* Re-enable register update, commit all changes */ + if (ret >= 0) + ret = reg_clear(icd, MT9T031_OUTPUT_CONTROL, 1); + + return ret < 0 ? ret : 0; +} + +static int mt9t031_set_crop(struct soc_camera_device *icd, + struct v4l2_rect *rect) +{ + struct mt9t031 *mt9t031 = container_of(icd, struct mt9t031, icd); + + /* CROP - no change in scaling, or in limits */ + return mt9t031_set_params(icd, rect, mt9t031->xskip, mt9t031->yskip); +} + +static int mt9t031_set_fmt(struct soc_camera_device *icd, + struct v4l2_format *f) +{ + struct mt9t031 *mt9t031 = container_of(icd, struct mt9t031, icd); + int ret; + u16 xskip, yskip; + struct v4l2_rect rect = { + .left = icd->x_current, + .top = icd->y_current, + .width = f->fmt.pix.width, + .height = f->fmt.pix.height, + }; + + /* + * try_fmt has put rectangle within limits. + * S_FMT - use binning and skipping for scaling, recalculate + * limits, used for cropping + */ + /* Is this more optimal than just a division? */ + for (xskip = 8; xskip > 1; xskip--) + if (rect.width * xskip <= MT9T031_MAX_WIDTH) + break; + + for (yskip = 8; yskip > 1; yskip--) + if (rect.height * yskip <= MT9T031_MAX_HEIGHT) + break; + + recalculate_limits(icd, xskip, yskip); + + ret = mt9t031_set_params(icd, &rect, xskip, yskip); + if (!ret) { mt9t031->xskip = xskip; mt9t031->yskip = yskip; } - /* Re-enable register update, commit all changes */ - reg_clear(icd, MT9T031_OUTPUT_CONTROL, 1); - - return ret < 0 ? ret : 0; + return ret; } static int mt9t031_try_fmt(struct soc_camera_device *icd, @@ -470,6 +489,7 @@ static struct soc_camera_ops mt9t031_ops = { .release = mt9t031_release, .start_capture = mt9t031_start_capture, .stop_capture = mt9t031_stop_capture, + .set_crop = mt9t031_set_crop, .set_fmt = mt9t031_set_fmt, .try_fmt = mt9t031_try_fmt, .set_bus_param = mt9t031_set_bus_param, diff --git a/linux/drivers/media/video/mt9v022.c b/linux/drivers/media/video/mt9v022.c index 59efb8ff0..3bee30caa 100644 --- a/linux/drivers/media/video/mt9v022.c +++ b/linux/drivers/media/video/mt9v022.c @@ -13,7 +13,6 @@ #include <linux/i2c.h> #include <linux/delay.h> #include <linux/log2.h> -#include <linux/gpio.h> #include <media/v4l2-common.h> #include <media/v4l2-chip-ident.h> @@ -89,9 +88,7 @@ struct mt9v022 { struct i2c_client *client; struct soc_camera_device icd; int model; /* V4L2_IDENT_MT9V022* codes from v4l2-chip-ident.h */ - int switch_gpio; u16 chip_control; - unsigned char datawidth; }; static int reg_read(struct soc_camera_device *icd, const u8 reg) @@ -209,66 +206,6 @@ static int mt9v022_stop_capture(struct soc_camera_device *icd) return 0; } -static int bus_switch_request(struct mt9v022 *mt9v022, struct soc_camera_link *icl) -{ -#ifdef CONFIG_MT9V022_PCA9536_SWITCH - int ret; - unsigned int gpio = icl->gpio; - - if (gpio_is_valid(gpio)) { - /* We have a data bus switch. */ - ret = gpio_request(gpio, "mt9v022"); - if (ret < 0) { - dev_err(&mt9v022->client->dev, "Cannot get GPIO %u\n", gpio); - return ret; - } - - ret = gpio_direction_output(gpio, 0); - if (ret < 0) { - dev_err(&mt9v022->client->dev, - "Cannot set GPIO %u to output\n", gpio); - gpio_free(gpio); - return ret; - } - } - - mt9v022->switch_gpio = gpio; -#else - mt9v022->switch_gpio = -EINVAL; -#endif - return 0; -} - -static void bus_switch_release(struct mt9v022 *mt9v022) -{ -#ifdef CONFIG_MT9V022_PCA9536_SWITCH - if (gpio_is_valid(mt9v022->switch_gpio)) - gpio_free(mt9v022->switch_gpio); -#endif -} - -static int bus_switch_act(struct mt9v022 *mt9v022, int go8bit) -{ -#ifdef CONFIG_MT9V022_PCA9536_SWITCH - if (!gpio_is_valid(mt9v022->switch_gpio)) - return -ENODEV; - - gpio_set_value_cansleep(mt9v022->switch_gpio, go8bit); - return 0; -#else - return -ENODEV; -#endif -} - -static int bus_switch_possible(struct mt9v022 *mt9v022) -{ -#ifdef CONFIG_MT9V022_PCA9536_SWITCH - return gpio_is_valid(mt9v022->switch_gpio); -#else - return 0; -#endif -} - static int mt9v022_set_bus_param(struct soc_camera_device *icd, unsigned long flags) { @@ -282,19 +219,17 @@ static int mt9v022_set_bus_param(struct soc_camera_device *icd, if (!is_power_of_2(width_flag)) return -EINVAL; - if ((mt9v022->datawidth != 10 && (width_flag == SOCAM_DATAWIDTH_10)) || - (mt9v022->datawidth != 9 && (width_flag == SOCAM_DATAWIDTH_9)) || - (mt9v022->datawidth != 8 && (width_flag == SOCAM_DATAWIDTH_8))) { - /* Well, we actually only can do 10 or 8 bits... */ - if (width_flag == SOCAM_DATAWIDTH_9) - return -EINVAL; - - ret = bus_switch_act(mt9v022, - width_flag == SOCAM_DATAWIDTH_8); - if (ret < 0) + if (icl->set_bus_param) { + ret = icl->set_bus_param(icl, width_flag); + if (ret) return ret; - - mt9v022->datawidth = width_flag == SOCAM_DATAWIDTH_8 ? 8 : 10; + } else { + /* + * Without board specific bus width settings we only support the + * sensors native bus width + */ + if (width_flag != SOCAM_DATAWIDTH_10) + return -EINVAL; } flags = soc_camera_apply_sensor_flags(icl, flags); @@ -328,10 +263,14 @@ static int mt9v022_set_bus_param(struct soc_camera_device *icd, static unsigned long mt9v022_query_bus_param(struct soc_camera_device *icd) { struct mt9v022 *mt9v022 = container_of(icd, struct mt9v022, icd); - unsigned int width_flag = SOCAM_DATAWIDTH_10; + struct soc_camera_link *icl = mt9v022->client->dev.platform_data; + unsigned int width_flag; - if (bus_switch_possible(mt9v022)) - width_flag |= SOCAM_DATAWIDTH_8; + if (icl->query_bus_param) + width_flag = icl->query_bus_param(icl) & + SOCAM_DATAWIDTH_MASK; + else + width_flag = SOCAM_DATAWIDTH_10; return SOCAM_PCLK_SAMPLE_RISING | SOCAM_PCLK_SAMPLE_FALLING | SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_HSYNC_ACTIVE_LOW | @@ -340,32 +279,11 @@ static unsigned long mt9v022_query_bus_param(struct soc_camera_device *icd) width_flag; } -static int mt9v022_set_fmt(struct soc_camera_device *icd, - __u32 pixfmt, struct v4l2_rect *rect) +static int mt9v022_set_crop(struct soc_camera_device *icd, + struct v4l2_rect *rect) { - struct mt9v022 *mt9v022 = container_of(icd, struct mt9v022, icd); int ret; - /* The caller provides a supported format, as verified per call to - * icd->try_fmt(), datawidth is from our supported format list */ - switch (pixfmt) { - case V4L2_PIX_FMT_GREY: - case V4L2_PIX_FMT_Y16: - if (mt9v022->model != V4L2_IDENT_MT9V022IX7ATM) - return -EINVAL; - break; - case V4L2_PIX_FMT_SBGGR8: - case V4L2_PIX_FMT_SBGGR16: - if (mt9v022->model != V4L2_IDENT_MT9V022IX7ATC) - return -EINVAL; - break; - case 0: - /* No format change, only geometry */ - break; - default: - return -EINVAL; - } - /* Like in example app. Contradicts the datasheet though */ ret = reg_read(icd, MT9V022_AEC_AGC_ENABLE); if (ret >= 0) { @@ -403,6 +321,42 @@ static int mt9v022_set_fmt(struct soc_camera_device *icd, return 0; } +static int mt9v022_set_fmt(struct soc_camera_device *icd, + struct v4l2_format *f) +{ + struct mt9v022 *mt9v022 = container_of(icd, struct mt9v022, icd); + struct v4l2_pix_format *pix = &f->fmt.pix; + struct v4l2_rect rect = { + .left = icd->x_current, + .top = icd->y_current, + .width = pix->width, + .height = pix->height, + }; + + /* The caller provides a supported format, as verified per call to + * icd->try_fmt(), datawidth is from our supported format list */ + switch (pix->pixelformat) { + case V4L2_PIX_FMT_GREY: + case V4L2_PIX_FMT_Y16: + if (mt9v022->model != V4L2_IDENT_MT9V022IX7ATM) + return -EINVAL; + break; + case V4L2_PIX_FMT_SBGGR8: + case V4L2_PIX_FMT_SBGGR16: + if (mt9v022->model != V4L2_IDENT_MT9V022IX7ATC) + return -EINVAL; + break; + case 0: + /* No format change, only geometry */ + break; + default: + return -EINVAL; + } + + /* No support for scaling on this camera, just crop. */ + return mt9v022_set_crop(icd, &rect); +} + static int mt9v022_try_fmt(struct soc_camera_device *icd, struct v4l2_format *f) { @@ -544,6 +498,7 @@ static struct soc_camera_ops mt9v022_ops = { .release = mt9v022_release, .start_capture = mt9v022_start_capture, .stop_capture = mt9v022_stop_capture, + .set_crop = mt9v022_set_crop, .set_fmt = mt9v022_set_fmt, .try_fmt = mt9v022_try_fmt, .set_bus_param = mt9v022_set_bus_param, @@ -699,6 +654,7 @@ static int mt9v022_video_probe(struct soc_camera_device *icd) struct soc_camera_link *icl = mt9v022->client->dev.platform_data; s32 data; int ret; + unsigned long flags; if (!icd->dev.parent || to_soc_camera_host(icd->dev.parent)->nr != icd->iface) @@ -732,22 +688,36 @@ static int mt9v022_video_probe(struct soc_camera_device *icd) ret = reg_write(icd, MT9V022_PIXEL_OPERATION_MODE, 4 | 0x11); mt9v022->model = V4L2_IDENT_MT9V022IX7ATC; icd->formats = mt9v022_colour_formats; - if (gpio_is_valid(icl->gpio)) - icd->num_formats = ARRAY_SIZE(mt9v022_colour_formats); - else - icd->num_formats = 1; } else { ret = reg_write(icd, MT9V022_PIXEL_OPERATION_MODE, 0x11); mt9v022->model = V4L2_IDENT_MT9V022IX7ATM; icd->formats = mt9v022_monochrome_formats; - if (gpio_is_valid(icl->gpio)) - icd->num_formats = ARRAY_SIZE(mt9v022_monochrome_formats); - else - icd->num_formats = 1; } - if (!ret) - ret = soc_camera_video_start(icd); + if (ret < 0) + goto eisis; + + icd->num_formats = 0; + + /* + * This is a 10bit sensor, so by default we only allow 10bit. + * The platform may support different bus widths due to + * different routing of the data lines. + */ + if (icl->query_bus_param) + flags = icl->query_bus_param(icl); + else + flags = SOCAM_DATAWIDTH_10; + + if (flags & SOCAM_DATAWIDTH_10) + icd->num_formats++; + else + icd->formats++; + + if (flags & SOCAM_DATAWIDTH_8) + icd->num_formats++; + + ret = soc_camera_video_start(icd); if (ret < 0) goto eisis; @@ -771,8 +741,12 @@ static void mt9v022_video_remove(struct soc_camera_device *icd) soc_camera_video_stop(icd); } +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 26) static int mt9v022_probe(struct i2c_client *client, const struct i2c_device_id *did) +#else +static int mt9v022_probe(struct i2c_client *client) +#endif { struct mt9v022 *mt9v022; struct soc_camera_device *icd; @@ -812,14 +786,6 @@ static int mt9v022_probe(struct i2c_client *client, icd->height_max = 480; icd->y_skip_top = 1; icd->iface = icl->bus_id; - /* Default datawidth - this is the only width this camera (normally) - * supports. It is only with extra logic that it can support - * other widths. Therefore it seems to be a sensible default. */ - mt9v022->datawidth = 10; - - ret = bus_switch_request(mt9v022, icl); - if (ret) - goto eswinit; ret = soc_camera_device_register(icd); if (ret) @@ -828,8 +794,6 @@ static int mt9v022_probe(struct i2c_client *client, return 0; eisdr: - bus_switch_release(mt9v022); -eswinit: kfree(mt9v022); return ret; } @@ -839,7 +803,6 @@ static int mt9v022_remove(struct i2c_client *client) struct mt9v022 *mt9v022 = i2c_get_clientdata(client); soc_camera_device_unregister(&mt9v022->icd); - bus_switch_release(mt9v022); kfree(mt9v022); return 0; diff --git a/linux/drivers/media/video/mx3_camera.c b/linux/drivers/media/video/mx3_camera.c index f525dc48f..70629e172 100644 --- a/linux/drivers/media/video/mx3_camera.c +++ b/linux/drivers/media/video/mx3_camera.c @@ -544,16 +544,14 @@ static void mx3_camera_remove_device(struct soc_camera_device *icd) } static bool channel_change_requested(struct soc_camera_device *icd, - const struct soc_camera_format_xlate *xlate, - __u32 pixfmt, struct v4l2_rect *rect) + struct v4l2_rect *rect) { struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); struct mx3_camera_dev *mx3_cam = ici->priv; struct idmac_channel *ichan = mx3_cam->idmac_channel[0]; - /* So far only one configuration is supported */ - return pixfmt || (ichan && rect->width * rect->height > - icd->width * icd->height); + /* Do buffers have to be re-allocated or channel re-configured? */ + return ichan && rect->width * rect->height > icd->width * icd->height; } static int test_platform_param(struct mx3_camera_dev *mx3_cam, @@ -733,61 +731,10 @@ passthrough: return formats; } -static int mx3_camera_set_fmt(struct soc_camera_device *icd, - __u32 pixfmt, struct v4l2_rect *rect) +static void configure_geometry(struct mx3_camera_dev *mx3_cam, + struct v4l2_rect *rect) { - struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); - struct mx3_camera_dev *mx3_cam = ici->priv; - const struct soc_camera_format_xlate *xlate; u32 ctrl, width_field, height_field; - int ret; - - xlate = soc_camera_xlate_by_fourcc(icd, pixfmt); - if (pixfmt && !xlate) { - dev_warn(&ici->dev, "Format %x not found\n", pixfmt); - return -EINVAL; - } - - /* - * We now know pixel formats and can decide upon DMA-channel(s) - * So far only direct camera-to-memory is supported - */ - if (channel_change_requested(icd, xlate, pixfmt, rect)) { - dma_cap_mask_t mask; - struct dma_chan *chan; - struct idmac_channel **ichan = &mx3_cam->idmac_channel[0]; - /* We have to use IDMAC_IC_7 for Bayer / generic data */ - struct dma_chan_request rq = {.mx3_cam = mx3_cam, - .id = IDMAC_IC_7}; - - if (*ichan) { - struct videobuf_buffer *vb, *_vb; - dma_release_channel(&(*ichan)->dma_chan); - *ichan = NULL; - mx3_cam->active = NULL; - list_for_each_entry_safe(vb, _vb, &mx3_cam->capture, queue) { - list_del_init(&vb->queue); - vb->state = VIDEOBUF_ERROR; - wake_up(&vb->done); - } - } - - dma_cap_zero(mask); - dma_cap_set(DMA_SLAVE, mask); - dma_cap_set(DMA_PRIVATE, mask); - chan = dma_request_channel(mask, chan_filter, &rq); - if (!chan) - return -EBUSY; - - *ichan = to_idmac_chan(chan); - (*ichan)->client = mx3_cam; - } - - /* - * Might have to perform a complete interface initialisation like in - * ipu_csi_init_interface() in mxc_v4l2_s_param(). Also consider - * mxc_v4l2_s_fmt() - */ /* Setup frame size - this cannot be changed on-the-fly... */ width_field = rect->width - 1; @@ -808,9 +755,98 @@ static int mx3_camera_set_fmt(struct soc_camera_device *icd, * No need to free resources here if we fail, we'll see if we need to * do this next time we are called */ +} + +static int acquire_dma_channel(struct mx3_camera_dev *mx3_cam) +{ + dma_cap_mask_t mask; + struct dma_chan *chan; + struct idmac_channel **ichan = &mx3_cam->idmac_channel[0]; + /* We have to use IDMAC_IC_7 for Bayer / generic data */ + struct dma_chan_request rq = {.mx3_cam = mx3_cam, + .id = IDMAC_IC_7}; + + if (*ichan) { + struct videobuf_buffer *vb, *_vb; + dma_release_channel(&(*ichan)->dma_chan); + *ichan = NULL; + mx3_cam->active = NULL; + list_for_each_entry_safe(vb, _vb, &mx3_cam->capture, queue) { + list_del_init(&vb->queue); + vb->state = VIDEOBUF_ERROR; + wake_up(&vb->done); + } + } + + dma_cap_zero(mask); + dma_cap_set(DMA_SLAVE, mask); + dma_cap_set(DMA_PRIVATE, mask); + chan = dma_request_channel(mask, chan_filter, &rq); + if (!chan) + return -EBUSY; + + *ichan = to_idmac_chan(chan); + (*ichan)->client = mx3_cam; + + return 0; +} + +static int mx3_camera_set_crop(struct soc_camera_device *icd, + struct v4l2_rect *rect) +{ + struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); + struct mx3_camera_dev *mx3_cam = ici->priv; + + /* + * We now know pixel formats and can decide upon DMA-channel(s) + * So far only direct camera-to-memory is supported + */ + if (channel_change_requested(icd, rect)) { + int ret = acquire_dma_channel(mx3_cam); + if (ret < 0) + return ret; + } + + configure_geometry(mx3_cam, rect); + + return icd->ops->set_crop(icd, rect); +} + +static int mx3_camera_set_fmt(struct soc_camera_device *icd, + struct v4l2_format *f) +{ + struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); + struct mx3_camera_dev *mx3_cam = ici->priv; + const struct soc_camera_format_xlate *xlate; + struct v4l2_pix_format *pix = &f->fmt.pix; + struct v4l2_rect rect = { + .left = icd->x_current, + .top = icd->y_current, + .width = pix->width, + .height = pix->height, + }; + int ret; + + xlate = soc_camera_xlate_by_fourcc(icd, pix->pixelformat); + if (!xlate) { + dev_warn(&ici->dev, "Format %x not found\n", pix->pixelformat); + return -EINVAL; + } + + ret = acquire_dma_channel(mx3_cam); + if (ret < 0) + return ret; + + /* + * Might have to perform a complete interface initialisation like in + * ipu_csi_init_interface() in mxc_v4l2_s_param(). Also consider + * mxc_v4l2_s_fmt() + */ + + configure_geometry(mx3_cam, &rect); - ret = icd->ops->set_fmt(icd, pixfmt ? xlate->cam_fmt->fourcc : 0, rect); - if (pixfmt && !ret) { + ret = icd->ops->set_fmt(icd, f); + if (!ret) { icd->buswidth = xlate->buswidth; icd->current_fmt = xlate->host_fmt; } @@ -1031,6 +1067,7 @@ static struct soc_camera_host_ops mx3_soc_camera_host_ops = { .suspend = mx3_camera_suspend, .resume = mx3_camera_resume, #endif + .set_crop = mx3_camera_set_crop, .set_fmt = mx3_camera_set_fmt, .try_fmt = mx3_camera_try_fmt, .get_formats = mx3_camera_get_formats, diff --git a/linux/drivers/media/video/ov7670.c b/linux/drivers/media/video/ov7670.c index f0e1a56eb..7c97449fd 100644 --- a/linux/drivers/media/video/ov7670.c +++ b/linux/drivers/media/video/ov7670.c @@ -12,12 +12,12 @@ */ #include <linux/init.h> #include <linux/module.h> -#include <linux/slab.h> +#include <linux/i2c.h> #include <linux/delay.h> #include <linux/videodev2.h> -#include <media/v4l2-common.h> +#include <media/v4l2-device.h> #include <media/v4l2-chip-ident.h> -#include <linux/i2c.h> +#include <media/v4l2-i2c-drv.h> #include "compat.h" @@ -25,6 +25,10 @@ MODULE_AUTHOR("Jonathan Corbet <corbet@lwn.net>"); MODULE_DESCRIPTION("A low-level driver for OmniVision ov7670 sensors"); MODULE_LICENSE("GPL"); +static int debug; +module_param(debug, bool, 0644); +MODULE_PARM_DESC(debug, "Debug level (0-1)"); + /* * Basic window sizes. These probably belong somewhere more globally * useful. @@ -190,11 +194,16 @@ MODULE_LICENSE("GPL"); */ struct ov7670_format_struct; /* coming later */ struct ov7670_info { + struct v4l2_subdev sd; struct ov7670_format_struct *fmt; /* Current format */ unsigned char sat; /* Saturation value */ int hue; /* Hue value */ }; +static inline struct ov7670_info *to_state(struct v4l2_subdev *sd) +{ + return container_of(sd, struct ov7670_info, sd); +} @@ -401,24 +410,27 @@ static struct regval_list ov7670_fmt_raw[] = { * Low-level register I/O. */ -static int ov7670_read(struct i2c_client *c, unsigned char reg, +static int ov7670_read(struct v4l2_subdev *sd, unsigned char reg, unsigned char *value) { + struct i2c_client *client = v4l2_get_subdevdata(sd); int ret; - ret = i2c_smbus_read_byte_data(c, reg); + ret = i2c_smbus_read_byte_data(client, reg); if (ret >= 0) { - *value = (unsigned char) ret; + *value = (unsigned char)ret; ret = 0; } return ret; } -static int ov7670_write(struct i2c_client *c, unsigned char reg, +static int ov7670_write(struct v4l2_subdev *sd, unsigned char reg, unsigned char value) { - int ret = i2c_smbus_write_byte_data(c, reg, value); + struct i2c_client *client = v4l2_get_subdevdata(sd); + int ret = i2c_smbus_write_byte_data(client, reg, value); + if (reg == REG_COM7 && (value & COM7_RESET)) msleep(2); /* Wait for reset to run */ return ret; @@ -426,20 +438,20 @@ static int ov7670_write(struct i2c_client *c, unsigned char reg, #if 0 /* Not currently used, but maybe should be */ -static int ov7670_write_mask(struct i2c_client *c, unsigned char reg, +static int ov7670_write_mask(struct v4l2_subdev *sd, unsigned char reg, unsigned char value, unsigned char mask) { unsigned char v; int ret, tries = 0; - ret = ov7670_read(c, reg, &v); + ret = ov7670_read(sd, reg, &v); if (ret < 0) return ret; v &= ~mask; v |= (value & mask); msleep(10); /* FIXME experiment */ do { - ret = ov7670_write(c, reg, v); + ret = ov7670_write(sd, reg, v); } while (ret < 0 && ++tries < 3); return ret; } @@ -449,10 +461,10 @@ static int ov7670_write_mask(struct i2c_client *c, unsigned char reg, /* * Write a list of register settings; ff/ff stops the process. */ -static int ov7670_write_array(struct i2c_client *c, struct regval_list *vals) +static int ov7670_write_array(struct v4l2_subdev *sd, struct regval_list *vals) { while (vals->reg_num != 0xff || vals->value != 0xff) { - int ret = ov7670_write(c, vals->reg_num, vals->value); + int ret = ov7670_write(sd, vals->reg_num, vals->value); if (ret < 0) return ret; vals++; @@ -464,34 +476,35 @@ static int ov7670_write_array(struct i2c_client *c, struct regval_list *vals) /* * Stuff that knows about the sensor. */ -static void ov7670_reset(struct i2c_client *client) +static int ov7670_reset(struct v4l2_subdev *sd, u32 val) { - ov7670_write(client, REG_COM7, COM7_RESET); + ov7670_write(sd, REG_COM7, COM7_RESET); msleep(1); + return 0; } -static int ov7670_init(struct i2c_client *client) +static int ov7670_init(struct v4l2_subdev *sd, u32 val) { - return ov7670_write_array(client, ov7670_default_regs); + return ov7670_write_array(sd, ov7670_default_regs); } -static int ov7670_detect(struct i2c_client *client) +static int ov7670_detect(struct v4l2_subdev *sd) { unsigned char v; int ret; - ret = ov7670_init(client); + ret = ov7670_init(sd, 0); if (ret < 0) return ret; - ret = ov7670_read(client, REG_MIDH, &v); + ret = ov7670_read(sd, REG_MIDH, &v); if (ret < 0) return ret; if (v != 0x7f) /* OV manuf. id. */ return -ENODEV; - ret = ov7670_read(client, REG_MIDL, &v); + ret = ov7670_read(sd, REG_MIDL, &v); if (ret < 0) return ret; if (v != 0xa2) @@ -499,12 +512,12 @@ static int ov7670_detect(struct i2c_client *client) /* * OK, we know we have an OmniVision chip...but which one? */ - ret = ov7670_read(client, REG_PID, &v); + ret = ov7670_read(sd, REG_PID, &v); if (ret < 0) return ret; if (v != 0x76) /* PID + VER = 0x76 / 0x73 */ return -ENODEV; - ret = ov7670_read(client, REG_VER, &v); + ret = ov7670_read(sd, REG_VER, &v); if (ret < 0) return ret; if (v != 0x73) /* PID + VER = 0x76 / 0x73 */ @@ -649,7 +662,7 @@ static struct ov7670_win_size { /* * Store a set of start/stop values into the camera. */ -static int ov7670_set_hw(struct i2c_client *client, int hstart, int hstop, +static int ov7670_set_hw(struct v4l2_subdev *sd, int hstart, int hstop, int vstart, int vstop) { int ret; @@ -659,26 +672,26 @@ static int ov7670_set_hw(struct i2c_client *client, int hstart, int hstop, * hstart are in href[2:0], bottom 3 of hstop in href[5:3]. There is * a mystery "edge offset" value in the top two bits of href. */ - ret = ov7670_write(client, REG_HSTART, (hstart >> 3) & 0xff); - ret += ov7670_write(client, REG_HSTOP, (hstop >> 3) & 0xff); - ret += ov7670_read(client, REG_HREF, &v); + ret = ov7670_write(sd, REG_HSTART, (hstart >> 3) & 0xff); + ret += ov7670_write(sd, REG_HSTOP, (hstop >> 3) & 0xff); + ret += ov7670_read(sd, REG_HREF, &v); v = (v & 0xc0) | ((hstop & 0x7) << 3) | (hstart & 0x7); msleep(10); - ret += ov7670_write(client, REG_HREF, v); + ret += ov7670_write(sd, REG_HREF, v); /* * Vertical: similar arrangement, but only 10 bits. */ - ret += ov7670_write(client, REG_VSTART, (vstart >> 2) & 0xff); - ret += ov7670_write(client, REG_VSTOP, (vstop >> 2) & 0xff); - ret += ov7670_read(client, REG_VREF, &v); + ret += ov7670_write(sd, REG_VSTART, (vstart >> 2) & 0xff); + ret += ov7670_write(sd, REG_VSTOP, (vstop >> 2) & 0xff); + ret += ov7670_read(sd, REG_VREF, &v); v = (v & 0xf0) | ((vstop & 0x3) << 2) | (vstart & 0x3); msleep(10); - ret += ov7670_write(client, REG_VREF, v); + ret += ov7670_write(sd, REG_VREF, v); return ret; } -static int ov7670_enum_fmt(struct i2c_client *c, struct v4l2_fmtdesc *fmt) +static int ov7670_enum_fmt(struct v4l2_subdev *sd, struct v4l2_fmtdesc *fmt) { struct ov7670_format_struct *ofmt; @@ -693,7 +706,8 @@ static int ov7670_enum_fmt(struct i2c_client *c, struct v4l2_fmtdesc *fmt) } -static int ov7670_try_fmt(struct i2c_client *c, struct v4l2_format *fmt, +static int ov7670_try_fmt_internal(struct v4l2_subdev *sd, + struct v4l2_format *fmt, struct ov7670_format_struct **ret_fmt, struct ov7670_win_size **ret_wsize) { @@ -737,18 +751,23 @@ static int ov7670_try_fmt(struct i2c_client *c, struct v4l2_format *fmt, return 0; } +static int ov7670_try_fmt(struct v4l2_subdev *sd, struct v4l2_format *fmt) +{ + return ov7670_try_fmt_internal(sd, fmt, NULL, NULL); +} + /* * Set a format. */ -static int ov7670_s_fmt(struct i2c_client *c, struct v4l2_format *fmt) +static int ov7670_s_fmt(struct v4l2_subdev *sd, struct v4l2_format *fmt) { int ret; struct ov7670_format_struct *ovfmt; struct ov7670_win_size *wsize; - struct ov7670_info *info = i2c_get_clientdata(c); - unsigned char com7, clkrc; + struct ov7670_info *info = to_state(sd); + unsigned char com7, clkrc = 0; - ret = ov7670_try_fmt(c, fmt, &ovfmt, &wsize); + ret = ov7670_try_fmt_internal(sd, fmt, &ovfmt, &wsize); if (ret) return ret; /* @@ -757,7 +776,7 @@ static int ov7670_s_fmt(struct i2c_client *c, struct v4l2_format *fmt) * the colors. */ if (fmt->fmt.pix.pixelformat == V4L2_PIX_FMT_RGB565) { - ret = ov7670_read(c, REG_CLKRC, &clkrc); + ret = ov7670_read(sd, REG_CLKRC, &clkrc); if (ret) return ret; } @@ -769,20 +788,20 @@ static int ov7670_s_fmt(struct i2c_client *c, struct v4l2_format *fmt) */ com7 = ovfmt->regs[0].value; com7 |= wsize->com7_bit; - ov7670_write(c, REG_COM7, com7); + ov7670_write(sd, REG_COM7, com7); /* * Now write the rest of the array. Also store start/stops */ - ov7670_write_array(c, ovfmt->regs + 1); - ov7670_set_hw(c, wsize->hstart, wsize->hstop, wsize->vstart, + ov7670_write_array(sd, ovfmt->regs + 1); + ov7670_set_hw(sd, wsize->hstart, wsize->hstop, wsize->vstart, wsize->vstop); ret = 0; if (wsize->regs) - ret = ov7670_write_array(c, wsize->regs); + ret = ov7670_write_array(sd, wsize->regs); info->fmt = ovfmt; if (fmt->fmt.pix.pixelformat == V4L2_PIX_FMT_RGB565 && ret == 0) - ret = ov7670_write(c, REG_CLKRC, clkrc); + ret = ov7670_write(sd, REG_CLKRC, clkrc); return ret; } @@ -790,7 +809,7 @@ static int ov7670_s_fmt(struct i2c_client *c, struct v4l2_format *fmt) * Implement G/S_PARM. There is a "high quality" mode we could try * to do someday; for now, we just do the frame rate tweak. */ -static int ov7670_g_parm(struct i2c_client *c, struct v4l2_streamparm *parms) +static int ov7670_g_parm(struct v4l2_subdev *sd, struct v4l2_streamparm *parms) { struct v4l2_captureparm *cp = &parms->parm.capture; unsigned char clkrc; @@ -798,7 +817,7 @@ static int ov7670_g_parm(struct i2c_client *c, struct v4l2_streamparm *parms) if (parms->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) return -EINVAL; - ret = ov7670_read(c, REG_CLKRC, &clkrc); + ret = ov7670_read(sd, REG_CLKRC, &clkrc); if (ret < 0) return ret; memset(cp, 0, sizeof(struct v4l2_captureparm)); @@ -810,7 +829,7 @@ static int ov7670_g_parm(struct i2c_client *c, struct v4l2_streamparm *parms) return 0; } -static int ov7670_s_parm(struct i2c_client *c, struct v4l2_streamparm *parms) +static int ov7670_s_parm(struct v4l2_subdev *sd, struct v4l2_streamparm *parms) { struct v4l2_captureparm *cp = &parms->parm.capture; struct v4l2_fract *tpf = &cp->timeperframe; @@ -824,7 +843,7 @@ static int ov7670_s_parm(struct i2c_client *c, struct v4l2_streamparm *parms) /* * CLKRC has a reserved bit, so let's preserve it. */ - ret = ov7670_read(c, REG_CLKRC, &clkrc); + ret = ov7670_read(sd, REG_CLKRC, &clkrc); if (ret < 0) return ret; if (tpf->numerator == 0 || tpf->denominator == 0) @@ -838,7 +857,7 @@ static int ov7670_s_parm(struct i2c_client *c, struct v4l2_streamparm *parms) clkrc = (clkrc & 0x80) | div; tpf->numerator = 1; tpf->denominator = OV7670_FRAME_RATE/div; - return ov7670_write(c, REG_CLKRC, clkrc); + return ov7670_write(sd, REG_CLKRC, clkrc); } @@ -851,17 +870,17 @@ static int ov7670_s_parm(struct i2c_client *c, struct v4l2_streamparm *parms) /* * Fetch and store the color matrix. */ -static int ov7670_get_cmatrix(struct i2c_client *client, +static int ov7670_get_cmatrix(struct v4l2_subdev *sd, int matrix[CMATRIX_LEN]) { int i, ret; unsigned char signbits; - ret = ov7670_read(client, REG_CMATRIX_SIGN, &signbits); + ret = ov7670_read(sd, REG_CMATRIX_SIGN, &signbits); for (i = 0; i < CMATRIX_LEN; i++) { unsigned char raw; - ret += ov7670_read(client, REG_CMATRIX_BASE + i, &raw); + ret += ov7670_read(sd, REG_CMATRIX_BASE + i, &raw); matrix[i] = (int) raw; if (signbits & (1 << i)) matrix[i] *= -1; @@ -873,7 +892,7 @@ static int ov7670_get_cmatrix(struct i2c_client *client, -static int ov7670_store_cmatrix(struct i2c_client *client, +static int ov7670_store_cmatrix(struct v4l2_subdev *sd, int matrix[CMATRIX_LEN]) { int i, ret; @@ -883,7 +902,7 @@ static int ov7670_store_cmatrix(struct i2c_client *client, * Weird crap seems to exist in the upper part of * the sign bits register, so let's preserve it. */ - ret = ov7670_read(client, REG_CMATRIX_SIGN, &signbits); + ret = ov7670_read(sd, REG_CMATRIX_SIGN, &signbits); signbits &= 0xc0; for (i = 0; i < CMATRIX_LEN; i++) { @@ -902,9 +921,9 @@ static int ov7670_store_cmatrix(struct i2c_client *client, else raw = matrix[i] & 0xff; } - ret += ov7670_write(client, REG_CMATRIX_BASE + i, raw); + ret += ov7670_write(sd, REG_CMATRIX_BASE + i, raw); } - ret += ov7670_write(client, REG_CMATRIX_SIGN, signbits); + ret += ov7670_write(sd, REG_CMATRIX_SIGN, signbits); return ret; } @@ -987,29 +1006,29 @@ static void ov7670_calc_cmatrix(struct ov7670_info *info, -static int ov7670_t_sat(struct i2c_client *client, int value) +static int ov7670_s_sat(struct v4l2_subdev *sd, int value) { - struct ov7670_info *info = i2c_get_clientdata(client); + struct ov7670_info *info = to_state(sd); int matrix[CMATRIX_LEN]; int ret; info->sat = value; ov7670_calc_cmatrix(info, matrix); - ret = ov7670_store_cmatrix(client, matrix); + ret = ov7670_store_cmatrix(sd, matrix); return ret; } -static int ov7670_q_sat(struct i2c_client *client, __s32 *value) +static int ov7670_g_sat(struct v4l2_subdev *sd, __s32 *value) { - struct ov7670_info *info = i2c_get_clientdata(client); + struct ov7670_info *info = to_state(sd); *value = info->sat; return 0; } -static int ov7670_t_hue(struct i2c_client *client, int value) +static int ov7670_s_hue(struct v4l2_subdev *sd, int value) { - struct ov7670_info *info = i2c_get_clientdata(client); + struct ov7670_info *info = to_state(sd); int matrix[CMATRIX_LEN]; int ret; @@ -1017,14 +1036,14 @@ static int ov7670_t_hue(struct i2c_client *client, int value) return -EINVAL; info->hue = value; ov7670_calc_cmatrix(info, matrix); - ret = ov7670_store_cmatrix(client, matrix); + ret = ov7670_store_cmatrix(sd, matrix); return ret; } -static int ov7670_q_hue(struct i2c_client *client, __s32 *value) +static int ov7670_g_hue(struct v4l2_subdev *sd, __s32 *value) { - struct ov7670_info *info = i2c_get_clientdata(client); + struct ov7670_info *info = to_state(sd); *value = info->hue; return 0; @@ -1038,8 +1057,7 @@ static unsigned char ov7670_sm_to_abs(unsigned char v) { if ((v & 0x80) == 0) return v + 128; - else - return 128 - (v & 0x7f); + return 128 - (v & 0x7f); } @@ -1047,369 +1065,279 @@ static unsigned char ov7670_abs_to_sm(unsigned char v) { if (v > 127) return v & 0x7f; - else - return (128 - v) | 0x80; + return (128 - v) | 0x80; } -static int ov7670_t_brightness(struct i2c_client *client, int value) +static int ov7670_s_brightness(struct v4l2_subdev *sd, int value) { unsigned char com8 = 0, v; int ret; - ov7670_read(client, REG_COM8, &com8); + ov7670_read(sd, REG_COM8, &com8); com8 &= ~COM8_AEC; - ov7670_write(client, REG_COM8, com8); + ov7670_write(sd, REG_COM8, com8); v = ov7670_abs_to_sm(value); - ret = ov7670_write(client, REG_BRIGHT, v); + ret = ov7670_write(sd, REG_BRIGHT, v); return ret; } -static int ov7670_q_brightness(struct i2c_client *client, __s32 *value) +static int ov7670_g_brightness(struct v4l2_subdev *sd, __s32 *value) { unsigned char v = 0; - int ret = ov7670_read(client, REG_BRIGHT, &v); + int ret = ov7670_read(sd, REG_BRIGHT, &v); *value = ov7670_sm_to_abs(v); return ret; } -static int ov7670_t_contrast(struct i2c_client *client, int value) +static int ov7670_s_contrast(struct v4l2_subdev *sd, int value) { - return ov7670_write(client, REG_CONTRAS, (unsigned char) value); + return ov7670_write(sd, REG_CONTRAS, (unsigned char) value); } -static int ov7670_q_contrast(struct i2c_client *client, __s32 *value) +static int ov7670_g_contrast(struct v4l2_subdev *sd, __s32 *value) { unsigned char v = 0; - int ret = ov7670_read(client, REG_CONTRAS, &v); + int ret = ov7670_read(sd, REG_CONTRAS, &v); *value = v; return ret; } -static int ov7670_q_hflip(struct i2c_client *client, __s32 *value) +static int ov7670_g_hflip(struct v4l2_subdev *sd, __s32 *value) { int ret; unsigned char v = 0; - ret = ov7670_read(client, REG_MVFP, &v); + ret = ov7670_read(sd, REG_MVFP, &v); *value = (v & MVFP_MIRROR) == MVFP_MIRROR; return ret; } -static int ov7670_t_hflip(struct i2c_client *client, int value) +static int ov7670_s_hflip(struct v4l2_subdev *sd, int value) { unsigned char v = 0; int ret; - ret = ov7670_read(client, REG_MVFP, &v); + ret = ov7670_read(sd, REG_MVFP, &v); if (value) v |= MVFP_MIRROR; else v &= ~MVFP_MIRROR; msleep(10); /* FIXME */ - ret += ov7670_write(client, REG_MVFP, v); + ret += ov7670_write(sd, REG_MVFP, v); return ret; } -static int ov7670_q_vflip(struct i2c_client *client, __s32 *value) +static int ov7670_g_vflip(struct v4l2_subdev *sd, __s32 *value) { int ret; unsigned char v = 0; - ret = ov7670_read(client, REG_MVFP, &v); + ret = ov7670_read(sd, REG_MVFP, &v); *value = (v & MVFP_FLIP) == MVFP_FLIP; return ret; } -static int ov7670_t_vflip(struct i2c_client *client, int value) +static int ov7670_s_vflip(struct v4l2_subdev *sd, int value) { unsigned char v = 0; int ret; - ret = ov7670_read(client, REG_MVFP, &v); + ret = ov7670_read(sd, REG_MVFP, &v); if (value) v |= MVFP_FLIP; else v &= ~MVFP_FLIP; msleep(10); /* FIXME */ - ret += ov7670_write(client, REG_MVFP, v); + ret += ov7670_write(sd, REG_MVFP, v); return ret; } - -static struct ov7670_control { - struct v4l2_queryctrl qc; - int (*query)(struct i2c_client *c, __s32 *value); - int (*tweak)(struct i2c_client *c, int value); -} ov7670_controls[] = +static int ov7670_queryctrl(struct v4l2_subdev *sd, + struct v4l2_queryctrl *qc) { - { - .qc = { - .id = V4L2_CID_BRIGHTNESS, - .type = V4L2_CTRL_TYPE_INTEGER, - .name = "Brightness", - .minimum = 0, - .maximum = 255, - .step = 1, - .default_value = 0x80, - .flags = V4L2_CTRL_FLAG_SLIDER - }, - .tweak = ov7670_t_brightness, - .query = ov7670_q_brightness, - }, - { - .qc = { - .id = V4L2_CID_CONTRAST, - .type = V4L2_CTRL_TYPE_INTEGER, - .name = "Contrast", - .minimum = 0, - .maximum = 127, - .step = 1, - .default_value = 0x40, /* XXX ov7670 spec */ - .flags = V4L2_CTRL_FLAG_SLIDER - }, - .tweak = ov7670_t_contrast, - .query = ov7670_q_contrast, - }, - { - .qc = { - .id = V4L2_CID_SATURATION, - .type = V4L2_CTRL_TYPE_INTEGER, - .name = "Saturation", - .minimum = 0, - .maximum = 256, - .step = 1, - .default_value = 0x80, - .flags = V4L2_CTRL_FLAG_SLIDER - }, - .tweak = ov7670_t_sat, - .query = ov7670_q_sat, - }, - { - .qc = { - .id = V4L2_CID_HUE, - .type = V4L2_CTRL_TYPE_INTEGER, - .name = "HUE", - .minimum = -180, - .maximum = 180, - .step = 5, - .default_value = 0, - .flags = V4L2_CTRL_FLAG_SLIDER - }, - .tweak = ov7670_t_hue, - .query = ov7670_q_hue, - }, - { - .qc = { - .id = V4L2_CID_VFLIP, - .type = V4L2_CTRL_TYPE_BOOLEAN, - .name = "Vertical flip", - .minimum = 0, - .maximum = 1, - .step = 1, - .default_value = 0, - }, - .tweak = ov7670_t_vflip, - .query = ov7670_q_vflip, - }, - { - .qc = { - .id = V4L2_CID_HFLIP, - .type = V4L2_CTRL_TYPE_BOOLEAN, - .name = "Horizontal mirror", - .minimum = 0, - .maximum = 1, - .step = 1, - .default_value = 0, - }, - .tweak = ov7670_t_hflip, - .query = ov7670_q_hflip, - }, -}; -#define N_CONTROLS (ARRAY_SIZE(ov7670_controls)) + /* Fill in min, max, step and default value for these controls. */ + switch (qc->id) { + case V4L2_CID_BRIGHTNESS: + return v4l2_ctrl_query_fill(qc, 0, 255, 1, 128); + case V4L2_CID_CONTRAST: + return v4l2_ctrl_query_fill(qc, 0, 127, 1, 64); + case V4L2_CID_VFLIP: + case V4L2_CID_HFLIP: + return v4l2_ctrl_query_fill(qc, 0, 1, 1, 0); + case V4L2_CID_SATURATION: + return v4l2_ctrl_query_fill(qc, 0, 256, 1, 128); + case V4L2_CID_HUE: + return v4l2_ctrl_query_fill(qc, -180, 180, 5, 0); + } + return -EINVAL; +} -static struct ov7670_control *ov7670_find_control(__u32 id) +static int ov7670_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) { - int i; - - for (i = 0; i < N_CONTROLS; i++) - if (ov7670_controls[i].qc.id == id) - return ov7670_controls + i; - return NULL; + switch (ctrl->id) { + case V4L2_CID_BRIGHTNESS: + return ov7670_g_brightness(sd, &ctrl->value); + case V4L2_CID_CONTRAST: + return ov7670_g_contrast(sd, &ctrl->value); + case V4L2_CID_SATURATION: + return ov7670_g_sat(sd, &ctrl->value); + case V4L2_CID_HUE: + return ov7670_g_hue(sd, &ctrl->value); + case V4L2_CID_VFLIP: + return ov7670_g_vflip(sd, &ctrl->value); + case V4L2_CID_HFLIP: + return ov7670_g_hflip(sd, &ctrl->value); + } + return -EINVAL; } +static int ov7670_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) +{ + switch (ctrl->id) { + case V4L2_CID_BRIGHTNESS: + return ov7670_s_brightness(sd, ctrl->value); + case V4L2_CID_CONTRAST: + return ov7670_s_contrast(sd, ctrl->value); + case V4L2_CID_SATURATION: + return ov7670_s_sat(sd, ctrl->value); + case V4L2_CID_HUE: + return ov7670_s_hue(sd, ctrl->value); + case V4L2_CID_VFLIP: + return ov7670_s_vflip(sd, ctrl->value); + case V4L2_CID_HFLIP: + return ov7670_s_hflip(sd, ctrl->value); + } + return -EINVAL; +} -static int ov7670_queryctrl(struct i2c_client *client, - struct v4l2_queryctrl *qc) +static int ov7670_g_chip_ident(struct v4l2_subdev *sd, + struct v4l2_dbg_chip_ident *chip) { - struct ov7670_control *ctrl = ov7670_find_control(qc->id); + struct i2c_client *client = v4l2_get_subdevdata(sd); - if (ctrl == NULL) - return -EINVAL; - *qc = ctrl->qc; - return 0; + return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_OV7670, 0); } -static int ov7670_g_ctrl(struct i2c_client *client, struct v4l2_control *ctrl) +#ifdef CONFIG_VIDEO_ADV_DEBUG +static int ov7670_g_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg) { - struct ov7670_control *octrl = ov7670_find_control(ctrl->id); + struct i2c_client *client = v4l2_get_subdevdata(sd); + unsigned char val = 0; int ret; - if (octrl == NULL) + if (!v4l2_chip_match_i2c_client(client, ®->match)) return -EINVAL; - ret = octrl->query(client, &ctrl->value); - if (ret >= 0) - return 0; + if (!capable(CAP_SYS_ADMIN)) + return -EPERM; + ret = ov7670_read(sd, reg->reg & 0xff, &val); + reg->val = val; + reg->size = 1; return ret; } -static int ov7670_s_ctrl(struct i2c_client *client, struct v4l2_control *ctrl) +static int ov7670_s_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg) { - struct ov7670_control *octrl = ov7670_find_control(ctrl->id); - int ret; + struct i2c_client *client = v4l2_get_subdevdata(sd); - if (octrl == NULL) + if (!v4l2_chip_match_i2c_client(client, ®->match)) return -EINVAL; - ret = octrl->tweak(client, ctrl->value); - if (ret >= 0) - return 0; - return ret; + if (!capable(CAP_SYS_ADMIN)) + return -EPERM; + ov7670_write(sd, reg->reg & 0xff, reg->val & 0xff); + return 0; } +#endif +/* ----------------------------------------------------------------------- */ + +static const struct v4l2_subdev_core_ops ov7670_core_ops = { + .g_chip_ident = ov7670_g_chip_ident, + .g_ctrl = ov7670_g_ctrl, + .s_ctrl = ov7670_s_ctrl, + .queryctrl = ov7670_queryctrl, + .reset = ov7670_reset, + .init = ov7670_init, +#ifdef CONFIG_VIDEO_ADV_DEBUG + .g_register = ov7670_g_register, + .s_register = ov7670_s_register, +#endif +}; +static const struct v4l2_subdev_video_ops ov7670_video_ops = { + .enum_fmt = ov7670_enum_fmt, + .try_fmt = ov7670_try_fmt, + .s_fmt = ov7670_s_fmt, + .s_parm = ov7670_s_parm, + .g_parm = ov7670_g_parm, +}; +static const struct v4l2_subdev_ops ov7670_ops = { + .core = &ov7670_core_ops, + .video = &ov7670_video_ops, +}; +/* ----------------------------------------------------------------------- */ - -/* - * Basic i2c stuff. - */ -static struct i2c_driver ov7670_driver; - -static int ov7670_attach(struct i2c_adapter *adapter) +static int ov7670_probe(struct i2c_client *client, + const struct i2c_device_id *id) { - int ret; - struct i2c_client *client; + struct v4l2_subdev *sd; struct ov7670_info *info; + int ret; - /* - * For now: only deal with adapters we recognize. - */ - if (adapter->id != I2C_HW_SMBUS_CAFE) - return -ENODEV; - - client = kzalloc(sizeof (struct i2c_client), GFP_KERNEL); - if (! client) + info = kzalloc(sizeof(struct ov7670_info), GFP_KERNEL); + if (info == NULL) return -ENOMEM; - client->adapter = adapter; - client->addr = OV7670_I2C_ADDR; - client->driver = &ov7670_driver, - strcpy(client->name, "OV7670"); - /* - * Set up our info structure. - */ - info = kzalloc(sizeof (struct ov7670_info), GFP_KERNEL); - if (! info) { - ret = -ENOMEM; - goto out_free; + sd = &info->sd; + v4l2_i2c_subdev_init(sd, client, &ov7670_ops); + + /* Make sure it's an ov7670 */ + ret = ov7670_detect(sd); + if (ret) { + v4l_dbg(1, debug, client, + "chip found @ 0x%x (%s) is not an ov7670 chip.\n", + client->addr << 1, client->adapter->name); + kfree(info); + return ret; } + v4l_info(client, "chip found @ 0x%02x (%s)\n", + client->addr << 1, client->adapter->name); + info->fmt = &ov7670_formats[0]; info->sat = 128; /* Review this */ - i2c_set_clientdata(client, info); - /* - * Make sure it's an ov7670 - */ - ret = ov7670_detect(client); - if (ret) - goto out_free_info; - ret = i2c_attach_client(client); - if (ret) - goto out_free_info; return 0; - - out_free_info: - kfree(info); - out_free: - kfree(client); - return ret; } -static int ov7670_detach(struct i2c_client *client) +static int ov7670_remove(struct i2c_client *client) { - i2c_detach_client(client); - kfree(i2c_get_clientdata(client)); - kfree(client); - return 0; -} - + struct v4l2_subdev *sd = i2c_get_clientdata(client); -static int ov7670_command(struct i2c_client *client, unsigned int cmd, - void *arg) -{ - switch (cmd) { - case VIDIOC_DBG_G_CHIP_IDENT: - return v4l2_chip_ident_i2c_client(client, arg, V4L2_IDENT_OV7670, 0); - - case VIDIOC_INT_RESET: - ov7670_reset(client); - return 0; - - case VIDIOC_INT_INIT: - return ov7670_init(client); - - case VIDIOC_ENUM_FMT: - return ov7670_enum_fmt(client, (struct v4l2_fmtdesc *) arg); - case VIDIOC_TRY_FMT: - return ov7670_try_fmt(client, (struct v4l2_format *) arg, NULL, NULL); - case VIDIOC_S_FMT: - return ov7670_s_fmt(client, (struct v4l2_format *) arg); - case VIDIOC_QUERYCTRL: - return ov7670_queryctrl(client, (struct v4l2_queryctrl *) arg); - case VIDIOC_S_CTRL: - return ov7670_s_ctrl(client, (struct v4l2_control *) arg); - case VIDIOC_G_CTRL: - return ov7670_g_ctrl(client, (struct v4l2_control *) arg); - case VIDIOC_S_PARM: - return ov7670_s_parm(client, (struct v4l2_streamparm *) arg); - case VIDIOC_G_PARM: - return ov7670_g_parm(client, (struct v4l2_streamparm *) arg); - } - return -EINVAL; + v4l2_device_unregister_subdev(sd); + kfree(to_state(sd)); + return 0; } - - -static struct i2c_driver ov7670_driver = { - .driver = { - .name = "ov7670", - }, - .id = I2C_DRIVERID_OV7670, - .attach_adapter = ov7670_attach, - .detach_client = ov7670_detach, - .command = ov7670_command, +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 26) +static const struct i2c_device_id ov7670_id[] = { + { "ov7670", 0 }, + { } }; +MODULE_DEVICE_TABLE(i2c, ov7670_id); - -/* - * Module initialization - */ -static int __init ov7670_mod_init(void) -{ - printk(KERN_NOTICE "OmniVision ov7670 sensor driver, at your service\n"); - return i2c_add_driver(&ov7670_driver); -} - -static void __exit ov7670_mod_exit(void) -{ - i2c_del_driver(&ov7670_driver); -} - -module_init(ov7670_mod_init); -module_exit(ov7670_mod_exit); +#endif +static struct v4l2_i2c_driver_data v4l2_i2c_data = { + .name = "ov7670", + .probe = ov7670_probe, + .remove = ov7670_remove, +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 26) + .id_table = ov7670_id, +#endif +}; diff --git a/linux/drivers/media/video/ov772x.c b/linux/drivers/media/video/ov772x.c index 2f3313524..cde3a1019 100644 --- a/linux/drivers/media/video/ov772x.c +++ b/linux/drivers/media/video/ov772x.c @@ -646,6 +646,8 @@ static int ov772x_start_capture(struct soc_camera_device *icd) return -EPERM; } + ov772x_mask_set(priv->client, COM2, SOFT_SLEEP_MODE, 0); + dev_dbg(&icd->dev, "format %s, win %s\n", priv->fmt->name, priv->win->name); @@ -654,6 +656,8 @@ static int ov772x_start_capture(struct soc_camera_device *icd) static int ov772x_stop_capture(struct soc_camera_device *icd) { + struct ov772x_priv *priv = container_of(icd, struct ov772x_priv, icd); + ov772x_mask_set(priv->client, COM2, SOFT_SLEEP_MODE, SOFT_SLEEP_MODE); return 0; } @@ -781,11 +785,9 @@ ov772x_select_win(u32 width, u32 height) return win; } -static int ov772x_set_fmt(struct soc_camera_device *icd, - __u32 pixfmt, - struct v4l2_rect *rect) +static int ov772x_set_params(struct ov772x_priv *priv, u32 width, u32 height, + u32 pixfmt) { - struct ov772x_priv *priv = container_of(icd, struct ov772x_priv, icd); int ret = -EINVAL; u8 val; int i; @@ -806,7 +808,7 @@ static int ov772x_set_fmt(struct soc_camera_device *icd, /* * select win */ - priv->win = ov772x_select_win(rect->width, rect->height); + priv->win = ov772x_select_win(width, height); /* * reset hardware @@ -870,6 +872,28 @@ ov772x_set_fmt_error: return ret; } +static int ov772x_set_crop(struct soc_camera_device *icd, + struct v4l2_rect *rect) +{ + struct ov772x_priv *priv = container_of(icd, struct ov772x_priv, icd); + + if (!priv->fmt) + return -EINVAL; + + return ov772x_set_params(priv, rect->width, rect->height, + priv->fmt->fourcc); +} + +static int ov772x_set_fmt(struct soc_camera_device *icd, + struct v4l2_format *f) +{ + struct ov772x_priv *priv = container_of(icd, struct ov772x_priv, icd); + struct v4l2_pix_format *pix = &f->fmt.pix; + + return ov772x_set_params(priv, pix->width, pix->height, + pix->pixelformat); +} + static int ov772x_try_fmt(struct soc_camera_device *icd, struct v4l2_format *f) { @@ -959,6 +983,7 @@ static struct soc_camera_ops ov772x_ops = { .release = ov772x_release, .start_capture = ov772x_start_capture, .stop_capture = ov772x_stop_capture, + .set_crop = ov772x_set_crop, .set_fmt = ov772x_set_fmt, .try_fmt = ov772x_try_fmt, .set_bus_param = ov772x_set_bus_param, diff --git a/linux/drivers/media/video/pvrusb2/Kconfig b/linux/drivers/media/video/pvrusb2/Kconfig index 17cde1757..f9b6001e1 100644 --- a/linux/drivers/media/video/pvrusb2/Kconfig +++ b/linux/drivers/media/video/pvrusb2/Kconfig @@ -41,9 +41,9 @@ config VIDEO_PVRUSB2_DVB select DVB_S5H1409 if !DVB_FE_CUSTOMISE select DVB_S5H1411 if !DVB_FE_CUSTOMISE select DVB_TDA10048 if !DVB_FE_CUSTOMISE - select MEDIA_TUNER_TDA18271 if !MEDIA_TUNER_CUSTOMIZE - select MEDIA_TUNER_SIMPLE if !MEDIA_TUNER_CUSTOMIZE - select MEDIA_TUNER_TDA8290 if !MEDIA_TUNER_CUSTOMIZE + select MEDIA_TUNER_TDA18271 if !MEDIA_TUNER_CUSTOMISE + select MEDIA_TUNER_SIMPLE if !MEDIA_TUNER_CUSTOMISE + select MEDIA_TUNER_TDA8290 if !MEDIA_TUNER_CUSTOMISE ---help--- This option enables a DVB interface for the pvrusb2 driver. diff --git a/linux/drivers/media/video/pvrusb2/Makefile b/linux/drivers/media/video/pvrusb2/Makefile index 4fda2de69..de2fc14f0 100644 --- a/linux/drivers/media/video/pvrusb2/Makefile +++ b/linux/drivers/media/video/pvrusb2/Makefile @@ -2,14 +2,15 @@ obj-pvrusb2-sysfs-$(CONFIG_VIDEO_PVRUSB2_SYSFS) := pvrusb2-sysfs.o obj-pvrusb2-debugifc-$(CONFIG_VIDEO_PVRUSB2_DEBUGIFC) := pvrusb2-debugifc.o obj-pvrusb2-dvb-$(CONFIG_VIDEO_PVRUSB2_DVB) := pvrusb2-dvb.o -pvrusb2-objs := pvrusb2-i2c-core.o pvrusb2-i2c-cmd-v4l2.o \ - pvrusb2-audio.o pvrusb2-i2c-chips-v4l2.o \ +pvrusb2-objs := pvrusb2-i2c-core.o \ + pvrusb2-audio.o \ pvrusb2-encoder.o pvrusb2-video-v4l.o \ - pvrusb2-eeprom.o pvrusb2-tuner.o \ + pvrusb2-eeprom.o \ pvrusb2-main.o pvrusb2-hdw.o pvrusb2-v4l2.o \ pvrusb2-ctrl.o pvrusb2-std.o pvrusb2-devattr.o \ pvrusb2-context.o pvrusb2-io.o pvrusb2-ioread.o \ pvrusb2-cx2584x-v4l.o pvrusb2-wm8775.o \ + pvrusb2-cs53l32a.o \ $(obj-pvrusb2-dvb-y) \ $(obj-pvrusb2-sysfs-y) $(obj-pvrusb2-debugifc-y) diff --git a/linux/drivers/media/video/pvrusb2/pvrusb2-audio.c b/linux/drivers/media/video/pvrusb2/pvrusb2-audio.c index 65babb878..61cc80ef2 100644 --- a/linux/drivers/media/video/pvrusb2/pvrusb2-audio.c +++ b/linux/drivers/media/video/pvrusb2/pvrusb2-audio.c @@ -27,14 +27,6 @@ #include <media/v4l2-common.h> #include "compat.h" -struct pvr2_msp3400_handler { - struct pvr2_hdw *hdw; - struct pvr2_i2c_client *client; - struct pvr2_i2c_handler i2c_handler; - unsigned long stale_mask; -}; - - struct routing_scheme { const int *def; @@ -64,123 +56,33 @@ static const struct routing_scheme routing_schemes[] = { }, }; -/* This function selects the correct audio input source */ -static void set_stereo(struct pvr2_msp3400_handler *ctxt) -{ - struct pvr2_hdw *hdw = ctxt->hdw; - struct v4l2_routing route; - const struct routing_scheme *sp; - unsigned int sid = hdw->hdw_desc->signal_routing_scheme; - - pvr2_trace(PVR2_TRACE_CHIPS,"i2c msp3400 v4l2 set_stereo"); - - if ((sid < ARRAY_SIZE(routing_schemes)) && - ((sp = routing_schemes + sid) != NULL) && - (hdw->input_val >= 0) && - (hdw->input_val < sp->cnt)) { - route.input = sp->def[hdw->input_val]; - } else { - pvr2_trace(PVR2_TRACE_ERROR_LEGS, - "*** WARNING *** i2c msp3400 v4l2 set_stereo:" - " Invalid routing scheme (%u) and/or input (%d)", - sid,hdw->input_val); - return; - } - route.output = MSP_OUTPUT(MSP_SC_IN_DSP_SCART1); - pvr2_i2c_client_cmd(ctxt->client,VIDIOC_INT_S_AUDIO_ROUTING,&route); -} - - -static int check_stereo(struct pvr2_msp3400_handler *ctxt) +void pvr2_msp3400_subdev_update(struct pvr2_hdw *hdw, struct v4l2_subdev *sd) { - struct pvr2_hdw *hdw = ctxt->hdw; - return hdw->input_dirty; -} - - -struct pvr2_msp3400_ops { - void (*update)(struct pvr2_msp3400_handler *); - int (*check)(struct pvr2_msp3400_handler *); -}; - - -static const struct pvr2_msp3400_ops msp3400_ops[] = { - { .update = set_stereo, .check = check_stereo}, -}; - - -static int msp3400_check(struct pvr2_msp3400_handler *ctxt) -{ - unsigned long msk; - unsigned int idx; - - for (idx = 0; idx < ARRAY_SIZE(msp3400_ops); idx++) { - msk = 1 << idx; - if (ctxt->stale_mask & msk) continue; - if (msp3400_ops[idx].check(ctxt)) { - ctxt->stale_mask |= msk; + if (hdw->input_dirty || hdw->force_dirty) { + struct v4l2_routing route; + const struct routing_scheme *sp; + unsigned int sid = hdw->hdw_desc->signal_routing_scheme; + + pvr2_trace(PVR2_TRACE_CHIPS, "subdev msp3400 v4l2 set_stereo"); + + if ((sid < ARRAY_SIZE(routing_schemes)) && + ((sp = routing_schemes + sid) != NULL) && + (hdw->input_val >= 0) && + (hdw->input_val < sp->cnt)) { + route.input = sp->def[hdw->input_val]; + } else { + pvr2_trace(PVR2_TRACE_ERROR_LEGS, + "*** WARNING *** subdev msp3400 set_input:" + " Invalid routing scheme (%u)" + " and/or input (%d)", + sid, hdw->input_val); + return; } + route.output = MSP_OUTPUT(MSP_SC_IN_DSP_SCART1); + sd->ops->audio->s_routing(sd, &route); } - return ctxt->stale_mask != 0; } - -static void msp3400_update(struct pvr2_msp3400_handler *ctxt) -{ - unsigned long msk; - unsigned int idx; - - for (idx = 0; idx < ARRAY_SIZE(msp3400_ops); idx++) { - msk = 1 << idx; - if (!(ctxt->stale_mask & msk)) continue; - ctxt->stale_mask &= ~msk; - msp3400_ops[idx].update(ctxt); - } -} - - -static void pvr2_msp3400_detach(struct pvr2_msp3400_handler *ctxt) -{ - ctxt->client->handler = NULL; - kfree(ctxt); -} - - -static unsigned int pvr2_msp3400_describe(struct pvr2_msp3400_handler *ctxt, - char *buf,unsigned int cnt) -{ - return scnprintf(buf,cnt,"handler: pvrusb2-audio v4l2"); -} - - -static const struct pvr2_i2c_handler_functions msp3400_funcs = { - .detach = (void (*)(void *))pvr2_msp3400_detach, - .check = (int (*)(void *))msp3400_check, - .update = (void (*)(void *))msp3400_update, - .describe = (unsigned int (*)(void *,char *,unsigned int))pvr2_msp3400_describe, -}; - - -int pvr2_i2c_msp3400_setup(struct pvr2_hdw *hdw,struct pvr2_i2c_client *cp) -{ - struct pvr2_msp3400_handler *ctxt; - if (cp->handler) return 0; - - ctxt = kzalloc(sizeof(*ctxt),GFP_KERNEL); - if (!ctxt) return 0; - - ctxt->i2c_handler.func_data = ctxt; - ctxt->i2c_handler.func_table = &msp3400_funcs; - ctxt->client = cp; - ctxt->hdw = hdw; - ctxt->stale_mask = (1 << ARRAY_SIZE(msp3400_ops)) - 1; - cp->handler = &ctxt->i2c_handler; - pvr2_trace(PVR2_TRACE_CHIPS,"i2c 0x%x msp3400 V4L2 handler set up", - cp->client->addr); - return !0; -} - - /* Stuff for Emacs to see, in order to encourage consistent editing style: *** Local Variables: *** diff --git a/linux/drivers/media/video/pvrusb2/pvrusb2-audio.h b/linux/drivers/media/video/pvrusb2/pvrusb2-audio.h index ac54eed37..e3e63d750 100644 --- a/linux/drivers/media/video/pvrusb2/pvrusb2-audio.h +++ b/linux/drivers/media/video/pvrusb2/pvrusb2-audio.h @@ -22,10 +22,8 @@ #ifndef __PVRUSB2_AUDIO_H #define __PVRUSB2_AUDIO_H -#include "pvrusb2-i2c-core.h" - -int pvr2_i2c_msp3400_setup(struct pvr2_hdw *,struct pvr2_i2c_client *); - +#include "pvrusb2-hdw-internal.h" +void pvr2_msp3400_subdev_update(struct pvr2_hdw *, struct v4l2_subdev *); #endif /* __PVRUSB2_AUDIO_H */ /* diff --git a/linux/drivers/media/video/pvrusb2/pvrusb2-cs53l32a.c b/linux/drivers/media/video/pvrusb2/pvrusb2-cs53l32a.c new file mode 100644 index 000000000..932943bd7 --- /dev/null +++ b/linux/drivers/media/video/pvrusb2/pvrusb2-cs53l32a.c @@ -0,0 +1,96 @@ +/* + * + * + * Copyright (C) 2005 Mike Isely <isely@pobox.com> + * Copyright (C) 2004 Aurelien Alleaume <slts@free.fr> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +/* + + This source file is specifically designed to interface with the + v4l-dvb cs53l32a module. + +*/ + +#include "pvrusb2-cs53l32a.h" + + +#include "pvrusb2-hdw-internal.h" +#include "pvrusb2-debug.h" +#include <linux/videodev2.h> +#include <media/v4l2-common.h> +#include <linux/errno.h> +#include <linux/slab.h> +#include "compat.h" + +struct routing_scheme { + const int *def; + unsigned int cnt; +}; + + +static const int routing_scheme1[] = { + [PVR2_CVAL_INPUT_TV] = 2, /* 1 or 2 seems to work here */ + [PVR2_CVAL_INPUT_RADIO] = 2, + [PVR2_CVAL_INPUT_COMPOSITE] = 0, + [PVR2_CVAL_INPUT_SVIDEO] = 0, +}; + +static const struct routing_scheme routing_schemes[] = { + [PVR2_ROUTING_SCHEME_ONAIR] = { + .def = routing_scheme1, + .cnt = ARRAY_SIZE(routing_scheme1), + }, +}; + + +void pvr2_cs53l32a_subdev_update(struct pvr2_hdw *hdw, struct v4l2_subdev *sd) +{ + if (hdw->input_dirty || hdw->force_dirty) { + struct v4l2_routing route; + const struct routing_scheme *sp; + unsigned int sid = hdw->hdw_desc->signal_routing_scheme; + pvr2_trace(PVR2_TRACE_CHIPS, "subdev v4l2 set_input(%d)", + hdw->input_val); + if ((sid < ARRAY_SIZE(routing_schemes)) && + ((sp = routing_schemes + sid) != NULL) && + (hdw->input_val >= 0) && + (hdw->input_val < sp->cnt)) { + route.input = sp->def[hdw->input_val]; + } else { + pvr2_trace(PVR2_TRACE_ERROR_LEGS, + "*** WARNING *** subdev v4l2 set_input:" + " Invalid routing scheme (%u)" + " and/or input (%d)", + sid, hdw->input_val); + return; + } + route.output = 0; + sd->ops->audio->s_routing(sd, &route); + } +} + + +/* + Stuff for Emacs to see, in order to encourage consistent editing style: + *** Local Variables: *** + *** mode: c *** + *** fill-column: 70 *** + *** tab-width: 8 *** + *** c-basic-offset: 8 *** + *** End: *** + */ diff --git a/linux/drivers/media/video/pvrusb2/pvrusb2-tuner.h b/linux/drivers/media/video/pvrusb2/pvrusb2-cs53l32a.h index ef4afaf37..53ba548b7 100644 --- a/linux/drivers/media/video/pvrusb2/pvrusb2-tuner.h +++ b/linux/drivers/media/video/pvrusb2/pvrusb2-cs53l32a.h @@ -2,6 +2,7 @@ * * * Copyright (C) 2005 Mike Isely <isely@pobox.com> + * Copyright (C) 2004 Aurelien Alleaume <slts@free.fr> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,14 +18,24 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ -#ifndef __PVRUSB2_TUNER_H -#define __PVRUSB2_TUNER_H -#include "pvrusb2-i2c-core.h" +#ifndef __PVRUSB2_CS53L32A_H +#define __PVRUSB2_CS53L32A_H -int pvr2_i2c_tuner_setup(struct pvr2_hdw *,struct pvr2_i2c_client *); +/* + + This module connects the pvrusb2 driver to the I2C chip level + driver which handles device video processing. This interface is + used internally by the driver; higher level code should only + interact through the interface provided by pvrusb2-hdw.h. + +*/ + + +#include "pvrusb2-hdw-internal.h" +void pvr2_cs53l32a_subdev_update(struct pvr2_hdw *, struct v4l2_subdev *); -#endif /* __PVRUSB2_TUNER_H */ +#endif /* __PVRUSB2_AUDIO_CS53L32A_H */ /* Stuff for Emacs to see, in order to encourage consistent editing style: diff --git a/linux/drivers/media/video/pvrusb2/pvrusb2-cx2584x-v4l.c b/linux/drivers/media/video/pvrusb2/pvrusb2-cx2584x-v4l.c index 2f051f797..e0a6de5ae 100644 --- a/linux/drivers/media/video/pvrusb2/pvrusb2-cx2584x-v4l.c +++ b/linux/drivers/media/video/pvrusb2/pvrusb2-cx2584x-v4l.c @@ -28,7 +28,6 @@ #include "pvrusb2-cx2584x-v4l.h" #include "pvrusb2-video-v4l.h" -#include "pvrusb2-i2c-cmd-v4l2.h" #include "pvrusb2-hdw-internal.h" @@ -40,14 +39,6 @@ #include <linux/slab.h> #include "compat.h" -struct pvr2_v4l_cx2584x { - struct pvr2_i2c_handler handler; - struct pvr2_decoder_ctrl ctrl; - struct pvr2_i2c_client *client; - struct pvr2_hdw *hdw; - unsigned long stale_mask; -}; - struct routing_scheme_item { int vid; @@ -111,218 +102,44 @@ static const struct routing_scheme routing_schemes[] = { }, }; -static void set_input(struct pvr2_v4l_cx2584x *ctxt) -{ - struct pvr2_hdw *hdw = ctxt->hdw; - struct v4l2_routing route; - enum cx25840_video_input vid_input; - enum cx25840_audio_input aud_input; - const struct routing_scheme *sp; - unsigned int sid = hdw->hdw_desc->signal_routing_scheme; - - memset(&route,0,sizeof(route)); - - if ((sid < ARRAY_SIZE(routing_schemes)) && - ((sp = routing_schemes + sid) != NULL) && - (hdw->input_val >= 0) && - (hdw->input_val < sp->cnt)) { - vid_input = sp->def[hdw->input_val].vid; - aud_input = sp->def[hdw->input_val].aud; - } else { - pvr2_trace(PVR2_TRACE_ERROR_LEGS, - "*** WARNING *** i2c cx2584x set_input:" - " Invalid routing scheme (%u) and/or input (%d)", - sid,hdw->input_val); - return; - } - - pvr2_trace(PVR2_TRACE_CHIPS,"i2c cx2584x set_input vid=0x%x aud=0x%x", - vid_input,aud_input); - route.input = (u32)vid_input; - pvr2_i2c_client_cmd(ctxt->client,VIDIOC_INT_S_VIDEO_ROUTING,&route); - route.input = (u32)aud_input; - pvr2_i2c_client_cmd(ctxt->client,VIDIOC_INT_S_AUDIO_ROUTING,&route); -} - - -static int check_input(struct pvr2_v4l_cx2584x *ctxt) -{ - struct pvr2_hdw *hdw = ctxt->hdw; - return hdw->input_dirty != 0; -} - - -static void set_audio(struct pvr2_v4l_cx2584x *ctxt) -{ - u32 val; - struct pvr2_hdw *hdw = ctxt->hdw; - - pvr2_trace(PVR2_TRACE_CHIPS,"i2c cx2584x set_audio %d", - hdw->srate_val); - switch (hdw->srate_val) { - default: - case V4L2_MPEG_AUDIO_SAMPLING_FREQ_48000: - val = 48000; - break; - case V4L2_MPEG_AUDIO_SAMPLING_FREQ_44100: - val = 44100; - break; - case V4L2_MPEG_AUDIO_SAMPLING_FREQ_32000: - val = 32000; - break; - } - pvr2_i2c_client_cmd(ctxt->client,VIDIOC_INT_AUDIO_CLOCK_FREQ,&val); -} - - -static int check_audio(struct pvr2_v4l_cx2584x *ctxt) -{ - struct pvr2_hdw *hdw = ctxt->hdw; - return hdw->srate_dirty != 0; -} - - -struct pvr2_v4l_cx2584x_ops { - void (*update)(struct pvr2_v4l_cx2584x *); - int (*check)(struct pvr2_v4l_cx2584x *); -}; - - -static const struct pvr2_v4l_cx2584x_ops decoder_ops[] = { - { .update = set_input, .check = check_input}, - { .update = set_audio, .check = check_audio}, -}; - - -static void decoder_detach(struct pvr2_v4l_cx2584x *ctxt) +void pvr2_cx25840_subdev_update(struct pvr2_hdw *hdw, struct v4l2_subdev *sd) { - ctxt->client->handler = NULL; - pvr2_hdw_set_decoder(ctxt->hdw,NULL); - kfree(ctxt); -} - - -static int decoder_check(struct pvr2_v4l_cx2584x *ctxt) -{ - unsigned long msk; - unsigned int idx; - - for (idx = 0; idx < ARRAY_SIZE(decoder_ops); idx++) { - msk = 1 << idx; - if (ctxt->stale_mask & msk) continue; - if (decoder_ops[idx].check(ctxt)) { - ctxt->stale_mask |= msk; + pvr2_trace(PVR2_TRACE_CHIPS, "subdev cx2584x update..."); + if (hdw->input_dirty || hdw->force_dirty) { + struct v4l2_routing route; + enum cx25840_video_input vid_input; + enum cx25840_audio_input aud_input; + const struct routing_scheme *sp; + unsigned int sid = hdw->hdw_desc->signal_routing_scheme; + + memset(&route, 0, sizeof(route)); + + if ((sid < ARRAY_SIZE(routing_schemes)) && + ((sp = routing_schemes + sid) != NULL) && + (hdw->input_val >= 0) && + (hdw->input_val < sp->cnt)) { + vid_input = sp->def[hdw->input_val].vid; + aud_input = sp->def[hdw->input_val].aud; + } else { + pvr2_trace(PVR2_TRACE_ERROR_LEGS, + "*** WARNING *** subdev cx2584x set_input:" + " Invalid routing scheme (%u)" + " and/or input (%d)", + sid, hdw->input_val); + return; } - } - return ctxt->stale_mask != 0; -} - -static void decoder_update(struct pvr2_v4l_cx2584x *ctxt) -{ - unsigned long msk; - unsigned int idx; - - for (idx = 0; idx < ARRAY_SIZE(decoder_ops); idx++) { - msk = 1 << idx; - if (!(ctxt->stale_mask & msk)) continue; - ctxt->stale_mask &= ~msk; - decoder_ops[idx].update(ctxt); + pvr2_trace(PVR2_TRACE_CHIPS, + "subdev cx2584x set_input vid=0x%x aud=0x%x", + vid_input, aud_input); + route.input = (u32)vid_input; + sd->ops->video->s_routing(sd, &route); + route.input = (u32)aud_input; + sd->ops->audio->s_routing(sd, &route); } } -static void decoder_enable(struct pvr2_v4l_cx2584x *ctxt,int fl) -{ - pvr2_trace(PVR2_TRACE_CHIPS,"i2c cx25840 decoder_enable(%d)",fl); - pvr2_v4l2_cmd_stream(ctxt->client,fl); -} - - -static int decoder_detect(struct pvr2_i2c_client *cp) -{ - int ret; - /* Attempt to query the decoder - let's see if it will answer */ - struct v4l2_queryctrl qc; - - memset(&qc,0,sizeof(qc)); - - qc.id = V4L2_CID_BRIGHTNESS; - - ret = pvr2_i2c_client_cmd(cp,VIDIOC_QUERYCTRL,&qc); - return ret == 0; /* Return true if it answered */ -} - - -static unsigned int decoder_describe(struct pvr2_v4l_cx2584x *ctxt, - char *buf,unsigned int cnt) -{ - return scnprintf(buf,cnt,"handler: pvrusb2-cx2584x-v4l"); -} - - -static void decoder_reset(struct pvr2_v4l_cx2584x *ctxt) -{ - int ret; - ret = pvr2_i2c_client_cmd(ctxt->client,VIDIOC_INT_RESET,NULL); - pvr2_trace(PVR2_TRACE_CHIPS,"i2c cx25840 decoder_reset (ret=%d)",ret); -} - - -static const struct pvr2_i2c_handler_functions hfuncs = { - .detach = (void (*)(void *))decoder_detach, - .check = (int (*)(void *))decoder_check, - .update = (void (*)(void *))decoder_update, - .describe = (unsigned int (*)(void *,char *,unsigned int))decoder_describe, -}; - - -int pvr2_i2c_cx2584x_v4l_setup(struct pvr2_hdw *hdw, - struct pvr2_i2c_client *cp) -{ - struct pvr2_v4l_cx2584x *ctxt; - - if (hdw->decoder_ctrl) return 0; - if (cp->handler) return 0; - if (!decoder_detect(cp)) return 0; - - ctxt = kzalloc(sizeof(*ctxt),GFP_KERNEL); - if (!ctxt) return 0; - - ctxt->handler.func_data = ctxt; - ctxt->handler.func_table = &hfuncs; - ctxt->ctrl.ctxt = ctxt; - ctxt->ctrl.detach = (void (*)(void *))decoder_detach; - ctxt->ctrl.enable = (void (*)(void *,int))decoder_enable; - ctxt->ctrl.force_reset = (void (*)(void*))decoder_reset; - ctxt->client = cp; - ctxt->hdw = hdw; - ctxt->stale_mask = (1 << ARRAY_SIZE(decoder_ops)) - 1; - pvr2_hdw_set_decoder(hdw,&ctxt->ctrl); - cp->handler = &ctxt->handler; - { - /* - Mike Isely <isely@pobox.com> 19-Nov-2006 - This bit - of nuttiness for cx25840 causes that module to - correctly set up its video scaling. This is really - a problem in the cx25840 module itself, but we work - around it here. The problem has not been seen in - ivtv because there VBI is supported and set up. We - don't do VBI here (at least not yet) and thus we - never attempted to even set it up. - */ - struct v4l2_format fmt; - memset(&fmt,0,sizeof(fmt)); - fmt.type = V4L2_BUF_TYPE_SLICED_VBI_CAPTURE; - pvr2_i2c_client_cmd(ctxt->client,VIDIOC_S_FMT,&fmt); - } - pvr2_trace(PVR2_TRACE_CHIPS,"i2c 0x%x cx2584x V4L2 handler set up", - cp->client->addr); - return !0; -} - - - /* Stuff for Emacs to see, in order to encourage consistent editing style: diff --git a/linux/drivers/media/video/pvrusb2/pvrusb2-cx2584x-v4l.h b/linux/drivers/media/video/pvrusb2/pvrusb2-cx2584x-v4l.h index 66abf77f5..e35c2322a 100644 --- a/linux/drivers/media/video/pvrusb2/pvrusb2-cx2584x-v4l.h +++ b/linux/drivers/media/video/pvrusb2/pvrusb2-cx2584x-v4l.h @@ -34,9 +34,9 @@ -#include "pvrusb2-i2c-core.h" +#include "pvrusb2-hdw-internal.h" -int pvr2_i2c_cx2584x_v4l_setup(struct pvr2_hdw *,struct pvr2_i2c_client *); +void pvr2_cx25840_subdev_update(struct pvr2_hdw *, struct v4l2_subdev *sd); #endif /* __PVRUSB2_CX2584X_V4L_H */ diff --git a/linux/drivers/media/video/pvrusb2/pvrusb2-debugifc.c b/linux/drivers/media/video/pvrusb2/pvrusb2-debugifc.c index ca892fb78..fbe3856bd 100644 --- a/linux/drivers/media/video/pvrusb2/pvrusb2-debugifc.c +++ b/linux/drivers/media/video/pvrusb2/pvrusb2-debugifc.c @@ -23,7 +23,6 @@ #include "pvrusb2-debugifc.h" #include "pvrusb2-hdw.h" #include "pvrusb2-debug.h" -#include "pvrusb2-i2c-core.h" struct debugifc_mask_item { const char *name; @@ -147,10 +146,6 @@ int pvr2_debugifc_print_info(struct pvr2_hdw *hdw,char *buf,unsigned int acnt) bcnt += ccnt; acnt -= ccnt; buf += ccnt; ccnt = pvr2_hdw_state_report(hdw,buf,acnt); bcnt += ccnt; acnt -= ccnt; buf += ccnt; - ccnt = scnprintf(buf,acnt,"Attached I2C modules:\n"); - bcnt += ccnt; acnt -= ccnt; buf += ccnt; - ccnt = pvr2_i2c_report(hdw,buf,acnt); - bcnt += ccnt; acnt -= ccnt; buf += ccnt; return bcnt; } diff --git a/linux/drivers/media/video/pvrusb2/pvrusb2-debugifc.h b/linux/drivers/media/video/pvrusb2/pvrusb2-debugifc.h index e24ff59f8..2f8d46761 100644 --- a/linux/drivers/media/video/pvrusb2/pvrusb2-debugifc.h +++ b/linux/drivers/media/video/pvrusb2/pvrusb2-debugifc.h @@ -22,16 +22,16 @@ struct pvr2_hdw; -/* Non-intrusively print some useful debugging info from inside the - driver. This should work even if the driver appears to be - wedged. */ -int pvr2_debugifc_print_info(struct pvr2_hdw *, - char *buf_ptr,unsigned int buf_size); - /* Print general status of driver. This will also trigger a probe of the USB link. Unlike print_info(), this one synchronizes with the driver so the information should be self-consistent (but it will hang if the driver is wedged). */ +int pvr2_debugifc_print_info(struct pvr2_hdw *, + char *buf_ptr, unsigned int buf_size); + +/* Non-intrusively print some useful debugging info from inside the + driver. This should work even if the driver appears to be + wedged. */ int pvr2_debugifc_print_status(struct pvr2_hdw *, char *buf_ptr,unsigned int buf_size); diff --git a/linux/drivers/media/video/pvrusb2/pvrusb2-devattr.c b/linux/drivers/media/video/pvrusb2/pvrusb2-devattr.c index cbe2a3417..1cb6a260e 100644 --- a/linux/drivers/media/video/pvrusb2/pvrusb2-devattr.c +++ b/linux/drivers/media/video/pvrusb2/pvrusb2-devattr.c @@ -46,10 +46,11 @@ pvr2_device_desc structures. /*------------------------------------------------------------------------*/ /* Hauppauge PVR-USB2 Model 29xxx */ -static const char *pvr2_client_29xxx[] = { - "msp3400", - "saa7115", - "tuner", +static const struct pvr2_device_client_desc pvr2_cli_29xxx[] = { + { .module_id = PVR2_CLIENT_ID_SAA7115 }, + { .module_id = PVR2_CLIENT_ID_MSP3400 }, + { .module_id = PVR2_CLIENT_ID_TUNER }, + { .module_id = PVR2_CLIENT_ID_DEMOD }, }; static const char *pvr2_fw1_names_29xxx[] = { @@ -59,8 +60,8 @@ static const char *pvr2_fw1_names_29xxx[] = { static const struct pvr2_device_desc pvr2_device_29xxx = { .description = "WinTV PVR USB2 Model Category 29xxx", .shortname = "29xxx", - .client_modules.lst = pvr2_client_29xxx, - .client_modules.cnt = ARRAY_SIZE(pvr2_client_29xxx), + .client_table.lst = pvr2_cli_29xxx, + .client_table.cnt = ARRAY_SIZE(pvr2_cli_29xxx), .fx2_firmware.lst = pvr2_fw1_names_29xxx, .fx2_firmware.cnt = ARRAY_SIZE(pvr2_fw1_names_29xxx), .flag_has_hauppauge_rom = !0, @@ -77,10 +78,11 @@ static const struct pvr2_device_desc pvr2_device_29xxx = { /*------------------------------------------------------------------------*/ /* Hauppauge PVR-USB2 Model 24xxx */ -static const char *pvr2_client_24xxx[] = { - "cx25840", - "tuner", - "wm8775", +static const struct pvr2_device_client_desc pvr2_cli_24xxx[] = { + { .module_id = PVR2_CLIENT_ID_CX25840 }, + { .module_id = PVR2_CLIENT_ID_TUNER }, + { .module_id = PVR2_CLIENT_ID_WM8775 }, + { .module_id = PVR2_CLIENT_ID_DEMOD }, }; static const char *pvr2_fw1_names_24xxx[] = { @@ -90,8 +92,8 @@ static const char *pvr2_fw1_names_24xxx[] = { static const struct pvr2_device_desc pvr2_device_24xxx = { .description = "WinTV PVR USB2 Model Category 24xxx", .shortname = "24xxx", - .client_modules.lst = pvr2_client_24xxx, - .client_modules.cnt = ARRAY_SIZE(pvr2_client_24xxx), + .client_table.lst = pvr2_cli_24xxx, + .client_table.cnt = ARRAY_SIZE(pvr2_cli_24xxx), .fx2_firmware.lst = pvr2_fw1_names_24xxx, .fx2_firmware.cnt = ARRAY_SIZE(pvr2_fw1_names_24xxx), .flag_has_cx25840 = !0, @@ -111,16 +113,16 @@ static const struct pvr2_device_desc pvr2_device_24xxx = { /*------------------------------------------------------------------------*/ /* GOTVIEW USB2.0 DVD2 */ -static const char *pvr2_client_gotview_2[] = { - "cx25840", - "tuner", +static const struct pvr2_device_client_desc pvr2_cli_gotview_2[] = { + { .module_id = PVR2_CLIENT_ID_CX25840 }, + { .module_id = PVR2_CLIENT_ID_TUNER }, }; static const struct pvr2_device_desc pvr2_device_gotview_2 = { .description = "Gotview USB 2.0 DVD 2", .shortname = "gv2", - .client_modules.lst = pvr2_client_gotview_2, - .client_modules.cnt = ARRAY_SIZE(pvr2_client_gotview_2), + .client_table.lst = pvr2_cli_gotview_2, + .client_table.cnt = ARRAY_SIZE(pvr2_cli_gotview_2), .flag_has_cx25840 = !0, .default_tuner_type = TUNER_PHILIPS_FM1216ME_MK3, .flag_has_analogtuner = !0, @@ -140,8 +142,8 @@ static const struct pvr2_device_desc pvr2_device_gotview_2 = { static const struct pvr2_device_desc pvr2_device_gotview_2d = { .description = "Gotview USB 2.0 DVD Deluxe", .shortname = "gv2d", - .client_modules.lst = pvr2_client_gotview_2, - .client_modules.cnt = ARRAY_SIZE(pvr2_client_gotview_2), + .client_table.lst = pvr2_cli_gotview_2, + .client_table.cnt = ARRAY_SIZE(pvr2_cli_gotview_2), .flag_has_cx25840 = !0, .default_tuner_type = TUNER_PHILIPS_FM1216ME_MK3, .flag_has_analogtuner = !0, @@ -181,29 +183,29 @@ static int pvr2_lgh06xf_attach(struct pvr2_dvb_adapter *adap) return 0; } -static struct pvr2_dvb_props pvr2_onair_creator_fe_props = { +static const struct pvr2_dvb_props pvr2_onair_creator_fe_props = { .frontend_attach = pvr2_lgdt3303_attach, .tuner_attach = pvr2_lgh06xf_attach, }; #endif -static const char *pvr2_client_onair_creator[] = { - "saa7115", - "tuner", - "cs53l32a", +static const struct pvr2_device_client_desc pvr2_cli_onair_creator[] = { + { .module_id = PVR2_CLIENT_ID_SAA7115 }, + { .module_id = PVR2_CLIENT_ID_CS53L32A }, + { .module_id = PVR2_CLIENT_ID_TUNER }, }; static const struct pvr2_device_desc pvr2_device_onair_creator = { .description = "OnAir Creator Hybrid USB tuner", .shortname = "oac", - .client_modules.lst = pvr2_client_onair_creator, - .client_modules.cnt = ARRAY_SIZE(pvr2_client_onair_creator), + .client_table.lst = pvr2_cli_onair_creator, + .client_table.cnt = ARRAY_SIZE(pvr2_cli_onair_creator), .default_tuner_type = TUNER_LG_TDVS_H06XF, .flag_has_analogtuner = !0, .flag_has_composite = !0, .flag_has_svideo = !0, .flag_digital_requires_cx23416 = !0, - .signal_routing_scheme = PVR2_ROUTING_SCHEME_HAUPPAUGE, + .signal_routing_scheme = PVR2_ROUTING_SCHEME_ONAIR, .digital_control_scheme = PVR2_DIGITAL_SCHEME_ONAIR, .default_std_mask = V4L2_STD_NTSC_M, #ifdef CONFIG_VIDEO_PVRUSB2_DVB @@ -241,29 +243,29 @@ static int pvr2_fcv1236d_attach(struct pvr2_dvb_adapter *adap) return 0; } -static struct pvr2_dvb_props pvr2_onair_usb2_fe_props = { +static const struct pvr2_dvb_props pvr2_onair_usb2_fe_props = { .frontend_attach = pvr2_lgdt3302_attach, .tuner_attach = pvr2_fcv1236d_attach, }; #endif -static const char *pvr2_client_onair_usb2[] = { - "saa7115", - "tuner", - "cs53l32a", +static const struct pvr2_device_client_desc pvr2_cli_onair_usb2[] = { + { .module_id = PVR2_CLIENT_ID_SAA7115 }, + { .module_id = PVR2_CLIENT_ID_CS53L32A }, + { .module_id = PVR2_CLIENT_ID_TUNER }, }; static const struct pvr2_device_desc pvr2_device_onair_usb2 = { .description = "OnAir USB2 Hybrid USB tuner", .shortname = "oa2", - .client_modules.lst = pvr2_client_onair_usb2, - .client_modules.cnt = ARRAY_SIZE(pvr2_client_onair_usb2), + .client_table.lst = pvr2_cli_onair_usb2, + .client_table.cnt = ARRAY_SIZE(pvr2_cli_onair_usb2), .default_tuner_type = TUNER_PHILIPS_FCV1236D, .flag_has_analogtuner = !0, .flag_has_composite = !0, .flag_has_svideo = !0, .flag_digital_requires_cx23416 = !0, - .signal_routing_scheme = PVR2_ROUTING_SCHEME_HAUPPAUGE, + .signal_routing_scheme = PVR2_ROUTING_SCHEME_ONAIR, .digital_control_scheme = PVR2_DIGITAL_SCHEME_ONAIR, .default_std_mask = V4L2_STD_NTSC_M, #ifdef CONFIG_VIDEO_PVRUSB2_DVB @@ -314,15 +316,16 @@ static int pvr2_73xxx_tda18271_8295_attach(struct pvr2_dvb_adapter *adap) return 0; } -static struct pvr2_dvb_props pvr2_73xxx_dvb_props = { +static const struct pvr2_dvb_props pvr2_73xxx_dvb_props = { .frontend_attach = pvr2_tda10048_attach, .tuner_attach = pvr2_73xxx_tda18271_8295_attach, }; #endif -static const char *pvr2_client_73xxx[] = { - "cx25840", - "tuner", +static const struct pvr2_device_client_desc pvr2_cli_73xxx[] = { + { .module_id = PVR2_CLIENT_ID_CX25840 }, + { .module_id = PVR2_CLIENT_ID_TUNER, + .i2c_address_list = "\x42"}, }; static const char *pvr2_fw1_names_73xxx[] = { @@ -332,8 +335,8 @@ static const char *pvr2_fw1_names_73xxx[] = { static const struct pvr2_device_desc pvr2_device_73xxx = { .description = "WinTV HVR-1900 Model Category 73xxx", .shortname = "73xxx", - .client_modules.lst = pvr2_client_73xxx, - .client_modules.cnt = ARRAY_SIZE(pvr2_client_73xxx), + .client_table.lst = pvr2_cli_73xxx, + .client_table.cnt = ARRAY_SIZE(pvr2_cli_73xxx), .fx2_firmware.lst = pvr2_fw1_names_73xxx, .fx2_firmware.cnt = ARRAY_SIZE(pvr2_fw1_names_73xxx), .flag_has_cx25840 = !0, @@ -418,22 +421,17 @@ static int pvr2_tda18271_8295_attach(struct pvr2_dvb_adapter *adap) return 0; } -static struct pvr2_dvb_props pvr2_750xx_dvb_props = { +static const struct pvr2_dvb_props pvr2_750xx_dvb_props = { .frontend_attach = pvr2_s5h1409_attach, .tuner_attach = pvr2_tda18271_8295_attach, }; -static struct pvr2_dvb_props pvr2_751xx_dvb_props = { +static const struct pvr2_dvb_props pvr2_751xx_dvb_props = { .frontend_attach = pvr2_s5h1411_attach, .tuner_attach = pvr2_tda18271_8295_attach, }; #endif -static const char *pvr2_client_75xxx[] = { - "cx25840", - "tuner", -}; - static const char *pvr2_fw1_names_75xxx[] = { "v4l-pvrusb2-73xxx-01.fw", }; @@ -441,8 +439,8 @@ static const char *pvr2_fw1_names_75xxx[] = { static const struct pvr2_device_desc pvr2_device_750xx = { .description = "WinTV HVR-1950 Model Category 750xx", .shortname = "750xx", - .client_modules.lst = pvr2_client_75xxx, - .client_modules.cnt = ARRAY_SIZE(pvr2_client_75xxx), + .client_table.lst = pvr2_cli_73xxx, + .client_table.cnt = ARRAY_SIZE(pvr2_cli_73xxx), .fx2_firmware.lst = pvr2_fw1_names_75xxx, .fx2_firmware.cnt = ARRAY_SIZE(pvr2_fw1_names_75xxx), .flag_has_cx25840 = !0, @@ -463,8 +461,8 @@ static const struct pvr2_device_desc pvr2_device_750xx = { static const struct pvr2_device_desc pvr2_device_751xx = { .description = "WinTV HVR-1950 Model Category 751xx", .shortname = "751xx", - .client_modules.lst = pvr2_client_75xxx, - .client_modules.cnt = ARRAY_SIZE(pvr2_client_75xxx), + .client_table.lst = pvr2_cli_73xxx, + .client_table.cnt = ARRAY_SIZE(pvr2_cli_73xxx), .fx2_firmware.lst = pvr2_fw1_names_75xxx, .fx2_firmware.cnt = ARRAY_SIZE(pvr2_fw1_names_75xxx), .flag_has_cx25840 = !0, diff --git a/linux/drivers/media/video/pvrusb2/pvrusb2-devattr.h b/linux/drivers/media/video/pvrusb2/pvrusb2-devattr.h index cb3a33eb0..3e553389c 100644 --- a/linux/drivers/media/video/pvrusb2/pvrusb2-devattr.h +++ b/linux/drivers/media/video/pvrusb2/pvrusb2-devattr.h @@ -33,6 +33,34 @@ */ +#define PVR2_CLIENT_ID_NULL 0 +#define PVR2_CLIENT_ID_MSP3400 1 +#define PVR2_CLIENT_ID_CX25840 2 +#define PVR2_CLIENT_ID_SAA7115 3 +#define PVR2_CLIENT_ID_TUNER 4 +#define PVR2_CLIENT_ID_CS53L32A 5 +#define PVR2_CLIENT_ID_WM8775 6 +#define PVR2_CLIENT_ID_DEMOD 7 + +struct pvr2_device_client_desc { + /* One ovr PVR2_CLIENT_ID_xxxx */ + unsigned char module_id; + + /* Null-terminated array of I2C addresses to try in order + initialize the module. It's safe to make this null terminated + since we're never going to encounter an i2c device with an + address of zero. If this is a null pointer or zero-length, + then no I2C addresses have been specified, in which case we'll + try some compiled in defaults for now. */ + unsigned char *i2c_address_list; +}; + +struct pvr2_device_client_table { + const struct pvr2_device_client_desc *lst; + unsigned char cnt; +}; + + struct pvr2_string_table { const char **lst; unsigned int cnt; @@ -40,6 +68,7 @@ struct pvr2_string_table { #define PVR2_ROUTING_SCHEME_HAUPPAUGE 0 #define PVR2_ROUTING_SCHEME_GOTVIEW 1 +#define PVR2_ROUTING_SCHEME_ONAIR 2 #define PVR2_DIGITAL_SCHEME_NONE 0 #define PVR2_DIGITAL_SCHEME_HAUPPAUGE 1 @@ -66,6 +95,9 @@ struct pvr2_device_desc { /* List of additional client modules we need to load */ struct pvr2_string_table client_modules; + /* List of defined client modules we need to load */ + struct pvr2_device_client_table client_table; + /* List of FX2 firmware file names we should search; if empty then FX2 firmware check / load is skipped and we assume the device was initialized from internal ROM. */ @@ -73,7 +105,7 @@ struct pvr2_device_desc { #ifdef CONFIG_VIDEO_PVRUSB2_DVB /* callback functions to handle attachment of digital tuner & demod */ - struct pvr2_dvb_props *dvb_props; + const struct pvr2_dvb_props *dvb_props; #endif /* Initial standard bits to use for this device, if not zero. diff --git a/linux/drivers/media/video/pvrusb2/pvrusb2-dvb.c b/linux/drivers/media/video/pvrusb2/pvrusb2-dvb.c index 29d18e867..14decf216 100644 --- a/linux/drivers/media/video/pvrusb2/pvrusb2-dvb.c +++ b/linux/drivers/media/video/pvrusb2/pvrusb2-dvb.c @@ -326,7 +326,7 @@ static int pvr2_dvb_adapter_exit(struct pvr2_dvb_adapter *adap) static int pvr2_dvb_frontend_init(struct pvr2_dvb_adapter *adap) { struct pvr2_hdw *hdw = adap->channel.hdw; - struct pvr2_dvb_props *dvb_props = hdw->hdw_desc->dvb_props; + const struct pvr2_dvb_props *dvb_props = hdw->hdw_desc->dvb_props; int ret = 0; if (dvb_props == NULL) { diff --git a/linux/drivers/media/video/pvrusb2/pvrusb2-encoder.c b/linux/drivers/media/video/pvrusb2/pvrusb2-encoder.c index 744bc192c..452981827 100644 --- a/linux/drivers/media/video/pvrusb2/pvrusb2-encoder.c +++ b/linux/drivers/media/video/pvrusb2/pvrusb2-encoder.c @@ -380,7 +380,7 @@ static int pvr2_encoder_prep_config(struct pvr2_hdw *hdw) int encMisc3Arg = 0; #if 0 /* keep */ - /* This inexplicable bit happens in the Hauppage windows + /* This inexplicable bit happens in the Hauppauge windows driver (for both 24xxx and 29xxx devices). However I currently see no difference in behavior with or without this stuff. Leave this here as a note of its existence, diff --git a/linux/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h b/linux/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h index d96f0f510..5d75eb521 100644 --- a/linux/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h +++ b/linux/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h @@ -38,6 +38,7 @@ #include <linux/mutex.h> #include "pvrusb2-hdw.h" #include "pvrusb2-io.h" +#include <media/v4l2-device.h> #include <media/cx2341x.h> #include "pvrusb2-devattr.h" @@ -57,8 +58,6 @@ #define LOCK_TAKE(x) do { mutex_lock(&x##_mutex); x##_held = !0; } while (0) #define LOCK_GIVE(x) do { x##_held = 0; mutex_unlock(&x##_mutex); } while (0) -struct pvr2_decoder; - typedef int (*pvr2_ctlf_is_dirty)(struct pvr2_ctrl *); typedef void (*pvr2_ctlf_clear_dirty)(struct pvr2_ctrl *); typedef int (*pvr2_ctlf_check_value)(struct pvr2_ctrl *,int); @@ -139,22 +138,6 @@ struct pvr2_ctrl { }; -struct pvr2_decoder_ctrl { - void *ctxt; - void (*detach)(void *); - void (*enable)(void *,int); - void (*force_reset)(void *); -}; - -#define PVR2_I2C_PEND_DETECT 0x01 /* Need to detect a client type */ -#define PVR2_I2C_PEND_CLIENT 0x02 /* Client needs a specific update */ -#define PVR2_I2C_PEND_REFRESH 0x04 /* Client has specific pending bits */ -#define PVR2_I2C_PEND_STALE 0x08 /* Broadcast pending bits */ - -#define PVR2_I2C_PEND_ALL (PVR2_I2C_PEND_DETECT |\ - PVR2_I2C_PEND_CLIENT |\ - PVR2_I2C_PEND_REFRESH |\ - PVR2_I2C_PEND_STALE) /* Disposition of firmware1 loading situation */ #define FW1_STATE_UNKNOWN 0 @@ -179,6 +162,8 @@ struct pvr2_hdw { struct usb_device *usb_dev; struct usb_interface *usb_intf; + /* Our handle into the v4l2 sub-device architecture */ + struct v4l2_device v4l2_dev; /* Device description, anything that must adjust behavior based on device specific info will use information held here. */ const struct pvr2_device_desc *hdw_desc; @@ -186,7 +171,6 @@ struct pvr2_hdw { /* Kernel worker thread handling */ struct workqueue_struct *workqueue; struct work_struct workpoll; /* Update driver state */ - struct work_struct worki2csync; /* Update i2c clients */ /* Video spigot */ struct pvr2_stream *vid_stream; @@ -215,12 +199,6 @@ struct pvr2_hdw { pvr2_i2c_func i2c_func[PVR2_I2C_FUNC_CNT]; int i2c_cx25840_hack_state; int i2c_linked; - unsigned int i2c_pend_types; /* Which types of update are needed */ - unsigned long i2c_pend_mask; /* Change bits we need to scan */ - unsigned long i2c_stale_mask; /* Pending broadcast change bits */ - unsigned long i2c_active_mask; /* All change bits currently in use */ - struct list_head i2c_clients; - struct mutex i2c_list_lock; /* Frequency table */ unsigned int freqTable[FREQTABLE_SIZE]; @@ -287,6 +265,7 @@ struct pvr2_hdw { wait_queue_head_t state_wait_data; + int force_dirty; /* consider all controls dirty if true */ int flag_ok; /* device in known good state */ int flag_disconnected; /* flag_ok == 0 due to disconnect */ int flag_init_ok; /* true if structure is fully initialized */ @@ -295,17 +274,13 @@ struct pvr2_hdw { int flag_decoder_missed;/* We've noticed missing decoder */ int flag_tripped; /* Indicates overall failure to start */ - struct pvr2_decoder_ctrl *decoder_ctrl; + unsigned int decoder_client_id; // CPU firmware info (used to help find / save firmware data) char *fw_buffer; unsigned int fw_size; int fw_cpu_flag; /* True if we are dealing with the CPU */ - // True if there is a request to trigger logging of state in each - // module. - int log_requested; - /* Tuner / frequency control stuff */ unsigned int tuner_type; int tuner_updated; @@ -403,7 +378,8 @@ struct pvr2_hdw { /* This function gets the current frequency */ unsigned long pvr2_hdw_get_cur_freq(struct pvr2_hdw *); -void pvr2_hdw_set_decoder(struct pvr2_hdw *,struct pvr2_decoder_ctrl *); + +void pvr2_hdw_status_poll(struct pvr2_hdw *); #endif /* __PVRUSB2_HDW_INTERNAL_H */ diff --git a/linux/drivers/media/video/pvrusb2/pvrusb2-hdw.c b/linux/drivers/media/video/pvrusb2/pvrusb2-hdw.c index 19e12c5aa..bea17cd64 100644 --- a/linux/drivers/media/video/pvrusb2/pvrusb2-hdw.c +++ b/linux/drivers/media/video/pvrusb2/pvrusb2-hdw.c @@ -24,17 +24,22 @@ #include <linux/firmware.h> #include <linux/videodev2.h> #include <media/v4l2-common.h> +#include <media/tuner.h> #include "pvrusb2.h" #include "pvrusb2-std.h" #include "pvrusb2-util.h" #include "pvrusb2-hdw.h" #include "pvrusb2-i2c-core.h" -#include "pvrusb2-tuner.h" #include "pvrusb2-eeprom.h" #include "pvrusb2-hdw-internal.h" #include "pvrusb2-encoder.h" #include "pvrusb2-debug.h" #include "pvrusb2-fx2-cmd.h" +#include "pvrusb2-wm8775.h" +#include "pvrusb2-video-v4l.h" +#include "pvrusb2-cx2584x-v4l.h" +#include "pvrusb2-cs53l32a.h" +#include "pvrusb2-audio.h" #include "compat.h" #define TV_MIN_FREQ 55250000L @@ -105,6 +110,39 @@ MODULE_PARM_DESC(radio_freq, "specify initial radio frequency"); /* size of a firmware chunk */ #define FIRMWARE_CHUNK_SIZE 0x2000 +typedef void (*pvr2_subdev_update_func)(struct pvr2_hdw *, + struct v4l2_subdev *); + +static const pvr2_subdev_update_func pvr2_module_update_functions[] = { + [PVR2_CLIENT_ID_WM8775] = pvr2_wm8775_subdev_update, + [PVR2_CLIENT_ID_SAA7115] = pvr2_saa7115_subdev_update, + [PVR2_CLIENT_ID_MSP3400] = pvr2_msp3400_subdev_update, + [PVR2_CLIENT_ID_CX25840] = pvr2_cx25840_subdev_update, + [PVR2_CLIENT_ID_CS53L32A] = pvr2_cs53l32a_subdev_update, +}; + +static const char *module_names[] = { + [PVR2_CLIENT_ID_MSP3400] = "msp3400", + [PVR2_CLIENT_ID_CX25840] = "cx25840", + [PVR2_CLIENT_ID_SAA7115] = "saa7115", + [PVR2_CLIENT_ID_TUNER] = "tuner", + [PVR2_CLIENT_ID_DEMOD] = "tuner", + [PVR2_CLIENT_ID_CS53L32A] = "cs53l32a", + [PVR2_CLIENT_ID_WM8775] = "wm8775", +}; + + +static const unsigned char *module_i2c_addresses[] = { + [PVR2_CLIENT_ID_TUNER] = "\x60\x61\x62\x63", + [PVR2_CLIENT_ID_DEMOD] = "\x43", + [PVR2_CLIENT_ID_MSP3400] = "\x40", + [PVR2_CLIENT_ID_SAA7115] = "\x21", + [PVR2_CLIENT_ID_WM8775] = "\x1b", + [PVR2_CLIENT_ID_CX25840] = "\x44", + [PVR2_CLIENT_ID_CS53L32A] = "\x11", +}; + + /* Define the list of additional controls we'll dynamically construct based on query of the cx2341x module. */ struct pvr2_mpeg_ids { @@ -278,7 +316,6 @@ static int pvr2_hdw_set_input(struct pvr2_hdw *hdw,int v); static void pvr2_hdw_state_sched(struct pvr2_hdw *); static int pvr2_hdw_state_eval(struct pvr2_hdw *); static void pvr2_hdw_set_cur_freq(struct pvr2_hdw *,unsigned long); -static void pvr2_hdw_worker_i2c(struct work_struct *work); static void pvr2_hdw_worker_poll(struct work_struct *work); static int pvr2_hdw_wait(struct pvr2_hdw *,int state); static int pvr2_hdw_untrip_unlocked(struct pvr2_hdw *); @@ -643,7 +680,7 @@ static int ctrl_freq_max_get(struct pvr2_ctrl *cptr, int *vp) unsigned long fv; struct pvr2_hdw *hdw = cptr->hdw; if (hdw->tuner_signal_stale) { - pvr2_i2c_core_status_poll(hdw); + pvr2_hdw_status_poll(hdw); } fv = hdw->tuner_signal_info.rangehigh; if (!fv) { @@ -665,7 +702,7 @@ static int ctrl_freq_min_get(struct pvr2_ctrl *cptr, int *vp) unsigned long fv; struct pvr2_hdw *hdw = cptr->hdw; if (hdw->tuner_signal_stale) { - pvr2_i2c_core_status_poll(hdw); + pvr2_hdw_status_poll(hdw); } fv = hdw->tuner_signal_info.rangelow; if (!fv) { @@ -859,7 +896,7 @@ static void ctrl_stdcur_clear_dirty(struct pvr2_ctrl *cptr) static int ctrl_signal_get(struct pvr2_ctrl *cptr,int *vp) { struct pvr2_hdw *hdw = cptr->hdw; - pvr2_i2c_core_status_poll(hdw); + pvr2_hdw_status_poll(hdw); *vp = hdw->tuner_signal_info.signal; return 0; } @@ -869,7 +906,7 @@ static int ctrl_audio_modes_present_get(struct pvr2_ctrl *cptr,int *vp) int val = 0; unsigned int subchan; struct pvr2_hdw *hdw = cptr->hdw; - pvr2_i2c_core_status_poll(hdw); + pvr2_hdw_status_poll(hdw); subchan = hdw->tuner_signal_info.rxsubchans; if (subchan & V4L2_TUNER_SUB_MONO) { val |= (1 << V4L2_TUNER_MODE_MONO); @@ -1650,33 +1687,27 @@ static const char *pvr2_get_state_name(unsigned int st) static int pvr2_decoder_enable(struct pvr2_hdw *hdw,int enablefl) { - if (!hdw->decoder_ctrl) { - if (!hdw->flag_decoder_missed) { - pvr2_trace(PVR2_TRACE_ERROR_LEGS, - "WARNING: No decoder present"); - hdw->flag_decoder_missed = !0; - trace_stbit("flag_decoder_missed", - hdw->flag_decoder_missed); - } - return -EIO; + /* Even though we really only care about the video decoder chip at + this point, we'll broadcast stream on/off to all sub-devices + anyway, just in case somebody else wants to hear the + command... */ + pvr2_trace(PVR2_TRACE_CHIPS, "subdev v4l2 stream=%s", + (enablefl ? "on" : "off")); + v4l2_device_call_all(&hdw->v4l2_dev, 0, video, s_stream, enablefl); + if (hdw->decoder_client_id) { + /* We get here if the encoder has been noticed. Otherwise + we'll issue a warning to the user (which should + normally never happen). */ + return 0; } - hdw->decoder_ctrl->enable(hdw->decoder_ctrl->ctxt,enablefl); - return 0; -} - - -void pvr2_hdw_set_decoder(struct pvr2_hdw *hdw,struct pvr2_decoder_ctrl *ptr) -{ - if (hdw->decoder_ctrl == ptr) return; - hdw->decoder_ctrl = ptr; - if (hdw->decoder_ctrl && hdw->flag_decoder_missed) { - hdw->flag_decoder_missed = 0; + if (!hdw->flag_decoder_missed) { + pvr2_trace(PVR2_TRACE_ERROR_LEGS, + "WARNING: No decoder present"); + hdw->flag_decoder_missed = !0; trace_stbit("flag_decoder_missed", hdw->flag_decoder_missed); - pvr2_trace(PVR2_TRACE_ERROR_LEGS, - "Decoder has appeared"); - pvr2_hdw_state_sched(hdw); } + return -EIO; } @@ -1950,6 +1981,166 @@ static void pvr2_hdw_setup_std(struct pvr2_hdw *hdw) } +static unsigned int pvr2_copy_i2c_addr_list( + unsigned short *dst, const unsigned char *src, + unsigned int dst_max) +{ + unsigned int cnt = 0; + if (!src) return 0; + while (src[cnt] && (cnt + 1) < dst_max) { + dst[cnt] = src[cnt]; + cnt++; + } + dst[cnt] = I2C_CLIENT_END; + return cnt; +} + + +static int pvr2_hdw_load_subdev(struct pvr2_hdw *hdw, + const struct pvr2_device_client_desc *cd) +{ + const char *fname; + unsigned char mid; + struct v4l2_subdev *sd; + unsigned int i2ccnt; + const unsigned char *p; + /* Arbitrary count - max # i2c addresses we will probe */ + unsigned short i2caddr[25]; + + mid = cd->module_id; + fname = (mid < ARRAY_SIZE(module_names)) ? module_names[mid] : NULL; + if (!fname) { + pvr2_trace(PVR2_TRACE_ERROR_LEGS, + "Module ID %u for device %s has no name", + mid, + hdw->hdw_desc->description); + return -EINVAL; + } + pvr2_trace(PVR2_TRACE_INIT, + "Module ID %u (%s) for device %s being loaded...", + mid, fname, + hdw->hdw_desc->description); + + i2ccnt = pvr2_copy_i2c_addr_list(i2caddr, cd->i2c_address_list, + ARRAY_SIZE(i2caddr)); + if (!i2ccnt && ((p = (mid < ARRAY_SIZE(module_i2c_addresses)) ? + module_i2c_addresses[mid] : NULL) != NULL)) { + /* Second chance: Try default i2c address list */ + i2ccnt = pvr2_copy_i2c_addr_list(i2caddr, p, + ARRAY_SIZE(i2caddr)); + if (i2ccnt) { + pvr2_trace(PVR2_TRACE_INIT, + "Module ID %u:" + " Using default i2c address list", + mid); + } + } + + if (!i2ccnt) { + pvr2_trace(PVR2_TRACE_ERROR_LEGS, + "Module ID %u (%s) for device %s:" + " No i2c addresses", + mid, fname, hdw->hdw_desc->description); + return -EINVAL; + } + + /* Note how the 2nd and 3rd arguments are the same for both + * v4l2_i2c_new_subdev() and v4l2_i2c_new_probed_subdev(). Why? + * Well the 2nd argument is the module name to load, while the 3rd + * argument is documented in the framework as being the "chipid" - + * and every other place where I can find examples of this, the + * "chipid" appears to just be the module name again. So here we + * just do the same thing. */ + if (i2ccnt == 1) { + pvr2_trace(PVR2_TRACE_INIT, + "Module ID %u:" + " Setting up with specified i2c address 0x%x", + mid, i2caddr[0]); + sd = v4l2_i2c_new_subdev(&hdw->i2c_adap, + fname, fname, + i2caddr[0]); + } else { + pvr2_trace(PVR2_TRACE_INIT, + "Module ID %u:" + " Setting up with address probe list", + mid); + sd = v4l2_i2c_new_probed_subdev(&hdw->i2c_adap, + fname, fname, + i2caddr); + } + + if (!sd) { + pvr2_trace(PVR2_TRACE_ERROR_LEGS, + "Module ID %u (%s) for device %s failed to load", + mid, fname, hdw->hdw_desc->description); + return -EIO; + } + + /* Tag this sub-device instance with the module ID we know about. + In other places we'll use that tag to determine if the instance + requires special handling. */ + sd->grp_id = mid; + + pvr2_trace(PVR2_TRACE_INFO, "Attached sub-driver %s", fname); + + + /* client-specific setup... */ + switch (mid) { + case PVR2_CLIENT_ID_CX25840: + hdw->decoder_client_id = mid; + { + /* + Mike Isely <isely@pobox.com> 19-Nov-2006 - This + bit of nuttiness for cx25840 causes that module + to correctly set up its video scaling. This is + really a problem in the cx25840 module itself, + but we work around it here. The problem has not + been seen in ivtv because there VBI is supported + and set up. We don't do VBI here (at least not + yet) and thus we never attempted to even set it + up. + */ + struct v4l2_format fmt; + pvr2_trace(PVR2_TRACE_INIT, + "Module ID %u:" + " Executing cx25840 VBI hack", + mid); + memset(&fmt, 0, sizeof(fmt)); + fmt.type = V4L2_BUF_TYPE_SLICED_VBI_CAPTURE; + v4l2_device_call_all(&hdw->v4l2_dev, mid, + video, s_fmt, &fmt); + } + break; + case PVR2_CLIENT_ID_SAA7115: + hdw->decoder_client_id = mid; + break; + default: break; + } + + return 0; +} + + +static void pvr2_hdw_load_modules(struct pvr2_hdw *hdw) +{ + unsigned int idx; + const struct pvr2_string_table *cm; + const struct pvr2_device_client_table *ct; + int okFl = !0; + + cm = &hdw->hdw_desc->client_modules; + for (idx = 0; idx < cm->cnt; idx++) { + request_module(cm->lst[idx]); + } + + ct = &hdw->hdw_desc->client_table; + for (idx = 0; idx < ct->cnt; idx++) { + if (pvr2_hdw_load_subdev(hdw, &ct->lst[idx]) < 0) okFl = 0; + } + if (!okFl) pvr2_hdw_render_useless(hdw); +} + + static void pvr2_hdw_setup_low(struct pvr2_hdw *hdw) { int ret; @@ -1989,9 +2180,7 @@ static void pvr2_hdw_setup_low(struct pvr2_hdw *hdw) if (!pvr2_hdw_dev_ok(hdw)) return; - for (idx = 0; idx < hdw->hdw_desc->client_modules.cnt; idx++) { - request_module(hdw->hdw_desc->client_modules.lst[idx]); - } + hdw->force_dirty = !0; if (!hdw->hdw_desc->flag_no_powerup) { pvr2_hdw_cmd_powerup(hdw); @@ -2010,6 +2199,11 @@ static void pvr2_hdw_setup_low(struct pvr2_hdw *hdw) pvr2_i2c_core_init(hdw); if (!pvr2_hdw_dev_ok(hdw)) return; + pvr2_hdw_load_modules(hdw); + if (!pvr2_hdw_dev_ok(hdw)) return; + + v4l2_device_call_all(&hdw->v4l2_dev, 0, core, init, 0); + for (idx = 0; idx < CTRLDEF_COUNT; idx++) { cptr = hdw->controls + idx; if (cptr->info->skip_init) continue; @@ -2068,8 +2262,6 @@ static void pvr2_hdw_setup_low(struct pvr2_hdw *hdw) hdw->tuner_type); } - pvr2_i2c_core_check_stale(hdw); - hdw->tuner_updated = 0; if (!pvr2_hdw_dev_ok(hdw)) return; @@ -2207,11 +2399,14 @@ struct pvr2_hdw *pvr2_hdw_create(struct usb_interface *intf, struct pvr2_hdw *hdw = NULL; int valid_std_mask; struct pvr2_ctrl *cptr; + struct usb_device *usb_dev; const struct pvr2_device_desc *hdw_desc; __u8 ifnum; struct v4l2_queryctrl qctrl; struct pvr2_ctl_info *ciptr; + usb_dev = interface_to_usbdev(intf); + hdw_desc = (const struct pvr2_device_desc *)(devid->driver_info); if (hdw_desc == NULL) { @@ -2396,6 +2591,11 @@ struct pvr2_hdw *pvr2_hdw_create(struct usb_interface *intf, hdw->ctl_read_urb = usb_alloc_urb(0,GFP_KERNEL); if (!hdw->ctl_read_urb) goto fail; + if (v4l2_device_register(&usb_dev->dev, &hdw->v4l2_dev) != 0) { + pvr2_trace(PVR2_TRACE_ERROR_LEGS, + "Error registering with v4l core, giving up"); + goto fail; + } mutex_lock(&pvr2_unit_mtx); do { for (idx = 0; idx < PVR_NUM; idx++) { if (unit_pointers[idx]) continue; @@ -2420,11 +2620,8 @@ struct pvr2_hdw *pvr2_hdw_create(struct usb_interface *intf, #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20) INIT_WORK(&hdw->workpoll,(void (*)(void*))pvr2_hdw_worker_poll, &hdw->workpoll); - INIT_WORK(&hdw->worki2csync,(void (*)(void*))pvr2_hdw_worker_i2c, - &hdw->worki2csync); #else INIT_WORK(&hdw->workpoll,pvr2_hdw_worker_poll); - INIT_WORK(&hdw->worki2csync,pvr2_hdw_worker_i2c); #endif pvr2_trace(PVR2_TRACE_INIT,"Driver unit number is %d, name is %s", @@ -2434,7 +2631,7 @@ struct pvr2_hdw *pvr2_hdw_create(struct usb_interface *intf, hdw->flag_ok = !0; hdw->usb_intf = intf; - hdw->usb_dev = interface_to_usbdev(intf); + hdw->usb_dev = usb_dev; usb_make_path(hdw->usb_dev, hdw->bus_info, sizeof(hdw->bus_info)); @@ -2494,6 +2691,10 @@ static void pvr2_hdw_remove_usb_stuff(struct pvr2_hdw *hdw) hdw->ctl_write_buffer = NULL; } hdw->flag_disconnected = !0; + /* If we don't do this, then there will be a dangling struct device + reference to our disappearing device persisting inside the V4L + core... */ + v4l2_device_disconnect(&hdw->v4l2_dev); hdw->usb_dev = NULL; hdw->usb_intf = NULL; pvr2_hdw_render_useless(hdw); @@ -2521,10 +2722,8 @@ void pvr2_hdw_destroy(struct pvr2_hdw *hdw) pvr2_stream_destroy(hdw->vid_stream); hdw->vid_stream = NULL; } - if (hdw->decoder_ctrl) { - hdw->decoder_ctrl->detach(hdw->decoder_ctrl->ctxt); - } pvr2_i2c_core_done(hdw); + v4l2_device_unregister(&hdw->v4l2_dev); pvr2_hdw_remove_usb_stuff(hdw); mutex_lock(&pvr2_unit_mtx); do { if ((hdw->unit_number >= 0) && @@ -2718,6 +2917,150 @@ static const char *get_ctrl_typename(enum pvr2_ctl_type tp) } +static void pvr2_subdev_set_control(struct pvr2_hdw *hdw, int id, + const char *name, int val) +{ + struct v4l2_control ctrl; + pvr2_trace(PVR2_TRACE_CHIPS, "subdev v4l2 %s=%d", name, val); + memset(&ctrl, 0, sizeof(ctrl)); + ctrl.id = id; + ctrl.value = val; + v4l2_device_call_all(&hdw->v4l2_dev, 0, core, s_ctrl, &ctrl); +} + +#define PVR2_SUBDEV_SET_CONTROL(hdw, id, lab) \ + if ((hdw)->lab##_dirty || (hdw)->force_dirty) { \ + pvr2_subdev_set_control(hdw, id, #lab, (hdw)->lab##_val); \ + } + +/* Execute whatever commands are required to update the state of all the + sub-devices so that they match our current control values. */ +static void pvr2_subdev_update(struct pvr2_hdw *hdw) +{ + struct v4l2_subdev *sd; + unsigned int id; + pvr2_subdev_update_func fp; + + pvr2_trace(PVR2_TRACE_CHIPS, "subdev update..."); + + if (hdw->tuner_updated || hdw->force_dirty) { + struct tuner_setup setup; + pvr2_trace(PVR2_TRACE_CHIPS, "subdev tuner set_type(%d)", + hdw->tuner_type); + if (((int)(hdw->tuner_type)) >= 0) { + setup.addr = ADDR_UNSET; + setup.type = hdw->tuner_type; + setup.mode_mask = T_RADIO | T_ANALOG_TV; + v4l2_device_call_all(&hdw->v4l2_dev, 0, + tuner, s_type_addr, &setup); + } + } + + if (hdw->input_dirty || hdw->std_dirty || hdw->force_dirty) { + pvr2_trace(PVR2_TRACE_CHIPS, "subdev v4l2 set_standard"); + if (hdw->input_val == PVR2_CVAL_INPUT_RADIO) { + v4l2_device_call_all(&hdw->v4l2_dev, 0, + tuner, s_radio); + } else { + v4l2_std_id vs; + vs = hdw->std_mask_cur; + v4l2_device_call_all(&hdw->v4l2_dev, 0, + tuner, s_std, vs); + } + hdw->tuner_signal_stale = !0; + hdw->cropcap_stale = !0; + } + + PVR2_SUBDEV_SET_CONTROL(hdw, V4L2_CID_BRIGHTNESS, brightness); + PVR2_SUBDEV_SET_CONTROL(hdw, V4L2_CID_CONTRAST, contrast); + PVR2_SUBDEV_SET_CONTROL(hdw, V4L2_CID_SATURATION, saturation); + PVR2_SUBDEV_SET_CONTROL(hdw, V4L2_CID_HUE, hue); + PVR2_SUBDEV_SET_CONTROL(hdw, V4L2_CID_AUDIO_MUTE, mute); + PVR2_SUBDEV_SET_CONTROL(hdw, V4L2_CID_AUDIO_VOLUME, volume); + PVR2_SUBDEV_SET_CONTROL(hdw, V4L2_CID_AUDIO_BALANCE, balance); + PVR2_SUBDEV_SET_CONTROL(hdw, V4L2_CID_AUDIO_BASS, bass); + PVR2_SUBDEV_SET_CONTROL(hdw, V4L2_CID_AUDIO_TREBLE, treble); + + if (hdw->input_dirty || hdw->audiomode_dirty || hdw->force_dirty) { + struct v4l2_tuner vt; + memset(&vt, 0, sizeof(vt)); + vt.audmode = hdw->audiomode_val; + v4l2_device_call_all(&hdw->v4l2_dev, 0, tuner, s_tuner, &vt); + } + + if (hdw->freqDirty || hdw->force_dirty) { + unsigned long fv; + struct v4l2_frequency freq; + fv = pvr2_hdw_get_cur_freq(hdw); + pvr2_trace(PVR2_TRACE_CHIPS, "subdev v4l2 set_freq(%lu)", fv); + if (hdw->tuner_signal_stale) pvr2_hdw_status_poll(hdw); + memset(&freq, 0, sizeof(freq)); + if (hdw->tuner_signal_info.capability & V4L2_TUNER_CAP_LOW) { + /* ((fv * 1000) / 62500) */ + freq.frequency = (fv * 2) / 125; + } else { + freq.frequency = fv / 62500; + } + /* tuner-core currently doesn't seem to care about this, but + let's set it anyway for completeness. */ + if (hdw->input_val == PVR2_CVAL_INPUT_RADIO) { + freq.type = V4L2_TUNER_RADIO; + } else { + freq.type = V4L2_TUNER_ANALOG_TV; + } + freq.tuner = 0; + v4l2_device_call_all(&hdw->v4l2_dev, 0, tuner, + s_frequency, &freq); + } + + if (hdw->res_hor_dirty || hdw->res_ver_dirty || hdw->force_dirty) { + struct v4l2_format fmt; + memset(&fmt, 0, sizeof(fmt)); + fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; + fmt.fmt.pix.width = hdw->res_hor_val; + fmt.fmt.pix.height = hdw->res_ver_val; + pvr2_trace(PVR2_TRACE_CHIPS, "subdev v4l2 set_size(%dx%d)", + fmt.fmt.pix.width, fmt.fmt.pix.height); + v4l2_device_call_all(&hdw->v4l2_dev, 0, video, s_fmt, &fmt); + } + + if (hdw->srate_dirty || hdw->force_dirty) { + u32 val; + pvr2_trace(PVR2_TRACE_CHIPS, "subdev v4l2 set_audio %d", + hdw->srate_val); + switch (hdw->srate_val) { + default: + case V4L2_MPEG_AUDIO_SAMPLING_FREQ_48000: + val = 48000; + break; + case V4L2_MPEG_AUDIO_SAMPLING_FREQ_44100: + val = 44100; + break; + case V4L2_MPEG_AUDIO_SAMPLING_FREQ_32000: + val = 32000; + break; + } + v4l2_device_call_all(&hdw->v4l2_dev, 0, + audio, s_clock_freq, val); + } + + /* Unable to set crop parameters; there is apparently no equivalent + for VIDIOC_S_CROP */ + + v4l2_device_for_each_subdev(sd, &hdw->v4l2_dev) { + id = sd->grp_id; + if (id >= ARRAY_SIZE(pvr2_module_update_functions)) continue; + fp = pvr2_module_update_functions[id]; + if (!fp) continue; + (*fp)(hdw, sd); + } + + if (hdw->tuner_signal_stale || hdw->cropcap_stale) { + pvr2_hdw_status_poll(hdw); + } +} + + /* Figure out if we need to commit control changes. If so, mark internal state flags to indicate this fact and return true. Otherwise do nothing else and return false. */ @@ -2726,7 +3069,7 @@ static int pvr2_hdw_commit_setup(struct pvr2_hdw *hdw) unsigned int idx; struct pvr2_ctrl *cptr; int value; - int commit_flag = 0; + int commit_flag = hdw->force_dirty; char buf[100]; unsigned int bcnt,ccnt; @@ -2882,18 +3225,6 @@ static int pvr2_hdw_commit_execute(struct pvr2_hdw *hdw) cx2341x_ext_ctrls(&hdw->enc_ctl_state, 0, &cs,VIDIOC_S_EXT_CTRLS); } - /* Scan i2c core at this point - before we clear all the dirty - bits. Various parts of the i2c core will notice dirty bits as - appropriate and arrange to broadcast or directly send updates to - the client drivers in order to keep everything in sync */ - pvr2_i2c_core_check_stale(hdw); - - for (idx = 0; idx < hdw->control_cnt; idx++) { - cptr = hdw->controls + idx; - if (!cptr->info->clear_dirty) continue; - cptr->info->clear_dirty(cptr); - } - if (hdw->active_stream_type != hdw->desired_stream_type) { /* Handle any side effects of stream config here */ hdw->active_stream_type = hdw->desired_stream_type; @@ -2913,8 +3244,16 @@ static int pvr2_hdw_commit_execute(struct pvr2_hdw *hdw) } } - /* Now execute i2c core update */ - pvr2_i2c_core_sync(hdw); + /* Check and update state for all sub-devices. */ + pvr2_subdev_update(hdw); + + hdw->tuner_updated = 0; + hdw->force_dirty = 0; + for (idx = 0; idx < hdw->control_cnt; idx++) { + cptr = hdw->controls + idx; + if (!cptr->info->clear_dirty) continue; + cptr->info->clear_dirty(cptr); + } if ((hdw->pathway_state == PVR2_PATHWAY_ANALOG) && hdw->state_encoder_run) { @@ -2944,15 +3283,6 @@ int pvr2_hdw_commit_ctl(struct pvr2_hdw *hdw) } -static void pvr2_hdw_worker_i2c(struct work_struct *work) -{ - struct pvr2_hdw *hdw = container_of(work,struct pvr2_hdw,worki2csync); - LOCK_TAKE(hdw->big_lock); do { - pvr2_i2c_core_sync(hdw); - } while (0); LOCK_GIVE(hdw->big_lock); -} - - static void pvr2_hdw_worker_poll(struct work_struct *work) { int fl = 0; @@ -3013,7 +3343,7 @@ int pvr2_hdw_is_hsm(struct pvr2_hdw *hdw) void pvr2_hdw_execute_tuner_poll(struct pvr2_hdw *hdw) { LOCK_TAKE(hdw->big_lock); do { - pvr2_i2c_core_status_poll(hdw); + pvr2_hdw_status_poll(hdw); } while (0); LOCK_GIVE(hdw->big_lock); } @@ -3023,7 +3353,7 @@ static int pvr2_hdw_check_cropcap(struct pvr2_hdw *hdw) if (!hdw->cropcap_stale) { return 0; } - pvr2_i2c_core_status_poll(hdw); + pvr2_hdw_status_poll(hdw); if (hdw->cropcap_stale) { return -EIO; } @@ -3050,7 +3380,7 @@ int pvr2_hdw_get_tuner_status(struct pvr2_hdw *hdw,struct v4l2_tuner *vtp) { LOCK_TAKE(hdw->big_lock); do { if (hdw->tuner_signal_stale) { - pvr2_i2c_core_status_poll(hdw); + pvr2_hdw_status_poll(hdw); } memcpy(vtp,&hdw->tuner_signal_info,sizeof(struct v4l2_tuner)); } while (0); LOCK_GIVE(hdw->big_lock); @@ -3069,11 +3399,8 @@ void pvr2_hdw_trigger_module_log(struct pvr2_hdw *hdw) { int nr = pvr2_hdw_get_unit_number(hdw); LOCK_TAKE(hdw->big_lock); do { - hdw->log_requested = !0; printk(KERN_INFO "pvrusb2: ================= START STATUS CARD #%d =================\n", nr); - pvr2_i2c_core_check_stale(hdw); - hdw->log_requested = 0; - pvr2_i2c_core_sync(hdw); + v4l2_device_call_all(&hdw->v4l2_dev, 0, core, log_status); pvr2_trace(PVR2_TRACE_INFO,"cx2341x config:"); cx2341x_log_status(&hdw->enc_ctl_state, "pvrusb2"); pvr2_hdw_state_log_state(hdw); @@ -3828,22 +4155,16 @@ int pvr2_hdw_cmd_powerdown(struct pvr2_hdw *hdw) int pvr2_hdw_cmd_decoder_reset(struct pvr2_hdw *hdw) { - if (!hdw->decoder_ctrl) { - pvr2_trace(PVR2_TRACE_INIT, - "Unable to reset decoder: nothing attached"); - return -ENOTTY; - } - - if (!hdw->decoder_ctrl->force_reset) { - pvr2_trace(PVR2_TRACE_INIT, - "Unable to reset decoder: not implemented"); - return -ENOTTY; - } - pvr2_trace(PVR2_TRACE_INIT, "Requesting decoder reset"); - hdw->decoder_ctrl->force_reset(hdw->decoder_ctrl->ctxt); - return 0; + if (hdw->decoder_client_id) { + v4l2_device_call_all(&hdw->v4l2_dev, hdw->decoder_client_id, + core, reset, 0); + return 0; + } + pvr2_trace(PVR2_TRACE_INIT, + "Unable to reset decoder: nothing attached"); + return -ENOTTY; } @@ -4588,6 +4909,79 @@ static unsigned int pvr2_hdw_report_unlocked(struct pvr2_hdw *hdw,int which, } +/* Generate report containing info about attached sub-devices and attached + i2c clients, including an indication of which attached i2c clients are + actually sub-devices. */ +static unsigned int pvr2_hdw_report_clients(struct pvr2_hdw *hdw, + char *buf, unsigned int acnt) +{ + struct v4l2_subdev *sd; + unsigned int tcnt = 0; + unsigned int ccnt; + struct i2c_client *client; + struct list_head *item; + void *cd; + const char *p; + unsigned int id; + + ccnt = scnprintf(buf, acnt, "Associated v4l2-subdev drivers:"); + tcnt += ccnt; + v4l2_device_for_each_subdev(sd, &hdw->v4l2_dev) { + id = sd->grp_id; + p = NULL; + if (id < ARRAY_SIZE(module_names)) p = module_names[id]; + if (p) { + ccnt = scnprintf(buf + tcnt, acnt - tcnt, " %s", p); + tcnt += ccnt; + } else { + ccnt = scnprintf(buf + tcnt, acnt - tcnt, + " (unknown id=%u)", id); + tcnt += ccnt; + } + } + ccnt = scnprintf(buf + tcnt, acnt - tcnt, "\n"); + tcnt += ccnt; + + ccnt = scnprintf(buf + tcnt, acnt - tcnt, "I2C clients:\n"); + tcnt += ccnt; + + mutex_lock(&hdw->i2c_adap.clist_lock); + list_for_each(item, &hdw->i2c_adap.clients) { + client = list_entry(item, struct i2c_client, list); + ccnt = scnprintf(buf + tcnt, acnt - tcnt, + " %s: i2c=%02x", client->name, client->addr); + tcnt += ccnt; + cd = i2c_get_clientdata(client); + v4l2_device_for_each_subdev(sd, &hdw->v4l2_dev) { + if (cd == sd) { + id = sd->grp_id; + p = NULL; + if (id < ARRAY_SIZE(module_names)) { + p = module_names[id]; + } + if (p) { + ccnt = scnprintf(buf + tcnt, + acnt - tcnt, + " subdev=%s", p); + tcnt += ccnt; + } else { + ccnt = scnprintf(buf + tcnt, + acnt - tcnt, + " subdev= id %u)", + id); + tcnt += ccnt; + } + break; + } + } + ccnt = scnprintf(buf + tcnt, acnt - tcnt, "\n"); + tcnt += ccnt; + } + mutex_unlock(&hdw->i2c_adap.clist_lock); + return tcnt; +} + + unsigned int pvr2_hdw_state_report(struct pvr2_hdw *hdw, char *buf,unsigned int acnt) { @@ -4602,6 +4996,8 @@ unsigned int pvr2_hdw_state_report(struct pvr2_hdw *hdw, buf[0] = '\n'; ccnt = 1; bcnt += ccnt; acnt -= ccnt; buf += ccnt; } + ccnt = pvr2_hdw_report_clients(hdw, buf, acnt); + bcnt += ccnt; acnt -= ccnt; buf += ccnt; LOCK_GIVE(hdw->big_lock); return bcnt; } @@ -4609,14 +5005,25 @@ unsigned int pvr2_hdw_state_report(struct pvr2_hdw *hdw, static void pvr2_hdw_state_log_state(struct pvr2_hdw *hdw) { - char buf[128]; - unsigned int idx,ccnt; + char buf[256]; + unsigned int idx, ccnt; + unsigned int lcnt, ucnt; for (idx = 0; ; idx++) { ccnt = pvr2_hdw_report_unlocked(hdw,idx,buf,sizeof(buf)); if (!ccnt) break; printk(KERN_INFO "%s %.*s\n",hdw->name,ccnt,buf); } + ccnt = pvr2_hdw_report_clients(hdw, buf, sizeof(buf)); + ucnt = 0; + while (ucnt < ccnt) { + lcnt = 0; + while ((lcnt + ucnt < ccnt) && (buf[lcnt + ucnt] != '\n')) { + lcnt++; + } + printk(KERN_INFO "%s %.*s\n", hdw->name, lcnt, buf + ucnt); + ucnt += lcnt + 1; + } } @@ -4796,6 +5203,30 @@ int pvr2_hdw_gpio_chg_out(struct pvr2_hdw *hdw,u32 msk,u32 val) } +void pvr2_hdw_status_poll(struct pvr2_hdw *hdw) +{ + struct v4l2_tuner *vtp = &hdw->tuner_signal_info; + memset(vtp, 0, sizeof(*vtp)); + hdw->tuner_signal_stale = 0; + /* Note: There apparently is no replacement for VIDIOC_CROPCAP + using v4l2-subdev - therefore we can't support that AT ALL right + now. (Of course, no sub-drivers seem to implement it either. + But now it's a a chicken and egg problem...) */ + v4l2_device_call_all(&hdw->v4l2_dev, 0, tuner, g_tuner, + &hdw->tuner_signal_info); + pvr2_trace(PVR2_TRACE_CHIPS, "subdev status poll" + " type=%u strength=%u audio=0x%x cap=0x%x" + " low=%u hi=%u", + vtp->type, + vtp->signal, vtp->rxsubchans, vtp->capability, + vtp->rangelow, vtp->rangehigh); + + /* We have to do this to avoid getting into constant polling if + there's nobody to answer a poll of cropcap info. */ + hdw->cropcap_stale = 0; +} + + unsigned int pvr2_hdw_get_input_available(struct pvr2_hdw *hdw) { return hdw->input_avail_mask; @@ -4891,7 +5322,6 @@ int pvr2_hdw_register_access(struct pvr2_hdw *hdw, int setFl, u64 *val_ptr) { #ifdef CONFIG_VIDEO_ADV_DEBUG - struct pvr2_i2c_client *cp; struct v4l2_dbg_register req; int stat = 0; int okFl = 0; @@ -4901,21 +5331,9 @@ int pvr2_hdw_register_access(struct pvr2_hdw *hdw, req.match = *match; req.reg = reg_id; if (setFl) req.val = *val_ptr; - mutex_lock(&hdw->i2c_list_lock); do { - list_for_each_entry(cp, &hdw->i2c_clients, list) { - if (!v4l2_chip_match_i2c_client( - cp->client, - &req.match)) { - continue; - } - stat = pvr2_i2c_client_cmd( - cp,(setFl ? VIDIOC_DBG_S_REGISTER : - VIDIOC_DBG_G_REGISTER),&req); - if (!setFl) *val_ptr = req.val; - okFl = !0; - break; - } - } while (0); mutex_unlock(&hdw->i2c_list_lock); + /* It would be nice to know if a sub-device answered the request */ + v4l2_device_call_all(&hdw->v4l2_dev, 0, core, g_register, &req); + if (!setFl) *val_ptr = req.val; if (okFl) { return stat; } diff --git a/linux/drivers/media/video/pvrusb2/pvrusb2-i2c-chips-v4l2.c b/linux/drivers/media/video/pvrusb2/pvrusb2-i2c-chips-v4l2.c deleted file mode 100644 index 073b02a4b..000000000 --- a/linux/drivers/media/video/pvrusb2/pvrusb2-i2c-chips-v4l2.c +++ /dev/null @@ -1,117 +0,0 @@ -/* - * - * - * Copyright (C) 2005 Mike Isely <isely@pobox.com> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -#include <linux/kernel.h> -#include "pvrusb2-i2c-core.h" -#include "pvrusb2-hdw-internal.h" -#include "pvrusb2-debug.h" -#include "pvrusb2-i2c-cmd-v4l2.h" -#include "pvrusb2-audio.h" -#include "pvrusb2-tuner.h" -#include "pvrusb2-video-v4l.h" -#include "pvrusb2-cx2584x-v4l.h" -#include "pvrusb2-wm8775.h" -#include "compat.h" - -#define trace_i2c(...) pvr2_trace(PVR2_TRACE_I2C,__VA_ARGS__) - -#define OP_INIT 0 /* MUST come first so it is run first */ -#define OP_STANDARD 1 -#define OP_AUDIOMODE 2 -#define OP_BCSH 3 -#define OP_VOLUME 4 -#define OP_FREQ 5 -#define OP_AUDIORATE 6 -#define OP_CROP 7 -#define OP_SIZE 8 -#define OP_LOG 9 - -static const struct pvr2_i2c_op * const ops[] = { - [OP_INIT] = &pvr2_i2c_op_v4l2_init, - [OP_STANDARD] = &pvr2_i2c_op_v4l2_standard, - [OP_AUDIOMODE] = &pvr2_i2c_op_v4l2_audiomode, - [OP_BCSH] = &pvr2_i2c_op_v4l2_bcsh, - [OP_VOLUME] = &pvr2_i2c_op_v4l2_volume, - [OP_FREQ] = &pvr2_i2c_op_v4l2_frequency, - [OP_CROP] = &pvr2_i2c_op_v4l2_crop, - [OP_SIZE] = &pvr2_i2c_op_v4l2_size, - [OP_LOG] = &pvr2_i2c_op_v4l2_log, -}; - -void pvr2_i2c_probe(struct pvr2_hdw *hdw,struct pvr2_i2c_client *cp) -{ - int id; - id = cp->client->driver->id; - cp->ctl_mask = ((1 << OP_INIT) | - (1 << OP_STANDARD) | - (1 << OP_AUDIOMODE) | - (1 << OP_BCSH) | - (1 << OP_VOLUME) | - (1 << OP_FREQ) | - (1 << OP_CROP) | - (1 << OP_SIZE) | - (1 << OP_LOG)); - cp->status_poll = pvr2_v4l2_cmd_status_poll; - - if (id == I2C_DRIVERID_MSP3400) { - if (pvr2_i2c_msp3400_setup(hdw,cp)) { - return; - } - } - if (id == I2C_DRIVERID_TUNER) { - if (pvr2_i2c_tuner_setup(hdw,cp)) { - return; - } - } - if (id == I2C_DRIVERID_CX25840) { - if (pvr2_i2c_cx2584x_v4l_setup(hdw,cp)) { - return; - } - } - if (id == I2C_DRIVERID_WM8775) { - if (pvr2_i2c_wm8775_setup(hdw,cp)) { - return; - } - } - if (id == I2C_DRIVERID_SAA711X) { - if (pvr2_i2c_decoder_v4l_setup(hdw,cp)) { - return; - } - } -} - - -const struct pvr2_i2c_op *pvr2_i2c_get_op(unsigned int idx) -{ - if (idx >= ARRAY_SIZE(ops)) - return NULL; - return ops[idx]; -} - - -/* - Stuff for Emacs to see, in order to encourage consistent editing style: - *** Local Variables: *** - *** mode: c *** - *** fill-column: 75 *** - *** tab-width: 8 *** - *** c-basic-offset: 8 *** - *** End: *** - */ diff --git a/linux/drivers/media/video/pvrusb2/pvrusb2-i2c-cmd-v4l2.c b/linux/drivers/media/video/pvrusb2/pvrusb2-i2c-cmd-v4l2.c deleted file mode 100644 index db61c1fb0..000000000 --- a/linux/drivers/media/video/pvrusb2/pvrusb2-i2c-cmd-v4l2.c +++ /dev/null @@ -1,337 +0,0 @@ -/* - * - * - * Copyright (C) 2005 Mike Isely <isely@pobox.com> - * Copyright (C) 2004 Aurelien Alleaume <slts@free.fr> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -#include "pvrusb2-i2c-cmd-v4l2.h" -#include "pvrusb2-hdw-internal.h" -#include "pvrusb2-debug.h" -#include <linux/videodev2.h> -#include <media/v4l2-common.h> -#include "compat.h" - -static void execute_init(struct pvr2_hdw *hdw) -{ - u32 dummy = 0; - pvr2_trace(PVR2_TRACE_CHIPS, "i2c v4l2 init"); - pvr2_i2c_core_cmd(hdw, VIDIOC_INT_INIT, &dummy); -} - - -const struct pvr2_i2c_op pvr2_i2c_op_v4l2_init = { - .update = execute_init, - .name = "v4l2_init", -}; - - -static void set_standard(struct pvr2_hdw *hdw) -{ - pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 set_standard"); - - if (hdw->input_val == PVR2_CVAL_INPUT_RADIO) { - pvr2_i2c_core_cmd(hdw,AUDC_SET_RADIO,NULL); - } else { - v4l2_std_id vs; - vs = hdw->std_mask_cur; - pvr2_i2c_core_cmd(hdw,VIDIOC_S_STD,&vs); - } - hdw->tuner_signal_stale = !0; - hdw->cropcap_stale = !0; -} - - -static int check_standard(struct pvr2_hdw *hdw) -{ - return (hdw->input_dirty != 0) || (hdw->std_dirty != 0); -} - - -const struct pvr2_i2c_op pvr2_i2c_op_v4l2_standard = { - .check = check_standard, - .update = set_standard, - .name = "v4l2_standard", -}; - - -static void set_bcsh(struct pvr2_hdw *hdw) -{ - struct v4l2_control ctrl; - pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 set_bcsh" - " b=%d c=%d s=%d h=%d", - hdw->brightness_val,hdw->contrast_val, - hdw->saturation_val,hdw->hue_val); - memset(&ctrl,0,sizeof(ctrl)); - ctrl.id = V4L2_CID_BRIGHTNESS; - ctrl.value = hdw->brightness_val; - pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl); - ctrl.id = V4L2_CID_CONTRAST; - ctrl.value = hdw->contrast_val; - pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl); - ctrl.id = V4L2_CID_SATURATION; - ctrl.value = hdw->saturation_val; - pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl); - ctrl.id = V4L2_CID_HUE; - ctrl.value = hdw->hue_val; - pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl); -} - - -static int check_bcsh(struct pvr2_hdw *hdw) -{ - return (hdw->brightness_dirty || - hdw->contrast_dirty || - hdw->saturation_dirty || - hdw->hue_dirty); -} - - -const struct pvr2_i2c_op pvr2_i2c_op_v4l2_bcsh = { - .check = check_bcsh, - .update = set_bcsh, - .name = "v4l2_bcsh", -}; - - -static void set_volume(struct pvr2_hdw *hdw) -{ - struct v4l2_control ctrl; - pvr2_trace(PVR2_TRACE_CHIPS, - "i2c v4l2 set_volume" - "(vol=%d bal=%d bas=%d treb=%d mute=%d)", - hdw->volume_val, - hdw->balance_val, - hdw->bass_val, - hdw->treble_val, - hdw->mute_val); - memset(&ctrl,0,sizeof(ctrl)); - ctrl.id = V4L2_CID_AUDIO_MUTE; - ctrl.value = hdw->mute_val ? 1 : 0; - pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl); - ctrl.id = V4L2_CID_AUDIO_VOLUME; - ctrl.value = hdw->volume_val; - pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl); - ctrl.id = V4L2_CID_AUDIO_BALANCE; - ctrl.value = hdw->balance_val; - pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl); - ctrl.id = V4L2_CID_AUDIO_BASS; - ctrl.value = hdw->bass_val; - pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl); - ctrl.id = V4L2_CID_AUDIO_TREBLE; - ctrl.value = hdw->treble_val; - pvr2_i2c_core_cmd(hdw,VIDIOC_S_CTRL,&ctrl); -} - - -static int check_volume(struct pvr2_hdw *hdw) -{ - return (hdw->volume_dirty || - hdw->balance_dirty || - hdw->bass_dirty || - hdw->treble_dirty || - hdw->mute_dirty); -} - - -const struct pvr2_i2c_op pvr2_i2c_op_v4l2_volume = { - .check = check_volume, - .update = set_volume, - .name = "v4l2_volume", -}; - - -static void set_audiomode(struct pvr2_hdw *hdw) -{ - struct v4l2_tuner vt; - memset(&vt,0,sizeof(vt)); - vt.audmode = hdw->audiomode_val; - pvr2_i2c_core_cmd(hdw,VIDIOC_S_TUNER,&vt); -} - - -static int check_audiomode(struct pvr2_hdw *hdw) -{ - return (hdw->input_dirty || - hdw->audiomode_dirty); -} - - -const struct pvr2_i2c_op pvr2_i2c_op_v4l2_audiomode = { - .check = check_audiomode, - .update = set_audiomode, - .name = "v4l2_audiomode", -}; - - -static void set_frequency(struct pvr2_hdw *hdw) -{ - unsigned long fv; - struct v4l2_frequency freq; - fv = pvr2_hdw_get_cur_freq(hdw); - pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 set_freq(%lu)",fv); - if (hdw->tuner_signal_stale) { - pvr2_i2c_core_status_poll(hdw); - } - memset(&freq,0,sizeof(freq)); - if (hdw->tuner_signal_info.capability & V4L2_TUNER_CAP_LOW) { - // ((fv * 1000) / 62500) - freq.frequency = (fv * 2) / 125; - } else { - freq.frequency = fv / 62500; - } - /* tuner-core currently doesn't seem to care about this, but - let's set it anyway for completeness. */ - if (hdw->input_val == PVR2_CVAL_INPUT_RADIO) { - freq.type = V4L2_TUNER_RADIO; - } else { - freq.type = V4L2_TUNER_ANALOG_TV; - } - freq.tuner = 0; - pvr2_i2c_core_cmd(hdw,VIDIOC_S_FREQUENCY,&freq); -} - - -static int check_frequency(struct pvr2_hdw *hdw) -{ - return hdw->freqDirty != 0; -} - - -const struct pvr2_i2c_op pvr2_i2c_op_v4l2_frequency = { - .check = check_frequency, - .update = set_frequency, - .name = "v4l2_freq", -}; - - -static void set_size(struct pvr2_hdw *hdw) -{ - struct v4l2_format fmt; - - memset(&fmt,0,sizeof(fmt)); - - fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - fmt.fmt.pix.width = hdw->res_hor_val; - fmt.fmt.pix.height = hdw->res_ver_val; - - pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 set_size(%dx%d)", - fmt.fmt.pix.width,fmt.fmt.pix.height); - - pvr2_i2c_core_cmd(hdw,VIDIOC_S_FMT,&fmt); -} - - -static int check_size(struct pvr2_hdw *hdw) -{ - return (hdw->res_hor_dirty || hdw->res_ver_dirty); -} - - -const struct pvr2_i2c_op pvr2_i2c_op_v4l2_size = { - .check = check_size, - .update = set_size, - .name = "v4l2_size", -}; - - -static void set_crop(struct pvr2_hdw *hdw) -{ - struct v4l2_crop crop; - - memset(&crop, 0, sizeof crop); - crop.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - crop.c.left = hdw->cropl_val; - crop.c.top = hdw->cropt_val; - crop.c.height = hdw->croph_val; - crop.c.width = hdw->cropw_val; - - pvr2_trace(PVR2_TRACE_CHIPS, - "i2c v4l2 set_crop crop=%d:%d:%d:%d", - crop.c.width, crop.c.height, crop.c.left, crop.c.top); - - pvr2_i2c_core_cmd(hdw, VIDIOC_S_CROP, &crop); -} - -static int check_crop(struct pvr2_hdw *hdw) -{ - return (hdw->cropl_dirty || hdw->cropt_dirty || - hdw->cropw_dirty || hdw->croph_dirty); -} - -const struct pvr2_i2c_op pvr2_i2c_op_v4l2_crop = { - .check = check_crop, - .update = set_crop, - .name = "v4l2_crop", -}; - - -static void do_log(struct pvr2_hdw *hdw) -{ - pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 do_log()"); - pvr2_i2c_core_cmd(hdw,VIDIOC_LOG_STATUS,NULL); - -} - - -static int check_log(struct pvr2_hdw *hdw) -{ - return hdw->log_requested != 0; -} - - -const struct pvr2_i2c_op pvr2_i2c_op_v4l2_log = { - .check = check_log, - .update = do_log, - .name = "v4l2_log", -}; - - -void pvr2_v4l2_cmd_stream(struct pvr2_i2c_client *cp,int fl) -{ - pvr2_i2c_client_cmd(cp, - (fl ? VIDIOC_STREAMON : VIDIOC_STREAMOFF),NULL); -} - - -void pvr2_v4l2_cmd_status_poll(struct pvr2_i2c_client *cp) -{ - int stat; - struct pvr2_hdw *hdw = cp->hdw; - if (hdw->cropcap_stale) { - hdw->cropcap_info.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - stat = pvr2_i2c_client_cmd(cp, VIDIOC_CROPCAP, - &hdw->cropcap_info); - if (stat == 0) { - /* Check was successful, so the data is no - longer considered stale. */ - hdw->cropcap_stale = 0; - } - } - pvr2_i2c_client_cmd(cp, VIDIOC_G_TUNER, &hdw->tuner_signal_info); -} - - -/* - Stuff for Emacs to see, in order to encourage consistent editing style: - *** Local Variables: *** - *** mode: c *** - *** fill-column: 70 *** - *** tab-width: 8 *** - *** c-basic-offset: 8 *** - *** End: *** - */ diff --git a/linux/drivers/media/video/pvrusb2/pvrusb2-i2c-cmd-v4l2.h b/linux/drivers/media/video/pvrusb2/pvrusb2-i2c-cmd-v4l2.h deleted file mode 100644 index 69a63f2a8..000000000 --- a/linux/drivers/media/video/pvrusb2/pvrusb2-i2c-cmd-v4l2.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * - * - * Copyright (C) 2005 Mike Isely <isely@pobox.com> - * Copyright (C) 2004 Aurelien Alleaume <slts@free.fr> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -#ifndef __PVRUSB2_CMD_V4L2_H -#define __PVRUSB2_CMD_V4L2_H - -#include "pvrusb2-i2c-core.h" - -extern const struct pvr2_i2c_op pvr2_i2c_op_v4l2_init; -extern const struct pvr2_i2c_op pvr2_i2c_op_v4l2_standard; -extern const struct pvr2_i2c_op pvr2_i2c_op_v4l2_radio; -extern const struct pvr2_i2c_op pvr2_i2c_op_v4l2_bcsh; -extern const struct pvr2_i2c_op pvr2_i2c_op_v4l2_volume; -extern const struct pvr2_i2c_op pvr2_i2c_op_v4l2_frequency; -extern const struct pvr2_i2c_op pvr2_i2c_op_v4l2_crop; -extern const struct pvr2_i2c_op pvr2_i2c_op_v4l2_size; -extern const struct pvr2_i2c_op pvr2_i2c_op_v4l2_audiomode; -extern const struct pvr2_i2c_op pvr2_i2c_op_v4l2_log; - -void pvr2_v4l2_cmd_stream(struct pvr2_i2c_client *,int); -void pvr2_v4l2_cmd_status_poll(struct pvr2_i2c_client *); - -#endif /* __PVRUSB2_CMD_V4L2_H */ - -/* - Stuff for Emacs to see, in order to encourage consistent editing style: - *** Local Variables: *** - *** mode: c *** - *** fill-column: 70 *** - *** tab-width: 8 *** - *** c-basic-offset: 8 *** - *** End: *** - */ diff --git a/linux/drivers/media/video/pvrusb2/pvrusb2-i2c-core.c b/linux/drivers/media/video/pvrusb2/pvrusb2-i2c-core.c index d95abcc55..fde4d3bd1 100644 --- a/linux/drivers/media/video/pvrusb2/pvrusb2-i2c-core.c +++ b/linux/drivers/media/video/pvrusb2/pvrusb2-i2c-core.c @@ -18,6 +18,7 @@ * */ +#include <linux/i2c.h> #include "pvrusb2-i2c-core.h" #include "pvrusb2-hdw-internal.h" #include "pvrusb2-debug.h" @@ -30,8 +31,7 @@ /* This module attempts to implement a compliant I2C adapter for the pvrusb2 - device. By doing this we can then make use of existing functionality in - V4L (e.g. tuner.c) rather than rolling our own. + device. */ @@ -43,10 +43,6 @@ static int ir_mode[PVR_NUM] = { [0 ... PVR_NUM-1] = 1 }; module_param_array(ir_mode, int, NULL, 0444); MODULE_PARM_DESC(ir_mode,"specify: 0=disable IR reception, 1=normal IR"); -static unsigned int pvr2_i2c_client_describe(struct pvr2_i2c_client *cp, - unsigned int detail, - char *buf,unsigned int maxlen); - static int pvr2_i2c_write(struct pvr2_hdw *hdw, /* Context */ u8 i2c_addr, /* I2C address we're talking to */ u8 *data, /* Data to write */ @@ -599,414 +595,13 @@ static u32 pvr2_i2c_functionality(struct i2c_adapter *adap) return I2C_FUNC_SMBUS_EMUL | I2C_FUNC_I2C; } -static int pvr2_i2c_core_singleton(struct i2c_client *cp, - unsigned int cmd,void *arg) -{ - int stat; - if (!cp) return -EINVAL; - if (!(cp->driver)) return -EINVAL; - if (!(cp->driver->command)) return -EINVAL; - if (!try_module_get(cp->driver->driver.owner)) return -EAGAIN; - stat = cp->driver->command(cp,cmd,arg); - module_put(cp->driver->driver.owner); - return stat; -} - -int pvr2_i2c_client_cmd(struct pvr2_i2c_client *cp,unsigned int cmd,void *arg) -{ - int stat; - if (pvrusb2_debug & PVR2_TRACE_I2C_CMD) { - char buf[100]; - unsigned int cnt; - cnt = pvr2_i2c_client_describe(cp,PVR2_I2C_DETAIL_DEBUG, - buf,sizeof(buf)); - pvr2_trace(PVR2_TRACE_I2C_CMD, - "i2c COMMAND (code=%u 0x%x) to %.*s", - cmd,cmd,cnt,buf); - } - stat = pvr2_i2c_core_singleton(cp->client,cmd,arg); - if (pvrusb2_debug & PVR2_TRACE_I2C_CMD) { - char buf[100]; - unsigned int cnt; - cnt = pvr2_i2c_client_describe(cp,PVR2_I2C_DETAIL_DEBUG, - buf,sizeof(buf)); - pvr2_trace(PVR2_TRACE_I2C_CMD, - "i2c COMMAND to %.*s (ret=%d)",cnt,buf,stat); - } - return stat; -} - -int pvr2_i2c_core_cmd(struct pvr2_hdw *hdw,unsigned int cmd,void *arg) -{ - struct pvr2_i2c_client *cp, *ncp; - int stat = -EINVAL; - - if (!hdw) return stat; - - mutex_lock(&hdw->i2c_list_lock); - list_for_each_entry_safe(cp, ncp, &hdw->i2c_clients, list) { - if (!cp->recv_enable) continue; - mutex_unlock(&hdw->i2c_list_lock); - stat = pvr2_i2c_client_cmd(cp,cmd,arg); - mutex_lock(&hdw->i2c_list_lock); - } - mutex_unlock(&hdw->i2c_list_lock); - return stat; -} - - -static int handler_check(struct pvr2_i2c_client *cp) -{ - struct pvr2_i2c_handler *hp = cp->handler; - if (!hp) return 0; - if (!hp->func_table->check) return 0; - return hp->func_table->check(hp->func_data) != 0; -} - -#define BUFSIZE 500 - - -void pvr2_i2c_core_status_poll(struct pvr2_hdw *hdw) -{ - struct pvr2_i2c_client *cp; - mutex_lock(&hdw->i2c_list_lock); do { - struct v4l2_tuner *vtp = &hdw->tuner_signal_info; - memset(vtp,0,sizeof(*vtp)); - list_for_each_entry(cp, &hdw->i2c_clients, list) { - if (!cp->detected_flag) continue; - if (!cp->status_poll) continue; - cp->status_poll(cp); - } - hdw->tuner_signal_stale = 0; - pvr2_trace(PVR2_TRACE_CHIPS,"i2c status poll" - " type=%u strength=%u audio=0x%x cap=0x%x" - " low=%u hi=%u", - vtp->type, - vtp->signal,vtp->rxsubchans,vtp->capability, - vtp->rangelow,vtp->rangehigh); - } while (0); mutex_unlock(&hdw->i2c_list_lock); -} - - -/* Issue various I2C operations to bring chip-level drivers into sync with - state stored in this driver. */ -void pvr2_i2c_core_sync(struct pvr2_hdw *hdw) -{ - unsigned long msk; - unsigned int idx; - struct pvr2_i2c_client *cp, *ncp; - - if (!hdw->i2c_linked) return; - if (!(hdw->i2c_pend_types & PVR2_I2C_PEND_ALL)) { - return; - } - mutex_lock(&hdw->i2c_list_lock); do { - pvr2_trace(PVR2_TRACE_I2C_CORE,"i2c: core_sync BEGIN"); - if (hdw->i2c_pend_types & PVR2_I2C_PEND_DETECT) { - /* One or more I2C clients have attached since we - last synced. So scan the list and identify the - new clients. */ - char *buf; - unsigned int cnt; - unsigned long amask = 0; - buf = kmalloc(BUFSIZE,GFP_KERNEL); - pvr2_trace(PVR2_TRACE_I2C_CORE,"i2c: PEND_DETECT"); - hdw->i2c_pend_types &= ~PVR2_I2C_PEND_DETECT; - list_for_each_entry(cp, &hdw->i2c_clients, list) { - if (!cp->detected_flag) { - cp->ctl_mask = 0; - pvr2_i2c_probe(hdw,cp); - cp->detected_flag = !0; - msk = cp->ctl_mask; - cnt = 0; - if (buf) { - cnt = pvr2_i2c_client_describe( - cp, - PVR2_I2C_DETAIL_ALL, - buf,BUFSIZE); - } - trace_i2c("Probed: %.*s",cnt,buf); - if (handler_check(cp)) { - hdw->i2c_pend_types |= - PVR2_I2C_PEND_CLIENT; - } - cp->pend_mask = msk; - hdw->i2c_pend_mask |= msk; - hdw->i2c_pend_types |= - PVR2_I2C_PEND_REFRESH; - } - amask |= cp->ctl_mask; - } - hdw->i2c_active_mask = amask; - if (buf) kfree(buf); - } - if (hdw->i2c_pend_types & PVR2_I2C_PEND_STALE) { - /* Need to do one or more global updates. Arrange - for this to happen. */ - unsigned long m2; - pvr2_trace(PVR2_TRACE_I2C_CORE, - "i2c: PEND_STALE (0x%lx)", - hdw->i2c_stale_mask); - hdw->i2c_pend_types &= ~PVR2_I2C_PEND_STALE; - list_for_each_entry(cp, &hdw->i2c_clients, list) { - m2 = hdw->i2c_stale_mask; - m2 &= cp->ctl_mask; - m2 &= ~cp->pend_mask; - if (m2) { - pvr2_trace(PVR2_TRACE_I2C_CORE, - "i2c: cp=%p setting 0x%lx", - cp,m2); - cp->pend_mask |= m2; - } - } - hdw->i2c_pend_mask |= hdw->i2c_stale_mask; - hdw->i2c_stale_mask = 0; - hdw->i2c_pend_types |= PVR2_I2C_PEND_REFRESH; - } - if (hdw->i2c_pend_types & PVR2_I2C_PEND_CLIENT) { - /* One or more client handlers are asking for an - update. Run through the list of known clients - and update each one. */ - pvr2_trace(PVR2_TRACE_I2C_CORE,"i2c: PEND_CLIENT"); - hdw->i2c_pend_types &= ~PVR2_I2C_PEND_CLIENT; - list_for_each_entry_safe(cp, ncp, &hdw->i2c_clients, - list) { - if (!cp->handler) continue; - if (!cp->handler->func_table->update) continue; - pvr2_trace(PVR2_TRACE_I2C_CORE, - "i2c: cp=%p update",cp); - mutex_unlock(&hdw->i2c_list_lock); - cp->handler->func_table->update( - cp->handler->func_data); - mutex_lock(&hdw->i2c_list_lock); - /* If client's update function set some - additional pending bits, account for that - here. */ - if (cp->pend_mask & ~hdw->i2c_pend_mask) { - hdw->i2c_pend_mask |= cp->pend_mask; - hdw->i2c_pend_types |= - PVR2_I2C_PEND_REFRESH; - } - } - } - if (hdw->i2c_pend_types & PVR2_I2C_PEND_REFRESH) { - const struct pvr2_i2c_op *opf; - unsigned long pm; - /* Some actual updates are pending. Walk through - each update type and perform it. */ - pvr2_trace(PVR2_TRACE_I2C_CORE,"i2c: PEND_REFRESH" - " (0x%lx)",hdw->i2c_pend_mask); - hdw->i2c_pend_types &= ~PVR2_I2C_PEND_REFRESH; - pm = hdw->i2c_pend_mask; - hdw->i2c_pend_mask = 0; - for (idx = 0, msk = 1; pm; idx++, msk <<= 1) { - if (!(pm & msk)) continue; - pm &= ~msk; - list_for_each_entry(cp, &hdw->i2c_clients, - list) { - if (cp->pend_mask & msk) { - cp->pend_mask &= ~msk; - cp->recv_enable = !0; - } else { - cp->recv_enable = 0; - } - } - opf = pvr2_i2c_get_op(idx); - if (!opf) continue; - mutex_unlock(&hdw->i2c_list_lock); - opf->update(hdw); - mutex_lock(&hdw->i2c_list_lock); - } - } - pvr2_trace(PVR2_TRACE_I2C_CORE,"i2c: core_sync END"); - } while (0); mutex_unlock(&hdw->i2c_list_lock); -} - -int pvr2_i2c_core_check_stale(struct pvr2_hdw *hdw) -{ - unsigned long msk,sm,pm; - unsigned int idx; - const struct pvr2_i2c_op *opf; - struct pvr2_i2c_client *cp; - unsigned int pt = 0; - - pvr2_trace(PVR2_TRACE_I2C_CORE,"pvr2_i2c_core_check_stale BEGIN"); - - pm = hdw->i2c_active_mask; - sm = 0; - for (idx = 0, msk = 1; pm; idx++, msk <<= 1) { - if (!(msk & pm)) continue; - pm &= ~msk; - opf = pvr2_i2c_get_op(idx); - if (!(opf && opf->check)) continue; - if (opf->check(hdw)) { - sm |= msk; - } - } - if (sm) pt |= PVR2_I2C_PEND_STALE; - - list_for_each_entry(cp, &hdw->i2c_clients, list) - if (handler_check(cp)) - pt |= PVR2_I2C_PEND_CLIENT; - - if (pt) { - mutex_lock(&hdw->i2c_list_lock); do { - hdw->i2c_pend_types |= pt; - hdw->i2c_stale_mask |= sm; - hdw->i2c_pend_mask |= hdw->i2c_stale_mask; - } while (0); mutex_unlock(&hdw->i2c_list_lock); - } - - pvr2_trace(PVR2_TRACE_I2C_CORE, - "i2c: types=0x%x stale=0x%lx pend=0x%lx", - hdw->i2c_pend_types, - hdw->i2c_stale_mask, - hdw->i2c_pend_mask); - pvr2_trace(PVR2_TRACE_I2C_CORE,"pvr2_i2c_core_check_stale END"); - - return (hdw->i2c_pend_types & PVR2_I2C_PEND_ALL) != 0; -} - -static unsigned int pvr2_i2c_client_describe(struct pvr2_i2c_client *cp, - unsigned int detail, - char *buf,unsigned int maxlen) -{ - unsigned int ccnt,bcnt; - int spcfl = 0; - const struct pvr2_i2c_op *opf; - - ccnt = 0; - if (detail & PVR2_I2C_DETAIL_DEBUG) { - bcnt = scnprintf(buf,maxlen, - "ctxt=%p ctl_mask=0x%lx", - cp,cp->ctl_mask); - ccnt += bcnt; buf += bcnt; maxlen -= bcnt; - spcfl = !0; - } - bcnt = scnprintf(buf,maxlen, - "%s%s @ 0x%x", - (spcfl ? " " : ""), - cp->client->name, - cp->client->addr); - ccnt += bcnt; buf += bcnt; maxlen -= bcnt; - if ((detail & PVR2_I2C_DETAIL_HANDLER) && - cp->handler && cp->handler->func_table->describe) { - bcnt = scnprintf(buf,maxlen," ("); - ccnt += bcnt; buf += bcnt; maxlen -= bcnt; - bcnt = cp->handler->func_table->describe( - cp->handler->func_data,buf,maxlen); - ccnt += bcnt; buf += bcnt; maxlen -= bcnt; - bcnt = scnprintf(buf,maxlen,")"); - ccnt += bcnt; buf += bcnt; maxlen -= bcnt; - } - if ((detail & PVR2_I2C_DETAIL_CTLMASK) && cp->ctl_mask) { - unsigned int idx; - unsigned long msk,sm; - - bcnt = scnprintf(buf,maxlen," ["); - ccnt += bcnt; buf += bcnt; maxlen -= bcnt; - sm = 0; - spcfl = 0; - for (idx = 0, msk = 1; msk; idx++, msk <<= 1) { - if (!(cp->ctl_mask & msk)) continue; - opf = pvr2_i2c_get_op(idx); - if (opf) { - bcnt = scnprintf(buf,maxlen,"%s%s", - spcfl ? " " : "", - opf->name); - ccnt += bcnt; buf += bcnt; maxlen -= bcnt; - spcfl = !0; - } else { - sm |= msk; - } - } - if (sm) { - bcnt = scnprintf(buf,maxlen,"%s%lx", - idx != 0 ? " " : "",sm); - ccnt += bcnt; buf += bcnt; maxlen -= bcnt; - } - bcnt = scnprintf(buf,maxlen,"]"); - ccnt += bcnt; buf += bcnt; maxlen -= bcnt; - } - return ccnt; -} - -unsigned int pvr2_i2c_report(struct pvr2_hdw *hdw, - char *buf,unsigned int maxlen) -{ - unsigned int ccnt,bcnt; - struct pvr2_i2c_client *cp; - ccnt = 0; - mutex_lock(&hdw->i2c_list_lock); do { - list_for_each_entry(cp, &hdw->i2c_clients, list) { - bcnt = pvr2_i2c_client_describe( - cp, - (PVR2_I2C_DETAIL_HANDLER| - PVR2_I2C_DETAIL_CTLMASK), - buf,maxlen); - ccnt += bcnt; buf += bcnt; maxlen -= bcnt; - bcnt = scnprintf(buf,maxlen,"\n"); - ccnt += bcnt; buf += bcnt; maxlen -= bcnt; - } - } while (0); mutex_unlock(&hdw->i2c_list_lock); - return ccnt; -} - static int pvr2_i2c_attach_inform(struct i2c_client *client) { - struct pvr2_hdw *hdw = (struct pvr2_hdw *)(client->adapter->algo_data); - struct pvr2_i2c_client *cp; - int fl = !(hdw->i2c_pend_types & PVR2_I2C_PEND_ALL); - cp = kzalloc(sizeof(*cp),GFP_KERNEL); - trace_i2c("i2c_attach [client=%s @ 0x%x ctxt=%p]", - client->name, - client->addr,cp); - if (!cp) return -ENOMEM; - cp->hdw = hdw; - INIT_LIST_HEAD(&cp->list); - cp->client = client; - mutex_lock(&hdw->i2c_list_lock); do { - hdw->cropcap_stale = !0; - list_add_tail(&cp->list,&hdw->i2c_clients); - hdw->i2c_pend_types |= PVR2_I2C_PEND_DETECT; - } while (0); mutex_unlock(&hdw->i2c_list_lock); - if (fl) queue_work(hdw->workqueue,&hdw->worki2csync); return 0; } static int pvr2_i2c_detach_inform(struct i2c_client *client) { - struct pvr2_hdw *hdw = (struct pvr2_hdw *)(client->adapter->algo_data); - struct pvr2_i2c_client *cp, *ncp; - unsigned long amask = 0; - int foundfl = 0; - mutex_lock(&hdw->i2c_list_lock); do { - hdw->cropcap_stale = !0; - list_for_each_entry_safe(cp, ncp, &hdw->i2c_clients, list) { - if (cp->client == client) { - trace_i2c("pvr2_i2c_detach" - " [client=%s @ 0x%x ctxt=%p]", - client->name, - client->addr,cp); - if (cp->handler && - cp->handler->func_table->detach) { - cp->handler->func_table->detach( - cp->handler->func_data); - } - list_del(&cp->list); - kfree(cp); - foundfl = !0; - continue; - } - amask |= cp->ctl_mask; - } - hdw->i2c_active_mask = amask; - } while (0); mutex_unlock(&hdw->i2c_list_lock); - if (!foundfl) { - trace_i2c("pvr2_i2c_detach [client=%s @ 0x%x ctxt=<unknown>]", - client->name, - client->addr); - } return 0; } @@ -1020,7 +615,7 @@ static struct i2c_algorithm pvr2_i2c_algo_template = { static struct i2c_adapter pvr2_i2c_adap_template = { .owner = THIS_MODULE, - .class = I2C_CLASS_TV_ANALOG, + .class = 0, .id = I2C_HW_B_BT848, .client_register = pvr2_i2c_attach_inform, .client_unregister = pvr2_i2c_detach_inform, @@ -1087,12 +682,8 @@ void pvr2_i2c_core_init(struct pvr2_hdw *hdw) hdw->i2c_adap.dev.parent = &hdw->usb_dev->dev; hdw->i2c_adap.algo = &hdw->i2c_algo; hdw->i2c_adap.algo_data = hdw; - hdw->i2c_pend_mask = 0; - hdw->i2c_stale_mask = 0; - hdw->i2c_active_mask = 0; - INIT_LIST_HEAD(&hdw->i2c_clients); - mutex_init(&hdw->i2c_list_lock); hdw->i2c_linked = !0; + i2c_set_adapdata(&hdw->i2c_adap, &hdw->v4l2_dev); i2c_add_adapter(&hdw->i2c_adap); if (hdw->i2c_func[0x18] == i2c_24xxx_ir) { /* Probe for a different type of IR receiver on this diff --git a/linux/drivers/media/video/pvrusb2/pvrusb2-i2c-core.h b/linux/drivers/media/video/pvrusb2/pvrusb2-i2c-core.h index 6ef7a1c0e..6a7576920 100644 --- a/linux/drivers/media/video/pvrusb2/pvrusb2-i2c-core.h +++ b/linux/drivers/media/video/pvrusb2/pvrusb2-i2c-core.h @@ -20,68 +20,13 @@ #ifndef __PVRUSB2_I2C_CORE_H #define __PVRUSB2_I2C_CORE_H -#include <linux/list.h> -#include <linux/i2c.h> - struct pvr2_hdw; -struct pvr2_i2c_client; -struct pvr2_i2c_handler; -struct pvr2_i2c_handler_functions; -struct pvr2_i2c_op; -struct pvr2_i2c_op_functions; - -struct pvr2_i2c_client { - struct i2c_client *client; - struct pvr2_i2c_handler *handler; - struct list_head list; - struct pvr2_hdw *hdw; - int detected_flag; - int recv_enable; - unsigned long pend_mask; - unsigned long ctl_mask; - void (*status_poll)(struct pvr2_i2c_client *); -}; - -struct pvr2_i2c_handler { - void *func_data; - const struct pvr2_i2c_handler_functions *func_table; -}; - -struct pvr2_i2c_handler_functions { - void (*detach)(void *); - int (*check)(void *); - void (*update)(void *); - unsigned int (*describe)(void *,char *,unsigned int); -}; - -struct pvr2_i2c_op { - int (*check)(struct pvr2_hdw *); - void (*update)(struct pvr2_hdw *); - const char *name; -}; void pvr2_i2c_core_init(struct pvr2_hdw *); void pvr2_i2c_core_done(struct pvr2_hdw *); -int pvr2_i2c_client_cmd(struct pvr2_i2c_client *,unsigned int cmd,void *arg); -int pvr2_i2c_core_cmd(struct pvr2_hdw *,unsigned int cmd,void *arg); - -int pvr2_i2c_core_check_stale(struct pvr2_hdw *); -void pvr2_i2c_core_sync(struct pvr2_hdw *); -void pvr2_i2c_core_status_poll(struct pvr2_hdw *); -unsigned int pvr2_i2c_report(struct pvr2_hdw *,char *buf,unsigned int maxlen); -#define PVR2_I2C_DETAIL_DEBUG 0x0001 -#define PVR2_I2C_DETAIL_HANDLER 0x0002 -#define PVR2_I2C_DETAIL_CTLMASK 0x0004 -#define PVR2_I2C_DETAIL_ALL (\ - PVR2_I2C_DETAIL_DEBUG |\ - PVR2_I2C_DETAIL_HANDLER |\ - PVR2_I2C_DETAIL_CTLMASK) - -void pvr2_i2c_probe(struct pvr2_hdw *,struct pvr2_i2c_client *); -const struct pvr2_i2c_op *pvr2_i2c_get_op(unsigned int idx); -#endif /* __PVRUSB2_I2C_CORE_H */ +#endif /* __PVRUSB2_I2C_ADAPTER_H */ /* diff --git a/linux/drivers/media/video/pvrusb2/pvrusb2-tuner.c b/linux/drivers/media/video/pvrusb2/pvrusb2-tuner.c deleted file mode 100644 index efec78516..000000000 --- a/linux/drivers/media/video/pvrusb2/pvrusb2-tuner.c +++ /dev/null @@ -1,121 +0,0 @@ -/* - * - * - * Copyright (C) 2005 Mike Isely <isely@pobox.com> - * Copyright (C) 2004 Aurelien Alleaume <slts@free.fr> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -#include "pvrusb2.h" -#include "pvrusb2-util.h" -#include "pvrusb2-tuner.h" -#include "pvrusb2-hdw-internal.h" -#include "pvrusb2-debug.h" -#include "compat.h" -#include <linux/videodev2.h> -#include <media/tuner.h> -#include <media/v4l2-common.h> - -struct pvr2_tuner_handler { - struct pvr2_hdw *hdw; - struct pvr2_i2c_client *client; - struct pvr2_i2c_handler i2c_handler; - int type_update_fl; -}; - - -static void set_type(struct pvr2_tuner_handler *ctxt) -{ - struct pvr2_hdw *hdw = ctxt->hdw; - struct tuner_setup setup; - pvr2_trace(PVR2_TRACE_CHIPS,"i2c tuner set_type(%d)",hdw->tuner_type); - if (((int)(hdw->tuner_type)) < 0) return; - - setup.addr = ADDR_UNSET; - setup.type = hdw->tuner_type; - setup.mode_mask = T_RADIO | T_ANALOG_TV; - /* We may really want mode_mask to be T_ANALOG_TV for now */ - pvr2_i2c_client_cmd(ctxt->client,TUNER_SET_TYPE_ADDR,&setup); - ctxt->type_update_fl = 0; -} - - -static int tuner_check(struct pvr2_tuner_handler *ctxt) -{ - struct pvr2_hdw *hdw = ctxt->hdw; - if (hdw->tuner_updated) ctxt->type_update_fl = !0; - return ctxt->type_update_fl != 0; -} - - -static void tuner_update(struct pvr2_tuner_handler *ctxt) -{ - if (ctxt->type_update_fl) set_type(ctxt); -} - - -static void pvr2_tuner_detach(struct pvr2_tuner_handler *ctxt) -{ - ctxt->client->handler = NULL; - kfree(ctxt); -} - - -static unsigned int pvr2_tuner_describe(struct pvr2_tuner_handler *ctxt,char *buf,unsigned int cnt) -{ - return scnprintf(buf,cnt,"handler: pvrusb2-tuner"); -} - - -static const struct pvr2_i2c_handler_functions tuner_funcs = { - .detach = (void (*)(void *))pvr2_tuner_detach, - .check = (int (*)(void *))tuner_check, - .update = (void (*)(void *))tuner_update, - .describe = (unsigned int (*)(void *,char *,unsigned int))pvr2_tuner_describe, -}; - - -int pvr2_i2c_tuner_setup(struct pvr2_hdw *hdw,struct pvr2_i2c_client *cp) -{ - struct pvr2_tuner_handler *ctxt; - if (cp->handler) return 0; - - ctxt = kzalloc(sizeof(*ctxt),GFP_KERNEL); - if (!ctxt) return 0; - - ctxt->i2c_handler.func_data = ctxt; - ctxt->i2c_handler.func_table = &tuner_funcs; - ctxt->type_update_fl = !0; - ctxt->client = cp; - ctxt->hdw = hdw; - cp->handler = &ctxt->i2c_handler; - pvr2_trace(PVR2_TRACE_CHIPS,"i2c 0x%x tuner handler set up", - cp->client->addr); - return !0; -} - - - - -/* - Stuff for Emacs to see, in order to encourage consistent editing style: - *** Local Variables: *** - *** mode: c *** - *** fill-column: 70 *** - *** tab-width: 8 *** - *** c-basic-offset: 8 *** - *** End: *** - */ diff --git a/linux/drivers/media/video/pvrusb2/pvrusb2-v4l2.c b/linux/drivers/media/video/pvrusb2/pvrusb2-v4l2.c index e4bf0278c..c7fc605f8 100644 --- a/linux/drivers/media/video/pvrusb2/pvrusb2-v4l2.c +++ b/linux/drivers/media/video/pvrusb2/pvrusb2-v4l2.c @@ -953,10 +953,6 @@ static long pvr2_v4l2_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { -/* Temporary hack : use ivtv api until a v4l2 one is available. */ -#define IVTV_IOC_G_CODEC 0xFFEE7703 -#define IVTV_IOC_S_CODEC 0xFFEE7704 - if (cmd == IVTV_IOC_G_CODEC || cmd == IVTV_IOC_S_CODEC) return 0; return video_usercopy(file, cmd, arg, pvr2_v4l2_do_ioctl); } diff --git a/linux/drivers/media/video/pvrusb2/pvrusb2-video-v4l.c b/linux/drivers/media/video/pvrusb2/pvrusb2-video-v4l.c index b1ff3803f..b29a42ef5 100644 --- a/linux/drivers/media/video/pvrusb2/pvrusb2-video-v4l.c +++ b/linux/drivers/media/video/pvrusb2/pvrusb2-video-v4l.c @@ -28,7 +28,7 @@ */ #include "pvrusb2-video-v4l.h" -#include "pvrusb2-i2c-cmd-v4l2.h" + #include "pvrusb2-hdw-internal.h" @@ -40,15 +40,6 @@ #include <linux/slab.h> #include "compat.h" -struct pvr2_v4l_decoder { - struct pvr2_i2c_handler handler; - struct pvr2_decoder_ctrl ctrl; - struct pvr2_i2c_client *client; - struct pvr2_hdw *hdw; - unsigned long stale_mask; -}; - - struct routing_scheme { const int *def; unsigned int cnt; @@ -64,190 +55,51 @@ static const int routing_scheme0[] = { [PVR2_CVAL_INPUT_SVIDEO] = SAA7115_SVIDEO2, }; +static const int routing_scheme1[] = { + [PVR2_CVAL_INPUT_TV] = SAA7115_COMPOSITE4, + [PVR2_CVAL_INPUT_RADIO] = SAA7115_COMPOSITE5, + [PVR2_CVAL_INPUT_COMPOSITE] = SAA7115_COMPOSITE3, + [PVR2_CVAL_INPUT_SVIDEO] = SAA7115_SVIDEO2, /* or SVIDEO0, it seems */ +}; + static const struct routing_scheme routing_schemes[] = { [PVR2_ROUTING_SCHEME_HAUPPAUGE] = { .def = routing_scheme0, .cnt = ARRAY_SIZE(routing_scheme0), }, + [PVR2_ROUTING_SCHEME_ONAIR] = { + .def = routing_scheme1, + .cnt = ARRAY_SIZE(routing_scheme1), + }, }; -static void set_input(struct pvr2_v4l_decoder *ctxt) -{ - struct pvr2_hdw *hdw = ctxt->hdw; - struct v4l2_routing route; - const struct routing_scheme *sp; - unsigned int sid = hdw->hdw_desc->signal_routing_scheme; - - pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 set_input(%d)",hdw->input_val); - - if ((sid < ARRAY_SIZE(routing_schemes)) && - ((sp = routing_schemes + sid) != NULL) && - (hdw->input_val >= 0) && - (hdw->input_val < sp->cnt)) { - route.input = sp->def[hdw->input_val]; - } else { - pvr2_trace(PVR2_TRACE_ERROR_LEGS, - "*** WARNING *** i2c v4l2 set_input:" - " Invalid routing scheme (%u) and/or input (%d)", - sid,hdw->input_val); - return; - } - - route.output = 0; - pvr2_i2c_client_cmd(ctxt->client,VIDIOC_INT_S_VIDEO_ROUTING,&route); -} - - -static int check_input(struct pvr2_v4l_decoder *ctxt) -{ - struct pvr2_hdw *hdw = ctxt->hdw; - return hdw->input_dirty != 0; -} - - -static void set_audio(struct pvr2_v4l_decoder *ctxt) -{ - u32 val; - struct pvr2_hdw *hdw = ctxt->hdw; - - pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 set_audio %d", - hdw->srate_val); - switch (hdw->srate_val) { - default: - case V4L2_MPEG_AUDIO_SAMPLING_FREQ_48000: - val = 48000; - break; - case V4L2_MPEG_AUDIO_SAMPLING_FREQ_44100: - val = 44100; - break; - case V4L2_MPEG_AUDIO_SAMPLING_FREQ_32000: - val = 32000; - break; - } - pvr2_i2c_client_cmd(ctxt->client,VIDIOC_INT_AUDIO_CLOCK_FREQ,&val); -} - - -static int check_audio(struct pvr2_v4l_decoder *ctxt) -{ - struct pvr2_hdw *hdw = ctxt->hdw; - return hdw->srate_dirty != 0; -} - - -struct pvr2_v4l_decoder_ops { - void (*update)(struct pvr2_v4l_decoder *); - int (*check)(struct pvr2_v4l_decoder *); -}; - - -static const struct pvr2_v4l_decoder_ops decoder_ops[] = { - { .update = set_input, .check = check_input}, - { .update = set_audio, .check = check_audio}, -}; - - -static void decoder_detach(struct pvr2_v4l_decoder *ctxt) +void pvr2_saa7115_subdev_update(struct pvr2_hdw *hdw, struct v4l2_subdev *sd) { - ctxt->client->handler = NULL; - pvr2_hdw_set_decoder(ctxt->hdw,NULL); - kfree(ctxt); -} - - -static int decoder_check(struct pvr2_v4l_decoder *ctxt) -{ - unsigned long msk; - unsigned int idx; - - for (idx = 0; idx < ARRAY_SIZE(decoder_ops); idx++) { - msk = 1 << idx; - if (ctxt->stale_mask & msk) continue; - if (decoder_ops[idx].check(ctxt)) { - ctxt->stale_mask |= msk; + if (hdw->input_dirty || hdw->force_dirty) { + struct v4l2_routing route; + const struct routing_scheme *sp; + unsigned int sid = hdw->hdw_desc->signal_routing_scheme; + pvr2_trace(PVR2_TRACE_CHIPS, "subdev v4l2 set_input(%d)", + hdw->input_val); + if ((sid < ARRAY_SIZE(routing_schemes)) && + ((sp = routing_schemes + sid) != NULL) && + (hdw->input_val >= 0) && + (hdw->input_val < sp->cnt)) { + route.input = sp->def[hdw->input_val]; + } else { + pvr2_trace(PVR2_TRACE_ERROR_LEGS, + "*** WARNING *** subdev v4l2 set_input:" + " Invalid routing scheme (%u)" + " and/or input (%d)", + sid, hdw->input_val); + return; } + route.output = 0; + sd->ops->video->s_routing(sd, &route); } - return ctxt->stale_mask != 0; -} - - -static void decoder_update(struct pvr2_v4l_decoder *ctxt) -{ - unsigned long msk; - unsigned int idx; - - for (idx = 0; idx < ARRAY_SIZE(decoder_ops); idx++) { - msk = 1 << idx; - if (!(ctxt->stale_mask & msk)) continue; - ctxt->stale_mask &= ~msk; - decoder_ops[idx].update(ctxt); - } -} - - -static int decoder_detect(struct pvr2_i2c_client *cp) -{ - /* Attempt to query the decoder - let's see if it will answer */ - struct v4l2_tuner vt; - int ret; - - memset(&vt,0,sizeof(vt)); - ret = pvr2_i2c_client_cmd(cp,VIDIOC_G_TUNER,&vt); - return ret == 0; /* Return true if it answered */ -} - - -static void decoder_enable(struct pvr2_v4l_decoder *ctxt,int fl) -{ - pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 decoder_enable(%d)",fl); - pvr2_v4l2_cmd_stream(ctxt->client,fl); -} - - -static unsigned int decoder_describe(struct pvr2_v4l_decoder *ctxt,char *buf,unsigned int cnt) -{ - return scnprintf(buf,cnt,"handler: pvrusb2-video-v4l"); -} - - -static const struct pvr2_i2c_handler_functions hfuncs = { - .detach = (void (*)(void *))decoder_detach, - .check = (int (*)(void *))decoder_check, - .update = (void (*)(void *))decoder_update, - .describe = (unsigned int (*)(void *,char *,unsigned int))decoder_describe, -}; - - -int pvr2_i2c_decoder_v4l_setup(struct pvr2_hdw *hdw, - struct pvr2_i2c_client *cp) -{ - struct pvr2_v4l_decoder *ctxt; - - if (hdw->decoder_ctrl) return 0; - if (cp->handler) return 0; - if (!decoder_detect(cp)) return 0; - - ctxt = kzalloc(sizeof(*ctxt),GFP_KERNEL); - if (!ctxt) return 0; - - ctxt->handler.func_data = ctxt; - ctxt->handler.func_table = &hfuncs; - ctxt->ctrl.ctxt = ctxt; - ctxt->ctrl.detach = (void (*)(void *))decoder_detach; - ctxt->ctrl.enable = (void (*)(void *,int))decoder_enable; - ctxt->client = cp; - ctxt->hdw = hdw; - ctxt->stale_mask = (1 << ARRAY_SIZE(decoder_ops)) - 1; - pvr2_hdw_set_decoder(hdw,&ctxt->ctrl); - cp->handler = &ctxt->handler; - pvr2_trace(PVR2_TRACE_CHIPS,"i2c 0x%x saa711x V4L2 handler set up", - cp->client->addr); - return !0; } - - /* Stuff for Emacs to see, in order to encourage consistent editing style: *** Local Variables: *** diff --git a/linux/drivers/media/video/pvrusb2/pvrusb2-video-v4l.h b/linux/drivers/media/video/pvrusb2/pvrusb2-video-v4l.h index 4ff5b892b..3b0bd5db6 100644 --- a/linux/drivers/media/video/pvrusb2/pvrusb2-video-v4l.h +++ b/linux/drivers/media/video/pvrusb2/pvrusb2-video-v4l.h @@ -32,11 +32,8 @@ */ - -#include "pvrusb2-i2c-core.h" - -int pvr2_i2c_decoder_v4l_setup(struct pvr2_hdw *,struct pvr2_i2c_client *); - +#include "pvrusb2-hdw-internal.h" +void pvr2_saa7115_subdev_update(struct pvr2_hdw *, struct v4l2_subdev *); #endif /* __PVRUSB2_VIDEO_V4L_H */ diff --git a/linux/drivers/media/video/pvrusb2/pvrusb2-wm8775.c b/linux/drivers/media/video/pvrusb2/pvrusb2-wm8775.c index 6cdcbf2fe..6364434a5 100644 --- a/linux/drivers/media/video/pvrusb2/pvrusb2-wm8775.c +++ b/linux/drivers/media/video/pvrusb2/pvrusb2-wm8775.c @@ -27,7 +27,6 @@ */ #include "pvrusb2-wm8775.h" -#include "pvrusb2-i2c-cmd-v4l2.h" #include "pvrusb2-hdw-internal.h" @@ -38,128 +37,31 @@ #include <linux/slab.h> #include "compat.h" -struct pvr2_v4l_wm8775 { - struct pvr2_i2c_handler handler; - struct pvr2_i2c_client *client; - struct pvr2_hdw *hdw; - unsigned long stale_mask; -}; - - -static void set_input(struct pvr2_v4l_wm8775 *ctxt) -{ - struct v4l2_routing route; - struct pvr2_hdw *hdw = ctxt->hdw; - - memset(&route,0,sizeof(route)); - - switch(hdw->input_val) { - case PVR2_CVAL_INPUT_RADIO: - route.input = 1; - break; - default: - /* All other cases just use the second input */ - route.input = 2; - break; - } - pvr2_trace(PVR2_TRACE_CHIPS,"i2c wm8775 set_input(val=%d route=0x%x)", - hdw->input_val,route.input); - - pvr2_i2c_client_cmd(ctxt->client,VIDIOC_INT_S_AUDIO_ROUTING,&route); -} - -static int check_input(struct pvr2_v4l_wm8775 *ctxt) -{ - struct pvr2_hdw *hdw = ctxt->hdw; - return hdw->input_dirty != 0; -} - - -struct pvr2_v4l_wm8775_ops { - void (*update)(struct pvr2_v4l_wm8775 *); - int (*check)(struct pvr2_v4l_wm8775 *); -}; - - -static const struct pvr2_v4l_wm8775_ops wm8775_ops[] = { - { .update = set_input, .check = check_input}, -}; - - -static unsigned int wm8775_describe(struct pvr2_v4l_wm8775 *ctxt, - char *buf,unsigned int cnt) -{ - return scnprintf(buf,cnt,"handler: pvrusb2-wm8775"); -} - - -static void wm8775_detach(struct pvr2_v4l_wm8775 *ctxt) +void pvr2_wm8775_subdev_update(struct pvr2_hdw *hdw, struct v4l2_subdev *sd) { - ctxt->client->handler = NULL; - kfree(ctxt); -} - - -static int wm8775_check(struct pvr2_v4l_wm8775 *ctxt) -{ - unsigned long msk; - unsigned int idx; - - for (idx = 0; idx < ARRAY_SIZE(wm8775_ops); idx++) { - msk = 1 << idx; - if (ctxt->stale_mask & msk) continue; - if (wm8775_ops[idx].check(ctxt)) { - ctxt->stale_mask |= msk; + if (hdw->input_dirty || hdw->force_dirty) { + struct v4l2_routing route; + + memset(&route, 0, sizeof(route)); + + switch (hdw->input_val) { + case PVR2_CVAL_INPUT_RADIO: + route.input = 1; + break; + default: + /* All other cases just use the second input */ + route.input = 2; + break; } - } - return ctxt->stale_mask != 0; -} - - -static void wm8775_update(struct pvr2_v4l_wm8775 *ctxt) -{ - unsigned long msk; - unsigned int idx; + pvr2_trace(PVR2_TRACE_CHIPS, "subdev wm8775" + " set_input(val=%d route=0x%x)", + hdw->input_val, route.input); - for (idx = 0; idx < ARRAY_SIZE(wm8775_ops); idx++) { - msk = 1 << idx; - if (!(ctxt->stale_mask & msk)) continue; - ctxt->stale_mask &= ~msk; - wm8775_ops[idx].update(ctxt); + sd->ops->audio->s_routing(sd, &route); } } -static const struct pvr2_i2c_handler_functions hfuncs = { - .detach = (void (*)(void *))wm8775_detach, - .check = (int (*)(void *))wm8775_check, - .update = (void (*)(void *))wm8775_update, - .describe = (unsigned int (*)(void *,char *,unsigned int))wm8775_describe, -}; - - -int pvr2_i2c_wm8775_setup(struct pvr2_hdw *hdw,struct pvr2_i2c_client *cp) -{ - struct pvr2_v4l_wm8775 *ctxt; - - if (cp->handler) return 0; - - ctxt = kzalloc(sizeof(*ctxt),GFP_KERNEL); - if (!ctxt) return 0; - - ctxt->handler.func_data = ctxt; - ctxt->handler.func_table = &hfuncs; - ctxt->client = cp; - ctxt->hdw = hdw; - ctxt->stale_mask = (1 << ARRAY_SIZE(wm8775_ops)) - 1; - cp->handler = &ctxt->handler; - pvr2_trace(PVR2_TRACE_CHIPS,"i2c 0x%x wm8775 V4L2 handler set up", - cp->client->addr); - return !0; -} - - - /* Stuff for Emacs to see, in order to encourage consistent editing style: diff --git a/linux/drivers/media/video/pvrusb2/pvrusb2-wm8775.h b/linux/drivers/media/video/pvrusb2/pvrusb2-wm8775.h index 807090961..0577bc724 100644 --- a/linux/drivers/media/video/pvrusb2/pvrusb2-wm8775.h +++ b/linux/drivers/media/video/pvrusb2/pvrusb2-wm8775.h @@ -34,9 +34,9 @@ -#include "pvrusb2-i2c-core.h" +#include "pvrusb2-hdw-internal.h" -int pvr2_i2c_wm8775_setup(struct pvr2_hdw *,struct pvr2_i2c_client *); +void pvr2_wm8775_subdev_update(struct pvr2_hdw *, struct v4l2_subdev *sd); #endif /* __PVRUSB2_WM8775_H */ diff --git a/linux/drivers/media/video/pxa_camera.c b/linux/drivers/media/video/pxa_camera.c index dd524b3c6..d1aa540ba 100644 --- a/linux/drivers/media/video/pxa_camera.c +++ b/linux/drivers/media/video/pxa_camera.c @@ -1160,8 +1160,43 @@ static int pxa_camera_get_formats(struct soc_camera_device *icd, int idx, return formats; } +static int pxa_camera_set_crop(struct soc_camera_device *icd, + struct v4l2_rect *rect) +{ + struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); + struct pxa_camera_dev *pcdev = ici->priv; + struct soc_camera_sense sense = { + .master_clock = pcdev->mclk, + .pixel_clock_max = pcdev->ciclk / 4, + }; + int ret; + + /* If PCLK is used to latch data from the sensor, check sense */ + if (pcdev->platform_flags & PXA_CAMERA_PCLK_EN) + icd->sense = &sense; + + ret = icd->ops->set_crop(icd, rect); + + icd->sense = NULL; + + if (ret < 0) { + dev_warn(&ici->dev, "Failed to crop to %ux%u@%u:%u\n", + rect->width, rect->height, rect->left, rect->top); + } else if (sense.flags & SOCAM_SENSE_PCLK_CHANGED) { + if (sense.pixel_clock > sense.pixel_clock_max) { + dev_err(&ici->dev, + "pixel clock %lu set by the camera too high!", + sense.pixel_clock); + return -EIO; + } + recalculate_fifo_timeout(pcdev, sense.pixel_clock); + } + + return ret; +} + static int pxa_camera_set_fmt(struct soc_camera_device *icd, - __u32 pixfmt, struct v4l2_rect *rect) + struct v4l2_format *f) { struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); struct pxa_camera_dev *pcdev = ici->priv; @@ -1171,35 +1206,30 @@ static int pxa_camera_set_fmt(struct soc_camera_device *icd, .master_clock = pcdev->mclk, .pixel_clock_max = pcdev->ciclk / 4, }; + struct v4l2_pix_format *pix = &f->fmt.pix; + struct v4l2_format cam_f = *f; int ret; - if (pixfmt) { - xlate = soc_camera_xlate_by_fourcc(icd, pixfmt); - if (!xlate) { - dev_warn(&ici->dev, "Format %x not found\n", pixfmt); - return -EINVAL; - } - - cam_fmt = xlate->cam_fmt; + xlate = soc_camera_xlate_by_fourcc(icd, pix->pixelformat); + if (!xlate) { + dev_warn(&ici->dev, "Format %x not found\n", pix->pixelformat); + return -EINVAL; } + cam_fmt = xlate->cam_fmt; + /* If PCLK is used to latch data from the sensor, check sense */ if (pcdev->platform_flags & PXA_CAMERA_PCLK_EN) icd->sense = &sense; - switch (pixfmt) { - case 0: /* Only geometry change */ - ret = icd->ops->set_fmt(icd, pixfmt, rect); - break; - default: - ret = icd->ops->set_fmt(icd, cam_fmt->fourcc, rect); - } + cam_f.fmt.pix.pixelformat = cam_fmt->fourcc; + ret = icd->ops->set_fmt(icd, &cam_f); icd->sense = NULL; if (ret < 0) { dev_warn(&ici->dev, "Failed to configure for format %x\n", - pixfmt); + pix->pixelformat); } else if (sense.flags & SOCAM_SENSE_PCLK_CHANGED) { if (sense.pixel_clock > sense.pixel_clock_max) { dev_err(&ici->dev, @@ -1210,7 +1240,7 @@ static int pxa_camera_set_fmt(struct soc_camera_device *icd, recalculate_fifo_timeout(pcdev, sense.pixel_clock); } - if (pixfmt && !ret) { + if (!ret) { icd->buswidth = xlate->buswidth; icd->current_fmt = xlate->host_fmt; } @@ -1374,6 +1404,7 @@ static struct soc_camera_host_ops pxa_soc_camera_host_ops = { .remove = pxa_camera_remove_device, .suspend = pxa_camera_suspend, .resume = pxa_camera_resume, + .set_crop = pxa_camera_set_crop, .get_formats = pxa_camera_get_formats, .set_fmt = pxa_camera_set_fmt, .try_fmt = pxa_camera_try_fmt, diff --git a/linux/drivers/media/video/saa7134/Kconfig b/linux/drivers/media/video/saa7134/Kconfig index e62b29967..a2089acb0 100644 --- a/linux/drivers/media/video/saa7134/Kconfig +++ b/linux/drivers/media/video/saa7134/Kconfig @@ -36,15 +36,15 @@ config VIDEO_SAA7134_DVB select DVB_TDA826X if !DVB_FE_CUSTOMISE select DVB_ISL6421 if !DVB_FE_CUSTOMISE select DVB_ISL6405 if !DVB_FE_CUSTOMISE - select MEDIA_TUNER_TDA827X if !MEDIA_TUNER_CUSTOMIZE - select MEDIA_TUNER_SIMPLE if !MEDIA_TUNER_CUSTOMIZE + select MEDIA_TUNER_TDA827X if !MEDIA_TUNER_CUSTOMISE + select MEDIA_TUNER_SIMPLE if !MEDIA_TUNER_CUSTOMISE select DVB_ZL10036 if !DVB_FE_CUSTOMISE select DVB_MT312 if !DVB_FE_CUSTOMISE select DVB_LNBP21 if !DVB_FE_CUSTOMISE select DVB_ZL10353 if !DVB_FE_CUSTOMISE select DVB_LGDT3305 if !DVB_FE_CUSTOMISE - select MEDIA_TUNER_TDA18271 if !MEDIA_TUNER_CUSTOMIZE - select MEDIA_TUNER_TDA8290 if !MEDIA_TUNER_CUSTOMIZE + select MEDIA_TUNER_TDA18271 if !MEDIA_TUNER_CUSTOMISE + select MEDIA_TUNER_TDA8290 if !MEDIA_TUNER_CUSTOMISE ---help--- This adds support for DVB cards based on the Philips saa7134 chip. diff --git a/linux/drivers/media/video/saa7134/saa7134-core.c b/linux/drivers/media/video/saa7134/saa7134-core.c index d499064ee..b99b1ed1c 100644 --- a/linux/drivers/media/video/saa7134/saa7134-core.c +++ b/linux/drivers/media/video/saa7134/saa7134-core.c @@ -837,7 +837,7 @@ static struct video_device *vdev_init(struct saa7134_dev *dev, return NULL; *vfd = *template; vfd->minor = -1; - vfd->parent = &dev->pci->dev; + vfd->v4l2_dev = &dev->v4l2_dev; vfd->release = video_device_release; vfd->debug = video_debug; snprintf(vfd->name, sizeof(vfd->name), "%s %s (%s)", diff --git a/linux/drivers/media/video/sh_mobile_ceu_camera.c b/linux/drivers/media/video/sh_mobile_ceu_camera.c index 29ff02802..cd796b33f 100644 --- a/linux/drivers/media/video/sh_mobile_ceu_camera.c +++ b/linux/drivers/media/video/sh_mobile_ceu_camera.c @@ -95,7 +95,7 @@ struct sh_mobile_ceu_dev { spinlock_t lock; struct list_head capture; struct videobuf_buffer *active; - int is_interlace; + int is_interlaced; struct sh_mobile_ceu_info *pdata; @@ -175,6 +175,7 @@ static void free_buffer(struct videobuf_queue *vq, if (in_interrupt()) BUG(); + videobuf_waiton(&buf->vb, 0, 0); videobuf_dma_contig_free(vq, &buf->vb); dev_dbg(&icd->dev, "%s freed\n", __func__); buf->vb.state = VIDEOBUF_NEEDS_INIT; @@ -206,7 +207,7 @@ static void sh_mobile_ceu_capture(struct sh_mobile_ceu_dev *pcdev) phys_addr_top = videobuf_to_dma_contig(pcdev->active); ceu_write(pcdev, CDAYR, phys_addr_top); - if (pcdev->is_interlace) { + if (pcdev->is_interlaced) { phys_addr_bottom = phys_addr_top + icd->width; ceu_write(pcdev, CDBYR, phys_addr_bottom); } @@ -218,7 +219,7 @@ static void sh_mobile_ceu_capture(struct sh_mobile_ceu_dev *pcdev) case V4L2_PIX_FMT_NV61: phys_addr_top += icd->width * icd->height; ceu_write(pcdev, CDACR, phys_addr_top); - if (pcdev->is_interlace) { + if (pcdev->is_interlaced) { phys_addr_bottom = phys_addr_top + icd->width; ceu_write(pcdev, CDBCR, phys_addr_bottom); } @@ -482,7 +483,7 @@ static int sh_mobile_ceu_set_bus_param(struct soc_camera_device *icd, ceu_write(pcdev, CAMCR, value); ceu_write(pcdev, CAPCR, 0x00300000); - ceu_write(pcdev, CAIFR, (pcdev->is_interlace) ? 0x101 : 0); + ceu_write(pcdev, CAIFR, pcdev->is_interlaced ? 0x101 : 0); mdelay(1); @@ -498,7 +499,7 @@ static int sh_mobile_ceu_set_bus_param(struct soc_camera_device *icd, } height = icd->height; - if (pcdev->is_interlace) { + if (pcdev->is_interlaced) { height /= 2; cdwdr_width *= 2; } @@ -639,24 +640,30 @@ add_single_format: return formats; } +static int sh_mobile_ceu_set_crop(struct soc_camera_device *icd, + struct v4l2_rect *rect) +{ + return icd->ops->set_crop(icd, rect); +} + static int sh_mobile_ceu_set_fmt(struct soc_camera_device *icd, - __u32 pixfmt, struct v4l2_rect *rect) + struct v4l2_format *f) { struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); struct sh_mobile_ceu_dev *pcdev = ici->priv; + __u32 pixfmt = f->fmt.pix.pixelformat; const struct soc_camera_format_xlate *xlate; + struct v4l2_format cam_f = *f; int ret; - if (!pixfmt) - return icd->ops->set_fmt(icd, pixfmt, rect); - xlate = soc_camera_xlate_by_fourcc(icd, pixfmt); if (!xlate) { dev_warn(&ici->dev, "Format %x not found\n", pixfmt); return -EINVAL; } - ret = icd->ops->set_fmt(icd, xlate->cam_fmt->fourcc, rect); + cam_f.fmt.pix.pixelformat = xlate->cam_fmt->fourcc; + ret = icd->ops->set_fmt(icd, &cam_f); if (!ret) { icd->buswidth = xlate->buswidth; @@ -706,13 +713,13 @@ static int sh_mobile_ceu_try_fmt(struct soc_camera_device *icd, switch (f->fmt.pix.field) { case V4L2_FIELD_INTERLACED: - pcdev->is_interlace = 1; + pcdev->is_interlaced = 1; break; case V4L2_FIELD_ANY: f->fmt.pix.field = V4L2_FIELD_NONE; /* fall-through */ case V4L2_FIELD_NONE: - pcdev->is_interlace = 0; + pcdev->is_interlaced = 0; break; default: ret = -EINVAL; @@ -778,7 +785,8 @@ static void sh_mobile_ceu_init_videobuf(struct videobuf_queue *q, &sh_mobile_ceu_videobuf_ops, &ici->dev, &pcdev->lock, V4L2_BUF_TYPE_VIDEO_CAPTURE, - V4L2_FIELD_ANY, + pcdev->is_interlaced ? + V4L2_FIELD_INTERLACED : V4L2_FIELD_NONE, sizeof(struct sh_mobile_ceu_buffer), icd); } @@ -788,6 +796,7 @@ static struct soc_camera_host_ops sh_mobile_ceu_host_ops = { .add = sh_mobile_ceu_add_device, .remove = sh_mobile_ceu_remove_device, .get_formats = sh_mobile_ceu_get_formats, + .set_crop = sh_mobile_ceu_set_crop, .set_fmt = sh_mobile_ceu_set_fmt, .try_fmt = sh_mobile_ceu_try_fmt, .reqbufs = sh_mobile_ceu_reqbufs, diff --git a/linux/drivers/media/video/sn9c102/sn9c102_devtable.h b/linux/drivers/media/video/sn9c102/sn9c102_devtable.h index 41dfb60f4..38a716020 100644 --- a/linux/drivers/media/video/sn9c102/sn9c102_devtable.h +++ b/linux/drivers/media/video/sn9c102/sn9c102_devtable.h @@ -96,9 +96,7 @@ static const struct usb_device_id sn9c102_id_table[] = { #if !defined CONFIG_USB_GSPCA && !defined CONFIG_USB_GSPCA_MODULE { SN9C102_USB_DEVICE(0x045e, 0x00f5, BRIDGE_SN9C105), }, { SN9C102_USB_DEVICE(0x045e, 0x00f7, BRIDGE_SN9C105), }, -#endif { SN9C102_USB_DEVICE(0x0471, 0x0327, BRIDGE_SN9C105), }, -#if !defined CONFIG_USB_GSPCA && !defined CONFIG_USB_GSPCA_MODULE { SN9C102_USB_DEVICE(0x0471, 0x0328, BRIDGE_SN9C105), }, #endif { SN9C102_USB_DEVICE(0x0c45, 0x60c0, BRIDGE_SN9C105), }, diff --git a/linux/drivers/media/video/soc_camera.c b/linux/drivers/media/video/soc_camera.c index 356b77e10..da6d224eb 100644 --- a/linux/drivers/media/video/soc_camera.c +++ b/linux/drivers/media/video/soc_camera.c @@ -31,6 +31,10 @@ #include <media/soc_camera.h> #include "compat.h" +/* Default to VGA resolution */ +#define DEFAULT_WIDTH 640 +#define DEFAULT_HEIGHT 480 + static LIST_HEAD(hosts); static LIST_HEAD(devices); static DEFINE_MUTEX(list_lock); @@ -257,6 +261,46 @@ static void soc_camera_free_user_formats(struct soc_camera_device *icd) vfree(icd->user_formats); } +/* Called with .vb_lock held */ +static int soc_camera_set_fmt(struct soc_camera_file *icf, + struct v4l2_format *f) +{ + struct soc_camera_device *icd = icf->icd; + struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); + struct v4l2_pix_format *pix = &f->fmt.pix; + int ret; + + /* We always call try_fmt() before set_fmt() or set_crop() */ + ret = ici->ops->try_fmt(icd, f); + if (ret < 0) + return ret; + + ret = ici->ops->set_fmt(icd, f); + if (ret < 0) { + return ret; + } else if (!icd->current_fmt || + icd->current_fmt->fourcc != pix->pixelformat) { + dev_err(&ici->dev, + "Host driver hasn't set up current format correctly!\n"); + return -EINVAL; + } + + icd->width = pix->width; + icd->height = pix->height; + icf->vb_vidq.field = + icd->field = pix->field; + + if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) + dev_warn(&icd->dev, "Attention! Wrong buf-type %d\n", + f->type); + + dev_dbg(&icd->dev, "set width: %d height: %d\n", + icd->width, icd->height); + + /* set physical bus parameters */ + return ici->ops->set_bus_param(icd, pix->pixelformat); +} + static int soc_camera_open(struct file *file) { struct video_device *vdev; @@ -298,14 +342,28 @@ static int soc_camera_open(struct file *file) /* Now we really have to activate the camera */ if (icd->use_count == 1) { - ret = soc_camera_init_user_formats(icd); - if (ret < 0) - goto eiufmt; + /* Restore parameters before the last close() per V4L2 API */ + struct v4l2_format f = { + .type = V4L2_BUF_TYPE_VIDEO_CAPTURE, + .fmt.pix = { + .width = icd->width, + .height = icd->height, + .field = icd->field, + .pixelformat = icd->current_fmt->fourcc, + .colorspace = icd->current_fmt->colorspace, + }, + }; + ret = ici->ops->add(icd); if (ret < 0) { dev_err(&icd->dev, "Couldn't activate the camera: %d\n", ret); goto eiciadd; } + + /* Try to configure with default parameters */ + ret = soc_camera_set_fmt(icf, &f); + if (ret < 0) + goto esfmt; } mutex_unlock(&icd->video_lock); @@ -317,10 +375,13 @@ static int soc_camera_open(struct file *file) return 0; - /* First two errors are entered with the .video_lock held */ + /* + * First three errors are entered with the .video_lock held + * and use_count == 1 + */ +esfmt: + ici->ops->remove(icd); eiciadd: - soc_camera_free_user_formats(icd); -eiufmt: icd->use_count--; mutex_unlock(&icd->video_lock); module_put(ici->ops->owner); @@ -340,10 +401,9 @@ static int soc_camera_close(struct file *file) mutex_lock(&icd->video_lock); icd->use_count--; - if (!icd->use_count) { + if (!icd->use_count) ici->ops->remove(icd); - soc_camera_free_user_formats(icd); - } + mutex_unlock(&icd->video_lock); module_put(icd->ops->owner); @@ -416,18 +476,10 @@ static int soc_camera_s_fmt_vid_cap(struct file *file, void *priv, { struct soc_camera_file *icf = file->private_data; struct soc_camera_device *icd = icf->icd; - struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); - struct v4l2_pix_format *pix = &f->fmt.pix; - __u32 pixfmt = pix->pixelformat; int ret; - struct v4l2_rect rect; WARN_ON(priv != file->private_data); - ret = soc_camera_try_fmt_vid_cap(file, priv, f); - if (ret < 0) - return ret; - mutex_lock(&icf->vb_vidq.vb_lock); if (videobuf_queue_is_busy(&icf->vb_vidq)) { @@ -436,33 +488,7 @@ static int soc_camera_s_fmt_vid_cap(struct file *file, void *priv, goto unlock; } - rect.left = icd->x_current; - rect.top = icd->y_current; - rect.width = pix->width; - rect.height = pix->height; - ret = ici->ops->set_fmt(icd, pix->pixelformat, &rect); - if (ret < 0) { - goto unlock; - } else if (!icd->current_fmt || - icd->current_fmt->fourcc != pixfmt) { - dev_err(&ici->dev, - "Host driver hasn't set up current format correctly!\n"); - ret = -EINVAL; - goto unlock; - } - - icd->width = rect.width; - icd->height = rect.height; - icf->vb_vidq.field = pix->field; - if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) - dev_warn(&icd->dev, "Attention! Wrong buf-type %d\n", - f->type); - - dev_dbg(&icd->dev, "set width: %d height: %d\n", - icd->width, icd->height); - - /* set physical bus parameters */ - ret = ici->ops->set_bus_param(icd, pixfmt); + ret = soc_camera_set_fmt(icf, f); unlock: mutex_unlock(&icf->vb_vidq.vb_lock); @@ -649,8 +675,8 @@ static int soc_camera_cropcap(struct file *file, void *fh, a->bounds.height = icd->height_max; a->defrect.left = icd->x_min; a->defrect.top = icd->y_min; - a->defrect.width = 640; - a->defrect.height = 480; + a->defrect.width = DEFAULT_WIDTH; + a->defrect.height = DEFAULT_HEIGHT; a->pixelaspect.numerator = 1; a->pixelaspect.denominator = 1; @@ -686,7 +712,7 @@ static int soc_camera_s_crop(struct file *file, void *fh, /* Cropping is allowed during a running capture, guard consistency */ mutex_lock(&icf->vb_vidq.vb_lock); - ret = ici->ops->set_fmt(icd, 0, &a->c); + ret = ici->ops->set_crop(icd, &a->c); if (!ret) { icd->width = a->c.width; icd->height = a->c.height; @@ -845,9 +871,18 @@ static int soc_camera_probe(struct device *dev) qctrl = soc_camera_find_qctrl(icd->ops, V4L2_CID_EXPOSURE); icd->exposure = qctrl ? qctrl->default_value : (unsigned short)~0; + + ret = soc_camera_init_user_formats(icd); + if (ret < 0) + goto eiufmt; + + icd->height = DEFAULT_HEIGHT; + icd->width = DEFAULT_WIDTH; + icd->field = V4L2_FIELD_ANY; } - ici->ops->remove(icd); +eiufmt: + ici->ops->remove(icd); eiadd: mutex_unlock(&icd->video_lock); module_put(ici->ops->owner); @@ -866,6 +901,8 @@ static int soc_camera_remove(struct device *dev) if (icd->ops->remove) icd->ops->remove(icd); + soc_camera_free_user_formats(icd); + return 0; } @@ -919,6 +956,7 @@ int soc_camera_host_register(struct soc_camera_host *ici) if (!ici || !ici->ops || !ici->ops->try_fmt || !ici->ops->set_fmt || + !ici->ops->set_crop || !ici->ops->set_bus_param || !ici->ops->querycap || !ici->ops->init_videobuf || @@ -999,6 +1037,7 @@ int soc_camera_device_register(struct soc_camera_device *icd) !icd->ops->release || !icd->ops->start_capture || !icd->ops->stop_capture || + !icd->ops->set_crop || !icd->ops->set_fmt || !icd->ops->try_fmt || !icd->ops->query_bus_param || diff --git a/linux/drivers/media/video/soc_camera_platform.c b/linux/drivers/media/video/soc_camera_platform.c index 013ab06e3..c48676356 100644 --- a/linux/drivers/media/video/soc_camera_platform.c +++ b/linux/drivers/media/video/soc_camera_platform.c @@ -79,8 +79,14 @@ soc_camera_platform_query_bus_param(struct soc_camera_device *icd) return p->bus_param; } +static int soc_camera_platform_set_crop(struct soc_camera_device *icd, + struct v4l2_rect *rect) +{ + return 0; +} + static int soc_camera_platform_set_fmt(struct soc_camera_device *icd, - __u32 pixfmt, struct v4l2_rect *rect) + struct v4l2_format *f) { return 0; } @@ -125,6 +131,7 @@ static struct soc_camera_ops soc_camera_platform_ops = { .release = soc_camera_platform_release, .start_capture = soc_camera_platform_start_capture, .stop_capture = soc_camera_platform_stop_capture, + .set_crop = soc_camera_platform_set_crop, .set_fmt = soc_camera_platform_set_fmt, .try_fmt = soc_camera_platform_try_fmt, .set_bus_param = soc_camera_platform_set_bus_param, diff --git a/linux/drivers/media/video/tuner-core.c b/linux/drivers/media/video/tuner-core.c index a0cbd71e8..9960fb357 100644 --- a/linux/drivers/media/video/tuner-core.c +++ b/linux/drivers/media/video/tuner-core.c @@ -454,7 +454,8 @@ static void set_type(struct i2c_client *c, unsigned int type, struct dvb_tuner_ops *xc_tuner_ops; xc5000_cfg.i2c_address = t->i2c->addr; - xc5000_cfg.if_khz = 5380; + /* if_khz will be set when the digital dvb_attach() occurs */ + xc5000_cfg.if_khz = 0; if (!dvb_attach(xc5000_attach, &t->fe, t->i2c->adapter, &xc5000_cfg)) goto attach_failed; diff --git a/linux/drivers/media/video/tveeprom.c b/linux/drivers/media/video/tveeprom.c index acd601a52..cdea91aae 100644 --- a/linux/drivers/media/video/tveeprom.c +++ b/linux/drivers/media/video/tveeprom.c @@ -262,7 +262,7 @@ hauppauge_tuner[] = { TUNER_ABSENT, "MaxLinear MXL5005_v2"}, { TUNER_PHILIPS_TDA8290, "Philips 18271_8295"}, /* 150-159 */ - { TUNER_ABSENT, "Xceive XC5000"}, + { TUNER_XC5000, "Xceive XC5000"}, { TUNER_ABSENT, "Xceive XC3028L"}, { TUNER_ABSENT, "NXP 18271C2_716x"}, { TUNER_ABSENT, "Xceive XC4000"}, diff --git a/linux/drivers/media/video/tw9910.c b/linux/drivers/media/video/tw9910.c index ed8dca3bf..5c145085a 100644 --- a/linux/drivers/media/video/tw9910.c +++ b/linux/drivers/media/video/tw9910.c @@ -641,25 +641,12 @@ static int tw9910_set_register(struct soc_camera_device *icd, } #endif -static int tw9910_set_fmt(struct soc_camera_device *icd, __u32 pixfmt, - struct v4l2_rect *rect) +static int tw9910_set_crop(struct soc_camera_device *icd, + struct v4l2_rect *rect) { struct tw9910_priv *priv = container_of(icd, struct tw9910_priv, icd); int ret = -EINVAL; u8 val; - int i; - - /* - * check color format - */ - for (i = 0 ; i < ARRAY_SIZE(tw9910_color_fmt) ; i++) { - if (pixfmt == tw9910_color_fmt[i].fourcc) { - ret = 0; - break; - } - } - if (ret < 0) - goto tw9910_set_fmt_error; /* * select suitable norm @@ -746,8 +733,33 @@ tw9910_set_fmt_error: return ret; } +static int tw9910_set_fmt(struct soc_camera_device *icd, + struct v4l2_format *f) +{ + struct v4l2_pix_format *pix = &f->fmt.pix; + struct v4l2_rect rect = { + .left = icd->x_current, + .top = icd->y_current, + .width = pix->width, + .height = pix->height, + }; + int i; + + /* + * check color format + */ + for (i = 0; i < ARRAY_SIZE(tw9910_color_fmt); i++) + if (pix->pixelformat == tw9910_color_fmt[i].fourcc) + break; + + if (i == ARRAY_SIZE(tw9910_color_fmt)) + return -EINVAL; + + return tw9910_set_crop(icd, &rect); +} + static int tw9910_try_fmt(struct soc_camera_device *icd, - struct v4l2_format *f) + struct v4l2_format *f) { struct v4l2_pix_format *pix = &f->fmt.pix; const struct tw9910_scale_ctrl *scale; @@ -835,6 +847,7 @@ static struct soc_camera_ops tw9910_ops = { .release = tw9910_release, .start_capture = tw9910_start_capture, .stop_capture = tw9910_stop_capture, + .set_crop = tw9910_set_crop, .set_fmt = tw9910_set_fmt, .try_fmt = tw9910_try_fmt, .set_bus_param = tw9910_set_bus_param, diff --git a/linux/drivers/media/video/usbvideo/vicam.c b/linux/drivers/media/video/usbvideo/vicam.c index 5a039b5d6..3b332ef52 100644 --- a/linux/drivers/media/video/usbvideo/vicam.c +++ b/linux/drivers/media/video/usbvideo/vicam.c @@ -489,7 +489,7 @@ initialize_camera(struct vicam_camera *cam) #else int err; const struct ihex_binrec *rec; - const struct firmware *fw; + const struct firmware *uninitialized_var(fw); err = request_ihex_firmware(&fw, "vicam/firmware.fw", &cam->udev->dev); if (err) { diff --git a/linux/drivers/media/video/usbvision/usbvision-core.c b/linux/drivers/media/video/usbvision/usbvision-core.c index 7fe361668..734df263f 100644 --- a/linux/drivers/media/video/usbvision/usbvision-core.c +++ b/linux/drivers/media/video/usbvision/usbvision-core.c @@ -2524,7 +2524,7 @@ int usbvision_init_isoc(struct usb_usbvision *usbvision) urb->dev = dev; urb->context = usbvision; urb->pipe = usb_rcvisocpipe(dev, usbvision->video_endp); - urb->transfer_flags = URB_ISO_ASAP; + urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP; urb->interval = 1; urb->transfer_buffer = usbvision->sbuf[bufIdx].data; urb->complete = usbvision_isocIrq; diff --git a/linux/drivers/media/video/usbvision/usbvision-video.c b/linux/drivers/media/video/usbvision/usbvision-video.c index 3d400e4b7..74a7652de 100644 --- a/linux/drivers/media/video/usbvision/usbvision-video.c +++ b/linux/drivers/media/video/usbvision/usbvision-video.c @@ -1771,6 +1771,8 @@ static void __devexit usbvision_disconnect(struct usb_interface *intf) // At this time we ask to cancel outstanding URBs usbvision_stop_isoc(usbvision); + v4l2_device_disconnect(&usbvision->v4l2_dev); + if (usbvision->power) { usbvision_i2c_unregister(usbvision); usbvision_power_off(usbvision); diff --git a/linux/drivers/media/video/usbvision/usbvision.h b/linux/drivers/media/video/usbvision/usbvision.h index dc86c2139..42a926799 100644 --- a/linux/drivers/media/video/usbvision/usbvision.h +++ b/linux/drivers/media/video/usbvision/usbvision.h @@ -6,7 +6,7 @@ * Dwaine Garden <dwainegarden@rogers.com> * * - * Report problems to v4l MailingList : http://www.redhat.com/mailman/listinfo/video4linux-list + * Report problems to v4l MailingList: linux-media@vger.kernel.org * * This module is part of usbvision driver project. * Updates to driver completed by Dwaine P. Garden diff --git a/linux/drivers/media/video/v4l2-common.c b/linux/drivers/media/video/v4l2-common.c index 32d0246d5..b153575fb 100644 --- a/linux/drivers/media/video/v4l2-common.c +++ b/linux/drivers/media/video/v4l2-common.c @@ -570,6 +570,7 @@ int v4l2_ctrl_query_fill(struct v4l2_queryctrl *qctrl, s32 min, s32 max, s32 ste case V4L2_CID_RED_BALANCE: case V4L2_CID_BLUE_BALANCE: case V4L2_CID_GAMMA: + case V4L2_CID_SHARPNESS: qctrl->flags |= V4L2_CTRL_FLAG_SLIDER; break; case V4L2_CID_PAN_RELATIVE: @@ -828,10 +829,10 @@ struct v4l2_subdev *v4l2_i2c_new_subdev(struct i2c_adapter *adapter, #endif BUG_ON(!dev); -#ifdef MODULE + if (module_name) request_module(module_name); -#endif + #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 22) /* Setup the i2c board info with the device type and the device address. */ @@ -896,10 +897,10 @@ struct v4l2_subdev *v4l2_i2c_new_probed_subdev(struct i2c_adapter *adapter, #endif BUG_ON(!dev); -#ifdef MODULE + if (module_name) request_module(module_name); -#endif + #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 22) /* Setup the i2c board info with the device type and the device address. */ diff --git a/linux/drivers/media/video/v4l2-dev.c b/linux/drivers/media/video/v4l2-dev.c index 110cde853..2c4d38979 100644 --- a/linux/drivers/media/video/v4l2-dev.c +++ b/linux/drivers/media/video/v4l2-dev.c @@ -236,6 +236,23 @@ static long v4l2_unlocked_ioctl(struct file *filp, return vdev->fops->unlocked_ioctl(filp, cmd, arg); } +#ifdef CONFIG_MMU +#define v4l2_get_unmapped_area NULL +#else +static unsigned long v4l2_get_unmapped_area(struct file *filp, + unsigned long addr, unsigned long len, unsigned long pgoff, + unsigned long flags) +{ + struct video_device *vdev = video_devdata(filp); + + if (!vdev->fops->get_unmapped_area) + return -ENOSYS; + if (video_is_unregistered(vdev)) + return -ENODEV; + return vdev->fops->get_unmapped_area(filp, addr, len, pgoff, flags); +} +#endif + static int v4l2_mmap(struct file *filp, struct vm_area_struct *vm) { struct video_device *vdev = video_devdata(filp); @@ -288,6 +305,7 @@ static const struct file_operations v4l2_unlocked_fops = { .read = v4l2_read, .write = v4l2_write, .open = v4l2_open, + .get_unmapped_area = v4l2_get_unmapped_area, .mmap = v4l2_mmap, .unlocked_ioctl = v4l2_unlocked_ioctl, #ifdef CONFIG_COMPAT @@ -303,6 +321,7 @@ static const struct file_operations v4l2_fops = { .read = v4l2_read, .write = v4l2_write, .open = v4l2_open, + .get_unmapped_area = v4l2_get_unmapped_area, .mmap = v4l2_mmap, .ioctl = v4l2_ioctl, #ifdef CONFIG_COMPAT @@ -433,7 +452,7 @@ int video_register_device_index(struct video_device *vdev, int type, int nr, vdev->vfl_type = type; vdev->cdev = NULL; - if (vdev->v4l2_dev) + if (vdev->v4l2_dev && vdev->v4l2_dev->dev) vdev->parent = vdev->v4l2_dev->dev; /* Part 2: find a free minor, kernel number and device index. */ diff --git a/linux/drivers/media/video/v4l2-device.c b/linux/drivers/media/video/v4l2-device.c index 35e42e947..2cb81c210 100644 --- a/linux/drivers/media/video/v4l2-device.c +++ b/linux/drivers/media/video/v4l2-device.c @@ -50,19 +50,26 @@ int v4l2_device_register(struct device *dev, struct v4l2_device *v4l2_dev) } EXPORT_SYMBOL_GPL(v4l2_device_register); +void v4l2_device_disconnect(struct v4l2_device *v4l2_dev) +{ + if (v4l2_dev->dev) { + dev_set_drvdata(v4l2_dev->dev, NULL); + v4l2_dev->dev = NULL; + } +} +EXPORT_SYMBOL_GPL(v4l2_device_disconnect); + void v4l2_device_unregister(struct v4l2_device *v4l2_dev) { struct v4l2_subdev *sd, *next; if (v4l2_dev == NULL) return; - if (v4l2_dev->dev) - dev_set_drvdata(v4l2_dev->dev, NULL); + v4l2_device_disconnect(v4l2_dev); + /* Unregister subdevs */ list_for_each_entry_safe(sd, next, &v4l2_dev->subdevs, list) v4l2_device_unregister_subdev(sd); - - v4l2_dev->dev = NULL; } EXPORT_SYMBOL_GPL(v4l2_device_unregister); diff --git a/linux/drivers/media/video/v4l2-subdev.c b/linux/drivers/media/video/v4l2-subdev.c index 923ec8d01..dc881671d 100644 --- a/linux/drivers/media/video/v4l2-subdev.c +++ b/linux/drivers/media/video/v4l2-subdev.c @@ -98,6 +98,10 @@ int v4l2_subdev_command(struct v4l2_subdev *sd, unsigned cmd, void *arg) return v4l2_subdev_call(sd, video, g_vbi_data, arg); case VIDIOC_G_SLICED_VBI_CAP: return v4l2_subdev_call(sd, video, g_sliced_vbi_cap, arg); + case VIDIOC_ENUM_FMT: + return v4l2_subdev_call(sd, video, enum_fmt, arg); + case VIDIOC_TRY_FMT: + return v4l2_subdev_call(sd, video, try_fmt, arg); case VIDIOC_S_FMT: return v4l2_subdev_call(sd, video, s_fmt, arg); case VIDIOC_G_FMT: @@ -112,6 +116,10 @@ int v4l2_subdev_command(struct v4l2_subdev *sd, unsigned cmd, void *arg) return v4l2_subdev_call(sd, video, s_stream, 1); case VIDIOC_STREAMOFF: return v4l2_subdev_call(sd, video, s_stream, 0); + case VIDIOC_S_PARM: + return v4l2_subdev_call(sd, video, s_parm, arg); + case VIDIOC_G_PARM: + return v4l2_subdev_call(sd, video, g_parm, arg); default: return v4l2_subdev_call(sd, core, ioctl, cmd, arg); diff --git a/linux/drivers/media/video/w9968cf.c b/linux/drivers/media/video/w9968cf.c index 0478ee33e..cf8548a7f 100644 --- a/linux/drivers/media/video/w9968cf.c +++ b/linux/drivers/media/video/w9968cf.c @@ -3571,7 +3571,9 @@ static void w9968cf_usb_disconnect(struct usb_interface* intf) cam->disconnected = 1; - DBG(2, "Disconnecting %s...", symbolic(camlist, cam->id)) + DBG(2, "Disconnecting %s...", symbolic(camlist, cam->id)); + + v4l2_device_disconnect(&cam->v4l2_dev); wake_up_interruptible_all(&cam->open); diff --git a/linux/drivers/media/video/zoran/zoran_card.c b/linux/drivers/media/video/zoran/zoran_card.c index 4a76df3f8..b7dea2b8a 100644 --- a/linux/drivers/media/video/zoran/zoran_card.c +++ b/linux/drivers/media/video/zoran/zoran_card.c @@ -38,9 +38,7 @@ #include <linux/proc_fs.h> #include <linux/i2c.h> #include <linux/i2c-algo-bit.h> -#include "compat.h" #include <linux/videodev2.h> -#include <media/v4l2-common.h> #include <linux/spinlock.h> #include <linux/sem.h> #include <linux/kmod.h> @@ -49,8 +47,10 @@ #include <linux/pci.h> #include <linux/interrupt.h> #include <linux/mutex.h> - -#include <asm/io.h> +#include <linux/io.h> +#include <media/v4l2-common.h> +#include <media/bt819.h> +#include "compat.h" #include "videocodec.h" #include "zoran.h" @@ -1197,6 +1197,18 @@ zoran_setup_videocodec (struct zoran *zr, return m; } +static void zoran_subdev_notify(struct v4l2_subdev *sd, unsigned int cmd, void *arg) +{ + struct zoran *zr = to_zoran(sd->v4l2_dev); + + /* Bt819 needs to reset its FIFO buffer using #FRST pin and + LML33 card uses GPIO(7) for that. */ + if (cmd == BT819_FIFO_RESET_LOW) + GPIO(zr, 7, 0); + else if (cmd == BT819_FIFO_RESET_HIGH) + GPIO(zr, 7, 1); +} + /* * Scan for a Buz card (actually for the PCI controller ZR36057), * request the irq and map the io memory @@ -1227,6 +1239,7 @@ static int __devinit zoran_probe(struct pci_dev *pdev, ZORAN_NAME, __func__); return -ENOMEM; } + zr->v4l2_dev.notify = zoran_subdev_notify; if (v4l2_device_register(&pdev->dev, &zr->v4l2_dev)) goto zr_free_mem; zr->pci_dev = pdev; diff --git a/linux/drivers/media/video/zoran/zoran_device.c b/linux/drivers/media/video/zoran/zoran_device.c index 9d93dd8c0..54a04ea5c 100644 --- a/linux/drivers/media/video/zoran/zoran_device.c +++ b/linux/drivers/media/video/zoran/zoran_device.c @@ -1590,8 +1590,8 @@ zoran_init_hardware (struct zoran *zr) route.input = zr->card.input[zr->input].muxsel; decoder_call(zr, core, init, 0); - decoder_s_std(zr, zr->norm); - decoder_s_routing(zr, &route); + decoder_call(zr, tuner, s_std, zr->norm); + decoder_call(zr, video, s_routing, &route); encoder_call(zr, core, init, 0); encoder_call(zr, video, s_std_output, zr->norm); @@ -1656,35 +1656,3 @@ zr36057_init_vfe (struct zoran *zr) reg |= ZR36057_VDCR_Triton; btwrite(reg, ZR36057_VDCR); } - -/* - * Interface to decoder and encoder chips using i2c bus - */ - -int decoder_s_std(struct zoran *zr, v4l2_std_id std) -{ - int res; - - /* Bt819 needs to reset its FIFO buffer using #FRST pin and - LML33 card uses GPIO(7) for that. */ - if (zr->card.type == LML33) - GPIO(zr, 7, 0); - res = decoder_call(zr, tuner, s_std, std); - if (zr->card.type == LML33) - GPIO(zr, 7, 1); /* Pull #FRST high. */ - return res; -} - -int decoder_s_routing(struct zoran *zr, struct v4l2_routing *route) -{ - int res; - - /* Bt819 needs to reset its FIFO buffer using #FRST pin and - LML33 card uses GPIO(7) for that. */ - if (zr->card.type == LML33) - GPIO(zr, 7, 0); - res = decoder_call(zr, video, s_routing, route); - if (zr->card.type == LML33) - GPIO(zr, 7, 1); /* Pull #FRST high. */ - return res; -} diff --git a/linux/drivers/media/video/zoran/zoran_device.h b/linux/drivers/media/video/zoran/zoran_device.h index e0a4f0ff9..bf8c94d03 100644 --- a/linux/drivers/media/video/zoran/zoran_device.h +++ b/linux/drivers/media/video/zoran/zoran_device.h @@ -98,7 +98,4 @@ extern int pass_through; #define encoder_call(zr, o, f, args...) \ v4l2_subdev_call(zr->encoder, o, f, ##args) -int decoder_s_std(struct zoran *zr, v4l2_std_id std); -int decoder_s_routing(struct zoran *zr, struct v4l2_routing *route); - #endif /* __ZORAN_DEVICE_H__ */ diff --git a/linux/drivers/media/video/zoran/zoran_driver.c b/linux/drivers/media/video/zoran/zoran_driver.c index a194bf180..c702ea0fe 100644 --- a/linux/drivers/media/video/zoran/zoran_driver.c +++ b/linux/drivers/media/video/zoran/zoran_driver.c @@ -246,9 +246,9 @@ static int v4l_fbuffer_alloc(struct zoran_fh *fh) SetPageReserved(virt_to_page(mem + off)); dprintk(4, KERN_INFO - "%s: %s - V4L frame %d mem 0x%lx (bus: 0x%lx)\n", + "%s: %s - V4L frame %d mem 0x%lx (bus: 0x%llx)\n", ZR_DEVNAME(zr), __func__, i, (unsigned long) mem, - virt_to_bus(mem)); + (unsigned long long)virt_to_bus(mem)); } fh->buffers.allocated = 1; @@ -1457,7 +1457,7 @@ zoran_set_norm (struct zoran *zr, v4l2_std_id std = 0; decoder_call(zr, video, querystd, &std); - decoder_s_std(zr, std); + decoder_call(zr, tuner, s_std, std); /* let changes come into effect */ ssleep(2); @@ -1469,7 +1469,7 @@ zoran_set_norm (struct zoran *zr, "%s: %s - no norm detected\n", ZR_DEVNAME(zr), __func__); /* reset norm */ - decoder_s_std(zr, zr->norm); + decoder_call(zr, tuner, s_std, zr->norm); return -EIO; } @@ -1488,7 +1488,7 @@ zoran_set_norm (struct zoran *zr, if (on) zr36057_overlay(zr, 0); - decoder_s_std(zr, norm); + decoder_call(zr, tuner, s_std, norm); encoder_call(zr, video, s_std_output, norm); if (on) @@ -1530,7 +1530,7 @@ zoran_set_input (struct zoran *zr, route.input = zr->card.input[input].muxsel; zr->input = input; - decoder_s_routing(zr, &route); + decoder_call(zr, video, s_routing, &route); return 0; } @@ -1783,7 +1783,7 @@ jpgreqbuf_unlock_and_return: goto gstat_unlock_and_return; } - decoder_s_routing(zr, &route); + decoder_call(zr, video, s_routing, &route); /* sleep 1 second */ ssleep(1); @@ -1794,7 +1794,7 @@ jpgreqbuf_unlock_and_return: /* restore previous input and norm */ route.input = zr->card.input[zr->input].muxsel; - decoder_s_routing(zr, &route); + decoder_call(zr, video, s_routing, &route); gstat_unlock_and_return: mutex_unlock(&zr->resource_lock); diff --git a/linux/include/linux/i2c-id.h b/linux/include/linux/i2c-id.h index 51c7106cd..372ab89dc 100644 --- a/linux/include/linux/i2c-id.h +++ b/linux/include/linux/i2c-id.h @@ -71,6 +71,7 @@ #define I2C_DRIVERID_VP27SMPX 93 /* Panasonic VP27s tuner internal MPX */ #define I2C_DRIVERID_M52790 95 /* Mitsubishi M52790SP/FP AV switch */ #define I2C_DRIVERID_CS5345 96 /* cs5345 audio processor */ +#define I2C_DRIVERID_AU8522 97 /* Auvitek au8522 */ #define I2C_DRIVERID_OV7670 1048 /* Omnivision 7670 camera */ @@ -88,6 +89,7 @@ #define I2C_HW_B_CX23885 0x010022 /* conexant 23885 based tv cards (bus1) */ #define I2C_HW_B_AU0828 0x010023 /* auvitek au0828 usb bridge */ #define I2C_HW_B_CX231XX 0x010024 /* Conexant CX231XX USB based cards */ +#define I2C_HW_B_HDPVR 0x010025 /* Hauppauge HD PVR */ /* --- SGI adapters */ #define I2C_HW_SGI_VINO 0x160000 diff --git a/linux/include/linux/ivtv.h b/linux/include/linux/ivtv.h index f2720280b..062d20f74 100644 --- a/linux/include/linux/ivtv.h +++ b/linux/include/linux/ivtv.h @@ -60,10 +60,10 @@ struct ivtv_dma_frame { #define IVTV_IOC_DMA_FRAME _IOW ('V', BASE_VIDIOC_PRIVATE+0, struct ivtv_dma_frame) -/* These are the VBI types as they appear in the embedded VBI private packets. */ -#define IVTV_SLICED_TYPE_TELETEXT_B (1) -#define IVTV_SLICED_TYPE_CAPTION_525 (4) -#define IVTV_SLICED_TYPE_WSS_625 (5) -#define IVTV_SLICED_TYPE_VPS (7) +/* Deprecated defines: applications should use the defines from videodev2.h */ +#define IVTV_SLICED_TYPE_TELETEXT_B V4L2_MPEG_VBI_IVTV_TELETEXT_B +#define IVTV_SLICED_TYPE_CAPTION_525 V4L2_MPEG_VBI_IVTV_CAPTION_525 +#define IVTV_SLICED_TYPE_WSS_625 V4L2_MPEG_VBI_IVTV_WSS_625 +#define IVTV_SLICED_TYPE_VPS V4L2_MPEG_VBI_IVTV_VPS #endif /* _LINUX_IVTV_H */ diff --git a/linux/include/linux/mmc/sdio_ids.h b/linux/include/linux/mmc/sdio_ids.h new file mode 100644 index 000000000..3d7533d1e --- /dev/null +++ b/linux/include/linux/mmc/sdio_ids.h @@ -0,0 +1,37 @@ +/* + * SDIO Classes, Interface Types, Manufacturer IDs, etc. + */ + +#ifndef MMC_SDIO_IDS_H +#define MMC_SDIO_IDS_H + +/* + * Standard SDIO Function Interfaces + */ + +#define SDIO_CLASS_NONE 0x00 /* Not a SDIO standard interface */ +#define SDIO_CLASS_UART 0x01 /* standard UART interface */ +#define SDIO_CLASS_BT_A 0x02 /* Type-A BlueTooth std interface */ +#define SDIO_CLASS_BT_B 0x03 /* Type-B BlueTooth std interface */ +#define SDIO_CLASS_GPS 0x04 /* GPS standard interface */ +#define SDIO_CLASS_CAMERA 0x05 /* Camera standard interface */ +#define SDIO_CLASS_PHS 0x06 /* PHS standard interface */ +#define SDIO_CLASS_WLAN 0x07 /* WLAN interface */ +#define SDIO_CLASS_ATA 0x08 /* Embedded SDIO-ATA std interface */ + +/* + * Vendors and devices. Sort key: vendor first, device next. + */ + +#define SDIO_VENDOR_ID_MARVELL 0x02df +#define SDIO_VENDOR_ID_SIANO 0x039a + +#define SDIO_DEVICE_ID_MARVELL_LIBERTAS 0x9103 +#define SDIO_DEVICE_ID_SIANO_STELLAR 0x5347 +#define SDIO_DEVICE_ID_SIANO_NOVA_A0 0x1100 +#define SDIO_DEVICE_ID_SIANO_NOVA_B0 0x0201 +#define SDIO_DEVICE_ID_SIANO_NICE 0x0202 +#define SDIO_DEVICE_ID_SIANO_VEGA_A0 0x0300 +#define SDIO_DEVICE_ID_SIANO_VENICE 0x0301 + +#endif diff --git a/linux/include/linux/videodev2.h b/linux/include/linux/videodev2.h index 7a8eafd43..87590454f 100644 --- a/linux/include/linux/videodev2.h +++ b/linux/include/linux/videodev2.h @@ -345,6 +345,7 @@ struct v4l2_pix_format { #define V4L2_PIX_FMT_SPCA561 v4l2_fourcc('S', '5', '6', '1') /* compressed GBRG bayer */ #define V4L2_PIX_FMT_PAC207 v4l2_fourcc('P', '2', '0', '7') /* compressed BGGR bayer */ #define V4L2_PIX_FMT_MR97310A v4l2_fourcc('M', '3', '1', '0') /* compressed BGGR bayer */ +#define V4L2_PIX_FMT_SQ905C v4l2_fourcc('9', '0', '5', 'C') /* compressed RGGB bayer */ #define V4L2_PIX_FMT_PJPG v4l2_fourcc('P', 'J', 'P', 'G') /* Pixart 73xx JPEG */ #define V4L2_PIX_FMT_YVYU v4l2_fourcc('Y', 'V', 'Y', 'U') /* 16 YVU 4:2:2 */ @@ -1348,6 +1349,53 @@ struct v4l2_sliced_vbi_data { }; /* + * Sliced VBI data inserted into MPEG Streams + */ + +/* + * V4L2_MPEG_STREAM_VBI_FMT_IVTV: + * + * Structure of payload contained in an MPEG 2 Private Stream 1 PES Packet in an + * MPEG-2 Program Pack that contains V4L2_MPEG_STREAM_VBI_FMT_IVTV Sliced VBI + * data + * + * Note, the MPEG-2 Program Pack and Private Stream 1 PES packet header + * definitions are not included here. See the MPEG-2 specifications for details + * on these headers. + */ + +/* Line type IDs */ +#define V4L2_MPEG_VBI_IVTV_TELETEXT_B (1) +#define V4L2_MPEG_VBI_IVTV_CAPTION_525 (4) +#define V4L2_MPEG_VBI_IVTV_WSS_625 (5) +#define V4L2_MPEG_VBI_IVTV_VPS (7) + +struct v4l2_mpeg_vbi_itv0_line { + __u8 id; /* One of V4L2_MPEG_VBI_IVTV_* above */ + __u8 data[42]; /* Sliced VBI data for the line */ +} __attribute__ ((packed)); + +struct v4l2_mpeg_vbi_itv0 { + __le32 linemask[2]; /* Bitmasks of VBI service lines present */ + struct v4l2_mpeg_vbi_itv0_line line[35]; +} __attribute__ ((packed)); + +struct v4l2_mpeg_vbi_ITV0 { + struct v4l2_mpeg_vbi_itv0_line line[36]; +} __attribute__ ((packed)); + +#define V4L2_MPEG_VBI_IVTV_MAGIC0 "itv0" +#define V4L2_MPEG_VBI_IVTV_MAGIC1 "ITV0" + +struct v4l2_mpeg_vbi_fmt_ivtv { + __u8 magic[4]; + union { + struct v4l2_mpeg_vbi_itv0 itv0; + struct v4l2_mpeg_vbi_ITV0 ITV0; + }; +} __attribute__ ((packed)); + +/* * A G G R E G A T E S T R U C T U R E S */ diff --git a/linux/include/media/bt819.h b/linux/include/media/bt819.h new file mode 100644 index 000000000..38f666bde --- /dev/null +++ b/linux/include/media/bt819.h @@ -0,0 +1,33 @@ +/* + bt819.h - bt819 notifications + + Copyright (C) 2009 Hans Verkuil (hverkuil@xs4all.nl) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#ifndef _BT819_H_ +#define _BT819_H_ + +#include <linux/ioctl.h> + +/* v4l2_device notifications. */ + +/* Needed to reset the FIFO buffer when changing the input + or the video standard. */ +#define BT819_FIFO_RESET_LOW _IO('b', 0) +#define BT819_FIFO_RESET_HIGH _IO('b', 1) + +#endif diff --git a/linux/include/media/soc_camera.h b/linux/include/media/soc_camera.h index c63a3409f..37013688a 100644 --- a/linux/include/media/soc_camera.h +++ b/linux/include/media/soc_camera.h @@ -45,6 +45,7 @@ struct soc_camera_device { int num_formats; struct soc_camera_format_xlate *user_formats; int num_user_formats; + enum v4l2_field field; /* Preserve field over close() */ struct module *owner; void *host_priv; /* Per-device host private data */ /* soc_camera.c private count. Only accessed with .video_lock held */ @@ -74,7 +75,8 @@ struct soc_camera_host_ops { int (*resume)(struct soc_camera_device *); int (*get_formats)(struct soc_camera_device *, int, struct soc_camera_format_xlate *); - int (*set_fmt)(struct soc_camera_device *, __u32, struct v4l2_rect *); + int (*set_crop)(struct soc_camera_device *, struct v4l2_rect *); + int (*set_fmt)(struct soc_camera_device *, struct v4l2_format *); int (*try_fmt)(struct soc_camera_device *, struct v4l2_format *); void (*init_videobuf)(struct videobuf_queue *, struct soc_camera_device *); @@ -93,13 +95,18 @@ struct soc_camera_host_ops { struct soc_camera_link { /* Camera bus id, used to match a camera and a bus */ int bus_id; - /* GPIO number to switch between 8 and 10 bit modes */ - unsigned int gpio; /* Per camera SOCAM_SENSOR_* bus flags */ unsigned long flags; /* Optional callbacks to power on or off and reset the sensor */ int (*power)(struct device *, int); int (*reset)(struct device *); + /* + * some platforms may support different data widths than the sensors + * native ones due to different data line routing. Let the board code + * overwrite the width flags. + */ + int (*set_bus_param)(struct soc_camera_link *, unsigned long flags); + unsigned long (*query_bus_param)(struct soc_camera_link *); }; static inline struct soc_camera_device *to_soc_camera_dev(struct device *dev) @@ -159,7 +166,8 @@ struct soc_camera_ops { int (*release)(struct soc_camera_device *); int (*start_capture)(struct soc_camera_device *); int (*stop_capture)(struct soc_camera_device *); - int (*set_fmt)(struct soc_camera_device *, __u32, struct v4l2_rect *); + int (*set_crop)(struct soc_camera_device *, struct v4l2_rect *); + int (*set_fmt)(struct soc_camera_device *, struct v4l2_format *); int (*try_fmt)(struct soc_camera_device *, struct v4l2_format *); unsigned long (*query_bus_param)(struct soc_camera_device *); int (*set_bus_param)(struct soc_camera_device *, unsigned long); diff --git a/linux/include/media/v4l2-chip-ident.h b/linux/include/media/v4l2-chip-ident.h index 43684f105..1be461a29 100644 --- a/linux/include/media/v4l2-chip-ident.h +++ b/linux/include/media/v4l2-chip-ident.h @@ -70,6 +70,9 @@ enum { V4L2_IDENT_CX23416 = 416, V4L2_IDENT_CX23418 = 418, + /* module au0828 */ + V4L2_IDENT_AU0828 = 828, + /* module indycam: just ident 2000 */ V4L2_IDENT_INDYCAM = 2000, @@ -143,21 +146,12 @@ enum { /* module tda9840: just ident 9840 */ V4L2_IDENT_TDA9840 = 9840, + /* module cafe_ccic, just ident 8801 */ + V4L2_IDENT_CAFE = 8801, + /* module tw9910: just ident 9910 */ V4L2_IDENT_TW9910 = 9910, - /* module cs53132a: just ident 53132 */ - V4L2_IDENT_CS53l32A = 53132, - - /* module upd64031a: just ident 64031 */ - V4L2_IDENT_UPD64031A = 64031, - - /* module upd64083: just ident 64083 */ - V4L2_IDENT_UPD64083 = 64083, - - /* module m52790: just ident 52790 */ - V4L2_IDENT_M52790 = 52790, - /* module msp3400: reserved range 34000-34999 and 44000-44999 */ V4L2_IDENT_MSPX4XX = 34000, /* generic MSPX4XX identifier, only use internally (tveeprom.c). */ @@ -234,6 +228,18 @@ enum { V4L2_IDENT_MT9V022IX7ATC = 45010, /* No way to detect "normal" I77ATx */ V4L2_IDENT_MT9V022IX7ATM = 45015, /* and "lead free" IA7ATx chips */ V4L2_IDENT_MT9T031 = 45020, + + /* module cs53132a: just ident 53132 */ + V4L2_IDENT_CS53l32A = 53132, + + /* module upd64031a: just ident 64031 */ + V4L2_IDENT_UPD64031A = 64031, + + /* module upd64083: just ident 64083 */ + V4L2_IDENT_UPD64083 = 64083, + + /* module m52790: just ident 52790 */ + V4L2_IDENT_M52790 = 52790, }; #endif diff --git a/linux/include/media/v4l2-dev.h b/linux/include/media/v4l2-dev.h index 96b4ea2d9..978e26506 100644 --- a/linux/include/media/v4l2-dev.h +++ b/linux/include/media/v4l2-dev.h @@ -40,6 +40,8 @@ struct v4l2_file_operations { unsigned int (*poll) (struct file *, struct poll_table_struct *); long (*ioctl) (struct file *, unsigned int, unsigned long); long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long); + unsigned long (*get_unmapped_area) (struct file *, unsigned long, + unsigned long, unsigned long, unsigned long); int (*mmap) (struct file *, struct vm_area_struct *); int (*open) (struct file *); int (*release) (struct file *); diff --git a/linux/include/media/v4l2-device.h b/linux/include/media/v4l2-device.h index 5d7146dc2..0dd3e8e86 100644 --- a/linux/include/media/v4l2-device.h +++ b/linux/include/media/v4l2-device.h @@ -44,13 +44,20 @@ struct v4l2_device { spinlock_t lock; /* unique device name, by default the driver name + bus ID */ char name[V4L2_DEVICE_NAME_SIZE]; + /* notify callback called by some sub-devices. */ + void (*notify)(struct v4l2_subdev *sd, + unsigned int notification, void *arg); }; /* Initialize v4l2_dev and make dev->driver_data point to v4l2_dev. dev may be NULL in rare cases (ISA devices). In that case you must fill in the v4l2_dev->name field before calling this function. */ int __must_check v4l2_device_register(struct device *dev, struct v4l2_device *v4l2_dev); -/* Set v4l2_dev->dev->driver_data to NULL and unregister all sub-devices */ +/* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects. + Since the parent disappears this ensures that v4l2_dev doesn't have an + invalid parent pointer. */ +void v4l2_device_disconnect(struct v4l2_device *v4l2_dev); +/* Unregister all sub-devices and any other resources related to v4l2_dev. */ void v4l2_device_unregister(struct v4l2_device *v4l2_dev); /* Register a subdev with a v4l2 device. While registered the subdev module diff --git a/linux/include/media/v4l2-subdev.h b/linux/include/media/v4l2-subdev.h index 05b69652e..d7a72d2d1 100644 --- a/linux/include/media/v4l2-subdev.h +++ b/linux/include/media/v4l2-subdev.h @@ -118,8 +118,12 @@ struct v4l2_subdev_video_ops { int (*querystd)(struct v4l2_subdev *sd, v4l2_std_id *std); int (*g_input_status)(struct v4l2_subdev *sd, u32 *status); int (*s_stream)(struct v4l2_subdev *sd, int enable); - int (*s_fmt)(struct v4l2_subdev *sd, struct v4l2_format *fmt); + int (*enum_fmt)(struct v4l2_subdev *sd, struct v4l2_fmtdesc *fmtdesc); int (*g_fmt)(struct v4l2_subdev *sd, struct v4l2_format *fmt); + int (*try_fmt)(struct v4l2_subdev *sd, struct v4l2_format *fmt); + int (*s_fmt)(struct v4l2_subdev *sd, struct v4l2_format *fmt); + int (*g_parm)(struct v4l2_subdev *sd, struct v4l2_streamparm *param); + int (*s_parm)(struct v4l2_subdev *sd, struct v4l2_streamparm *param); }; struct v4l2_subdev_ops { @@ -191,4 +195,9 @@ static inline void v4l2_subdev_init(struct v4l2_subdev *sd, (!(sd) ? -ENODEV : (((sd) && (sd)->ops->o && (sd)->ops->o->f) ? \ (sd)->ops->o->f((sd) , ##args) : -ENOIOCTLCMD)) +/* Send a notification to v4l2_device. */ +#define v4l2_subdev_notify(sd, notification, arg) \ + ((!(sd) || !(sd)->v4l2_dev || !(sd)->v4l2_dev->notify) ? -ENODEV : \ + (sd)->v4l2_dev->notify((sd), (notification), (arg))) + #endif diff --git a/linux/linux/drivers/media/dvb/siano/smssdio.c b/linux/linux/drivers/media/dvb/siano/smssdio.c new file mode 100644 index 000000000..4f8fa59a9 --- /dev/null +++ b/linux/linux/drivers/media/dvb/siano/smssdio.c @@ -0,0 +1,354 @@ +/* + * smssdio.c - Siano 1xxx SDIO interface driver + * + * Copyright 2008 Pierre Ossman + * + * Based on code by Siano Mobile Silicon, Inc., + * Copyright (C) 2006-2008, Uri Shkolnik + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * + * This hardware is a bit odd in that all transfers should be done + * to/from the SMSSDIO_DATA register, yet the "increase address" bit + * always needs to be set. + * + * Also, buffers from the card are always aligned to 128 byte + * boundaries. + */ + +/* + * General cleanup notes: + * + * - only typedefs should be name *_t + * + * - use ERR_PTR and friends for smscore_register_device() + * + * - smscore_getbuffer should zero fields + * + * Fix stop command + */ + +#include <linux/moduleparam.h> +#include <linux/firmware.h> +#include <linux/delay.h> +#include <linux/mmc/card.h> +#include <linux/mmc/sdio_func.h> +#include <linux/mmc/sdio_ids.h> + +#include "smscoreapi.h" +#include "sms-cards.h" + +/* Registers */ + +#define SMSSDIO_DATA 0x00 +#define SMSSDIO_INT 0x04 + +static const struct sdio_device_id smssdio_ids[] = { + {SDIO_DEVICE(SDIO_VENDOR_ID_SIANO, SDIO_DEVICE_ID_SIANO_STELLAR), + .driver_data = SMS1XXX_BOARD_SIANO_STELLAR}, + {SDIO_DEVICE(SDIO_VENDOR_ID_SIANO, SDIO_DEVICE_ID_SIANO_NOVA_A0), + .driver_data = SMS1XXX_BOARD_SIANO_NOVA_A}, + {SDIO_DEVICE(SDIO_VENDOR_ID_SIANO, SDIO_DEVICE_ID_SIANO_NOVA_B0), + .driver_data = SMS1XXX_BOARD_SIANO_NOVA_B}, + {SDIO_DEVICE(SDIO_VENDOR_ID_SIANO, SDIO_DEVICE_ID_SIANO_VEGA_A0), + .driver_data = SMS1XXX_BOARD_SIANO_VEGA}, + {SDIO_DEVICE(SDIO_VENDOR_ID_SIANO, SDIO_DEVICE_ID_SIANO_VENICE), + .driver_data = SMS1XXX_BOARD_SIANO_VEGA}, + { /* end: all zeroes */ }, +}; + +MODULE_DEVICE_TABLE(sdio, smssdio_ids); + +struct smssdio_device { + struct sdio_func *func; + + struct smscore_device_t *coredev; + + struct smscore_buffer_t *split_cb; +}; + +/*******************************************************************/ +/* Siano core callbacks */ +/*******************************************************************/ + +static int smssdio_sendrequest(void *context, void *buffer, size_t size) +{ + int ret; + struct smssdio_device *smsdev; + + smsdev = context; + + sdio_claim_host(smsdev->func); + + while (size >= smsdev->func->cur_blksize) { + ret = sdio_write_blocks(smsdev->func, SMSSDIO_DATA, buffer, 1); + if (ret) + goto out; + + buffer += smsdev->func->cur_blksize; + size -= smsdev->func->cur_blksize; + } + + if (size) { + ret = sdio_write_bytes(smsdev->func, SMSSDIO_DATA, + buffer, size); + } + +out: + sdio_release_host(smsdev->func); + + return ret; +} + +/*******************************************************************/ +/* SDIO callbacks */ +/*******************************************************************/ + +static void smssdio_interrupt(struct sdio_func *func) +{ + int ret, isr; + + struct smssdio_device *smsdev; + struct smscore_buffer_t *cb; + struct SmsMsgHdr_ST *hdr; + size_t size; + + smsdev = sdio_get_drvdata(func); + + /* + * The interrupt register has no defined meaning. It is just + * a way of turning of the level triggered interrupt. + */ + isr = sdio_readb(func, SMSSDIO_INT, &ret); + if (ret) { + dev_err(&smsdev->func->dev, + "Unable to read interrupt register!\n"); + return; + } + + if (smsdev->split_cb == NULL) { + cb = smscore_getbuffer(smsdev->coredev); + if (!cb) { + dev_err(&smsdev->func->dev, + "Unable to allocate data buffer!\n"); + return; + } + + ret = sdio_read_blocks(smsdev->func, cb->p, SMSSDIO_DATA, 1); + if (ret) { + dev_err(&smsdev->func->dev, + "Error %d reading initial block!\n", ret); + return; + } + + hdr = cb->p; + + if (hdr->msgFlags & MSG_HDR_FLAG_SPLIT_MSG) { + smsdev->split_cb = cb; + return; + } + + size = hdr->msgLength - smsdev->func->cur_blksize; + } else { + cb = smsdev->split_cb; + hdr = cb->p; + + size = hdr->msgLength - sizeof(struct SmsMsgHdr_ST); + + smsdev->split_cb = NULL; + } + + if (hdr->msgLength > smsdev->func->cur_blksize) { + void *buffer; + + size = ALIGN(size, 128); + buffer = cb->p + hdr->msgLength; + + BUG_ON(smsdev->func->cur_blksize != 128); + + /* + * First attempt to transfer all of it in one go... + */ + ret = sdio_read_blocks(smsdev->func, buffer, + SMSSDIO_DATA, size / 128); + if (ret && ret != -EINVAL) { + smscore_putbuffer(smsdev->coredev, cb); + dev_err(&smsdev->func->dev, + "Error %d reading data from card!\n", ret); + return; + } + + /* + * ..then fall back to one block at a time if that is + * not possible... + * + * (we have to do this manually because of the + * problem with the "increase address" bit) + */ + if (ret == -EINVAL) { + while (size) { + ret = sdio_read_blocks(smsdev->func, + buffer, SMSSDIO_DATA, 1); + if (ret) { + smscore_putbuffer(smsdev->coredev, cb); + dev_err(&smsdev->func->dev, + "Error %d reading " + "data from card!\n", ret); + return; + } + + buffer += smsdev->func->cur_blksize; + if (size > smsdev->func->cur_blksize) + size -= smsdev->func->cur_blksize; + else + size = 0; + } + } + } + + cb->size = hdr->msgLength; + cb->offset = 0; + + smscore_onresponse(smsdev->coredev, cb); +} + +static int smssdio_probe(struct sdio_func *func, + const struct sdio_device_id *id) +{ + int ret; + + int board_id; + struct smssdio_device *smsdev; + struct smsdevice_params_t params; + + board_id = id->driver_data; + + smsdev = kzalloc(sizeof(struct smssdio_device), GFP_KERNEL); + if (!smsdev) + return -ENOMEM; + + smsdev->func = func; + + memset(¶ms, 0, sizeof(struct smsdevice_params_t)); + + params.device = &func->dev; + params.buffer_size = 0x5000; /* ?? */ + params.num_buffers = 22; /* ?? */ + params.context = smsdev; + + snprintf(params.devpath, sizeof(params.devpath), + "sdio\\%s", sdio_func_id(func)); + + params.sendrequest_handler = smssdio_sendrequest; + + params.device_type = sms_get_board(board_id)->type; + + if (params.device_type != SMS_STELLAR) + params.flags |= SMS_DEVICE_FAMILY2; + else { + /* + * FIXME: Stellar needs special handling... + */ + ret = -ENODEV; + goto free; + } + + ret = smscore_register_device(¶ms, &smsdev->coredev); + if (ret < 0) + goto free; + + smscore_set_board_id(smsdev->coredev, board_id); + + sdio_claim_host(func); + + ret = sdio_enable_func(func); + if (ret) + goto release; + + ret = sdio_set_block_size(func, 128); + if (ret) + goto disable; + + ret = sdio_claim_irq(func, smssdio_interrupt); + if (ret) + goto disable; + + sdio_set_drvdata(func, smsdev); + + sdio_release_host(func); + + ret = smscore_start_device(smsdev->coredev); + if (ret < 0) + goto reclaim; + + return 0; + +reclaim: + sdio_claim_host(func); + sdio_release_irq(func); +disable: + sdio_disable_func(func); +release: + sdio_release_host(func); + smscore_unregister_device(smsdev->coredev); +free: + kfree(smsdev); + + return ret; +} + +static void smssdio_remove(struct sdio_func *func) +{ + struct smssdio_device *smsdev; + + smsdev = sdio_get_drvdata(func); + + /* FIXME: racy! */ + if (smsdev->split_cb) + smscore_putbuffer(smsdev->coredev, smsdev->split_cb); + + smscore_unregister_device(smsdev->coredev); + + sdio_claim_host(func); + sdio_release_irq(func); + sdio_disable_func(func); + sdio_release_host(func); + + kfree(smsdev); +} + +static struct sdio_driver smssdio_driver = { + .name = "smssdio", + .id_table = smssdio_ids, + .probe = smssdio_probe, + .remove = smssdio_remove, +}; + +/*******************************************************************/ +/* Module functions */ +/*******************************************************************/ + +int smssdio_register(void) +{ + int ret = 0; + + printk(KERN_INFO "smssdio: Siano SMS1xxx SDIO driver\n"); + printk(KERN_INFO "smssdio: Copyright Pierre Ossman\n"); + + ret = sdio_register_driver(&smssdio_driver); + + return ret; +} + +void smssdio_unregister(void) +{ + sdio_unregister_driver(&smssdio_driver); +} + +MODULE_DESCRIPTION("Siano SMS1xxx SDIO driver"); +MODULE_AUTHOR("Pierre Ossman"); +MODULE_LICENSE("GPL"); diff --git a/mailimport b/mailimport index 8ed624179..0050a1ded 100755 --- a/mailimport +++ b/mailimport @@ -120,7 +120,7 @@ apply_patch () { patch -s -t -p1 -l -N -d $pdir -i $next if [ "$?" != "0" ]; then echo "*** ERROR at: patch -s -t -p1 -l -N -d $pdir -i $next" - exit + exit -1 fi make cardlist make whitespace @@ -130,28 +130,36 @@ apply_patch () { hg addremove `diffstat -p1 -l $next` if [ "$?" != "0" ]; then echo "*** ERROR at hg addremove" - exit + echo hg addremove `diffstat -p1 -l $next` + patch -s -t -p1 -l -R -d $pdir -i $next + exit -1 fi # Commit the changed files CARDLIST="`hg status -n -m|grep CARDLIST.`" FILES="" + for i in $CARDLIST; do + FILES="$FILES $cur/$i" + done for i in `diffstat -p1 -l $next`; do FILES="$FILES `pwd`/$i" done if [ "$FILES" == "" ]; then echo "*** ERROR nothing to commit" + patch -s -t -p1 -l -R -d $pdir -i $next cd $cur - exit + exit -1 fi - hg commit -d "$date" -u "$committer" -m "`cat $TMP2|grep -v "^#"`" $CARDLIST $FILES + hg commit -d "$date" -u "$committer" -m "`cat $TMP2|grep -v "^#"`" $FILES if [ "$?" != "0" ]; then echo "*** ERROR at hg commit" + echo hg commit -d \"$date\" -u \"$committer\" -m "<msg>" $FILES + patch -s -t -p1 -l -R -d $pdir -i $next cd $cur - exit + exit -1 fi cd $cur fi @@ -250,7 +258,7 @@ DIR="$TMPDIR/mailimport$$" mkdir $DIR if [ "$?" != "0" ]; then echo "*** Error at mkdir $DIR" - exit; + exit -1; fi trap "rm -rf $DIR" EXIT diff --git a/v4l/API/V4L2_API.html b/v4l/API/V4L2_API.html deleted file mode 100644 index f1ef6aed3..000000000 --- a/v4l/API/V4L2_API.html +++ /dev/null @@ -1,39683 +0,0 @@ -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> -<HTML -><HEAD -><TITLE ->Video for Linux Two API Specification</TITLE -><META -NAME="GENERATOR" -CONTENT="Modular DocBook HTML Stylesheet Version 1.7"></HEAD -><BODY -CLASS="BOOK" -BGCOLOR="#FFFFFF" -TEXT="#000000" -LINK="#0000FF" -VLINK="#840084" -ALINK="#0000FF" -><DIV -CLASS="BOOK" -><A -NAME="INDEX" -></A -><DIV -CLASS="TITLEPAGE" -><H1 -CLASS="TITLE" -><A -NAME="AEN2" ->Video for Linux Two API Specification</A -></H1 -><H2 -CLASS="SUBTITLE" ->Draft 0.8</H2 -><H3 -CLASS="AUTHOR" -><A -NAME="AEN6" -></A ->Michael H Schimek</H3 -><DIV -CLASS="AFFILIATION" -><DIV -CLASS="ADDRESS" -><P -CLASS="ADDRESS" -> <CODE -CLASS="EMAIL" -><<A -HREF="mailto:mschimek@gmx.at" ->mschimek@gmx.at</A ->></CODE -><br> - </P -></DIV -></DIV -><H3 -CLASS="AUTHOR" -><A -NAME="AEN13" -></A ->Bill Dirks</H3 -><P -CLASS="COPYRIGHT" ->Copyright © 1999, 2000, 2001, 2002, 2003, 2004 Bill Dirks, Michael H. Schimek</P -><DIV -CLASS="LEGALNOTICE" -><P -></P -><A -NAME="AEN25" -></A -><P ->This document is copyrighted © 1999-2004 by Bill -Dirks and Michael H. Schimek.</P -><P ->Permission is granted to copy, distribute and/or modify -this document under the terms of the GNU Free Documentation License, -Version 1.1 or any later version published by the Free Software -Foundation; with no Invariant Sections, with no Front-Cover Texts, and -with no Back-Cover Texts. A copy of the license is included in the -appendix entitled "GNU Free Documentation License".</P -><P ->Programming examples can be used without -restriction.</P -><P -></P -></DIV -><HR></DIV -><DIV -CLASS="TOC" -><DL -><DT -><B ->Table of Contents</B -></DT -><DT -><A -HREF="#AEN71" ->Introduction</A -></DT -><DT ->1. <A -HREF="#COMMON" ->Common API Elements</A -></DT -><DD -><DL -><DT ->1.1. <A -HREF="#OPEN" ->Opening and Closing Devices</A -></DT -><DD -><DL -><DT ->1.1.1. <A -HREF="#AEN100" ->Device Naming</A -></DT -><DT ->1.1.2. <A -HREF="#RELATED" ->Related Devices</A -></DT -><DT ->1.1.3. <A -HREF="#AEN153" ->Multiple Opens</A -></DT -><DT ->1.1.4. <A -HREF="#AEN170" ->Shared Data Streams</A -></DT -><DT ->1.1.5. <A -HREF="#AEN173" ->Functions</A -></DT -></DL -></DD -><DT ->1.2. <A -HREF="#QUERYCAP" ->Querying Capabilities</A -></DT -><DT ->1.3. <A -HREF="#APP-PRI" ->Application Priority</A -></DT -><DT ->1.4. <A -HREF="#VIDEO" ->Video Inputs and Outputs</A -></DT -><DT ->1.5. <A -HREF="#AUDIO" ->Audio Inputs and Outputs</A -></DT -><DT ->1.6. <A -HREF="#TUNER" ->Tuners and Modulators</A -></DT -><DD -><DL -><DT ->1.6.1. <A -HREF="#AEN296" ->Tuners</A -></DT -><DT ->1.6.2. <A -HREF="#AEN318" ->Modulators</A -></DT -><DT ->1.6.3. <A -HREF="#AEN337" ->Radio Frequency</A -></DT -><DT ->1.6.4. <A -HREF="#AEN345" ->Satellite Receivers</A -></DT -></DL -></DD -><DT ->1.7. <A -HREF="#STANDARD" ->Video Standards</A -></DT -><DT ->1.8. <A -HREF="#CONTROL" ->Controls</A -></DT -><DT ->1.9. <A -HREF="#FORMAT" ->Data Formats</A -></DT -><DD -><DL -><DT ->1.9.1. <A -HREF="#AEN656" ->Data Format Negotiation</A -></DT -><DT ->1.9.2. <A -HREF="#AEN689" ->Image Format Enumeration</A -></DT -></DL -></DD -><DT ->1.10. <A -HREF="#CROP" ->Cropping and Scaling</A -></DT -><DT ->1.11. <A -HREF="#STREAMING-PAR" ->Streaming Parameters</A -></DT -></DL -></DD -><DT ->2. <A -HREF="#PIXFMT" ->Image Formats</A -></DT -><DD -><DL -><DT ->2.1. <A -HREF="#AEN880" ->Standard Image Formats</A -></DT -><DT ->2.2. <A -HREF="#COLORSPACES" ->Colorspaces</A -></DT -><DT ->2.3. <A -HREF="#PIXFMT-RGB" ->RGB Formats</A -></DT -><DT ->2.4. <A -HREF="#YUV-FORMATS" ->YUV Formats</A -></DT -><DD -><DL -><DT -><A -HREF="#PIXFMT-GREY" -><CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_GREY</CODE -></A -> -- Grey-scale image.</DT -><DT -><A -HREF="#PIXFMT-YUYV" -><CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_YUYV</CODE -></A -> -- Packed format with ½ horizontal chroma -resolution, also known as YUV 4:2:2.</DT -><DT -><A -HREF="#PIXFMT-UYVY" -><CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_UYVY</CODE -></A -> -- Variation of -<CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_YUYV</CODE -> with different order of samples -in memory.</DT -><DT -><A -HREF="#PIXFMT-Y41P" -><CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_Y41P</CODE -></A -> -- Packed format with ¼ horizontal chroma -resolution, also known as YUV 4:1:1.</DT -><DT -><A -HREF="#PIXFMT-YVU420" -><CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_YVU420</CODE ->, -<CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_YUV420</CODE -></A -> -- Planar formats with ½ horizontal and -vertical chroma resolution, also known as YUV 4:2:0.</DT -><DT -><A -HREF="#PIXFMT-YVU410" -><CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_YVU410</CODE ->, -<CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_YUV410</CODE -></A -> -- Planar formats with ¼ horizontal and -vertical chroma resolution, also known as YUV 4:1:0.</DT -><DT -><A -HREF="#PIXFMT-YUV422P" -><CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_YUV422P</CODE -></A -> -- Format with ½ horizontal chroma resolution, -also known as YUV 4:2:2. Planar layout as opposed to -<CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_YUYV</CODE ->.</DT -><DT -><A -HREF="#PIXFMT-YUV411P" -><CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_YUV411P</CODE -></A -> -- Format with ¼ horizontal chroma resolution, -also known as YUV 4:1:1. Planar layout as opposed to -<CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_Y41P</CODE ->.</DT -><DT -><A -HREF="#AEN3002" -><CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_NV12</CODE ->, -<CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_NV21</CODE -></A -> -- Formats with ½ horizontal and vertical -chroma resolution, also known as YUV 4:2:0. One luminance and one -chrominance plane with alternating chroma samples as opposed to -<CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_YVU420</CODE ->.</DT -></DL -></DD -><DT ->2.5. <A -HREF="#AEN3167" ->Compressed Formats</A -></DT -><DT ->2.6. <A -HREF="#PIXFMT-RESERVED" ->Reserved Format Identifiers</A -></DT -></DL -></DD -><DT ->3. <A -HREF="#IO" ->Input/Output</A -></DT -><DD -><DL -><DT ->3.1. <A -HREF="#RW" ->Read/Write</A -></DT -><DT ->3.2. <A -HREF="#MMAP" ->Streaming I/O (Memory Mapping)</A -></DT -><DT ->3.3. <A -HREF="#USERP" ->Streaming I/O (User Pointers)</A -></DT -><DT ->3.4. <A -HREF="#ASYNC" ->Asynchronous I/O</A -></DT -><DT ->3.5. <A -HREF="#BUFFER" ->Buffers</A -></DT -><DD -><DL -><DT ->3.5.1. <A -HREF="#AEN3738" ->Timecodes</A -></DT -></DL -></DD -><DT ->3.6. <A -HREF="#FIELD-ORDER" ->Field Order</A -></DT -></DL -></DD -><DT ->4. <A -HREF="#DEVICES" ->Device Types</A -></DT -><DD -><DL -><DT ->4.1. <A -HREF="#CAPTURE" ->Video Capture Interface</A -></DT -><DD -><DL -><DT ->4.1.1. <A -HREF="#AEN3960" ->Querying Capabilities</A -></DT -><DT ->4.1.2. <A -HREF="#AEN3972" ->Supplemental Functions</A -></DT -><DT ->4.1.3. <A -HREF="#AEN3982" ->Image Format Negotiation</A -></DT -><DT ->4.1.4. <A -HREF="#AEN4024" ->Reading Images</A -></DT -></DL -></DD -><DT ->4.2. <A -HREF="#OVERLAY" ->Video Overlay Interface</A -></DT -><DD -><DL -><DT ->4.2.1. <A -HREF="#AEN4048" ->Querying Capabilities</A -></DT -><DT ->4.2.2. <A -HREF="#AEN4056" ->Supplemental Functions</A -></DT -><DT ->4.2.3. <A -HREF="#AEN4066" ->Setup</A -></DT -><DT ->4.2.4. <A -HREF="#AEN4092" ->Overlay Window</A -></DT -><DT ->4.2.5. <A -HREF="#AEN4266" ->Enabling Overlay</A -></DT -></DL -></DD -><DT ->4.3. <A -HREF="#OUTPUT" ->Video Output Interface</A -></DT -><DD -><DL -><DT ->4.3.1. <A -HREF="#AEN4279" ->Querying Capabilities</A -></DT -><DT ->4.3.2. <A -HREF="#AEN4289" ->Supplemental Functions</A -></DT -><DT ->4.3.3. <A -HREF="#AEN4299" ->Image Format Negotiation</A -></DT -><DT ->4.3.4. <A -HREF="#AEN4341" ->Writing Images</A -></DT -></DL -></DD -><DT ->4.4. <A -HREF="#CODEC" ->Codec Interface</A -></DT -><DT ->4.5. <A -HREF="#EFFECT" ->Effect Devices Interface</A -></DT -><DT ->4.6. <A -HREF="#RAW-VBI" ->Raw VBI Data Interface</A -></DT -><DD -><DL -><DT ->4.6.1. <A -HREF="#AEN4383" ->Querying Capabilities</A -></DT -><DT ->4.6.2. <A -HREF="#AEN4392" ->Supplemental Functions</A -></DT -><DT ->4.6.3. <A -HREF="#AEN4399" ->Raw VBI Format Negotiation</A -></DT -><DT ->4.6.4. <A -HREF="#AEN4571" ->Reading and writing VBI images</A -></DT -></DL -></DD -><DT ->4.7. <A -HREF="#SLICED" ->Sliced VBI Data Interface</A -></DT -><DD -><DL -><DT ->4.7.1. <A -HREF="#AEN4599" ->Querying Capabilities</A -></DT -><DT ->4.7.2. <A -HREF="#AEN4608" ->Supplemental Functions</A -></DT -><DT ->4.7.3. <A -HREF="#AEN4615" ->Sliced VBI Format Negotiation</A -></DT -><DT ->4.7.4. <A -HREF="#AEN4760" ->Reading and writing sliced VBI data</A -></DT -></DL -></DD -><DT ->4.8. <A -HREF="#TTX" ->Teletext Interface</A -></DT -><DT ->4.9. <A -HREF="#RADIO" ->Radio Interface</A -></DT -><DD -><DL -><DT ->4.9.1. <A -HREF="#AEN4799" ->Querying Capabilities</A -></DT -><DT ->4.9.2. <A -HREF="#AEN4808" ->Supplemental Functions</A -></DT -><DT ->4.9.3. <A -HREF="#AEN4814" ->Programming</A -></DT -></DL -></DD -><DT ->4.10. <A -HREF="#RDS" ->RDS Interface</A -></DT -></DL -></DD -><DT ->I. <A -HREF="#USER-FUNC" ->Function Reference</A -></DT -><DD -><DL -><DT -><A -HREF="#FUNC-CLOSE" ->close</A -> -- Close a V4L2 device</DT -><DT -><A -HREF="#FUNC-IOCTL" ->ioctl</A -> -- Program a V4L2 device</DT -><DT -><A -HREF="#VIDIOC-CROPCAP" ->ioctl VIDIOC_CROPCAP</A -> -- Information about the video cropping and scaling abilities.</DT -><DT -><A -HREF="#VIDIOC-ENUMAUDIO" ->ioctl VIDIOC_ENUMAUDIO</A -> -- Enumerate audio inputs</DT -><DT -><A -HREF="#VIDIOC-ENUMAUDIOOUT" ->ioctl VIDIOC_ENUMAUDOUT</A -> -- Enumerate audio outputs</DT -><DT -><A -HREF="#VIDIOC-ENUM-FMT" ->ioctl VIDIOC_ENUM_FMT</A -> -- Enumerate image formats</DT -><DT -><A -HREF="#VIDIOC-ENUMINPUT" ->ioctl VIDIOC_ENUMINPUT</A -> -- Enumerate video inputs</DT -><DT -><A -HREF="#VIDIOC-ENUMOUTPUT" ->ioctl VIDIOC_ENUMOUTPUT</A -> -- Enumerate video outputs</DT -><DT -><A -HREF="#VIDIOC-ENUMSTD" ->ioctl VIDIOC_ENUMSTD</A -> -- Enumerate supported video standards</DT -><DT -><A -HREF="#VIDIOC-G-AUDIO" ->ioctl VIDIOC_G_AUDIO, VIDIOC_S_AUDIO</A -> -- Query or select the current audio input and its -attributes</DT -><DT -><A -HREF="#VIDIOC-G-AUDIOOUT" ->ioctl VIDIOC_G_AUDOUT, VIDIOC_S_AUDOUT</A -> -- Query or select the current audio output</DT -><DT -><A -HREF="#VIDIOC-G-COMP" ->ioctl VIDIOC_G_COMP, VIDIOC_S_COMP</A -> -- Get or set compression parameters</DT -><DT -><A -HREF="#VIDIOC-G-CROP" ->ioctl VIDIOC_G_CROP, VIDIOC_S_CROP</A -> -- Get or set the current cropping rectangle</DT -><DT -><A -HREF="#VIDIOC-G-CTRL" ->ioctl VIDIOC_G_CTRL, VIDIOC_S_CTRL</A -> -- Get or set the value of a control</DT -><DT -><A -HREF="#VIDIOC-G-FBUF" ->ioctl VIDIOC_G_FBUF, VIDIOC_S_FBUF</A -> -- Get or set frame buffer overlay parameters.</DT -><DT -><A -HREF="#VIDIOC-G-FMT" ->ioctl VIDIOC_G_FMT, VIDIOC_S_FMT, VIDIOC_TRY_FMT</A -> -- Get or set the data format, try a format.</DT -><DT -><A -HREF="#VIDIOC-G-FREQUENCY" ->ioctl VIDIOC_G_FREQUENCY, VIDIOC_S_FREQUENCY</A -> -- Get or set tuner or modulator radio -frequency</DT -><DT -><A -HREF="#VIDIOC-G-INPUT" ->ioctl VIDIOC_G_INPUT, VIDIOC_S_INPUT</A -> -- Query or select the current video input</DT -><DT -><A -HREF="#VIDIOC-G-JPEGCOMP" ->ioctl VIDIOC_G_JPEGCOMP, VIDIOC_S_JPEGCOMP</A -> -- </DT -><DT -><A -HREF="#VIDIOC-G-MODULATOR" ->ioctl VIDIOC_G_MODULATOR, VIDIOC_S_MODULATOR</A -> -- Get or set modulator attributes</DT -><DT -><A -HREF="#VIDIOC-G-OUTPUT" ->ioctl VIDIOC_G_OUTPUT, VIDIOC_S_OUTPUT</A -> -- Query or select the current video output</DT -><DT -><A -HREF="#VIDIOC-G-PARM" ->ioctl VIDIOC_G_PARM, VIDIOC_S_PARM</A -> -- Get or set streaming parameters</DT -><DT -><A -HREF="#VIDIOC-G-PRIORITY" ->ioctl VIDIOC_G_PRIORITY, VIDIOC_S_PRIORITY</A -> -- Query or request the access priority associated with a -file descriptor</DT -><DT -><A -HREF="#VIDIOC-G-STD" ->ioctl VIDIOC_G_STD, VIDIOC_S_STD</A -> -- Query or select the video standard of the current input</DT -><DT -><A -HREF="#VIDIOC-G-TUNER" ->ioctl VIDIOC_G_TUNER, VIDIOC_S_TUNER</A -> -- Get or set tuner attributes</DT -><DT -><A -HREF="#VIDIOC-OVERLAY" ->ioctl VIDIOC_OVERLAY</A -> -- Start or stop video overlay</DT -><DT -><A -HREF="#VIDIOC-QBUF" ->ioctl VIDIOC_QBUF, VIDIOC_DQBUF</A -> -- Exchange a buffer with the driver</DT -><DT -><A -HREF="#VIDIOC-QUERYBUF" ->ioctl VIDIOC_QUERYBUF</A -> -- Query the status of a buffer</DT -><DT -><A -HREF="#VIDIOC-QUERYCAP" ->ioctl VIDIOC_QUERYCAP</A -> -- Query device capabilities</DT -><DT -><A -HREF="#VIDIOC-QUERYCTRL" ->ioctl VIDIOC_QUERYCTRL, VIDIOC_QUERYMENU</A -> -- Enumerate controls and menu control items</DT -><DT -><A -HREF="#VIDIOC-QUERYSTD" ->ioctl VIDIOC_QUERYSTD</A -> -- Sense the video standard received by the current input</DT -><DT -><A -HREF="#VIDIOC-REQBUFS" ->ioctl VIDIOC_REQBUFS</A -> -- Initiate Memory Mapping or User Pointer I/O</DT -><DT -><A -HREF="#VIDIOC-STREAMON" ->ioctl VIDIOC_STREAMON, VIDIOC_STREAMOFF</A -> -- Start or stop streaming I/O.</DT -><DT -><A -HREF="#FUNC-MMAP" ->mmap</A -> -- Map device memory into application address space</DT -><DT -><A -HREF="#FUNC-MUNMAP" ->munmap</A -> -- Unmap device memory</DT -><DT -><A -HREF="#FUNC-OPEN" ->open</A -> -- Open a V4L2 device</DT -><DT -><A -HREF="#FUNC-POLL" ->poll</A -> -- Wait for some event on a file descriptor</DT -><DT -><A -HREF="#FUNC-READ" ->read</A -> -- Read from a V4L2 device</DT -><DT -><A -HREF="#FUNC-SELECT" ->select</A -> -- Synchronous I/O multiplexing</DT -><DT -><A -HREF="#FUNC-WRITE" ->write</A -> -- Write to a V4L2 device</DT -></DL -></DD -><DT ->5. <A -HREF="#DRIVER" ->Driver Interface</A -></DT -><DD -><DL -><DT ->5.1. <A -HREF="#FOO" ->to do</A -></DT -><DD -><DL -><DT ->5.1.1. <A -HREF="#AEN9774" ->to do</A -></DT -></DL -></DD -></DL -></DD -><DT ->6. <A -HREF="#COMPAT" ->History</A -></DT -><DD -><DL -><DT ->6.1. <A -HREF="#DIFF-V4L" ->Differences between V4L and V4L2</A -></DT -><DD -><DL -><DT ->6.1.1. <A -HREF="#AEN9783" ->Opening and Closing Devices</A -></DT -><DT ->6.1.2. <A -HREF="#AEN9847" ->Querying Capabilities</A -></DT -><DT ->6.1.3. <A -HREF="#AEN9977" ->Video Sources</A -></DT -><DT ->6.1.4. <A -HREF="#AEN10033" ->Tuning</A -></DT -><DT ->6.1.5. <A -HREF="#V4L-IMAGE-PROPERTIES" ->Image Properties</A -></DT -><DT ->6.1.6. <A -HREF="#AEN10276" ->Audio</A -></DT -><DT ->6.1.7. <A -HREF="#AEN10361" ->Frame Buffer Overlay</A -></DT -><DT ->6.1.8. <A -HREF="#AEN10425" ->Cropping</A -></DT -><DT ->6.1.9. <A -HREF="#AEN10458" ->Reading Images, Memory Mapping</A -></DT -><DT ->6.1.10. <A -HREF="#AEN10541" ->Reading Raw VBI Data</A -></DT -><DT ->6.1.11. <A -HREF="#AEN10594" ->Miscellaneous</A -></DT -></DL -></DD -><DT ->6.2. <A -HREF="#HIST-V4L2" ->History of the V4L2 API</A -></DT -><DD -><DL -><DT ->6.2.1. <A -HREF="#AEN10604" ->Early Versions</A -></DT -><DT ->6.2.2. <A -HREF="#AEN10618" ->V4L2 Version 0.16 1999-01-31</A -></DT -><DT ->6.2.3. <A -HREF="#AEN10621" ->V4L2 Version 0.18 1999-03-16</A -></DT -><DT ->6.2.4. <A -HREF="#AEN10624" ->V4L2 Version 0.19 1999-06-05</A -></DT -><DT ->6.2.5. <A -HREF="#AEN10633" ->V4L2 Version 0.20 1999-09-10</A -></DT -><DT ->6.2.6. <A -HREF="#AEN10672" ->V4L2 Version 0.20 incremental changes</A -></DT -><DT ->6.2.7. <A -HREF="#AEN10694" ->V4L2 Version 0.20 2000-11-23</A -></DT -><DT ->6.2.8. <A -HREF="#AEN10709" ->V4L2 Version 0.20 2002-07-25</A -></DT -><DT ->6.2.9. <A -HREF="#AEN10712" ->V4L2 in Linux 2.5.46, 2002-10</A -></DT -><DT ->6.2.10. <A -HREF="#AEN11094" ->V4L2 2003-06-19</A -></DT -><DT ->6.2.11. <A -HREF="#AEN11136" ->V4L2 2003-11-05</A -></DT -><DT ->6.2.12. <A -HREF="#AEN11178" ->V4L2 in Linux 2.6.6, 2004-05-09</A -></DT -><DT ->6.2.13. <A -HREF="#AEN11186" ->V4L2 in Linux 2.6.8</A -></DT -><DT ->6.2.14. <A -HREF="#AEN11196" ->V4L2 spec erratum 2004-08-01</A -></DT -></DL -></DD -><DT ->6.3. <A -HREF="#OTHER" ->Relation of V4L2 to other Linux multimedia APIs</A -></DT -><DD -><DL -><DT ->6.3.1. <A -HREF="#XVIDEO" ->X Video Extension</A -></DT -><DT ->6.3.2. <A -HREF="#AEN11233" ->Digital Video</A -></DT -><DT ->6.3.3. <A -HREF="#AEN11237" ->Audio Interfaces</A -></DT -></DL -></DD -></DL -></DD -><DT ->A. <A -HREF="#VIDEODEV" ->Video For Linux Two Header File</A -></DT -><DT ->B. <A -HREF="#CAPTURE-EXAMPLE" ->Video Capture Example</A -></DT -><DT ->C. <A -HREF="#FDL" ->GNU Free Documentation License</A -></DT -><DD -><DL -><DT ->C.1. <A -HREF="#FDL-PREAMBLE" ->0. PREAMBLE</A -></DT -><DT ->C.2. <A -HREF="#FDL-SECTION1" ->1. APPLICABILITY AND DEFINITIONS</A -></DT -><DT ->C.3. <A -HREF="#FDL-SECTION2" ->2. VERBATIM COPYING</A -></DT -><DT ->C.4. <A -HREF="#FDL-SECTION3" ->3. COPYING IN QUANTITY</A -></DT -><DT ->C.5. <A -HREF="#FDL-SECTION4" ->4. MODIFICATIONS</A -></DT -><DT ->C.6. <A -HREF="#FDL-SECTION5" ->5. COMBINING DOCUMENTS</A -></DT -><DT ->C.7. <A -HREF="#FDL-SECTION6" ->6. COLLECTIONS OF DOCUMENTS</A -></DT -><DT ->C.8. <A -HREF="#FDL-SECTION7" ->7. AGGREGATION WITH INDEPENDENT WORKS</A -></DT -><DT ->C.9. <A -HREF="#FDL-SECTION8" ->8. TRANSLATION</A -></DT -><DT ->C.10. <A -HREF="#FDL-SECTION9" ->9. TERMINATION</A -></DT -><DT ->C.11. <A -HREF="#FDL-SECTION10" ->10. FUTURE REVISIONS OF THIS LICENSE</A -></DT -><DT ->C.12. <A -HREF="#FDL-USING" ->Addendum</A -></DT -></DL -></DD -><DT -><A -HREF="#AEN11623" ->Bibliography</A -></DT -></DL -></DIV -><DIV -CLASS="LOT" -><DL -CLASS="LOT" -><DT -><B ->List of Tables</B -></DT -><DT ->1-1. <A -HREF="#CONTROL-ID" ->Control IDs</A -></DT -><DT ->2-1. <A -HREF="#V4L2-PIX-FORMAT" ->struct <CODE -CLASS="STRUCTNAME" ->v4l2_pix_format</CODE -></A -></DT -><DT ->2-2. <A -HREF="#V4L2-COLORSPACE" ->enum v4l2_colorspace</A -></DT -><DT ->2-3. <A -HREF="#RGB-FORMATS" ->Packed RGB Image Formats</A -></DT -><DT ->2-4. <A -HREF="#RESERVED-FORMATS" ->Reserved Image Formats</A -></DT -><DT ->3-1. <A -HREF="#V4L2-BUFFER" ->struct <CODE -CLASS="STRUCTNAME" ->v4l2_buffer</CODE -></A -></DT -><DT ->3-2. <A -HREF="#V4L2-BUF-TYPE" ->enum v4l2_buf_type</A -></DT -><DT ->3-3. <A -HREF="#BUFFER-FLAGS" ->Buffer Flags</A -></DT -><DT ->3-4. <A -HREF="#V4L2-MEMORY" ->enum v4l2_memory</A -></DT -><DT ->3-5. <A -HREF="#V4L2-TIMECODE" ->struct <CODE -CLASS="STRUCTNAME" ->v4l2_timecode</CODE -></A -></DT -><DT ->3-6. <A -HREF="#TIMECODE-TYPE" ->Timecode Types</A -></DT -><DT ->3-7. <A -HREF="#TIMECODE-FLAGS" ->Timecode Flags</A -></DT -><DT ->3-8. <A -HREF="#V4L2-FIELD" ->enum v4l2_field</A -></DT -><DT ->4-1. <A -HREF="#V4L2-WINDOW" ->struct <CODE -CLASS="STRUCTNAME" ->v4l2_window</CODE -></A -></DT -><DT ->4-2. <A -HREF="#V4L2-CLIP" ->struct <CODE -CLASS="STRUCTNAME" ->v4l2_clip</CODE -><A -NAME="AEN4216" -HREF="#FTN.AEN4216" -><SPAN -CLASS="footnote" ->[22]</SPAN -></A -></A -></DT -><DT ->4-3. <A -HREF="#V4L2-RECT" ->struct <CODE -CLASS="STRUCTNAME" ->v4l2_rect</CODE -></A -></DT -><DT ->4-4. <A -HREF="#V4L2-VBI-FORMAT" ->struct <CODE -CLASS="STRUCTNAME" ->v4l2_vbi_format</CODE -></A -></DT -><DT ->4-5. <A -HREF="#VBIFMT-FLAGS" ->Raw VBI Format Flags</A -></DT -><DT ->4-6. <A -HREF="#V4L2-SLICED-VBI-FORMAT" ->struct <CODE -CLASS="STRUCTNAME" ->v4l2_sliced_vbi_format</CODE -></A -></DT -><DT ->4-7. <A -HREF="#V4L2-SLICED-DATA" ->struct <CODE -CLASS="STRUCTNAME" ->v4l2_sliced_data</CODE -></A -></DT -><DT ->4-8. <A -HREF="#SLICED-VBI-TYPES" ->Sliced VBI data formats</A -></DT -><DT ->1. <A -HREF="#V4L2-CROPCAP" ->struct <CODE -CLASS="STRUCTNAME" ->v4l2_cropcap</CODE -></A -></DT -><DT ->2. <A -HREF="#V4L2-RECT-CROP" ->struct <CODE -CLASS="STRUCTNAME" ->v4l2_rect</CODE -></A -></DT -><DT ->1. <A -HREF="#V4L2-FMTDESC" ->struct <CODE -CLASS="STRUCTNAME" ->v4l2_fmtdesc</CODE -></A -></DT -><DT ->2. <A -HREF="#FMTDESC-FLAGS" ->Image Format Description Flags</A -></DT -><DT ->1. <A -HREF="#V4L2-INPUT" ->struct <CODE -CLASS="STRUCTNAME" ->v4l2_input</CODE -></A -></DT -><DT ->2. <A -HREF="#INPUT-TYPE" ->Input Types</A -></DT -><DT ->3. <A -HREF="#INPUT-STATUS" ->Input Status Flags</A -></DT -><DT ->1. <A -HREF="#V4L2-OUTPUT" ->struct <CODE -CLASS="STRUCTNAME" ->v4l2_output</CODE -></A -></DT -><DT ->2. <A -HREF="#OUTPUT-TYPE" ->Output Type</A -></DT -><DT ->1. <A -HREF="#V4L2-STANDARD" ->struct <CODE -CLASS="STRUCTNAME" ->v4l2_standard</CODE -></A -></DT -><DT ->2. <A -HREF="#V4L2-FRACT" ->struct <CODE -CLASS="STRUCTNAME" ->v4l2_fract</CODE -></A -></DT -><DT ->3. <A -HREF="#V4L2-STD-ID" ->typedef <CODE -CLASS="STRUCTNAME" ->v4l2_std_id</CODE -></A -></DT -><DT ->4. <A -HREF="#VIDEO-STANDARDS" ->Video Standards (based on [<A -HREF="#ITU470" -><ABBR -CLASS="ABBREV" ->ITU470</ABBR -></A ->])</A -></DT -><DT ->1. <A -HREF="#V4L2-AUDIO" ->struct <CODE -CLASS="STRUCTNAME" ->v4l2_audio</CODE -></A -></DT -><DT ->2. <A -HREF="#AUDIO-CAPABILITY" ->Audio Capability Flags</A -></DT -><DT ->3. <A -HREF="#AUDIO-MODE" ->Audio Modes</A -></DT -><DT ->1. <A -HREF="#V4L2-AUDIOOUT" ->struct <CODE -CLASS="STRUCTNAME" ->v4l2_audioout</CODE -></A -></DT -><DT ->1. <A -HREF="#V4L2-COMPRESSION" ->struct <CODE -CLASS="STRUCTNAME" ->v4l2_compression</CODE -></A -></DT -><DT ->1. <A -HREF="#V4L2-CROP" ->struct <CODE -CLASS="STRUCTNAME" ->v4l2_crop</CODE -></A -></DT -><DT ->1. <A -HREF="#V4L2-CONTROL" ->struct <CODE -CLASS="STRUCTNAME" ->v4l2_control</CODE -></A -></DT -><DT ->1. <A -HREF="#V4L2-FRAMEBUFFER" ->struct <CODE -CLASS="STRUCTNAME" ->v4l2_framebuffer</CODE -></A -></DT -><DT ->2. <A -HREF="#FRAMEBUFFER-CAP" ->Frame Buffer Capability Flags</A -></DT -><DT ->3. <A -HREF="#FRAMEBUFFER-FLAGS" ->Frame Buffer Flags</A -></DT -><DT ->1. <A -HREF="#V4L2-FORMAT" ->struct <CODE -CLASS="STRUCTNAME" ->v4l2_format</CODE -></A -></DT -><DT ->1. <A -HREF="#V4L2-FREQUENCY" ->struct <CODE -CLASS="STRUCTNAME" ->v4l2_frequency</CODE -></A -></DT -><DT ->1. <A -HREF="#V4L2-JPEGCOMPRESSION" ->struct <CODE -CLASS="STRUCTNAME" ->v4l2_jpegcompression</CODE -></A -></DT -><DT ->2. <A -HREF="#JPEG-MARKERS" ->JPEG Markers Flags</A -></DT -><DT ->1. <A -HREF="#V4L2-MODULATOR" ->struct <CODE -CLASS="STRUCTNAME" ->v4l2_modulator</CODE -></A -></DT -><DT ->2. <A -HREF="#MODULATOR-TXSUBCHANS" ->Modulator Audio Transmission Flags</A -></DT -><DT ->1. <A -HREF="#V4L2-STREAMPARM" ->struct <CODE -CLASS="STRUCTNAME" ->v4l2_streamparm</CODE -></A -></DT -><DT ->2. <A -HREF="#V4L2-CAPTUREPARM" ->struct <CODE -CLASS="STRUCTNAME" ->v4l2_captureparm</CODE -></A -></DT -><DT ->3. <A -HREF="#V4L2-OUTPUTPARM" ->struct <CODE -CLASS="STRUCTNAME" ->v4l2_outputparm</CODE -></A -></DT -><DT ->4. <A -HREF="#PARM-CAPS" ->Streaming Parameters Capabilites</A -></DT -><DT ->5. <A -HREF="#PARM-FLAGS" ->Capture Parameters Flags</A -></DT -><DT ->1. <A -HREF="#V4L2-PRIORITY" ->enum v4l2_priority</A -></DT -><DT ->1. <A -HREF="#V4L2-TUNER" ->struct <CODE -CLASS="STRUCTNAME" ->v4l2_tuner</CODE -></A -></DT -><DT ->2. <A -HREF="#V4L2-TUNER-TYPE" ->enum v4l2_tuner_type</A -></DT -><DT ->3. <A -HREF="#TUNER-CAPABILITY" ->Tuner and Modulator Capability Flags</A -></DT -><DT ->4. <A -HREF="#TUNER-RXSUBCHANS" ->Tuner Audio Reception Flags</A -></DT -><DT ->5. <A -HREF="#TUNER-AUDMODE" ->Tuner Audio Modes</A -></DT -><DT ->6. <A -HREF="#TUNER-MATRIX" ->Tuner Audio Matrix</A -></DT -><DT ->1. <A -HREF="#V4L2-CAPABILITY" ->struct <CODE -CLASS="STRUCTNAME" ->v4l2_capability</CODE -></A -></DT -><DT ->2. <A -HREF="#DEVICE-CAPABILITIES" ->Device Capabilities Flags</A -></DT -><DT ->1. <A -HREF="#V4L2-QUERYCTRL" ->struct <CODE -CLASS="STRUCTNAME" ->v4l2_queryctrl</CODE -></A -></DT -><DT ->2. <A -HREF="#V4L2-QUERYMENU" ->struct <CODE -CLASS="STRUCTNAME" ->v4l2_querymenu</CODE -></A -></DT -><DT ->3. <A -HREF="#V4L2-CTRL-TYPE" ->enum v4l2_ctrl_type</A -></DT -><DT ->4. <A -HREF="#CONTROL-FLAGS" ->Control Flags</A -></DT -><DT ->1. <A -HREF="#V4L2-REQUESTBUFFERS" ->struct <CODE -CLASS="STRUCTNAME" ->v4l2_requestbuffers</CODE -></A -></DT -><DT ->6-1. <A -HREF="#V4L-DEV" ->V4L Device Types, Names and Numbers</A -></DT -></DL -></DIV -><DIV -CLASS="LOT" -><DL -CLASS="LOT" -><DT -><B ->List of Figures</B -></DT -><DT ->1-1. <A -HREF="#CROP-SCALE" ->Cropping and Scaling</A -></DT -><DT ->3-1. <A -HREF="#FIELDSEQ-TB" ->Field Order, Top Field First Transmitted</A -></DT -><DT ->3-2. <A -HREF="#FIELDSEQ-BT" ->Field Order, Bottom Field First Transmitted</A -></DT -><DT ->4-1. <A -HREF="#VBI-HSYNC" ->Line synchronization</A -></DT -><DT ->4-2. <A -HREF="#VBI-525" ->ITU-R 525 line numbering (M/NTSC and M/PAL)</A -></DT -><DT ->4-3. <A -HREF="#VBI-625" ->ITU-R 625 line numbering</A -></DT -></DL -></DIV -><DIV -CLASS="LOT" -><DL -CLASS="LOT" -><DT -><B ->List of Examples</B -></DT -><DT ->1-1. <A -HREF="#AEN228" ->Information about the current video input</A -></DT -><DT ->1-2. <A -HREF="#AEN236" ->Switching to the first video input</A -></DT -><DT ->1-3. <A -HREF="#AEN282" ->Information about the current audio input</A -></DT -><DT ->1-4. <A -HREF="#AEN288" ->Switching to the first audio input</A -></DT -><DT ->1-5. <A -HREF="#AEN410" ->Information about the current video standard</A -></DT -><DT ->1-6. <A -HREF="#AEN419" ->Listing the video standards supported by the current -input</A -></DT -><DT ->1-7. <A -HREF="#AEN430" ->Selecting a new video standard</A -></DT -><DT ->1-8. <A -HREF="#AEN630" ->Enumerating all controls</A -></DT -><DT ->1-9. <A -HREF="#AEN641" ->Changing controls</A -></DT -><DT ->1-10. <A -HREF="#AEN747" ->Resetting the cropping parameters</A -></DT -><DT ->1-11. <A -HREF="#AEN757" ->Simple downscaling</A -></DT -><DT ->1-12. <A -HREF="#AEN765" ->Current scaling factor and pixel aspect</A -></DT -><DT ->2-1. <A -HREF="#AEN984" ->ITU-R Rec. BT.601 color conversion</A -></DT -><DT ->2-2. <A -HREF="#AEN1675" -><CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_BGR24</CODE -> 4 × 4 pixel -image</A -></DT -><DT ->2-1. <A -HREF="#AEN1819" -><CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_GREY</CODE -> 4 × 4 -pixel image</A -></DT -><DT ->2-1. <A -HREF="#AEN1881" -><CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_YUYV</CODE -> 4 × 4 -pixel image</A -></DT -><DT ->2-1. <A -HREF="#AEN2026" -><CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_UYVY</CODE -> 4 × 4 -pixel image</A -></DT -><DT ->2-1. <A -HREF="#AEN2175" -><CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_Y41P</CODE -> 8 × 4 -pixel image</A -></DT -><DT ->2-1. <A -HREF="#AEN2402" -><CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_YVU420</CODE -> 4 × 4 -pixel image</A -></DT -><DT ->2-1. <A -HREF="#AEN2564" -><CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_YVU410</CODE -> 4 × 4 -pixel image</A -></DT -><DT ->2-1. <A -HREF="#AEN2702" -><CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_YUV422P</CODE -> 4 × 4 -pixel image</A -></DT -><DT ->2-1. <A -HREF="#AEN2869" -><CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_YUV411P</CODE -> 4 × 4 -pixel image</A -></DT -><DT ->2-1. <A -HREF="#AEN3026" -><CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_NV12</CODE -> 4 × 4 -pixel image</A -></DT -><DT ->3-1. <A -HREF="#AEN3316" ->Mapping buffers</A -></DT -><DT ->3-2. <A -HREF="#AEN3392" ->Initiating streaming I/O with user pointers</A -></DT -></DL -></DIV -><DIV -CLASS="PREFACE" -><HR><H1 -><A -NAME="AEN71" -></A ->Introduction</H1 -><P ->[to do]</P -><P ->If you have questions or ideas regarding the API, please try -the Video4Linux mailing list: <A -HREF="https://listman.redhat.com/mailman/listinfo/video4linux-list" -TARGET="_top" ->https://listman.redhat.com/mailman/listinfo/video4linux-list</A -></P -><P ->For documentation related requests contact the maintainer at -<A -HREF="mailto:mschimek@gmx.at" -TARGET="_top" ->mschimek@gmx.at</A ->.</P -><P ->The latest version of this document and the DocBook SGML -sources is currently hosted at <A -HREF="http://bytesex.org" -TARGET="_top" ->http://bytesex.org</A ->, site of the V4L -and V4L2 source code maintainer Gerd Knorr.</P -></DIV -><DIV -CLASS="CHAPTER" -><HR><H1 -><A -NAME="COMMON" -></A ->Chapter 1. Common API Elements</H1 -><P ->Programming a V4L2 device consists of these -steps:</P -><P -></P -><UL -><LI -><P ->Opening the device</P -></LI -><LI -><P ->Changing device properties, selecting a video and audio -input, video standard, picture brightness a. o.</P -></LI -><LI -><P ->Negotiating a data format</P -></LI -><LI -><P ->Negotiating an input/output method</P -></LI -><LI -><P ->The actual input/output loop</P -></LI -><LI -><P ->Closing the device</P -></LI -></UL -><P ->In practice most steps are optional and can be executed out of -order. It depends on the V4L2 device type, you can read about the -details in <A -HREF="#DEVICES" ->Chapter 4</A ->. In this chapter we will discuss -the basic concepts applicable to all devices.</P -><DIV -CLASS="SECTION" -><HR><H2 -CLASS="SECTION" -><A -NAME="OPEN" ->1.1. Opening and Closing Devices</A -></H2 -><DIV -CLASS="SECTION" -><H3 -CLASS="SECTION" -><A -NAME="AEN100" ->1.1.1. Device Naming</A -></H3 -><P ->V4L2 drivers are implemented as kernel modules, loaded -manually by the system administrator or automatically when a device is -first opened. The driver modules plug into the "videodev" kernel -module. It provides helper functions and a common application -interface as specified in this document.</P -><P ->Each driver thus loaded registers one or more device nodes -with major number 81 and a minor number between 0 and 255. Assigning -minor numbers to V4L2 devices is entirely up to the system administrator, -this is primarily intended to solve conflicts between devices.<A -NAME="AEN104" -HREF="#FTN.AEN104" -><SPAN -CLASS="footnote" ->[1]</SPAN -></A -> The module options to select minor numbers are named -after the device special file with a "_nr" suffix. For example "video_nr" -for <TT -CLASS="FILENAME" ->/dev/video</TT -> video capture devices. The number is -an offset to the base minor number associated with the device type. -<A -NAME="AEN107" -HREF="#FTN.AEN107" -><SPAN -CLASS="footnote" ->[2]</SPAN -></A -> When the driver supports multiple devices of the same -type more than one minor number can be assigned, separated by commas: -<DIV -CLASS="INFORMALEXAMPLE" -><P -></P -><A -NAME="AEN109" -></A -><PRE -CLASS="SCREEN" ->> insmod mydriver.o video_nr=0,1 radio_nr=0,1</PRE -><P -></P -></DIV -></P -><P ->In <TT -CLASS="FILENAME" ->/etc/modules.conf</TT -> this may be -written as: <DIV -CLASS="INFORMALEXAMPLE" -><P -></P -><A -NAME="AEN113" -></A -><PRE -CLASS="SCREEN" ->alias char-major-81-0 mydriver -alias char-major-81-1 mydriver -alias char-major-81-64 mydriver <A -NAME="ALIAS" -><IMG -SRC="/usr/share/sgml/docbook/stylesheet/dsssl/modular/images/callouts1.gif" -HSPACE="0" -VSPACE="0" -BORDER="0" -ALT="(1)"></A -> -options mydriver video_nr=0,1 radio_nr=0,1 <A -NAME="OPTIONS" -><IMG -SRC="/usr/share/sgml/docbook/stylesheet/dsssl/modular/images/callouts2.gif" -HSPACE="0" -VSPACE="0" -BORDER="0" -ALT="(2)"></A -> - </PRE -><DIV -CLASS="CALLOUTLIST" -><DL -COMPACT="COMPACT" -><DT -><A -HREF="#ALIAS" -><IMG -SRC="/usr/share/sgml/docbook/stylesheet/dsssl/modular/images/callouts1.gif" -HSPACE="0" -VSPACE="0" -BORDER="0" -ALT="(1)"></A -></DT -><DD ->When an application attempts to open a device -special file with major number 81 and minor number 0, 1, or 64, load -"mydriver" (and the "videodev" module it depends upon).</DD -><DT -><A -HREF="#OPTIONS" -><IMG -SRC="/usr/share/sgml/docbook/stylesheet/dsssl/modular/images/callouts2.gif" -HSPACE="0" -VSPACE="0" -BORDER="0" -ALT="(2)"></A -></DT -><DD ->Register the first two video capture devices with -minor number 0 and 1 (base number is 0), the first two radio device -with minor number 64 and 65 (base 64).</DD -></DL -></DIV -><P -></P -></DIV -> When no minor number is given as module -option the driver supplies a default. <A -HREF="#DEVICES" ->Chapter 4</A -> -recommends the base minor numbers to be used for the various device -types. Obviously minor numbers must be unique. When the number is -already in use the <SPAN -CLASS="emphasis" -><I -CLASS="EMPHASIS" ->offending device</I -></SPAN -> will not be -registered. </P -><P ->By convention system administrators create various -character device special files with these major and minor numbers in -the <TT -CLASS="FILENAME" ->/dev</TT -> directory. The names recomended for the -different V4L2 device types are listed in <A -HREF="#DEVICES" ->Chapter 4</A ->.</P -><P ->The creation of character special files (with -<SPAN -CLASS="APPLICATION" ->mknod</SPAN ->) is a privileged operation and -devices cannot be opened by major and minor number. That means -applications cannot <SPAN -CLASS="emphasis" -><I -CLASS="EMPHASIS" ->reliable</I -></SPAN -> scan for loaded or -installed drivers. The user must enter a device name, or the -application can try the conventional device names.</P -><P ->Under the device filesystem (devfs) the minor number -options are ignored. V4L2 drivers (or by proxy the "videodev" module) -automatically create the required device files in the -<TT -CLASS="FILENAME" ->/dev/v4l</TT -> directory using the conventional device -names above.</P -></DIV -><DIV -CLASS="SECTION" -><HR><H3 -CLASS="SECTION" -><A -NAME="RELATED" ->1.1.2. Related Devices</A -></H3 -><P ->Devices can support several related functions. For example -video capturing, video overlay and VBI capturing are related because -these functions share, amongst other, the same video input and tuner -frequency. V4L and earlier versions of V4L2 used the same device name -and minor number for video capturing and overlay, but different ones -for VBI. Experience showed this approach has several problems<A -NAME="AEN135" -HREF="#FTN.AEN135" -><SPAN -CLASS="footnote" ->[3]</SPAN -></A ->, and to make things worse the V4L videodev module -used to prohibit multiple opens of a device.</P -><P ->As a remedy the present version of the V4L2 API relaxed the -concept of device types with specific names and minor numbers. For -compatibility with old applications drivers must still register different -minor numbers to assign a default function to the device. But if related -functions are supported by the driver they must be available under all -registered minor numbers. The desired function can be selected after -opening the device as described in <A -HREF="#DEVICES" ->Chapter 4</A ->.</P -><P ->Imagine a driver supporting video capturing, video -overlay, raw VBI capturing, and FM radio reception. It registers three -devices with minor number 0, 64 and 224 (this numbering scheme is -inherited from the V4L API). Regardless if -<TT -CLASS="FILENAME" ->/dev/video</TT -> (81, 0) or -<TT -CLASS="FILENAME" ->/dev/vbi</TT -> (81, 224) is opened the application can -select any one of the video capturing, overlay or VBI capturing -functions. Without programming (e. g. reading from the device -with <SPAN -CLASS="APPLICATION" ->dd</SPAN -> or <SPAN -CLASS="APPLICATION" ->cat</SPAN ->) -<TT -CLASS="FILENAME" ->/dev/video</TT -> captures video images, while -<TT -CLASS="FILENAME" ->/dev/vbi</TT -> captures raw VBI data. -<TT -CLASS="FILENAME" ->/dev/radio</TT -> (81, 64) is invariable a radio device, -unrelated to the video functions. Being unrelated does not imply the -devices can be used at the same time, however. The -<CODE -CLASS="FUNCTION" ->open()</CODE -> function may very well return an -<SPAN -CLASS="ERRORCODE" ->EBUSY</SPAN -> error code.</P -><P ->Besides video input or output the hardware may also -support audio sampling or playback. If so, these functions are -implemented as OSS or ALSA PCM devices and eventually OSS or ALSA -audio mixer. The V4L2 API makes no provisions yet to find these -related devices. If you have an idea please write to the Video4Linux -mailing list: <A -HREF="https://listman.redhat.com/mailman/listinfo/video4linux-list" -TARGET="_top" ->https://listman.redhat.com/mailman/listinfo/video4linux-list</A ->.</P -></DIV -><DIV -CLASS="SECTION" -><HR><H3 -CLASS="SECTION" -><A -NAME="AEN153" ->1.1.3. Multiple Opens</A -></H3 -><P ->In general, V4L2 devices can be opened more than once. -When this is supported by the driver, users can for example start a -"panel" application to change controls like brightness or audio -volume, while another application captures video and audio. In other words, panel -applications are comparable to an OSS or ALSA audio mixer application. -When a device supports multiple functions like capturing and overlay -<SPAN -CLASS="emphasis" -><I -CLASS="EMPHASIS" ->simultaneously</I -></SPAN ->, multiple opens allow concurrent -use of the device by forked processes or specialized applications.</P -><P ->Multiple opens are optional, although drivers should -permit at least concurrent accesses without data exchange, i. e. -panel applications. This implies <CODE -CLASS="FUNCTION" ->open()</CODE -> can -return an <SPAN -CLASS="ERRORCODE" ->EBUSY</SPAN -> error code when the device is already in use, as well as -<CODE -CLASS="FUNCTION" ->ioctl()</CODE -> functions initiating data exchange -(namely the <A -HREF="#VIDIOC-G-FMT" -><CODE -CLASS="CONSTANT" ->VIDIOC_S_FMT</CODE -></A -> ioctl), and the <CODE -CLASS="FUNCTION" ->read()</CODE -> -and <CODE -CLASS="FUNCTION" ->write()</CODE -> functions.</P -><P ->Mere opening a V4L2 device does not grant exclusive -access.<A -NAME="AEN166" -HREF="#FTN.AEN166" -><SPAN -CLASS="footnote" ->[4]</SPAN -></A -> Initiating data exchange however assigns the right -to read or write the requested type of data, and to change related -properties, to this file descriptor. Applications can request -additional access privileges using the priority mechanism described in -<A -HREF="#APP-PRI" ->Section 1.3</A ->.</P -></DIV -><DIV -CLASS="SECTION" -><HR><H3 -CLASS="SECTION" -><A -NAME="AEN170" ->1.1.4. Shared Data Streams</A -></H3 -><P ->V4L2 drivers should not support multiple applications -reading or writing the same data stream on a device by copying -buffers, time multiplexing or similar means. This is better handled by -a proxy application in user space. When the driver supports stream -sharing anyway it must be implemented transparently. The V4L2 API does -not specify how conflicts are solved. </P -></DIV -><DIV -CLASS="SECTION" -><HR><H3 -CLASS="SECTION" -><A -NAME="AEN173" ->1.1.5. Functions</A -></H3 -><P ->To open and close V4L2 devices applications use the <A -HREF="#FUNC-OPEN" -><CODE -CLASS="FUNCTION" ->open()</CODE -></A -> and <A -HREF="#FUNC-CLOSE" -><CODE -CLASS="FUNCTION" ->close()</CODE -></A -> function, -respectively. Devices are programmed using the <A -HREF="#FUNC-IOCTL" -><CODE -CLASS="FUNCTION" ->ioctl()</CODE -></A -> function as -explained in the following sections.</P -></DIV -></DIV -><DIV -CLASS="SECTION" -><HR><H2 -CLASS="SECTION" -><A -NAME="QUERYCAP" ->1.2. Querying Capabilities</A -></H2 -><P ->Because V4L2 covers a wide variety of devices not all -aspects of the API are equally applicable to all types of devices. -Furthermore devices of the same type have different capabilities and -this specification permits the omission of a few complicated and less -important parts of the API.</P -><P ->The <A -HREF="#VIDIOC-QUERYCAP" -><CODE -CLASS="CONSTANT" ->VIDIOC_QUERYCAP</CODE -></A -> ioctl is available to check if the kernel -device is compatible with this specification, and to query the <A -HREF="#DEVICES" ->functions</A -> and <A -HREF="#IO" ->I/O -methods</A -> supported by the device. Other features can be queried -by calling the respective ioctl, for example <A -HREF="#VIDIOC-ENUMINPUT" -><CODE -CLASS="CONSTANT" ->VIDIOC_ENUMINPUT</CODE -></A -> -to learn about the number, types and names of video connectors on the -device. Although abstraction is a major objective of this API, the -ioctl also allows driver specific applications to reliable identify -the driver.</P -><P ->All V4L2 drivers must support -<CODE -CLASS="CONSTANT" ->VIDIOC_QUERYCAP</CODE ->. Applications should always call -this ioctl after opening the device.</P -></DIV -><DIV -CLASS="SECTION" -><HR><H2 -CLASS="SECTION" -><A -NAME="APP-PRI" ->1.3. Application Priority</A -></H2 -><P ->When multiple applications share a device it may be -desirable to assign them different priorities. Contrary to the -traditional "rm -rf /" school of thought a video recording application -could for example block other applications from changing video -controls or switching the current TV channel. Another objective is to -permit low priority applications working in background, which can be -preempted by user controlled applications and automatically regain -control of the device at a later time.</P -><P ->Since these features cannot be implemented entirely in user -space V4L2 defines the <A -HREF="#VIDIOC-G-PRIORITY" -><CODE -CLASS="CONSTANT" ->VIDIOC_G_PRIORITY</CODE -></A -> and <A -HREF="#VIDIOC-G-PRIORITY" -><CODE -CLASS="CONSTANT" ->VIDIOC_S_PRIORITY</CODE -></A -> -ioctls to request and query the access priority associate with a file -descriptor. Opening a device assigns a medium priority, compatible -with earlier versions of V4L2 and drivers not supporting these ioctls. -Applications requiring a different priority will usually call -<CODE -CLASS="CONSTANT" ->VIDIOC_S_PRIORITY</CODE -> after verifying the device with -the <A -HREF="#VIDIOC-QUERYCAP" -><CODE -CLASS="CONSTANT" ->VIDIOC_QUERYCAP</CODE -></A -> ioctl.</P -><P ->Ioctls changing driver properties, such as <A -HREF="#VIDIOC-G-INPUT" -><CODE -CLASS="CONSTANT" ->VIDIOC_S_INPUT</CODE -></A ->, -return an <SPAN -CLASS="ERRORCODE" ->EBUSY</SPAN -> error code after another application obtained higher priority. -An event mechanism to notify applications about asynchronous property -changes has been proposed but not added yet.</P -></DIV -><DIV -CLASS="SECTION" -><HR><H2 -CLASS="SECTION" -><A -NAME="VIDEO" ->1.4. Video Inputs and Outputs</A -></H2 -><P ->Video inputs and outputs are physical connectors of a -device. These can be for example RF connectors (antenna/cable), CVBS -a.k.a. Composite Video, S-Video or RGB connectors. Only video and VBI -capture devices have inputs, output devices have outputs, at least one -each. Radio devices have no video inputs or outputs.</P -><P ->To learn about the number and attributes of the -available inputs and outputs applications can enumerate them with the -<A -HREF="#VIDIOC-ENUMINPUT" -><CODE -CLASS="CONSTANT" ->VIDIOC_ENUMINPUT</CODE -></A -> and <A -HREF="#VIDIOC-ENUMOUTPUT" -><CODE -CLASS="CONSTANT" ->VIDIOC_ENUMOUTPUT</CODE -></A -> ioctl, respectively. The -struct <A -HREF="#V4L2-INPUT" ->v4l2_input</A -> returned by the <CODE -CLASS="CONSTANT" ->VIDIOC_ENUMINPUT</CODE -> -ioctl also contains signal status information applicable when the -current video input is queried.</P -><P ->The <A -HREF="#VIDIOC-G-INPUT" -><CODE -CLASS="CONSTANT" ->VIDIOC_G_INPUT</CODE -></A -> and <A -HREF="#VIDIOC-G-OUTPUT" -><CODE -CLASS="CONSTANT" ->VIDIOC_G_OUTPUT</CODE -></A -> ioctl return the -index of the current video input or output. To select a different -input or output applications call the <A -HREF="#VIDIOC-G-INPUT" -><CODE -CLASS="CONSTANT" ->VIDIOC_S_INPUT</CODE -></A -> and -<A -HREF="#VIDIOC-G-OUTPUT" -><CODE -CLASS="CONSTANT" ->VIDIOC_S_OUTPUT</CODE -></A -> ioctl. Drivers must implement all the input ioctls -when the device has one or more inputs, all the output ioctls when the -device has one or more outputs.</P -><DIV -CLASS="EXAMPLE" -><A -NAME="AEN228" -></A -><P -><B ->Example 1-1. Information about the current video input</B -></P -><PRE -CLASS="PROGRAMLISTING" ->struct <A -HREF="#V4L2-INPUT" ->v4l2_input</A -> input; -int index; - -if (-1 == ioctl (fd, <A -HREF="#VIDIOC-G-INPUT" -><CODE -CLASS="CONSTANT" ->VIDIOC_G_INPUT</CODE -></A ->, &index)) { - perror ("VIDIOC_G_INPUT"); - exit (EXIT_FAILURE); -} - -memset (&input, 0, sizeof (input)); -input.index = index; - -if (-1 == ioctl (fd, <A -HREF="#VIDIOC-ENUMINPUT" -><CODE -CLASS="CONSTANT" ->VIDIOC_ENUMINPUT</CODE -></A ->, &input)) { - perror ("VIDIOC_ENUMINPUT"); - exit (EXIT_FAILURE); -} - -printf ("Current input: %s\n", input.name); - </PRE -></DIV -><DIV -CLASS="EXAMPLE" -><A -NAME="AEN236" -></A -><P -><B ->Example 1-2. Switching to the first video input</B -></P -><PRE -CLASS="PROGRAMLISTING" ->int index; - -index = 0; - -if (-1 == ioctl (fd, <A -HREF="#VIDIOC-G-INPUT" -><CODE -CLASS="CONSTANT" ->VIDIOC_S_INPUT</CODE -></A ->, &index)) { - perror ("VIDIOC_S_INPUT"); - exit (EXIT_FAILURE); -} - </PRE -></DIV -></DIV -><DIV -CLASS="SECTION" -><HR><H2 -CLASS="SECTION" -><A -NAME="AUDIO" ->1.5. Audio Inputs and Outputs</A -></H2 -><P ->Audio inputs and outputs are physical connectors of a -device. Video capture devices have inputs, output devices have -outputs, zero or more each. Radio devices have no audio inputs or -outputs. They have exactly one tuner which in fact -<SPAN -CLASS="emphasis" -><I -CLASS="EMPHASIS" ->is</I -></SPAN -> an audio source, but this API associates -tuners with video inputs or outputs only, and radio devices have -none of these.<A -NAME="AEN245" -HREF="#FTN.AEN245" -><SPAN -CLASS="footnote" ->[5]</SPAN -></A -> A connector on a TV card to loop back the received -audio signal to a sound card is not considered an audio output.</P -><P ->Audio and video inputs and outputs are associated. Selecting -a video source also selects an audio source. This is most evident when -the video and audio source is a tuner. Further audio connectors can -combine with more than one video input or output. Assumed two -composite video inputs and two audio inputs exist, there may be up to -four valid combinations. The relation of video and audio connectors -is defined in the <CODE -CLASS="STRUCTFIELD" ->audioset</CODE -> field of the -respective struct <A -HREF="#V4L2-INPUT" ->v4l2_input</A -> or struct <A -HREF="#V4L2-OUTPUT" ->v4l2_output</A ->, where each bit represents -the index number, starting at zero, of one audio input or output.</P -><P ->To learn about the number and attributes of the -available inputs and outputs applications can enumerate them with the -<A -HREF="#VIDIOC-ENUMAUDIO" -><CODE -CLASS="CONSTANT" ->VIDIOC_ENUMAUDIO</CODE -></A -> and <A -HREF="#VIDIOC-ENUMAUDIOOUT" -><CODE -CLASS="CONSTANT" ->VIDIOC_ENUMAUDOUT</CODE -></A -> ioctl, respectively. The -struct <A -HREF="#V4L2-AUDIO" ->v4l2_audio</A -> returned by the <CODE -CLASS="CONSTANT" ->VIDIOC_ENUMAUDIO</CODE -> ioctl -also contains signal status information applicable when the current -audio input is queried.</P -><P ->The <A -HREF="#VIDIOC-G-AUDIO" -><CODE -CLASS="CONSTANT" ->VIDIOC_G_AUDIO</CODE -></A -> and <A -HREF="#VIDIOC-G-AUDIOOUT" -><CODE -CLASS="CONSTANT" ->VIDIOC_G_AUDOUT</CODE -></A -> ioctl report -the current audio input and output, respectively. Note that, unlike -<A -HREF="#VIDIOC-G-INPUT" -><CODE -CLASS="CONSTANT" ->VIDIOC_G_INPUT</CODE -></A -> and <A -HREF="#VIDIOC-G-OUTPUT" -><CODE -CLASS="CONSTANT" ->VIDIOC_G_OUTPUT</CODE -></A -> these ioctls return a structure -as <CODE -CLASS="CONSTANT" ->VIDIOC_ENUMAUDIO</CODE -> and -<CODE -CLASS="CONSTANT" ->VIDIOC_ENUMAUDOUT</CODE -> do, not just an index.</P -><P ->To select an audio input and change its properties -applications call the <A -HREF="#VIDIOC-G-AUDIO" -><CODE -CLASS="CONSTANT" ->VIDIOC_S_AUDIO</CODE -></A -> ioctl. To select an audio -output (which presently has no changeable properties) applications -call the <A -HREF="#VIDIOC-G-AUDIOOUT" -><CODE -CLASS="CONSTANT" ->VIDIOC_S_AUDOUT</CODE -></A -> ioctl.</P -><P ->Drivers must implement all input ioctls when the device -has one or more inputs, all output ioctls when the device has one -or more outputs. When the device has any audio inputs or outputs the -driver must set the <CODE -CLASS="CONSTANT" ->V4L2_CAP_AUDIO</CODE -> flag in the -struct <A -HREF="#V4L2-CAPABILITY" ->v4l2_capability</A -> returned by the <A -HREF="#VIDIOC-QUERYCAP" -><CODE -CLASS="CONSTANT" ->VIDIOC_QUERYCAP</CODE -></A -> ioctl.</P -><DIV -CLASS="EXAMPLE" -><A -NAME="AEN282" -></A -><P -><B ->Example 1-3. Information about the current audio input</B -></P -><PRE -CLASS="PROGRAMLISTING" ->struct <A -HREF="#V4L2-AUDIO" ->v4l2_audio</A -> audio; - -memset (&audio, 0, sizeof (audio)); - -if (-1 == ioctl (fd, <A -HREF="#VIDIOC-G-AUDIO" -><CODE -CLASS="CONSTANT" ->VIDIOC_G_AUDIO</CODE -></A ->, &audio)) { - perror ("VIDIOC_G_AUDIO"); - exit (EXIT_FAILURE); -} - -printf ("Current input: %s\n", audio.name); - </PRE -></DIV -><DIV -CLASS="EXAMPLE" -><A -NAME="AEN288" -></A -><P -><B ->Example 1-4. Switching to the first audio input</B -></P -><PRE -CLASS="PROGRAMLISTING" ->struct <A -HREF="#V4L2-AUDIO" ->v4l2_audio</A -> audio; - -memset (&audio, 0, sizeof (audio)); /* clear audio.mode, audio.reserved */ - -audio.index = 0; - -if (-1 == ioctl (fd, <A -HREF="#VIDIOC-G-AUDIO" -><CODE -CLASS="CONSTANT" ->VIDIOC_S_AUDIO</CODE -></A ->, &audio)) { - perror ("VIDIOC_S_AUDIO"); - exit (EXIT_FAILURE); -} - </PRE -></DIV -></DIV -><DIV -CLASS="SECTION" -><HR><H2 -CLASS="SECTION" -><A -NAME="TUNER" ->1.6. Tuners and Modulators</A -></H2 -><DIV -CLASS="SECTION" -><H3 -CLASS="SECTION" -><A -NAME="AEN296" ->1.6.1. Tuners</A -></H3 -><P ->Video input devices can have one or more tuners -demodulating a RF signal. Each tuner is associated with one or more -video inputs, depending on the number of RF connectors on the tuner. -The <CODE -CLASS="STRUCTFIELD" ->type</CODE -> field of the respective -struct <A -HREF="#V4L2-INPUT" ->v4l2_input</A -> returned by the <A -HREF="#VIDIOC-ENUMINPUT" -><CODE -CLASS="CONSTANT" ->VIDIOC_ENUMINPUT</CODE -></A -> ioctl is set to -<CODE -CLASS="CONSTANT" ->V4L2_INPUT_TYPE_TUNER</CODE -> and its -<CODE -CLASS="STRUCTFIELD" ->tuner</CODE -> field contains the index number of -the tuner.</P -><P ->Radio devices have exactly one tuner with index zero, no -video inputs.</P -><P ->To query and change tuner properties applications use the -<A -HREF="#VIDIOC-G-TUNER" -><CODE -CLASS="CONSTANT" ->VIDIOC_G_TUNER</CODE -></A -> and <A -HREF="#VIDIOC-G-TUNER" -><CODE -CLASS="CONSTANT" ->VIDIOC_S_TUNER</CODE -></A -> ioctl, respectively. The -struct <A -HREF="#V4L2-TUNER" ->v4l2_tuner</A -> returned by <CODE -CLASS="CONSTANT" ->VIDIOC_G_TUNER</CODE -> also -contains signal status information applicable when the tuner of the -current video input, or a radio tuner is queried. Note that -<CODE -CLASS="CONSTANT" ->VIDIOC_S_TUNER</CODE -> does not switch the current tuner, -when there is more than one at all. The tuner is solely determined by -the current video input. Drivers must support both ioctls and set the -<CODE -CLASS="CONSTANT" ->V4L2_CAP_TUNER</CODE -> flag in the struct <A -HREF="#V4L2-CAPABILITY" ->v4l2_capability</A -> -returned by the <A -HREF="#VIDIOC-QUERYCAP" -><CODE -CLASS="CONSTANT" ->VIDIOC_QUERYCAP</CODE -></A -> ioctl when the device has one or -more tuners.</P -></DIV -><DIV -CLASS="SECTION" -><HR><H3 -CLASS="SECTION" -><A -NAME="AEN318" ->1.6.2. Modulators</A -></H3 -><P ->Video output devices can have one or more modulators, uh, -modulating a video signal for radiation or connection to the antenna -input of a TV set or video recorder. Each modulator is associated with -one or more video outputs, depending on the number of RF connectors on -the modulator. The <CODE -CLASS="STRUCTFIELD" ->type</CODE -> field of the -respective struct <A -HREF="#V4L2-OUTPUT" ->v4l2_output</A -> returned by the <A -HREF="#VIDIOC-ENUMOUTPUT" -><CODE -CLASS="CONSTANT" ->VIDIOC_ENUMOUTPUT</CODE -></A -> is set to -<CODE -CLASS="CONSTANT" ->V4L2_OUTPUT_TYPE_MODULATOR</CODE -> and its -<CODE -CLASS="STRUCTFIELD" ->modulator</CODE -> field contains the index number -of the modulator. This specification does not define radio output -devices.</P -><P ->To query and change modulator properties applications use -the <A -HREF="#VIDIOC-G-MODULATOR" -><CODE -CLASS="CONSTANT" ->VIDIOC_G_MODULATOR</CODE -></A -> and <A -HREF="#VIDIOC-G-MODULATOR" -><CODE -CLASS="CONSTANT" ->VIDIOC_S_MODULATOR</CODE -></A -> ioctl. Note that -<CODE -CLASS="CONSTANT" ->VIDIOC_S_MODULATOR</CODE -> does not switch the current -modulator, when there is more than one at all. The modulator is solely -determined by the current video output. Drivers must support both -ioctls and set the <CODE -CLASS="CONSTANT" ->V4L2_CAP_TUNER</CODE -> (sic) flag in -the struct <A -HREF="#V4L2-CAPABILITY" ->v4l2_capability</A -> returned by the <A -HREF="#VIDIOC-QUERYCAP" -><CODE -CLASS="CONSTANT" ->VIDIOC_QUERYCAP</CODE -></A -> ioctl when the -device has one or more modulators.</P -></DIV -><DIV -CLASS="SECTION" -><HR><H3 -CLASS="SECTION" -><A -NAME="AEN337" ->1.6.3. Radio Frequency</A -></H3 -><P ->To get and set the tuner or modulator radio frequency -applications use the <A -HREF="#VIDIOC-G-FREQUENCY" -><CODE -CLASS="CONSTANT" ->VIDIOC_G_FREQUENCY</CODE -></A -> and <A -HREF="#VIDIOC-G-FREQUENCY" -><CODE -CLASS="CONSTANT" ->VIDIOC_S_FREQUENCY</CODE -></A -> -ioctl which both take a pointer to a struct <A -HREF="#V4L2-FREQUENCY" ->v4l2_frequency</A ->. These ioctls -are used for TV and radio devices alike. Drivers must support both -ioctls when the tuner or modulator ioctls are supported, or -when the device is a radio device.</P -></DIV -><DIV -CLASS="SECTION" -><HR><H3 -CLASS="SECTION" -><A -NAME="AEN345" ->1.6.4. Satellite Receivers</A -></H3 -><P ->To be discussed. See also -proposals by Peter Schlaf, video4linux-list@redhat.com on 23 Oct 2002, -subject: "Re: [V4L] Re: v4l2 api".</P -></DIV -></DIV -><DIV -CLASS="SECTION" -><HR><H2 -CLASS="SECTION" -><A -NAME="STANDARD" ->1.7. Video Standards</A -></H2 -><P ->Video devices typically support one or more different video -standards or variations of standards. Each video input and output may -support another set of standards. This set is reported by the -<CODE -CLASS="STRUCTFIELD" ->std</CODE -> field of struct <A -HREF="#V4L2-INPUT" ->v4l2_input</A -> and -struct <A -HREF="#V4L2-OUTPUT" ->v4l2_output</A -> returned by the <A -HREF="#VIDIOC-ENUMINPUT" -><CODE -CLASS="CONSTANT" ->VIDIOC_ENUMINPUT</CODE -></A -> and -<A -HREF="#VIDIOC-ENUMOUTPUT" -><CODE -CLASS="CONSTANT" ->VIDIOC_ENUMOUTPUT</CODE -></A -> ioctl, respectively.</P -><P ->V4L2 defines one bit for each analog video standard -currently in use worldwide, and sets aside bits for driver defined -standards, e. g. hybrid standards to watch NTSC video tapes on PAL TVs -and vice versa. Applications can use the predefined bits to select a -particular standard, although presenting the user a menu of supported -standards is preferred. To enumerate and query the attributes of the -supported standards applications use the <A -HREF="#VIDIOC-ENUMSTD" -><CODE -CLASS="CONSTANT" ->VIDIOC_ENUMSTD</CODE -></A -> ioctl.</P -><P ->Many of the defined standards are actually just variations -of a few major standards. The hardware may in fact not distinguish -between them, or do so internal and switch automatically. Therefore -enumerated standards also contain sets of one or more standard -bits.</P -><P ->Assume a hypothetic tuner capable of demodulating B/PAL, -G/PAL and I/PAL signals. The first enumerated standard is a set of B -and G/PAL, switched automatically depending on the selected radio -frequency in UHF or VHF band. Enumeration gives a "PAL-B/G" or "PAL-I" -choice. Similar a Composite input may collapse standards, enumerating -"PAL-B/G/H/I", "NTSC-M" and "SECAM-D/K".<A -NAME="AEN363" -HREF="#FTN.AEN363" -><SPAN -CLASS="footnote" ->[6]</SPAN -></A -></P -><P ->To query and select the standard used by the current video -input or output applications call the <A -HREF="#VIDIOC-G-STD" -><CODE -CLASS="CONSTANT" ->VIDIOC_G_STD</CODE -></A -> and -<A -HREF="#VIDIOC-G-STD" -><CODE -CLASS="CONSTANT" ->VIDIOC_S_STD</CODE -></A -> ioctl, respectively. The <SPAN -CLASS="emphasis" -><I -CLASS="EMPHASIS" ->received</I -></SPAN -> -standard can be sensed with the <A -HREF="#VIDIOC-QUERYSTD" -><CODE -CLASS="CONSTANT" ->VIDIOC_QUERYSTD</CODE -></A -> ioctl. Note parameter of all these ioctls is a pointer to a <A -HREF="#V4L2-STD-ID" ->v4l2_std_id</A -> type (a standard set), <SPAN -CLASS="emphasis" -><I -CLASS="EMPHASIS" ->not</I -></SPAN -> an index into the standard enumeration.<A -NAME="AEN375" -HREF="#FTN.AEN375" -><SPAN -CLASS="footnote" ->[7]</SPAN -></A -> Drivers must implement all video standard ioctls -when the device has one or more video inputs or outputs.</P -><P ->Special rules apply to USB cameras where the notion of video -standards makes little sense. More generally any capture device, -output devices accordingly, which is <P -></P -><UL -><LI -><P ->incapable of capturing fields or frames at the nominal -rate of the video standard, or</P -></LI -><LI -><P ->where <A -HREF="#BUFFER" ->timestamps</A -> refer -to the instant the field or frame was received by the driver, not the -capture time, or</P -></LI -><LI -><P ->where <A -HREF="#BUFFER" ->sequence numbers</A -> -refer to the frames received by the driver, not the captured -frames.</P -></LI -></UL -> Here the driver shall set the -<CODE -CLASS="STRUCTFIELD" ->std</CODE -> field of struct <A -HREF="#V4L2-INPUT" ->v4l2_input</A -> and struct <A -HREF="#V4L2-OUTPUT" ->v4l2_output</A -> -to zero, the <CODE -CLASS="CONSTANT" ->VIDIOC_G_STD</CODE ->, -<CODE -CLASS="CONSTANT" ->VIDIOC_S_STD</CODE ->, -<CODE -CLASS="CONSTANT" ->VIDIOC_QUERYSTD</CODE -> and -<CODE -CLASS="CONSTANT" ->VIDIOC_ENUMSTD</CODE -> ioctls shall return the -<SPAN -CLASS="ERRORCODE" ->EINVAL</SPAN -> error code.<A -NAME="AEN407" -HREF="#FTN.AEN407" -><SPAN -CLASS="footnote" ->[8]</SPAN -></A -></P -><DIV -CLASS="EXAMPLE" -><A -NAME="AEN410" -></A -><P -><B ->Example 1-5. Information about the current video standard</B -></P -><PRE -CLASS="PROGRAMLISTING" -><A -HREF="#V4L2-STD-ID" ->v4l2_std_id</A -> std; -struct <A -HREF="#V4L2-STANDARD" ->v4l2_standard</A -> standard; - -if (-1 == ioctl (fd, <A -HREF="#VIDIOC-G-STD" -><CODE -CLASS="CONSTANT" ->VIDIOC_G_STD</CODE -></A ->, &std)) { - /* Note when VIDIOC_ENUMSTD always returns EINVAL this - is no video device or it falls under the USB exception, - and VIDIOC_G_STD returning EINVAL is no error. */ - - perror ("VIDIOC_G_STD"); - exit (EXIT_FAILURE); -} - -memset (&standard, 0, sizeof (standard)); -standard.index = 0; - -while (0 == ioctl (fd, <A -HREF="#VIDIOC-ENUMSTD" -><CODE -CLASS="CONSTANT" ->VIDIOC_ENUMSTD</CODE -></A ->, &standard)) { - if (standard.id & std) { - printf ("Current video standard: %s\n", standard.name); - exit (EXIT_SUCCESS); - } - - standard.index++; -} - -/* EINVAL indicates the end of the enumeration, which cannot be - empty unless this device falls under the USB exception. */ - -if (errno == EINVAL || standard.index == 0) { - perror ("VIDIOC_ENUMSTD"); - exit (EXIT_FAILURE); -} - </PRE -></DIV -><DIV -CLASS="EXAMPLE" -><A -NAME="AEN419" -></A -><P -><B ->Example 1-6. Listing the video standards supported by the current -input</B -></P -><PRE -CLASS="PROGRAMLISTING" ->struct <A -HREF="#V4L2-INPUT" ->v4l2_input</A -> input; -struct <A -HREF="#V4L2-STANDARD" ->v4l2_standard</A -> standard; - -memset (&input, 0, sizeof (input)); - -if (-1 == ioctl (fd, <A -HREF="#VIDIOC-G-INPUT" -><CODE -CLASS="CONSTANT" ->VIDIOC_G_INPUT</CODE -></A ->, &input.index)) { - perror ("VIDIOC_G_INPUT"); - exit (EXIT_FAILURE); -} - -if (-1 == ioctl (fd, <A -HREF="#VIDIOC-ENUMINPUT" -><CODE -CLASS="CONSTANT" ->VIDIOC_ENUMINPUT</CODE -></A ->, &input)) { - perror ("VIDIOC_ENUM_INPUT"); - exit (EXIT_FAILURE); -} - -printf ("Current input %s supports:\n", input.name); - -memset (&standard, 0, sizeof (standard)); -standard.index = 0; - -while (0 == ioctl (fd, <A -HREF="#VIDIOC-ENUMSTD" -><CODE -CLASS="CONSTANT" ->VIDIOC_ENUMSTD</CODE -></A ->, &standard)) { - if (standard.id & input.std) - printf ("%s\n", standard.name); - - standard.index++; -} - -/* EINVAL indicates the end of the enumeration, which cannot be - empty unless this device falls under the USB exception. */ - -if (errno != EINVAL || standard.index == 0) { - perror ("VIDIOC_ENUMSTD"); - exit (EXIT_FAILURE); -} - </PRE -></DIV -><DIV -CLASS="EXAMPLE" -><A -NAME="AEN430" -></A -><P -><B ->Example 1-7. Selecting a new video standard</B -></P -><PRE -CLASS="PROGRAMLISTING" ->struct <A -HREF="#V4L2-INPUT" ->v4l2_input</A -> input; - -memset (&input, 0, sizeof (input)); - -if (-1 == ioctl (fd, <A -HREF="#VIDIOC-G-INPUT" -><CODE -CLASS="CONSTANT" ->VIDIOC_G_INPUT</CODE -></A ->, &input.index)) { - perror ("VIDIOC_G_INPUT"); - exit (EXIT_FAILURE); -} - -if (-1 == ioctl (fd, <A -HREF="#VIDIOC-ENUMINPUT" -><CODE -CLASS="CONSTANT" ->VIDIOC_ENUMINPUT</CODE -></A ->, &input)) { - perror ("VIDIOC_ENUM_INPUT"); - exit (EXIT_FAILURE); -} - -if (0 == (input.std & V4L2_STD_PAL_BG)) { - fprintf (stderr, "Oops. B/G PAL is not supported.\n"); - exit (EXIT_FAILURE); -} - -/* Note this is also supposed to work when only B - <SPAN -CLASS="emphasis" -><I -CLASS="EMPHASIS" ->or</I -></SPAN -> G/PAL is supported. */ - -if (-1 == ioctl (fd, <A -HREF="#VIDIOC-G-STD" -><CODE -CLASS="CONSTANT" ->VIDIOC_S_STD</CODE -></A ->, V4L2_STD_PAL_BG)) { - perror ("VIDIOC_S_STD"); - exit (EXIT_FAILURE); -} - </PRE -></DIV -></DIV -><DIV -CLASS="SECTION" -><HR><H2 -CLASS="SECTION" -><A -NAME="CONTROL" ->1.8. Controls</A -></H2 -><P ->Devices typically have a number of user-settable controls -such as brightness, saturation and so on, which would be presented to -the user on a graphical user interface. But, different devices -will have different controls available, and furthermore, the range of -possible values, and the default value will vary from device to -device. The control ioctls provide the information and a mechanism to -create a nice user interface for these controls that will work -correctly with any device.</P -><P ->All controls are accessed using an ID value. V4L2 defines -several IDs for specific purposes. Drivers can also implement their -own custom controls using <CODE -CLASS="CONSTANT" ->V4L2_CID_PRIVATE_BASE</CODE -> -and higher values. The pre-defined control IDs have the prefix -<CODE -CLASS="CONSTANT" ->V4L2_CID_</CODE ->, and are listed in <A -HREF="#CONTROL-ID" ->Table 1-1</A ->. The ID is used when querying the attributes of -a control, and when getting or setting the current value.</P -><P ->Generally applications should present controls to the user -without assumptions about their purpose. Each control comes with a -name string the user is supposed to understand. When the purpose is -non-intuitive the driver writer should provide a user manual, a user -interface plug-in or a driver specific panel application. Predefined -IDs were introduced to change a few controls programmatically, for -example to mute a device during a channel switch.</P -><P ->Drivers may enumerate different controls after switching the -current video input or output, tuner or modulator, or audio input or -output. Different in the sense of other bounds, another default and -current value, step size or other menu items. A control with a certain -<SPAN -CLASS="emphasis" -><I -CLASS="EMPHASIS" ->custom</I -></SPAN -> ID can also change name and type.<A -NAME="AEN451" -HREF="#FTN.AEN451" -><SPAN -CLASS="footnote" ->[9]</SPAN -></A -> Control values are stored globally, they do not -change when switching except to stay within the reported bounds. They -also do not change e. g. when the device is opened or closed, when the -tuner radio frequency is changed or generally never without -application request. Since V4L2 specifies no event mechanism, panel -applications intended to cooperate with other panel applications (be -they built into a larger application, as a TV viewer) may need to -regularly poll control values to update their user -interface.<A -NAME="AEN454" -HREF="#FTN.AEN454" -><SPAN -CLASS="footnote" ->[10]</SPAN -></A -></P -><DIV -CLASS="TABLE" -><A -NAME="CONTROL-ID" -></A -><P -><B ->Table 1-1. Control IDs</B -></P -><TABLE -BORDER="0" -FRAME="void" -WIDTH="100%" -CLASS="CALSTABLE" -><COL -WIDTH="38%" -TITLE="C1"><COL -WIDTH="12%" -TITLE="C2"><COL -WIDTH="50%" -TITLE="C3"><THEAD -><TR -><TH ->ID</TH -><TH ->Type</TH -><TH ->Description</TH -></TR -></THEAD -><TBODY -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_CID_BASE</CODE -></TD -><TD -> </TD -><TD ->First predefined ID, equal to -<CODE -CLASS="CONSTANT" ->V4L2_CID_BRIGHTNESS</CODE ->.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_CID_BRIGHTNESS</CODE -></TD -><TD ->integer</TD -><TD ->Picture brightness, or more precisely, the black - level. Will not turn up the intelligence of the program - you're watching.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_CID_CONTRAST</CODE -></TD -><TD ->integer</TD -><TD ->Picture contrast or luma gain.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_CID_SATURATION</CODE -></TD -><TD ->integer</TD -><TD ->Picture color saturation or chroma gain.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_CID_HUE</CODE -></TD -><TD ->integer</TD -><TD ->Hue or color balance.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_CID_AUDIO_VOLUME</CODE -></TD -><TD ->integer</TD -><TD ->Overall audio volume. Note some drivers also -provide an OSS or ALSA mixer interface.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_CID_AUDIO_BALANCE</CODE -></TD -><TD ->integer</TD -><TD ->Audio stereo balance. Minimum corresponds to all -the way left, maximum to right.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_CID_AUDIO_BASS</CODE -></TD -><TD ->integer</TD -><TD ->Audio bass adjustment.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_CID_AUDIO_TREBLE</CODE -></TD -><TD ->integer</TD -><TD ->Audio treble adjustment.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_CID_AUDIO_MUTE</CODE -></TD -><TD ->boolean</TD -><TD ->Mute audio, i. e. set the volume to zero, however -without affecting <CODE -CLASS="CONSTANT" ->V4L2_CID_AUDIO_VOLUME</CODE ->. Like -ALSA drivers, V4L2 drivers must mute at load time to avoid excessive -noise. Actually the entire device should be reset to a low power -consumption state.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_CID_AUDIO_LOUDNESS</CODE -></TD -><TD ->boolean</TD -><TD ->Loudness mode (bass boost).</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_CID_BLACK_LEVEL</CODE -></TD -><TD ->integer</TD -><TD ->Another name for brightness (not a synonym of -<CODE -CLASS="CONSTANT" ->V4L2_CID_BRIGHTNESS</CODE ->). [?]</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_CID_AUTO_WHITE_BALANCE</CODE -></TD -><TD ->boolean</TD -><TD ->Automatic white balance (cameras).</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_CID_DO_WHITE_BALANCE</CODE -></TD -><TD ->button</TD -><TD ->This is an action control. When set (the value is -ignored), the device will do a white balance and then hold the current -setting. Contrast this with the boolean -<CODE -CLASS="CONSTANT" ->V4L2_CID_AUTO_WHITE_BALANCE</CODE ->, which, when -activated, keeps adjusting the white balance.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_CID_RED_BALANCE</CODE -></TD -><TD ->integer</TD -><TD ->Red chroma balance.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_CID_BLUE_BALANCE</CODE -></TD -><TD ->integer</TD -><TD ->Blue chroma balance.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_CID_GAMMA</CODE -></TD -><TD ->integer</TD -><TD ->Gamma adjust.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_CID_WHITENESS</CODE -></TD -><TD ->integer</TD -><TD ->Whiteness for grey-scale devices. This is a synonym -for <CODE -CLASS="CONSTANT" ->V4L2_CID_GAMMA</CODE ->.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_CID_EXPOSURE</CODE -></TD -><TD ->integer</TD -><TD ->Exposure (cameras). [Unit?]</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_CID_AUTOGAIN</CODE -></TD -><TD ->boolean</TD -><TD ->Automatic gain/exposure control.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_CID_GAIN</CODE -></TD -><TD ->integer</TD -><TD ->Gain control.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_CID_HFLIP</CODE -></TD -><TD ->boolean</TD -><TD ->Mirror the picture horizontally.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_CID_VFLIP</CODE -></TD -><TD ->boolean</TD -><TD ->Mirror the picture vertically.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_CID_HCENTER</CODE -></TD -><TD ->integer</TD -><TD ->Horizontal image centering.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_CID_VCENTER</CODE -></TD -><TD ->integer</TD -><TD ->Vertical image centering. Centering is intended to -<SPAN -CLASS="emphasis" -><I -CLASS="EMPHASIS" ->physically</I -></SPAN -> adjust cameras. For image cropping see -<A -HREF="#CROP" ->Section 1.10</A ->, for clipping <A -HREF="#OVERLAY" ->Section 4.2</A ->.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_CID_LASTP1</CODE -></TD -><TD -> </TD -><TD ->End of the predefined control IDs - (currently <CODE -CLASS="CONSTANT" ->V4L2_CID_VCENTER</CODE -> + 1).</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_CID_PRIVATE_BASE</CODE -></TD -><TD -> </TD -><TD ->ID of the first custom (driver specific) control. -Applications depending on particular custom controls should check the -driver name and version, see <A -HREF="#QUERYCAP" ->Section 1.2</A ->.</TD -></TR -></TBODY -></TABLE -></DIV -><P ->Applications can enumerate the available controls with the -<A -HREF="#VIDIOC-QUERYCTRL" -><CODE -CLASS="CONSTANT" ->VIDIOC_QUERYCTRL</CODE -></A -> and <A -HREF="#VIDIOC-QUERYCTRL" -><CODE -CLASS="CONSTANT" ->VIDIOC_QUERYMENU</CODE -></A -> ioctls, get and set a -control value with the <A -HREF="#VIDIOC-G-CTRL" -><CODE -CLASS="CONSTANT" ->VIDIOC_G_CTRL</CODE -></A -> and <A -HREF="#VIDIOC-G-CTRL" -><CODE -CLASS="CONSTANT" ->VIDIOC_S_CTRL</CODE -></A -> ioctls. -Drivers must implement <CODE -CLASS="CONSTANT" ->VIDIOC_QUERYCTRL</CODE ->, -<CODE -CLASS="CONSTANT" ->VIDIOC_G_CTRL</CODE -> and -<CODE -CLASS="CONSTANT" ->VIDIOC_S_CTRL</CODE -> when the device has one or more -controls, <CODE -CLASS="CONSTANT" ->VIDIOC_QUERYMENU</CODE -> when it has one or -more menu type controls.</P -><DIV -CLASS="EXAMPLE" -><A -NAME="AEN630" -></A -><P -><B ->Example 1-8. Enumerating all controls</B -></P -><PRE -CLASS="PROGRAMLISTING" ->struct <A -HREF="#V4L2-QUERYCTRL" ->v4l2_queryctrl</A -> queryctrl; -struct <A -HREF="#V4L2-QUERYMENU" ->v4l2_querymenu</A -> querymenu; - -static void -enumerate_menu (void) -{ - printf (" Menu items:\n"); - - memset (&querymenu, 0, sizeof (querymenu)); - querymenu.id = queryctrl.id; - - for (querymenu.index = queryctrl.minimum; - querymenu.index <= queryctrl.maximum; - querymenu.index++) { - if (0 == ioctl (fd, <A -HREF="#VIDIOC-QUERYCTRL" -><CODE -CLASS="CONSTANT" ->VIDIOC_QUERYMENU</CODE -></A ->, &querymenu)) { - printf (" %s\n", querymenu.name); - } else { - perror ("VIDIOC_QUERYMENU"); - exit (EXIT_FAILURE); - } - } -} - -memset (&queryctrl, 0, sizeof (queryctrl)); - -for (queryctrl.id = V4L2_CID_BASE; - queryctrl.id < V4L2_CID_LASTP1; - queryctrl.id++) { - if (0 == ioctl (fd, <A -HREF="#VIDIOC-QUERYCTRL" -><CODE -CLASS="CONSTANT" ->VIDIOC_QUERYCTRL</CODE -></A ->, &queryctrl)) { - if (queryctrl.flags & V4L2_CTRL_FLAG_DISABLED) - continue; - - printf ("Control %s\n", queryctrl.name); - - if (queryctrl.type == V4L2_CTRL_TYPE_MENU) - enumerate_menu (); - } else { - if (errno == EINVAL) - continue; - - perror ("VIDIOC_QUERYCTRL"); - exit (EXIT_FAILURE); - } -} - -for (queryctrl.id = V4L2_CID_PRIVATE_BASE;; - queryctrl.id++) { - if (0 == ioctl (fd, <A -HREF="#VIDIOC-QUERYCTRL" -><CODE -CLASS="CONSTANT" ->VIDIOC_QUERYCTRL</CODE -></A ->, &queryctrl)) { - if (queryctrl.flags & V4L2_CTRL_FLAG_DISABLED) - continue; - - printf ("Control %s\n", queryctrl.name); - - if (queryctrl.type == V4L2_CTRL_TYPE_MENU) - enumerate_menu (); - } else { - if (errno == EINVAL) - break; - - perror ("VIDIOC_QUERYCTRL"); - exit (EXIT_FAILURE); - } -} - </PRE -></DIV -><DIV -CLASS="EXAMPLE" -><A -NAME="AEN641" -></A -><P -><B ->Example 1-9. Changing controls</B -></P -><PRE -CLASS="PROGRAMLISTING" ->struct <A -HREF="#V4L2-QUERYCTRL" ->v4l2_queryctrl</A -> queryctrl; -struct <A -HREF="#V4L2-CONTROL" ->v4l2_control</A -> control; - -memset (&queryctrl, 0, sizeof (queryctrl)); -queryctrl.id = V4L2_CID_BRIGHTNESS; - -if (-1 == ioctl (fd, <A -HREF="#VIDIOC-QUERYCTRL" -><CODE -CLASS="CONSTANT" ->VIDIOC_QUERYCTRL</CODE -></A ->, &queryctrl)) { - if (errno != EINVAL) { - perror ("VIDIOC_QUERYCTRL"); - exit (EXIT_FAILURE); - } else { - printf ("V4L2_CID_BRIGHTNESS is not supported\n"); - } -} else if (queryctrl.flags & V4L2_CTRL_FLAG_DISABLED) { - printf ("V4L2_CID_BRIGHTNESS is not supported\n"); -} else { - memset (&control, 0, sizeof (control)); - control.id = V4L2_CID_BRIGHTNESS; - control.value = queryctrl.default_value; - - if (-1 == ioctl (fd, <A -HREF="#VIDIOC-G-CTRL" -><CODE -CLASS="CONSTANT" ->VIDIOC_S_CTRL</CODE -></A ->, &control)) { - perror ("VIDIOC_S_CTRL"); - exit (EXIT_FAILURE); - } -} - -memset (&control, 0, sizeof (control)); -control.id = V4L2_CID_CONTRAST; - -if (0 == ioctl (fd, <A -HREF="#VIDIOC-G-CTRL" -><CODE -CLASS="CONSTANT" ->VIDIOC_G_CTRL</CODE -></A ->, &control)) { - control.value += 1; - - /* The driver may clamp the value or return ERANGE, ignored here */ - - if (-1 == ioctl (fd, <A -HREF="#VIDIOC-G-CTRL" -><CODE -CLASS="CONSTANT" ->VIDIOC_S_CTRL</CODE -></A ->, &control) - && errno != ERANGE) { - perror ("VIDIOC_S_CTRL"); - exit (EXIT_FAILURE); - } -/* Ignore if V4L2_CID_CONTRAST is unsupported */ -} else if (errno != EINVAL) { - perror ("VIDIOC_G_CTRL"); - exit (EXIT_FAILURE); -} - -control.id = V4L2_CID_AUDIO_MUTE; -control.value = TRUE; /* silence */ - -/* Errors ignored */ -ioctl (fd, VIDIOC_S_CTRL, &control); - </PRE -></DIV -></DIV -><DIV -CLASS="SECTION" -><HR><H2 -CLASS="SECTION" -><A -NAME="FORMAT" ->1.9. Data Formats</A -></H2 -><DIV -CLASS="SECTION" -><H3 -CLASS="SECTION" -><A -NAME="AEN656" ->1.9.1. Data Format Negotiation</A -></H3 -><P ->Different devices exchange different kinds of data with -applications, for example video images, raw or sliced VBI data, RDS -datagrams. Even within one kind many different formats are possible, -in particular an abundance of image formats. Although drivers must -provide a default and the selection persists across closing and -reopening a device, applications should always negotiate a data format -before engaging in data exchange. Negotiation means the application -asks for a particular format and the driver selects and reports the -best the hardware can do to satisfy the request. Of course -applications can also just query the current selection.</P -><P ->A single mechanism exists to negotiate all data formats -using the aggregate struct <A -HREF="#V4L2-FORMAT" ->v4l2_format</A -> and the <A -HREF="#VIDIOC-G-FMT" -><CODE -CLASS="CONSTANT" ->VIDIOC_G_FMT</CODE -></A -> and -<A -HREF="#VIDIOC-G-FMT" -><CODE -CLASS="CONSTANT" ->VIDIOC_S_FMT</CODE -></A -> ioctls. Additionally the <A -HREF="#VIDIOC-G-FMT" -><CODE -CLASS="CONSTANT" ->VIDIOC_TRY_FMT</CODE -></A -> ioctl can be -used to examine what the hardware <SPAN -CLASS="emphasis" -><I -CLASS="EMPHASIS" ->could</I -></SPAN -> do, -without actually selecting a new data format. The data formats -supported by the V4L2 API are covered in the respective device section -in <A -HREF="#DEVICES" ->Chapter 4</A ->. For a closer look at image formats see -<A -HREF="#PIXFMT" ->Chapter 2</A ->.</P -><P ->The <CODE -CLASS="CONSTANT" ->VIDIOC_S_FMT</CODE -> ioctl is a major -turning-point in the initialization sequence. Prior to this point -multiple panel applications can access the same device concurrently to -select the current input, change controls or modify other properties. -The first <CODE -CLASS="CONSTANT" ->VIDIOC_S_FMT</CODE -> assigns a logical stream -(video data, VBI data etc.) exclusively to one file descriptor.</P -><P ->Exclusive means no other application, more precisely no -other file descriptor, can grab this stream or change device -properties inconsistent with the negotiated parameters. A video -standard change for example, when the new standard uses a different -number of scan lines, can invalidate the selected image format. -Therefore only the file descriptor owning the stream can make -invalidating changes. Accordingly multiple file descriptors which -grabbed different logical streams prevent each other from interfering -with their settings. When for example video overlay is about to start -or already in progress, simultaneous video capturing may be restricted -to the same cropping and image size.</P -><P ->When applications omit the -<CODE -CLASS="CONSTANT" ->VIDIOC_S_FMT</CODE -> ioctl its locking side effects are -implied by the next step, the selection of an I/O method with the -<A -HREF="#VIDIOC-REQBUFS" -><CODE -CLASS="CONSTANT" ->VIDIOC_REQBUFS</CODE -></A -> ioctl or implicit with the first <A -HREF="#FUNC-READ" -><CODE -CLASS="FUNCTION" ->read()</CODE -></A -> or -<A -HREF="#FUNC-WRITE" -><CODE -CLASS="FUNCTION" ->write()</CODE -></A -> call.</P -><P ->Generally only one logical stream can be assigned to a -file descriptor, the exception being drivers permitting simultaneous -video capturing and overlay using the same file descriptor for -compatibility with V4L and earlier versions of V4L2. Switching the -logical stream or returning into "panel mode" is possible by closing -and reopening the device. Drivers <SPAN -CLASS="emphasis" -><I -CLASS="EMPHASIS" ->may</I -></SPAN -> support a -switch using <CODE -CLASS="CONSTANT" ->VIDIOC_S_FMT</CODE ->.</P -><P ->All drivers exchanging data with -applications must support the <CODE -CLASS="CONSTANT" ->VIDIOC_G_FMT</CODE -> and -<CODE -CLASS="CONSTANT" ->VIDIOC_S_FMT</CODE -> ioctl. Implementation of the -<CODE -CLASS="CONSTANT" ->VIDIOC_TRY_FMT</CODE -> is highly recommended but -optional.</P -></DIV -><DIV -CLASS="SECTION" -><HR><H3 -CLASS="SECTION" -><A -NAME="AEN689" ->1.9.2. Image Format Enumeration</A -></H3 -><P ->Apart of the generic format negotiation functions -a special ioctl to enumerate all image formats supported by video -capture, overlay or output devices is available.<A -NAME="AEN692" -HREF="#FTN.AEN692" -><SPAN -CLASS="footnote" ->[11]</SPAN -></A -></P -><P ->The <A -HREF="#VIDIOC-ENUM-FMT" -><CODE -CLASS="CONSTANT" ->VIDIOC_ENUM_FMT</CODE -></A -> ioctl must be supported -by all drivers exchanging image data with applications.</P -><DIV -CLASS="IMPORTANT" -><BLOCKQUOTE -CLASS="IMPORTANT" -><P -><B ->Important: </B ->Drivers are not supposed to convert image formats in -kernel space. They must enumerate only formats directly supported by -the hardware. If necessary driver writers should publish an example -conversion routine or library for integration into applications.</P -></BLOCKQUOTE -></DIV -></DIV -></DIV -><DIV -CLASS="SECTION" -><HR><H2 -CLASS="SECTION" -><A -NAME="CROP" ->1.10. Cropping and Scaling</A -></H2 -><P ->Some video capture devices can take a subsection of the -complete picture and shrink or enlarge to an image of arbitrary size. -We call these abilities cropping and scaling. Not quite correct -"cropping" shall also refer to the inverse process, output devices -showing an image in only a region of the picture, and/or scaled -from a source image of different size.</P -><P ->To crop and scale this API defines a source and target -rectangle. On a video capture and overlay device the source is the -received video picture, the target is the captured or overlaid image. -On a video output device the source is the image passed by the -application and the target is the generated video picture. The -remainder of this section refers only to video capture drivers, the -definitions apply to output drivers accordingly.</P -><DIV -CLASS="FIGURE" -><A -NAME="CROP-SCALE" -></A -><P -><B ->Figure 1-1. Cropping and Scaling</B -></P -><DIV -CLASS="MEDIAOBJECT" -><P -><IMG -SRC="crop.gif"></P -></DIV -></DIV -><P ->It is assumed the driver can capture a subsection of the -picture within an arbitrary capture window. Its bounds are defined by -struct <A -HREF="#V4L2-CROPCAP" ->v4l2_cropcap</A ->, giving the coordinates of the top, left corner and -width and height of the window in pixels. Origin and units of the -coordinate system in the analog domain are arbitrarily chosen by the -driver writer.<A -NAME="AEN714" -HREF="#FTN.AEN714" -><SPAN -CLASS="footnote" ->[12]</SPAN -></A -></P -><P ->The source rectangle is defined by struct <A -HREF="#V4L2-CROP" ->v4l2_crop</A ->, giving the -coordinates of its top, left corner, width and height using the same -coordinate system as struct <A -HREF="#V4L2-CROPCAP" ->v4l2_cropcap</A ->. The source rectangle must lie -completely within the capture window. Further each driver defines a -default source rectangle. The center of this rectangle shall align -with the center of the active picture area of the video signal, and -cover what the driver writer considers the complete picture. The -source rectangle is set to the default when the driver is first -loaded, but not later.</P -><P ->The target rectangle is given either by the -<CODE -CLASS="STRUCTFIELD" ->width</CODE -> and <CODE -CLASS="STRUCTFIELD" ->height</CODE -> -fields of struct <A -HREF="#V4L2-PIX-FORMAT" ->v4l2_pix_format</A -> or the <CODE -CLASS="STRUCTFIELD" ->width</CODE -> -and <CODE -CLASS="STRUCTFIELD" ->height</CODE -> fields of the struct <A -HREF="#V4L2-RECT" ->v4l2_rect</A -> -<CODE -CLASS="STRUCTFIELD" ->w</CODE -> substructure of struct <A -HREF="#V4L2-WINDOW" ->v4l2_window</A ->.</P -><P ->In principle cropping and scaling always happens. When the -device supports scaling but not cropping, applications will be unable -to change the cropping rectangle. It remains at the defaults all the -time. When the device supports cropping but not scaling, changing the -image size will also affect the cropping size in order to maintain a -constant scaling factor. The position of the cropping rectangle is -only adjusted to move the rectangle completely inside the capture -window.</P -><P ->When cropping and scaling is supported applications can -change both the source and target rectangle. Various hardware -limitations must be expected, for example discrete scaling factors, -different scaling abilities in horizontal and vertical direction, -limitations of the image size or the cropping alignment. Therefore as -usual drivers adjust the requested parameters against hardware -capabilities and return the actual values selected. An important -difference, because two rectangles are defined, is that the last -rectangle changed shall take priority, and the driver may also adjust -the opposite rectangle.</P -><P ->Suppose scaling is restricted to a factor 1:1 or 2:1 in -either direction and the image size must be a multiple of -16 × 16 pixels. The cropping rectangle be set to the -upper limit, 640 × 400 pixels at offset 0, 0. Let -a video capture application request an image size of -300 × 225 pixels, assuming video will be scaled down -from the "full picture" accordingly. The driver will set the image -size to the closest possible values 304 × 224, then -choose the cropping rectangle closest to the requested size, that is -608 × 224 (224 × 2:1 would exceed the -limit 400). The offset 0, 0 is still valid, thus unmodified. -Given the default cropping rectangle reported by -<CODE -CLASS="CONSTANT" ->VIDIOC_CROPCAP</CODE -> the application can easily propose -another offset to center the cropping rectangle. Now the application may -insist on covering an area using an aspect closer to the original -request. Sheepish it asks for a cropping rectangle of -608 × 456 pixels. The present scaling factors limit -cropping to 640 × 384, so the driver returns the -cropping size 608 × 384 and accordingly adjusts -the image size to 304 × 192.</P -><P ->Eventually some crop or scale parameters are locked, for -example when the driver supports simultaneous video capturing and -overlay, another application already started overlay and the cropping -parameters cannot be changed anymore. Also <A -HREF="#VIDIOC-G-FMT" -><CODE -CLASS="CONSTANT" ->VIDIOC_TRY_FMT</CODE -></A -> cannot -change the cropping rectangle. In these cases the driver has to -approach the closest values possible without adjusting the opposite -rectangle.</P -><P ->The struct <A -HREF="#V4L2-CROPCAP" ->v4l2_cropcap</A ->, which also reports the pixel aspect ratio, -can be obtained with the <A -HREF="#VIDIOC-CROPCAP" -><CODE -CLASS="CONSTANT" ->VIDIOC_CROPCAP</CODE -></A -> ioctl. To get or set the -current cropping rectangle applications call the <A -HREF="#VIDIOC-G-CROP" -><CODE -CLASS="CONSTANT" ->VIDIOC_G_CROP</CODE -></A -> or -<A -HREF="#VIDIOC-G-CROP" -><CODE -CLASS="CONSTANT" ->VIDIOC_S_CROP</CODE -></A -> ioctl, respectively. All video capture and output -devices must support the <CODE -CLASS="CONSTANT" ->VIDIOC_CROPCAP</CODE -> ioctl. -The <CODE -CLASS="CONSTANT" ->VIDIOC_G_CROP</CODE -> and -<CODE -CLASS="CONSTANT" ->VIDIOC_S_CROP</CODE -> ioctls only when the cropping -rectangle can be changed.</P -><P ->Note as usual the cropping parameters remain unchanged -across closing and reopening a device. Applications should ensure the -parameters are suitable before starting I/O.</P -><DIV -CLASS="EXAMPLE" -><A -NAME="AEN747" -></A -><P -><B ->Example 1-10. Resetting the cropping parameters</B -></P -><P ->(A video capture device is assumed.)</P -><PRE -CLASS="PROGRAMLISTING" ->struct <A -HREF="#V4L2-CROPCAP" ->v4l2_cropcap</A -> cropcap; -struct <A -HREF="#V4L2-CROP" ->v4l2_crop</A -> crop; - -memset (&cropcap, 0, sizeof (cropcap)); -cropcap.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - -if (-1 == ioctl (fd, <A -HREF="#VIDIOC-CROPCAP" -><CODE -CLASS="CONSTANT" ->VIDIOC_CROPCAP</CODE -></A ->, &cropcap)) { - perror ("VIDIOC_CROPCAP"); - exit (EXIT_FAILURE); -} - -memset (&crop, 0, sizeof (crop)); -crop.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; -crop.c = cropcap.defrect; - -/* Ignore if cropping is not supported (EINVAL) */ - -if (-1 == ioctl (fd, <A -HREF="#VIDIOC-G-CROP" -><CODE -CLASS="CONSTANT" ->VIDIOC_S_CROP</CODE -></A ->, &crop) - && errno != EINVAL) { - perror ("VIDIOC_S_CROP"); - exit (EXIT_FAILURE); -} - </PRE -></DIV -><DIV -CLASS="EXAMPLE" -><A -NAME="AEN757" -></A -><P -><B ->Example 1-11. Simple downscaling</B -></P -><P ->(A video capture device is assumed.)</P -><PRE -CLASS="PROGRAMLISTING" ->struct <A -HREF="#V4L2-CROPCAP" ->v4l2_cropcap</A -> cropcap; -struct <A -HREF="#V4L2-FORMAT" ->v4l2_format</A -> format; - -reset_cropping_parameters (); - -/* Scale down to 1/4 size of full picture */ - -memset (&format, 0, sizeof (format)); /* defaults */ - -format.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - -format.fmt.pix.width = cropcap.defrect.width >> 1; -format.fmt.pix.height = cropcap.defrect.height >> 1; -format.fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV; - -if (-1 == ioctl (fd, <A -HREF="#VIDIOC-G-FMT" -><CODE -CLASS="CONSTANT" ->VIDIOC_S_FMT</CODE -></A ->, &format)) { - perror ("VIDIOC_S_FORMAT"); - exit (EXIT_FAILURE); -} - -/* We could check now what we got, the exact scaling factor - or if the driver can scale at all. At mere 2:1 the cropping - rectangle was probably not changed. */ - </PRE -></DIV -><DIV -CLASS="EXAMPLE" -><A -NAME="AEN765" -></A -><P -><B ->Example 1-12. Current scaling factor and pixel aspect</B -></P -><P ->(A video capture device is assumed.)</P -><PRE -CLASS="PROGRAMLISTING" ->struct <A -HREF="#V4L2-CROPCAP" ->v4l2_cropcap</A -> cropcap; -struct <A -HREF="#V4L2-CROP" ->v4l2_crop</A -> crop; -struct <A -HREF="#V4L2-FORMAT" ->v4l2_format</A -> format; -double hscale, vscale; -double aspect; -int dwidth, dheight; - -memset (&cropcap, 0, sizeof (cropcap)); -cropcap.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - -if (-1 == ioctl (fd, <A -HREF="#VIDIOC-CROPCAP" -><CODE -CLASS="CONSTANT" ->VIDIOC_CROPCAP</CODE -></A ->, &cropcap)) { - perror ("VIDIOC_CROPCAP"); - exit (EXIT_FAILURE); -} - -memset (&crop, 0, sizeof (crop)); -crop.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - -if (-1 == ioctl (fd, <A -HREF="#VIDIOC-G-CROP" -><CODE -CLASS="CONSTANT" ->VIDIOC_G_CROP</CODE -></A ->, &crop)) { - if (errno != EINVAL) { - perror ("VIDIOC_G_CROP"); - exit (EXIT_FAILURE); - } - - /* Cropping not supported */ - crop.c = cropcap.defrect; -} - -memset (&format, 0, sizeof (format)); -format.fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - -if (-1 == ioctl (fd, <A -HREF="#VIDIOC-G-FMT" -><CODE -CLASS="CONSTANT" ->VIDIOC_G_FMT</CODE -></A ->, &format)) { - perror ("VIDIOC_G_FMT"); - exit (EXIT_FAILURE); -} - -hscale = format.fmt.pix.width / (double) crop.c.width; -vscale = format.fmt.pix.height / (double) crop.c.height; - -aspect = cropcap.pixelaspect.numerator / - (double) cropcap.pixelaspect.denominator; -aspect = aspect * hscale / vscale; - -/* Aspect corrected display size */ - -dwidth = format.fmt.pix.width / aspect; -dheight = format.fmt.pix.height; - </PRE -></DIV -></DIV -><DIV -CLASS="SECTION" -><HR><H2 -CLASS="SECTION" -><A -NAME="STREAMING-PAR" ->1.11. Streaming Parameters</A -></H2 -><P ->Streaming parameters are intended to optimize the video -capture process as well as I/O. Presently applications can request a -high quality capture mode with the <A -HREF="#VIDIOC-G-PARM" -><CODE -CLASS="CONSTANT" ->VIDIOC_S_PARM</CODE -></A -> ioctl.</P -><P ->The current video standard determines a nominal number of -frames per second. If less than this number of frames is to be -captured or output, applications can request frame skipping or -duplicating on the driver side. This is espcially useful when using -the <CODE -CLASS="FUNCTION" ->read()</CODE -> or <CODE -CLASS="FUNCTION" ->write()</CODE ->, which -are not augmented by timestamps or sequence counters, and to avoid -uneccessary data copying.</P -><P ->Finally these ioctls can be used to determine the number of -buffers used internally by a driver in read/write mode. For -implications see the section discussing the <A -HREF="#FUNC-READ" -><CODE -CLASS="FUNCTION" ->read()</CODE -></A -> -function.</P -><P ->To get and set the streaming parameters applications call -the <A -HREF="#VIDIOC-G-PARM" -><CODE -CLASS="CONSTANT" ->VIDIOC_G_PARM</CODE -></A -> and <A -HREF="#VIDIOC-G-PARM" -><CODE -CLASS="CONSTANT" ->VIDIOC_S_PARM</CODE -></A -> ioctl, respectively. They take -a pointer to a struct <A -HREF="#V4L2-STREAMPARM" ->v4l2_streamparm</A ->, which contains a union holding -separate parameters for input and output devices.</P -><P ->These ioctls are optional, drivers need not implement -them. If so, they return the <SPAN -CLASS="ERRORCODE" ->EINVAL</SPAN -> error code.</P -></DIV -></DIV -><DIV -CLASS="CHAPTER" -><HR><H1 -><A -NAME="PIXFMT" -></A ->Chapter 2. Image Formats</H1 -><P ->The V4L2 API was primarily designed for devices exchanging -image data with applications. The -<CODE -CLASS="STRUCTNAME" ->v4l2_pix_format</CODE -> structure defines the format -and layout of an image in memory. Image formats are negotiated with -the <A -HREF="#VIDIOC-G-FMT" -><CODE -CLASS="CONSTANT" ->VIDIOC_S_FMT</CODE -></A -> ioctl. (The explanations here focus on video -capturing and output, for overlay frame buffer formats see also -<A -HREF="#VIDIOC-G-FBUF" -><CODE -CLASS="CONSTANT" ->VIDIOC_G_FBUF</CODE -></A ->.)</P -><DIV -CLASS="TABLE" -><A -NAME="V4L2-PIX-FORMAT" -></A -><P -><B ->Table 2-1. struct <CODE -CLASS="STRUCTNAME" ->v4l2_pix_format</CODE -></B -></P -><TABLE -BORDER="0" -FRAME="void" -WIDTH="100%" -CLASS="CALSTABLE" -><COL -WIDTH="25%" -TITLE="C1"><COL -WIDTH="25%" -TITLE="C2"><COL -WIDTH="50%" -TITLE="C3"><TBODY -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->width</CODE -></TD -><TD ->Image width in pixels.</TD -></TR -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->height</CODE -></TD -><TD ->Image height in pixels.</TD -></TR -><TR -><TD -COLSPAN="3" ->Applications set these fields to -request an image size, drivers return the closest possible values. In -case of planar formats the <CODE -CLASS="STRUCTFIELD" ->width</CODE -> and -<CODE -CLASS="STRUCTFIELD" ->height</CODE -> applies to the largest plane. To -avoid ambiguities drivers must return values rounded up to a multiple -of the scale factor of any smaller planes. For example when the image -format is YUV 4:2:0, <CODE -CLASS="STRUCTFIELD" ->width</CODE -> and -<CODE -CLASS="STRUCTFIELD" ->height</CODE -> must be multiples of two.</TD -></TR -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->pixelformat</CODE -></TD -><TD ->The pixel format or type of compression, set by the -application. This is a little endian <A -HREF="#V4L2-FOURCC" ->four character code</A ->. V4L2 defines -standard RGB formats in <A -HREF="#RGB-FORMATS" ->Table 2-3</A ->, YUV formats in <A -HREF="#YUV-FORMATS" ->Section 2.4</A ->, and reserved codes in <A -HREF="#RESERVED-FORMATS" ->Table 2-4</A -></TD -></TR -><TR -><TD ->enum <A -HREF="#V4L2-FIELD" ->v4l2_field</A -></TD -><TD -><CODE -CLASS="STRUCTFIELD" ->field</CODE -></TD -><TD ->Video images are typically interlaced. Applications -can request to capture or output only the top or bottom field, or both -fields interlaced or sequentially stored in one buffer or alternating -in separate buffers. Drivers return the actual field order selected. -For details see <A -HREF="#FIELD-ORDER" ->Section 3.6</A ->.</TD -></TR -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->bytesperline</CODE -></TD -><TD ->Distance in bytes between the leftmost pixels in two -adjacent lines.</TD -></TR -><TR -><TD -COLSPAN="3" -><P ->Both applications and drivers -can set this field to request padding bytes at the end of each line. -Drivers however may ignore the value requested by the application, -returning <CODE -CLASS="STRUCTFIELD" ->width</CODE -> times bytes per pixel or a -larger value required by the hardware. That implies applications can -just set this field to zero to get a reasonable -default.</P -><P ->Video hardware may access padding bytes, -therefore they must reside in accessible memory. Consider cases where -padding bytes after the last line of an image cross a system page -boundary. Input devices may write padding bytes, the value is -undefined. Output devices ignore the contents of padding -bytes.</P -><P ->When the image format is planar the -<CODE -CLASS="STRUCTFIELD" ->bytesperline</CODE -> value applies to the largest -plane and is divided by the same factor as the -<CODE -CLASS="STRUCTFIELD" ->width</CODE -> field for any smaller planes. For -example the Cb and Cr planes of a YUV 4:2:0 image have half as many -padding bytes following each line as the Y plane. To avoid ambiguities -drivers must return a <CODE -CLASS="STRUCTFIELD" ->bytesperline</CODE -> value -rounded up to a multiple of the scale factor.</P -></TD -></TR -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->sizeimage</CODE -></TD -><TD ->Size in bytes of the buffer to hold a complete image, -set by the driver. Usually this is -<CODE -CLASS="STRUCTFIELD" ->bytesperline</CODE -> times -<CODE -CLASS="STRUCTFIELD" ->height</CODE ->. When the image consists of variable -length compressed data this is the maximum number of bytes required to -hold an image.</TD -></TR -><TR -><TD ->enum <A -HREF="#V4L2-COLORSPACE" ->v4l2_colorspace</A -></TD -><TD -><CODE -CLASS="STRUCTFIELD" ->colorspace</CODE -></TD -><TD ->This information supplements the -<CODE -CLASS="STRUCTFIELD" ->pixelformat</CODE -> and must be set by the driver, -see <A -HREF="#COLORSPACES" ->Section 2.2</A ->.</TD -></TR -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->priv</CODE -></TD -><TD ->Reserved for custom (driver defined) additional -information about formats. When not used drivers and applications must -set this field to zero.</TD -></TR -></TBODY -></TABLE -></DIV -><DIV -CLASS="SECTION" -><HR><H2 -CLASS="SECTION" -><A -NAME="AEN880" ->2.1. Standard Image Formats</A -></H2 -><P ->In order to exchange images between drivers and -applications, it is necessary to have standard image data formats -which both sides will interpret the same way. V4L2 includes several -such formats, and this section is intended to be an unambiguous -specification of the standard image data formats in V4L2.</P -><P ->V4L2 drivers are not limited to these formats, however. -Driver-specific formats are possible. In that case the application may -depend on a codec to convert images to one of the standard formats -when needed. But the data can still be stored and retrieved in the -proprietary format. For example, a device may support a proprietary -compressed format. Applications can still capture and save the data in -the compressed format, saving much disk space, and later use a codec -to convert the images to the X Windows screen format when the video is -to be displayed.</P -><P ->Even so, ultimately, some standard formats are needed, so -the V4L2 specification would not be complete without well-defined -standard formats.</P -><P ->The V4L2 standard formats are mainly uncompressed formats. The -pixels are always arranged in memory from left to right, and from top -to bottom. The first byte of data in the image buffer is always for -the leftmost pixel of the topmost row. Following that is the pixel -immediately to its right, and so on until the end of the top row of -pixels. Following the rightmost pixel of the row there may be zero or -more bytes of padding to guarantee that each row of pixel data has a -certain alignment. Following the pad bytes, if any, is data for the -leftmost pixel of the second row from the top, and so on. The last row -has just as many pad bytes after it as the other rows.</P -><P ->In V4L2 each format has an identifier which looks like -<CODE -CLASS="CONSTANT" ->PIX_FMT_XXX</CODE ->, defined in the <A -HREF="#VIDEODEV" ->videodev.h</A -> header file. These identifiers -represent <A -HREF="#V4L2-FOURCC" ->four character codes</A -> -which are also listed below, however they are not the same as those -used in the Windows world.</P -></DIV -><DIV -CLASS="SECTION" -><HR><H2 -CLASS="SECTION" -><A -NAME="COLORSPACES" ->2.2. Colorspaces</A -></H2 -><P ->[intro]</P -><P -> <P -></P -><DIV -CLASS="VARIABLELIST" -><DL -><DT ->Gamma Correction</DT -><DD -><P ->[to do]</P -><P ->E'<SUB ->R</SUB -> = f(R)</P -><P ->E'<SUB ->G</SUB -> = f(G)</P -><P ->E'<SUB ->B</SUB -> = f(B)</P -></DD -><DT ->Construction of luminance and color-difference -signals</DT -><DD -><P ->[to do]</P -><P ->E'<SUB ->Y</SUB -> = -Coeff<SUB ->R</SUB -> E'<SUB ->R</SUB -> -+ Coeff<SUB ->G</SUB -> E'<SUB ->G</SUB -> -+ Coeff<SUB ->B</SUB -> E'<SUB ->B</SUB -></P -><P ->(E'<SUB ->R</SUB -> - E'<SUB ->Y</SUB ->) = E'<SUB ->R</SUB -> -- Coeff<SUB ->R</SUB -> E'<SUB ->R</SUB -> -- Coeff<SUB ->G</SUB -> E'<SUB ->G</SUB -> -- Coeff<SUB ->B</SUB -> E'<SUB ->B</SUB -></P -><P ->(E'<SUB ->B</SUB -> - E'<SUB ->Y</SUB ->) = E'<SUB ->B</SUB -> -- Coeff<SUB ->R</SUB -> E'<SUB ->R</SUB -> -- Coeff<SUB ->G</SUB -> E'<SUB ->G</SUB -> -- Coeff<SUB ->B</SUB -> E'<SUB ->B</SUB -></P -></DD -><DT ->Re-normalized color-difference signals</DT -><DD -><P ->The color-difference signals are scaled back to unity -range [-0.5;+0.5]:</P -><P ->K<SUB ->B</SUB -> = 0.5 / (1 - Coeff<SUB ->B</SUB ->)</P -><P ->K<SUB ->R</SUB -> = 0.5 / (1 - Coeff<SUB ->R</SUB ->)</P -><P ->P<SUB ->B</SUB -> = -K<SUB ->B</SUB -> (E'<SUB ->B</SUB -> - E'<SUB ->Y</SUB ->) = - 0.5 (Coeff<SUB ->R</SUB -> / Coeff<SUB ->B</SUB ->) E'<SUB ->R</SUB -> -+ 0.5 (Coeff<SUB ->G</SUB -> / Coeff<SUB ->B</SUB ->) E'<SUB ->G</SUB -> -+ 0.5 E'<SUB ->B</SUB -></P -><P ->P<SUB ->R</SUB -> = -K<SUB ->R</SUB -> (E'<SUB ->R</SUB -> - E'<SUB ->Y</SUB ->) = - 0.5 E'<SUB ->R</SUB -> -+ 0.5 (Coeff<SUB ->G</SUB -> / Coeff<SUB ->R</SUB ->) E'<SUB ->G</SUB -> -+ 0.5 (Coeff<SUB ->B</SUB -> / Coeff<SUB ->R</SUB ->) E'<SUB ->B</SUB -></P -></DD -><DT ->Quantization</DT -><DD -><P ->[to do]</P -><P ->Y' = (Lum. Levels - 1) · E'<SUB ->Y</SUB -> + Lum. Offset</P -><P ->C<SUB ->B</SUB -> = (Chrom. Levels - 1) -· P<SUB ->B</SUB -> + Chrom. Offset</P -><P ->C<SUB ->R</SUB -> = (Chrom. Levels - 1) -· P<SUB ->R</SUB -> + Chrom. Offset</P -><P ->Rounding to the nearest integer and clamping to the range -[0;255] finally yields the digital color components Y'CbCr -stored in YUV images.</P -></DD -></DL -></DIV -> - </P -><DIV -CLASS="EXAMPLE" -><A -NAME="AEN984" -></A -><P -><B ->Example 2-1. ITU-R Rec. BT.601 color conversion</B -></P -><P ->Forward Transformation</P -><PRE -CLASS="PROGRAMLISTING" ->int ER, EG, EB; /* gamma corrected RGB input [0;255] */ -int Y1, Cb, Cr; /* output [0;255] */ - -double r, g, b; /* temporaries */ -double y1, pb, pr; - -int -clamp (double x) -{ - int r = x; /* round to nearest */ - - if (r < 0) return 0; - else if (r > 255) return 255; - else return r; -} - -r = ER / 255.0; -g = EG / 255.0; -b = EB / 255.0; - -y1 = 0.299 * r + 0.587 * g + 0.114 * b; -pb = -0.169 * r - 0.331 * g + 0.5 * b; -pr = 0.5 * r - 0.419 * g - 0.081 * b; - -Y1 = clamp (219 * y1 + 16); -Cb = clamp (224 * pb + 128); -Cr = clamp (224 * pr + 128); - -/* or shorter */ - -y1 = 0.299 * ER + 0.587 * EG + 0.114 * EB; - -Y1 = clamp ( (219 / 255.0) * y1 + 16); -Cb = clamp (((224 / 255.0) / (2 - 2 * 0.114)) * (EB - y1) + 128); -Cr = clamp (((224 / 255.0) / (2 - 2 * 0.299)) * (ER - y1) + 128); - </PRE -><P ->Inverse Transformation</P -><PRE -CLASS="PROGRAMLISTING" ->int Y1, Cb, Cr; /* gamma pre-corrected input [0;255] */ -int ER, EG, EB; /* output [0;255] */ - -double r, g, b; /* temporaries */ -double y1, pb, pr; - -int -clamp (double x) -{ - int r = x; /* round to nearest */ - - if (r < 0) return 0; - else if (r > 255) return 255; - else return r; -} - -y1 = (255 / 219.0) * (Y1 - 16); -pb = (255 / 224.0) * (Cb - 128); -pr = (255 / 224.0) * (Cr - 128); - -r = 1.0 * y1 + 0 * pb + 1.402 * pr; -g = 1.0 * y1 - 0.344 * pb - 0.714 * pr; -b = 1.0 * y1 + 1.772 * pb + 0 * pr; - -ER = clamp (r * 255); /* [ok? one should prob. limit y1,pb,pr] */ -EG = clamp (g * 255); -EB = clamp (b * 255); - </PRE -></DIV -><DIV -CLASS="TABLE" -><A -NAME="V4L2-COLORSPACE" -></A -><P -><B ->Table 2-2. enum v4l2_colorspace</B -></P -><TABLE -BORDER="1" -WIDTH="100%" -CLASS="CALSTABLE" -><COL -WIDTH="9%" -ALIGN="LEFT"><COL -WIDTH="9%" -ALIGN="CENTER"><COL -WIDTH="9%" -ALIGN="LEFT"><COL -WIDTH="9%" -TITLE="CR"><COL -WIDTH="9%" -TITLE="CG"><COL -WIDTH="9%" -TITLE="CB"><COL -WIDTH="9%" -TITLE="WP"><COL -WIDTH="9%" -TITLE="GC"><COL -WIDTH="9%" -TITLE="LUM"><COL -WIDTH="9%" -TITLE="QY"><COL -WIDTH="9%" -TITLE="QC"><THEAD -><TR -><TH -ROWSPAN="2" ->Identifier</TH -><TH -ROWSPAN="2" ->Value</TH -><TH -ROWSPAN="2" ->Description</TH -><TH -COLSPAN="3" ->Chromaticities<A -NAME="AEN1013" -HREF="#FTN.AEN1013" -><SPAN -CLASS="footnote" ->[a]</SPAN -></A -></TH -><TH -ROWSPAN="2" ->White Point</TH -><TH -ROWSPAN="2" ->Gamma Correction</TH -><TH -ROWSPAN="2" ->Luminance E'<SUB ->Y</SUB -></TH -><TH -COLSPAN="2" ->Quantization</TH -></TR -><TR -><TH ->Red</TH -><TH ->Green</TH -><TH ->Blue</TH -><TH ->Y'</TH -><TH ->Cb, Cr</TH -></TR -></THEAD -><TBODY -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_COLORSPACE_SMPTE170M</CODE -></TD -><TD ->1</TD -><TD ->NTSC/PAL according to <A -HREF="#SMPTE170M" -><ABBR -CLASS="ABBREV" ->SMPTE170M</ABBR -></A ->, -<A -HREF="#ITU601" -><ABBR -CLASS="ABBREV" ->ITU601</ABBR -></A -></TD -><TD ->x = 0.630, y = 0.340</TD -><TD ->x = 0.310, y = 0.595</TD -><TD ->x = 0.155, y = 0.070</TD -><TD ->x = 0.3127, y = 0.3290, - Illuminant D<SUB ->65</SUB -></TD -><TD ->E' = 4.5 I for I ≤0.018, -1.099 I<SUP ->0.45</SUP -> - 0.099 for 0.018 < I</TD -><TD ->0.299 E'<SUB ->R</SUB -> -+ 0.587 E'<SUB ->G</SUB -> -+ 0.114 E'<SUB ->B</SUB -></TD -><TD ->219 E'<SUB ->Y</SUB -> + 16</TD -><TD ->224 P<SUB ->B,R</SUB -> + 128</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_COLORSPACE_SMPTE240M</CODE -></TD -><TD ->2</TD -><TD ->1125-Line (US) HDTV, see <A -HREF="#SMPTE240M" -><ABBR -CLASS="ABBREV" ->SMPTE240M</ABBR -></A -></TD -><TD ->x = 0.630, y = 0.340</TD -><TD ->x = 0.310, y = 0.595</TD -><TD ->x = 0.155, y = 0.070</TD -><TD ->x = 0.3127, y = 0.3290, - Illuminant D<SUB ->65</SUB -></TD -><TD ->E' = 4 I for I ≤0.0228, -1.1115 I<SUP ->0.45</SUP -> - 0.1115 for 0.0228 < I</TD -><TD ->0.212 E'<SUB ->R</SUB -> -+ 0.701 E'<SUB ->G</SUB -> -+ 0.087 E'<SUB ->B</SUB -></TD -><TD ->219 E'<SUB ->Y</SUB -> + 16</TD -><TD ->224 P<SUB ->B,R</SUB -> + 128</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_COLORSPACE_REC709</CODE -></TD -><TD ->3</TD -><TD ->HDTV and modern devices, see <A -HREF="#ITU709" -><ABBR -CLASS="ABBREV" ->ITU709</ABBR -></A -></TD -><TD ->x = 0.640, y = 0.330</TD -><TD ->x = 0.300, y = 0.600</TD -><TD ->x = 0.150, y = 0.060</TD -><TD ->x = 0.3127, y = 0.3290, - Illuminant D<SUB ->65</SUB -></TD -><TD ->E' = 4.5 I for I ≤0.018, -1.099 I<SUP ->0.45</SUP -> - 0.099 for 0.018 < I</TD -><TD ->0.2125 E'<SUB ->R</SUB -> -+ 0.7154 E'<SUB ->G</SUB -> -+ 0.0721 E'<SUB ->B</SUB -></TD -><TD ->219 E'<SUB ->Y</SUB -> + 16</TD -><TD ->224 P<SUB ->B,R</SUB -> + 128</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_COLORSPACE_BT878</CODE -></TD -><TD ->4</TD -><TD ->Broken Bt878 extents<A -NAME="AEN1096" -HREF="#FTN.AEN1096" -><SPAN -CLASS="footnote" ->[b]</SPAN -></A ->, <A -HREF="#ITU601" -><ABBR -CLASS="ABBREV" ->ITU601</ABBR -></A -></TD -><TD ->?</TD -><TD ->?</TD -><TD ->?</TD -><TD ->?</TD -><TD ->?</TD -><TD ->0.299 E'<SUB ->R</SUB -> -+ 0.587 E'<SUB ->G</SUB -> -+ 0.114 E'<SUB ->B</SUB -></TD -><TD -><SPAN -CLASS="emphasis" -><I -CLASS="EMPHASIS" ->237</I -></SPAN -> E'<SUB ->Y</SUB -> + 16</TD -><TD ->224 P<SUB ->B,R</SUB -> + 128 (probably)</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_COLORSPACE_470_SYSTEM_M</CODE -></TD -><TD ->5</TD -><TD ->M/NTSC<A -NAME="AEN1119" -HREF="#FTN.AEN1119" -><SPAN -CLASS="footnote" ->[c]</SPAN -></A -> according to <A -HREF="#ITU470" -><ABBR -CLASS="ABBREV" ->ITU470</ABBR -></A ->, <A -HREF="#ITU601" -><ABBR -CLASS="ABBREV" ->ITU601</ABBR -></A -></TD -><TD ->x = 0.67, y = 0.33</TD -><TD ->x = 0.21, y = 0.71</TD -><TD ->x = 0.14, y = 0.08</TD -><TD ->x = 0.310, y = 0.316, Illuminant C</TD -><TD ->?</TD -><TD ->0.299 E'<SUB ->R</SUB -> -+ 0.587 E'<SUB ->G</SUB -> -+ 0.114 E'<SUB ->B</SUB -></TD -><TD ->219 E'<SUB ->Y</SUB -> + 16</TD -><TD ->224 P<SUB ->B,R</SUB -> + 128</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_COLORSPACE_470_SYSTEM_BG</CODE -></TD -><TD ->6</TD -><TD ->625-line PAL and SECAM systems according to <A -HREF="#ITU470" -><ABBR -CLASS="ABBREV" ->ITU470</ABBR -></A ->, <A -HREF="#ITU601" -><ABBR -CLASS="ABBREV" ->ITU601</ABBR -></A -></TD -><TD ->x = 0.64, y = 0.33</TD -><TD ->x = 0.29, y = 0.60</TD -><TD ->x = 0.15, y = 0.06</TD -><TD ->x = 0.313, y = 0.329, -Illuminant D<SUB ->65</SUB -></TD -><TD ->?</TD -><TD ->0.299 E'<SUB ->R</SUB -> -+ 0.587 E'<SUB ->G</SUB -> -+ 0.114 E'<SUB ->B</SUB -></TD -><TD ->219 E'<SUB ->Y</SUB -> + 16</TD -><TD ->224 P<SUB ->B,R</SUB -> + 128</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_COLORSPACE_JPEG</CODE -></TD -><TD ->7</TD -><TD ->JPEG Y'CbCr, see <A -HREF="#JFIF" -><ABBR -CLASS="ABBREV" ->JFIF</ABBR -></A ->, <A -HREF="#ITU601" -><ABBR -CLASS="ABBREV" ->ITU601</ABBR -></A -></TD -><TD ->?</TD -><TD ->?</TD -><TD ->?</TD -><TD ->?</TD -><TD ->?</TD -><TD ->0.299 E'<SUB ->R</SUB -> -+ 0.587 E'<SUB ->G</SUB -> -+ 0.114 E'<SUB ->B</SUB -></TD -><TD ->256 E'<SUB ->Y</SUB -> + 16<A -NAME="AEN1175" -HREF="#FTN.AEN1175" -><SPAN -CLASS="footnote" ->[d]</SPAN -></A -></TD -><TD ->256 P<SUB ->B,R</SUB -> + 128</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_COLORSPACE_SRGB</CODE -></TD -><TD ->8</TD -><TD ->[?]</TD -><TD ->x = 0.640, y = 0.330</TD -><TD ->x = 0.300, y = 0.600</TD -><TD ->x = 0.150, y = 0.060</TD -><TD ->x = 0.3127, y = 0.3290, - Illuminant D<SUB ->65</SUB -></TD -><TD ->E' = 4.5 I for I ≤0.018, -1.099 I<SUP ->0.45</SUP -> - 0.099 for 0.018 < I</TD -><TD -COLSPAN="3" ->n/a</TD -></TR -></TBODY -><TR -><TD -COLSPAN="11" ->Notes:<BR><A -NAME="FTN.AEN1013" ->a. </A ->The coordinates of the color primaries are -given in the CIE system (1931)<BR><A -NAME="FTN.AEN1096" ->b. </A ->The ubiquitous Bt878 video capture chip -quantizes E'<SUB ->Y</SUB -> to 238 levels, yielding a range -of Y' = 16 … 253, unlike Rec. 601 Y' = 16 … -235. This is not a typo in the Bt878 documentation, it has been -implemented in silicon. The chroma extents are unclear.<BR><A -NAME="FTN.AEN1119" ->c. </A ->No identifier exists for M/PAL which uses -the chromaticities of M/NTSC, the remaining parameters are equal to B and -G/PAL.<BR><A -NAME="FTN.AEN1175" ->d. </A ->Note JFIF quantizes -Y'P<SUB ->B</SUB ->P<SUB ->R</SUB -> in range [0;+1] and -[-0.5;+0.5] to <SPAN -CLASS="emphasis" -><I -CLASS="EMPHASIS" ->257</I -></SPAN -> levels, however Y'CbCr signals -are still clamped to [0;255].<BR></TD -></TR -></TABLE -></DIV -></DIV -><DIV -CLASS="SECTION" -><HR><H2 -CLASS="SECTION" -><A -NAME="PIXFMT-RGB" ->2.3. RGB Formats</A -></H2 -><P ->These formats are designed to match the pixel formats of -typical PC graphics frame buffers. They occupy 8, 16, 24 or 32 bits -per pixel. These are all packed-pixel formats, meaning all the data -for a pixel lie next to each other in memory.</P -><P ->When one of these formats is used, drivers shall report the -colorspace <CODE -CLASS="CONSTANT" ->V4L2_COLORSPACE_SRGB</CODE ->.</P -><DIV -CLASS="TABLE" -><A -NAME="RGB-FORMATS" -></A -><P -><B ->Table 2-3. Packed RGB Image Formats</B -></P -><TABLE -BORDER="0" -FRAME="void" -WIDTH="100%" -CLASS="CALSTABLE" -><COL -WIDTH="9%" -ALIGN="LEFT" -TITLE="ID"><COL -WIDTH="9%" -TITLE="FOURCC"><COL -WIDTH="9%" -TITLE="BIT"><COL -WIDTH="9%" -TITLE="B07"><COL><COL><COL><COL><COL><COL><COL -WIDTH="9%" -TITLE="B00"><COL><COL -WIDTH="9%" -TITLE="B17"><COL><COL><COL><COL><COL><COL><COL -WIDTH="9%" -TITLE="B10"><COL><COL -WIDTH="9%" -TITLE="B27"><COL><COL><COL><COL><COL><COL><COL -WIDTH="9%" -TITLE="B20"><COL><COL -WIDTH="9%" -TITLE="B37"><COL><COL><COL><COL><COL><COL><THEAD -><TR -><TH -ROWSPAN="2" ->Identifier</TH -><TH -ROWSPAN="2" ->Code</TH -><TH -> </TH -><TH -COLSPAN="8" ->Byte 0</TH -><TH -> </TH -><TH -COLSPAN="8" ->Byte 1</TH -><TH -> </TH -><TH -COLSPAN="8" ->Byte 2</TH -><TH -> </TH -><TH -COLSPAN="8" ->Byte 3</TH -></TR -><TR -><TH ->Bit</TH -><TH ->7</TH -><TH ->6</TH -><TH ->5</TH -><TH ->4</TH -><TH ->3</TH -><TH ->2</TH -><TH ->1</TH -><TH ->0</TH -><TH -> </TH -><TH ->7</TH -><TH ->6</TH -><TH ->5</TH -><TH ->4</TH -><TH ->3</TH -><TH ->2</TH -><TH ->1</TH -><TH ->0</TH -><TH -> </TH -><TH ->7</TH -><TH ->6</TH -><TH ->5</TH -><TH ->4</TH -><TH ->3</TH -><TH ->2</TH -><TH ->1</TH -><TH ->0</TH -><TH -> </TH -><TH ->7</TH -><TH ->6</TH -><TH ->5</TH -><TH ->4</TH -><TH ->3</TH -><TH ->2</TH -><TH ->1</TH -><TH ->0</TH -></TR -></THEAD -><TBODY -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_RGB332</CODE -></TD -><TD ->'RGB1'</TD -><TD -> </TD -><TD ->b<SUB ->1</SUB -></TD -><TD ->b<SUB ->0</SUB -></TD -><TD ->g<SUB ->2</SUB -></TD -><TD ->g<SUB ->1</SUB -></TD -><TD ->g<SUB ->0</SUB -></TD -><TD ->r<SUB ->2</SUB -></TD -><TD ->r<SUB ->1</SUB -></TD -><TD ->r<SUB ->0</SUB -></TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_RGB555</CODE -></TD -><TD ->'RGBO'</TD -><TD -> </TD -><TD ->g<SUB ->2</SUB -></TD -><TD ->g<SUB ->1</SUB -></TD -><TD ->g<SUB ->0</SUB -></TD -><TD ->r<SUB ->4</SUB -></TD -><TD ->r<SUB ->3</SUB -></TD -><TD ->r<SUB ->2</SUB -></TD -><TD ->r<SUB ->1</SUB -></TD -><TD ->r<SUB ->0</SUB -></TD -><TD -> </TD -><TD ->?</TD -><TD ->b<SUB ->4</SUB -></TD -><TD ->b<SUB ->3</SUB -></TD -><TD ->b<SUB ->2</SUB -></TD -><TD ->b<SUB ->1</SUB -></TD -><TD ->b<SUB ->0</SUB -></TD -><TD ->g<SUB ->4</SUB -></TD -><TD ->g<SUB ->3</SUB -></TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_RGB565</CODE -></TD -><TD ->'RGBP'</TD -><TD -> </TD -><TD ->g<SUB ->2</SUB -></TD -><TD ->g<SUB ->1</SUB -></TD -><TD ->g<SUB ->0</SUB -></TD -><TD ->r<SUB ->4</SUB -></TD -><TD ->r<SUB ->3</SUB -></TD -><TD ->r<SUB ->2</SUB -></TD -><TD ->r<SUB ->1</SUB -></TD -><TD ->r<SUB ->0</SUB -></TD -><TD -> </TD -><TD ->b<SUB ->4</SUB -></TD -><TD ->b<SUB ->3</SUB -></TD -><TD ->b<SUB ->2</SUB -></TD -><TD ->b<SUB ->1</SUB -></TD -><TD ->b<SUB ->0</SUB -></TD -><TD ->g<SUB ->5</SUB -></TD -><TD ->g<SUB ->4</SUB -></TD -><TD ->g<SUB ->3</SUB -></TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_RGB555X</CODE -></TD -><TD ->'RGBQ'</TD -><TD -> </TD -><TD ->?</TD -><TD ->b<SUB ->4</SUB -></TD -><TD ->b<SUB ->3</SUB -></TD -><TD ->b<SUB ->2</SUB -></TD -><TD ->b<SUB ->1</SUB -></TD -><TD ->b<SUB ->0</SUB -></TD -><TD ->g<SUB ->4</SUB -></TD -><TD ->g<SUB ->3</SUB -></TD -><TD -> </TD -><TD ->g<SUB ->2</SUB -></TD -><TD ->g<SUB ->1</SUB -></TD -><TD ->g<SUB ->0</SUB -></TD -><TD ->r<SUB ->4</SUB -></TD -><TD ->r<SUB ->3</SUB -></TD -><TD ->r<SUB ->2</SUB -></TD -><TD ->r<SUB ->1</SUB -></TD -><TD ->r<SUB ->0</SUB -></TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_RGB565X</CODE -></TD -><TD ->'RGBR'</TD -><TD -> </TD -><TD ->b<SUB ->4</SUB -></TD -><TD ->b<SUB ->3</SUB -></TD -><TD ->b<SUB ->2</SUB -></TD -><TD ->b<SUB ->1</SUB -></TD -><TD ->b<SUB ->0</SUB -></TD -><TD ->g<SUB ->5</SUB -></TD -><TD ->g<SUB ->4</SUB -></TD -><TD ->g<SUB ->3</SUB -></TD -><TD -> </TD -><TD ->g<SUB ->2</SUB -></TD -><TD ->g<SUB ->1</SUB -></TD -><TD ->g<SUB ->0</SUB -></TD -><TD ->r<SUB ->4</SUB -></TD -><TD ->r<SUB ->3</SUB -></TD -><TD ->r<SUB ->2</SUB -></TD -><TD ->r<SUB ->1</SUB -></TD -><TD ->r<SUB ->0</SUB -></TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_BGR24</CODE -></TD -><TD ->'BGR3'</TD -><TD -> </TD -><TD ->b<SUB ->7</SUB -></TD -><TD ->b<SUB ->6</SUB -></TD -><TD ->b<SUB ->5</SUB -></TD -><TD ->b<SUB ->4</SUB -></TD -><TD ->b<SUB ->3</SUB -></TD -><TD ->b<SUB ->2</SUB -></TD -><TD ->b<SUB ->1</SUB -></TD -><TD ->b<SUB ->0</SUB -></TD -><TD -> </TD -><TD ->g<SUB ->7</SUB -></TD -><TD ->g<SUB ->6</SUB -></TD -><TD ->g<SUB ->5</SUB -></TD -><TD ->g<SUB ->4</SUB -></TD -><TD ->g<SUB ->3</SUB -></TD -><TD ->g<SUB ->2</SUB -></TD -><TD ->g<SUB ->1</SUB -></TD -><TD ->g<SUB ->0</SUB -></TD -><TD -> </TD -><TD ->r<SUB ->7</SUB -></TD -><TD ->r<SUB ->6</SUB -></TD -><TD ->r<SUB ->5</SUB -></TD -><TD ->r<SUB ->4</SUB -></TD -><TD ->r<SUB ->3</SUB -></TD -><TD ->r<SUB ->2</SUB -></TD -><TD ->r<SUB ->1</SUB -></TD -><TD ->r<SUB ->0</SUB -></TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_RGB24</CODE -></TD -><TD ->'RGB3'</TD -><TD -> </TD -><TD ->r<SUB ->7</SUB -></TD -><TD ->r<SUB ->6</SUB -></TD -><TD ->r<SUB ->5</SUB -></TD -><TD ->r<SUB ->4</SUB -></TD -><TD ->r<SUB ->3</SUB -></TD -><TD ->r<SUB ->2</SUB -></TD -><TD ->r<SUB ->1</SUB -></TD -><TD ->r<SUB ->0</SUB -></TD -><TD -> </TD -><TD ->g<SUB ->7</SUB -></TD -><TD ->g<SUB ->6</SUB -></TD -><TD ->g<SUB ->5</SUB -></TD -><TD ->g<SUB ->4</SUB -></TD -><TD ->g<SUB ->3</SUB -></TD -><TD ->g<SUB ->2</SUB -></TD -><TD ->g<SUB ->1</SUB -></TD -><TD ->g<SUB ->0</SUB -></TD -><TD -> </TD -><TD ->b<SUB ->7</SUB -></TD -><TD ->b<SUB ->6</SUB -></TD -><TD ->b<SUB ->5</SUB -></TD -><TD ->b<SUB ->4</SUB -></TD -><TD ->b<SUB ->3</SUB -></TD -><TD ->b<SUB ->2</SUB -></TD -><TD ->b<SUB ->1</SUB -></TD -><TD ->b<SUB ->0</SUB -></TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_BGR32</CODE -></TD -><TD ->'BGR4'</TD -><TD -> </TD -><TD ->b<SUB ->7</SUB -></TD -><TD ->b<SUB ->6</SUB -></TD -><TD ->b<SUB ->5</SUB -></TD -><TD ->b<SUB ->4</SUB -></TD -><TD ->b<SUB ->3</SUB -></TD -><TD ->b<SUB ->2</SUB -></TD -><TD ->b<SUB ->1</SUB -></TD -><TD ->b<SUB ->0</SUB -></TD -><TD -> </TD -><TD ->g<SUB ->7</SUB -></TD -><TD ->g<SUB ->6</SUB -></TD -><TD ->g<SUB ->5</SUB -></TD -><TD ->g<SUB ->4</SUB -></TD -><TD ->g<SUB ->3</SUB -></TD -><TD ->g<SUB ->2</SUB -></TD -><TD ->g<SUB ->1</SUB -></TD -><TD ->g<SUB ->0</SUB -></TD -><TD -> </TD -><TD ->r<SUB ->7</SUB -></TD -><TD ->r<SUB ->6</SUB -></TD -><TD ->r<SUB ->5</SUB -></TD -><TD ->r<SUB ->4</SUB -></TD -><TD ->r<SUB ->3</SUB -></TD -><TD ->r<SUB ->2</SUB -></TD -><TD ->r<SUB ->1</SUB -></TD -><TD ->r<SUB ->0</SUB -></TD -><TD -> </TD -><TD ->?</TD -><TD ->?</TD -><TD ->?</TD -><TD ->?</TD -><TD ->?</TD -><TD ->?</TD -><TD ->?</TD -><TD ->?</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_RGB32</CODE -></TD -><TD ->'RGB4'</TD -><TD -> </TD -><TD ->r<SUB ->7</SUB -></TD -><TD ->r<SUB ->6</SUB -></TD -><TD ->r<SUB ->5</SUB -></TD -><TD ->r<SUB ->4</SUB -></TD -><TD ->r<SUB ->3</SUB -></TD -><TD ->r<SUB ->2</SUB -></TD -><TD ->r<SUB ->1</SUB -></TD -><TD ->r<SUB ->0</SUB -></TD -><TD -> </TD -><TD ->g<SUB ->7</SUB -></TD -><TD ->g<SUB ->6</SUB -></TD -><TD ->g<SUB ->5</SUB -></TD -><TD ->g<SUB ->4</SUB -></TD -><TD ->g<SUB ->3</SUB -></TD -><TD ->g<SUB ->2</SUB -></TD -><TD ->g<SUB ->1</SUB -></TD -><TD ->g<SUB ->0</SUB -></TD -><TD -> </TD -><TD ->b<SUB ->7</SUB -></TD -><TD ->b<SUB ->6</SUB -></TD -><TD ->b<SUB ->5</SUB -></TD -><TD ->b<SUB ->4</SUB -></TD -><TD ->b<SUB ->3</SUB -></TD -><TD ->b<SUB ->2</SUB -></TD -><TD ->b<SUB ->1</SUB -></TD -><TD ->b<SUB ->0</SUB -></TD -><TD -> </TD -><TD ->?</TD -><TD ->?</TD -><TD ->?</TD -><TD ->?</TD -><TD ->?</TD -><TD ->?</TD -><TD ->?</TD -><TD ->?</TD -></TR -></TBODY -></TABLE -></DIV -><P ->Bit 7 is the most significant bit. ? = undefined bit, -ignored on output, random value on input.</P -><DIV -CLASS="EXAMPLE" -><A -NAME="AEN1675" -></A -><P -><B ->Example 2-2. <CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_BGR24</CODE -> 4 × 4 pixel -image</B -></P -><DIV -CLASS="FORMALPARA" -><P -><B ->Byte Order. </B ->Each cell is one byte. - <DIV -CLASS="INFORMALTABLE" -><P -></P -><A -NAME="AEN1681" -></A -><TABLE -BORDER="0" -FRAME="void" -CLASS="CALSTABLE" -><COL -WIDTH="2*" -ALIGN="LEFT"><COL><COL><COL><COL><COL><COL><COL><COL><COL><COL><COL><COL><TBODY -><TR -><TD ->start + 0:</TD -><TD ->B<SUB ->00</SUB -></TD -><TD ->G<SUB ->00</SUB -></TD -><TD ->R<SUB ->00</SUB -></TD -><TD ->B<SUB ->01</SUB -></TD -><TD ->G<SUB ->01</SUB -></TD -><TD ->R<SUB ->01</SUB -></TD -><TD ->B<SUB ->02</SUB -></TD -><TD ->G<SUB ->02</SUB -></TD -><TD ->R<SUB ->02</SUB -></TD -><TD ->B<SUB ->03</SUB -></TD -><TD ->G<SUB ->03</SUB -></TD -><TD ->R<SUB ->03</SUB -></TD -></TR -><TR -><TD ->start + 12:</TD -><TD ->B<SUB ->10</SUB -></TD -><TD ->G<SUB ->10</SUB -></TD -><TD ->R<SUB ->10</SUB -></TD -><TD ->B<SUB ->11</SUB -></TD -><TD ->G<SUB ->11</SUB -></TD -><TD ->R<SUB ->11</SUB -></TD -><TD ->B<SUB ->12</SUB -></TD -><TD ->G<SUB ->12</SUB -></TD -><TD ->R<SUB ->12</SUB -></TD -><TD ->B<SUB ->13</SUB -></TD -><TD ->G<SUB ->13</SUB -></TD -><TD ->R<SUB ->13</SUB -></TD -></TR -><TR -><TD ->start + 24:</TD -><TD ->B<SUB ->20</SUB -></TD -><TD ->G<SUB ->20</SUB -></TD -><TD ->R<SUB ->20</SUB -></TD -><TD ->B<SUB ->21</SUB -></TD -><TD ->G<SUB ->21</SUB -></TD -><TD ->R<SUB ->21</SUB -></TD -><TD ->B<SUB ->22</SUB -></TD -><TD ->G<SUB ->22</SUB -></TD -><TD ->R<SUB ->22</SUB -></TD -><TD ->B<SUB ->23</SUB -></TD -><TD ->G<SUB ->23</SUB -></TD -><TD ->R<SUB ->23</SUB -></TD -></TR -><TR -><TD ->start + 36:</TD -><TD ->B<SUB ->30</SUB -></TD -><TD ->G<SUB ->30</SUB -></TD -><TD ->R<SUB ->30</SUB -></TD -><TD ->B<SUB ->31</SUB -></TD -><TD ->G<SUB ->31</SUB -></TD -><TD ->R<SUB ->31</SUB -></TD -><TD ->B<SUB ->32</SUB -></TD -><TD ->G<SUB ->32</SUB -></TD -><TD ->R<SUB ->32</SUB -></TD -><TD ->B<SUB ->33</SUB -></TD -><TD ->G<SUB ->33</SUB -></TD -><TD ->R<SUB ->33</SUB -></TD -></TR -></TBODY -></TABLE -><P -></P -></DIV -> - </P -></DIV -></DIV -><DIV -CLASS="IMPORTANT" -><BLOCKQUOTE -CLASS="IMPORTANT" -><P -><B ->Important: </B ->Drivers may interpret these formats differently.</P -><P ->The <CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_RGB555</CODE ->, -<CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_RGB565</CODE ->, -<CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_RGB555X</CODE -> and -<CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_RGB565X</CODE -> formats are uncommon. Video -and display hardware typically supports variants with reversed order -of color components, i. e. blue towards the least, red towards the most -significant bit. Although presumably the original authors had the -common formats in mind, the definitions were always very clear and -cannot be simply regarded as erroneous.</P -><P ->If <CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_RGB332</CODE -> has been -chosen in accordance with the 15 and 16 bit formats, this format might -as well be interpreted differently, as "rrrgggbb" rather than -"bbgggrrr".</P -><P ->Finally some drivers, most prominently the BTTV driver, -might interpret <CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_RGB32</CODE -> as the -big-endian variant of <CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_BGR32</CODE ->, -consisting of bytes "?RGB" in memory. V4L2 never defined such a -format, lack of a <CODE -CLASS="CONSTANT" ->X</CODE -> suffix to the symbol suggests -it was intended this way, and a new symbol and four character code -should have been used instead.</P -><P ->Until these issues are solved, application writers are -advised that drivers might interpret these formats either way.</P -></BLOCKQUOTE -></DIV -></DIV -><DIV -CLASS="SECTION" -><HR><H2 -CLASS="SECTION" -><A -NAME="YUV-FORMATS" ->2.4. YUV Formats</A -></H2 -><DIV -CLASS="TOC" -><DL -><DT -><B ->Table of Contents</B -></DT -><DT -><A -HREF="#PIXFMT-GREY" -><CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_GREY</CODE -></A -> -- Grey-scale image.</DT -><DT -><A -HREF="#PIXFMT-YUYV" -><CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_YUYV</CODE -></A -> -- Packed format with ½ horizontal chroma -resolution, also known as YUV 4:2:2.</DT -><DT -><A -HREF="#PIXFMT-UYVY" -><CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_UYVY</CODE -></A -> -- Variation of -<CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_YUYV</CODE -> with different order of samples -in memory.</DT -><DT -><A -HREF="#PIXFMT-Y41P" -><CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_Y41P</CODE -></A -> -- Packed format with ¼ horizontal chroma -resolution, also known as YUV 4:1:1.</DT -><DT -><A -HREF="#PIXFMT-YVU420" -><CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_YVU420</CODE ->, -<CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_YUV420</CODE -></A -> -- Planar formats with ½ horizontal and -vertical chroma resolution, also known as YUV 4:2:0.</DT -><DT -><A -HREF="#PIXFMT-YVU410" -><CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_YVU410</CODE ->, -<CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_YUV410</CODE -></A -> -- Planar formats with ¼ horizontal and -vertical chroma resolution, also known as YUV 4:1:0.</DT -><DT -><A -HREF="#PIXFMT-YUV422P" -><CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_YUV422P</CODE -></A -> -- Format with ½ horizontal chroma resolution, -also known as YUV 4:2:2. Planar layout as opposed to -<CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_YUYV</CODE ->.</DT -><DT -><A -HREF="#PIXFMT-YUV411P" -><CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_YUV411P</CODE -></A -> -- Format with ¼ horizontal chroma resolution, -also known as YUV 4:1:1. Planar layout as opposed to -<CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_Y41P</CODE ->.</DT -><DT -><A -HREF="#AEN3002" -><CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_NV12</CODE ->, -<CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_NV21</CODE -></A -> -- Formats with ½ horizontal and vertical -chroma resolution, also known as YUV 4:2:0. One luminance and one -chrominance plane with alternating chroma samples as opposed to -<CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_YVU420</CODE ->.</DT -></DL -></DIV -><P ->YUV is the format native to TV broadcast and composite video -signals. It separates the brightness information (Y) from the color -information (U and V or Cb and Cr). The color information consists of -red and blue <SPAN -CLASS="emphasis" -><I -CLASS="EMPHASIS" ->color difference</I -></SPAN -> signals, this way -the green component can be reconstructed by subtracting from the -brightness component. See <A -HREF="#COLORSPACES" ->Section 2.2</A -> for conversion -examples. YUV was chosen because early television would only transmit -brightness information. To add color in a way compatible with existing -receivers a new signal carrier was added to transmit the color -difference signals. Secondary in the YUV format the U and V components -usually have lower resolution than the Y component. This is an analog -video compression technique taking advantage of a property of the -human visual system, being more sensitive to brightness -information.</P -><H1 -><A -NAME="PIXFMT-GREY" -></A -><CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_GREY</CODE -></H1 -><DIV -CLASS="REFNAMEDIV" -><A -NAME="AEN1812" -></A -><H2 ->Name</H2 -><CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_GREY</CODE -> ('GREY') -- Grey-scale image.</DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN1816" -></A -><H2 ->Description</H2 -><P ->This is a grey-scale image. It is really a degenerate -Y'CbCr format which simply contains no Cb or Cr data.</P -><DIV -CLASS="EXAMPLE" -><A -NAME="AEN1819" -></A -><P -><B ->Example 2-1. <CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_GREY</CODE -> 4 × 4 -pixel image</B -></P -><DIV -CLASS="FORMALPARA" -><P -><B ->Byte Order. </B ->Each cell is one byte. - <DIV -CLASS="INFORMALTABLE" -><P -></P -><A -NAME="AEN1825" -></A -><TABLE -BORDER="0" -FRAME="void" -CLASS="CALSTABLE" -><COL -WIDTH="2*" -ALIGN="LEFT"><COL><COL><COL><COL><TBODY -><TR -><TD ->start + 0:</TD -><TD ->Y'<SUB ->00</SUB -></TD -><TD ->Y'<SUB ->01</SUB -></TD -><TD ->Y'<SUB ->02</SUB -></TD -><TD ->Y'<SUB ->03</SUB -></TD -></TR -><TR -><TD ->start + 4:</TD -><TD ->Y'<SUB ->10</SUB -></TD -><TD ->Y'<SUB ->11</SUB -></TD -><TD ->Y'<SUB ->12</SUB -></TD -><TD ->Y'<SUB ->13</SUB -></TD -></TR -><TR -><TD ->start + 8:</TD -><TD ->Y'<SUB ->20</SUB -></TD -><TD ->Y'<SUB ->21</SUB -></TD -><TD ->Y'<SUB ->22</SUB -></TD -><TD ->Y'<SUB ->23</SUB -></TD -></TR -><TR -><TD ->start + 12:</TD -><TD ->Y'<SUB ->30</SUB -></TD -><TD ->Y'<SUB ->31</SUB -></TD -><TD ->Y'<SUB ->32</SUB -></TD -><TD ->Y'<SUB ->33</SUB -></TD -></TR -></TBODY -></TABLE -><P -></P -></DIV -> - </P -></DIV -></DIV -></DIV -><H1 -><A -NAME="PIXFMT-YUYV" -></A -><CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_YUYV</CODE -></H1 -><DIV -CLASS="REFNAMEDIV" -><A -NAME="AEN1873" -></A -><H2 ->Name</H2 -><CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_YUYV</CODE -> -('YUYV') -- Packed format with ½ horizontal chroma -resolution, also known as YUV 4:2:2.</DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN1877" -></A -><H2 ->Description</H2 -><P ->In this format each four bytes is two pixels. Each four -bytes is two Y's, a Cb and a Cr. Each Y goes to one of the pixels, and -the Cb and Cr belong to both pixels. As you can see, the Cr and Cb -components have half the horizontal resolution of the Y component. -<CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_YUYV </CODE -> is known in the Windows -environment as YUY2.</P -><DIV -CLASS="EXAMPLE" -><A -NAME="AEN1881" -></A -><P -><B ->Example 2-1. <CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_YUYV</CODE -> 4 × 4 -pixel image</B -></P -><DIV -CLASS="FORMALPARA" -><P -><B ->Byte Order. </B ->Each cell is one byte. - <DIV -CLASS="INFORMALTABLE" -><P -></P -><A -NAME="AEN1887" -></A -><TABLE -BORDER="0" -FRAME="void" -CLASS="CALSTABLE" -><COL -WIDTH="2*" -ALIGN="LEFT"><COL><COL><COL><COL><COL><COL><COL><COL><TBODY -><TR -><TD ->start + 0:</TD -><TD ->Y'<SUB ->00</SUB -></TD -><TD ->Cb<SUB ->00</SUB -></TD -><TD ->Y'<SUB ->01</SUB -></TD -><TD ->Cr<SUB ->00</SUB -></TD -><TD ->Y'<SUB ->02</SUB -></TD -><TD ->Cb<SUB ->01</SUB -></TD -><TD ->Y'<SUB ->03</SUB -></TD -><TD ->Cr<SUB ->01</SUB -></TD -></TR -><TR -><TD ->start + 8:</TD -><TD ->Y'<SUB ->10</SUB -></TD -><TD ->Cb<SUB ->10</SUB -></TD -><TD ->Y'<SUB ->11</SUB -></TD -><TD ->Cr<SUB ->10</SUB -></TD -><TD ->Y'<SUB ->12</SUB -></TD -><TD ->Cb<SUB ->11</SUB -></TD -><TD ->Y'<SUB ->13</SUB -></TD -><TD ->Cr<SUB ->11</SUB -></TD -></TR -><TR -><TD ->start + 16:</TD -><TD ->Y'<SUB ->20</SUB -></TD -><TD ->Cb<SUB ->20</SUB -></TD -><TD ->Y'<SUB ->21</SUB -></TD -><TD ->Cr<SUB ->20</SUB -></TD -><TD ->Y'<SUB ->22</SUB -></TD -><TD ->Cb<SUB ->21</SUB -></TD -><TD ->Y'<SUB ->23</SUB -></TD -><TD ->Cr<SUB ->21</SUB -></TD -></TR -><TR -><TD ->start + 24:</TD -><TD ->Y'<SUB ->30</SUB -></TD -><TD ->Cb<SUB ->30</SUB -></TD -><TD ->Y'<SUB ->31</SUB -></TD -><TD ->Cr<SUB ->30</SUB -></TD -><TD ->Y'<SUB ->32</SUB -></TD -><TD ->Cb<SUB ->31</SUB -></TD -><TD ->Y'<SUB ->33</SUB -></TD -><TD ->Cr<SUB ->31</SUB -></TD -></TR -></TBODY -></TABLE -><P -></P -></DIV -> - </P -></DIV -><DIV -CLASS="FORMALPARA" -><P -><B ->Color Sample Location. </B -> <DIV -CLASS="INFORMALTABLE" -><P -></P -><A -NAME="AEN1966" -></A -><TABLE -BORDER="0" -FRAME="void" -CLASS="CALSTABLE" -><COL><COL><COL><COL><COL><COL><COL><TBODY -><TR -><TD -> </TD -><TD ->0</TD -><TD -> </TD -><TD ->1</TD -><TD -> </TD -><TD ->2</TD -><TD -> </TD -><TD ->3</TD -></TR -><TR -><TD ->0</TD -><TD ->Y</TD -><TD ->C</TD -><TD ->Y</TD -><TD -> </TD -><TD ->Y</TD -><TD ->C</TD -><TD ->Y</TD -></TR -><TR -><TD ->1</TD -><TD ->Y</TD -><TD ->C</TD -><TD ->Y</TD -><TD -> </TD -><TD ->Y</TD -><TD ->C</TD -><TD ->Y</TD -></TR -><TR -><TD ->2</TD -><TD ->Y</TD -><TD ->C</TD -><TD ->Y</TD -><TD -> </TD -><TD ->Y</TD -><TD ->C</TD -><TD ->Y</TD -></TR -><TR -><TD ->3</TD -><TD ->Y</TD -><TD ->C</TD -><TD ->Y</TD -><TD -> </TD -><TD ->Y</TD -><TD ->C</TD -><TD ->Y</TD -></TR -></TBODY -></TABLE -><P -></P -></DIV -> - </P -></DIV -></DIV -></DIV -><H1 -><A -NAME="PIXFMT-UYVY" -></A -><CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_UYVY</CODE -></H1 -><DIV -CLASS="REFNAMEDIV" -><A -NAME="AEN2018" -></A -><H2 ->Name</H2 -><CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_UYVY</CODE -> -('UYVY') -- Variation of -<CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_YUYV</CODE -> with different order of samples -in memory.</DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN2023" -></A -><H2 ->Description</H2 -><P ->In this format each four bytes is two pixels. Each four -bytes is two Y's, a Cb and a Cr. Each Y goes to one of the pixels, and -the Cb and Cr belong to both pixels. As you can see, the Cr and Cb -components have half the horizontal resolution of the Y -component.</P -><DIV -CLASS="EXAMPLE" -><A -NAME="AEN2026" -></A -><P -><B ->Example 2-1. <CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_UYVY</CODE -> 4 × 4 -pixel image</B -></P -><DIV -CLASS="FORMALPARA" -><P -><B ->Byte Order. </B ->Each cell is one byte. - <DIV -CLASS="INFORMALTABLE" -><P -></P -><A -NAME="AEN2032" -></A -><TABLE -BORDER="0" -FRAME="void" -CLASS="CALSTABLE" -><COL -WIDTH="2*" -ALIGN="LEFT"><COL><COL><COL><COL><COL><COL><COL><COL><TBODY -><TR -><TD ->start + 0:</TD -><TD ->Cb<SUB ->00</SUB -></TD -><TD ->Y'<SUB ->00</SUB -></TD -><TD ->Cr<SUB ->00</SUB -></TD -><TD ->Y'<SUB ->01</SUB -></TD -><TD ->Cb<SUB ->01</SUB -></TD -><TD ->Y'<SUB ->02</SUB -></TD -><TD ->Cr<SUB ->01</SUB -></TD -><TD ->Y'<SUB ->03</SUB -></TD -></TR -><TR -><TD ->start + 8:</TD -><TD ->Cb<SUB ->10</SUB -></TD -><TD ->Y'<SUB ->10</SUB -></TD -><TD ->Cr<SUB ->10</SUB -></TD -><TD ->Y'<SUB ->11</SUB -></TD -><TD ->Cb<SUB ->11</SUB -></TD -><TD ->Y'<SUB ->12</SUB -></TD -><TD ->Cr<SUB ->11</SUB -></TD -><TD ->Y'<SUB ->13</SUB -></TD -></TR -><TR -><TD ->start + 16:</TD -><TD ->Cb<SUB ->20</SUB -></TD -><TD ->Y'<SUB ->20</SUB -></TD -><TD ->Cr<SUB ->20</SUB -></TD -><TD ->Y'<SUB ->21</SUB -></TD -><TD ->Cb<SUB ->21</SUB -></TD -><TD ->Y'<SUB ->22</SUB -></TD -><TD ->Cr<SUB ->21</SUB -></TD -><TD ->Y'<SUB ->23</SUB -></TD -></TR -><TR -><TD ->start + 24:</TD -><TD ->Cb<SUB ->30</SUB -></TD -><TD ->Y'<SUB ->30</SUB -></TD -><TD ->Cr<SUB ->30</SUB -></TD -><TD ->Y'<SUB ->31</SUB -></TD -><TD ->Cb<SUB ->31</SUB -></TD -><TD ->Y'<SUB ->32</SUB -></TD -><TD ->Cr<SUB ->31</SUB -></TD -><TD ->Y'<SUB ->33</SUB -></TD -></TR -></TBODY -></TABLE -><P -></P -></DIV -> - </P -></DIV -><DIV -CLASS="FORMALPARA" -><P -><B ->Color Sample Location. </B -> <DIV -CLASS="INFORMALTABLE" -><P -></P -><A -NAME="AEN2111" -></A -><TABLE -BORDER="0" -FRAME="void" -CLASS="CALSTABLE" -><COL><COL><COL><COL><COL><COL><COL><TBODY -><TR -><TD -> </TD -><TD ->0</TD -><TD -> </TD -><TD ->1</TD -><TD -> </TD -><TD ->2</TD -><TD -> </TD -><TD ->3</TD -></TR -><TR -><TD ->0</TD -><TD ->Y</TD -><TD ->C</TD -><TD ->Y</TD -><TD -> </TD -><TD ->Y</TD -><TD ->C</TD -><TD ->Y</TD -></TR -><TR -><TD ->1</TD -><TD ->Y</TD -><TD ->C</TD -><TD ->Y</TD -><TD -> </TD -><TD ->Y</TD -><TD ->C</TD -><TD ->Y</TD -></TR -><TR -><TD ->2</TD -><TD ->Y</TD -><TD ->C</TD -><TD ->Y</TD -><TD -> </TD -><TD ->Y</TD -><TD ->C</TD -><TD ->Y</TD -></TR -><TR -><TD ->3</TD -><TD ->Y</TD -><TD ->C</TD -><TD ->Y</TD -><TD -> </TD -><TD ->Y</TD -><TD ->C</TD -><TD ->Y</TD -></TR -></TBODY -></TABLE -><P -></P -></DIV -> - </P -></DIV -></DIV -></DIV -><H1 -><A -NAME="PIXFMT-Y41P" -></A -><CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_Y41P</CODE -></H1 -><DIV -CLASS="REFNAMEDIV" -><A -NAME="AEN2163" -></A -><H2 ->Name</H2 -><CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_Y41P</CODE -> -('Y41P') -- Packed format with ¼ horizontal chroma -resolution, also known as YUV 4:1:1.</DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN2167" -></A -><H2 ->Description</H2 -><P ->In this format each 12 bytes is eight pixels. In the -twelve bytes are two CbCr pairs and eight Y's. The first CbCr pair -goes with the first four Y's, and the second CbCr pair goes with the -other four Y's. The Cb and Cr components have one fourth the -horizontal resolution of the Y component.</P -><P ->Do not confuse this format with <A -HREF="#PIXFMT-YUV411P" -><CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_YUV411P</CODE -></A ->. -Y41P is derived from "YUV 4:1:1 <SPAN -CLASS="emphasis" -><I -CLASS="EMPHASIS" ->packed</I -></SPAN ->", possibly -in reference to a Windows FOURCC, while YUV411P stands for "YUV 4:1:1 -<SPAN -CLASS="emphasis" -><I -CLASS="EMPHASIS" ->planar</I -></SPAN ->".</P -><DIV -CLASS="EXAMPLE" -><A -NAME="AEN2175" -></A -><P -><B ->Example 2-1. <CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_Y41P</CODE -> 8 × 4 -pixel image</B -></P -><DIV -CLASS="FORMALPARA" -><P -><B ->Byte Order. </B ->Each cell is one byte. - <DIV -CLASS="INFORMALTABLE" -><P -></P -><A -NAME="AEN2181" -></A -><TABLE -BORDER="0" -FRAME="void" -CLASS="CALSTABLE" -><COL -WIDTH="2*" -ALIGN="LEFT"><COL><COL><COL><COL><COL><COL><COL><COL><COL><COL><COL><COL><TBODY -><TR -><TD ->start + 0:</TD -><TD ->Cb<SUB ->00</SUB -></TD -><TD ->Y'<SUB ->00</SUB -></TD -><TD ->Cr<SUB ->00</SUB -></TD -><TD ->Y'<SUB ->01</SUB -></TD -><TD ->Cb<SUB ->01</SUB -></TD -><TD ->Y'<SUB ->02</SUB -></TD -><TD ->Cr<SUB ->01</SUB -></TD -><TD ->Y'<SUB ->03</SUB -></TD -><TD ->Y'<SUB ->04</SUB -></TD -><TD ->Y'<SUB ->05</SUB -></TD -><TD ->Y'<SUB ->06</SUB -></TD -><TD ->Y'<SUB ->07</SUB -></TD -></TR -><TR -><TD ->start + 12:</TD -><TD ->Cb<SUB ->10</SUB -></TD -><TD ->Y'<SUB ->10</SUB -></TD -><TD ->Cr<SUB ->10</SUB -></TD -><TD ->Y'<SUB ->11</SUB -></TD -><TD ->Cb<SUB ->11</SUB -></TD -><TD ->Y'<SUB ->12</SUB -></TD -><TD ->Cr<SUB ->11</SUB -></TD -><TD ->Y'<SUB ->13</SUB -></TD -><TD ->Y'<SUB ->14</SUB -></TD -><TD ->Y'<SUB ->15</SUB -></TD -><TD ->Y'<SUB ->16</SUB -></TD -><TD ->Y'<SUB ->17</SUB -></TD -></TR -><TR -><TD ->start + 24:</TD -><TD ->Cb<SUB ->20</SUB -></TD -><TD ->Y'<SUB ->20</SUB -></TD -><TD ->Cr<SUB ->20</SUB -></TD -><TD ->Y'<SUB ->21</SUB -></TD -><TD ->Cb<SUB ->21</SUB -></TD -><TD ->Y'<SUB ->22</SUB -></TD -><TD ->Cr<SUB ->21</SUB -></TD -><TD ->Y'<SUB ->23</SUB -></TD -><TD ->Y'<SUB ->24</SUB -></TD -><TD ->Y'<SUB ->25</SUB -></TD -><TD ->Y'<SUB ->26</SUB -></TD -><TD ->Y'<SUB ->27</SUB -></TD -></TR -><TR -><TD ->start + 36:</TD -><TD ->Cb<SUB ->30</SUB -></TD -><TD ->Y'<SUB ->30</SUB -></TD -><TD ->Cr<SUB ->30</SUB -></TD -><TD ->Y'<SUB ->31</SUB -></TD -><TD ->Cb<SUB ->31</SUB -></TD -><TD ->Y'<SUB ->32</SUB -></TD -><TD ->Cr<SUB ->31</SUB -></TD -><TD ->Y'<SUB ->33</SUB -></TD -><TD ->Y'<SUB ->34</SUB -></TD -><TD ->Y'<SUB ->35</SUB -></TD -><TD ->Y'<SUB ->36</SUB -></TD -><TD ->Y'<SUB ->37</SUB -></TD -></TR -></TBODY -></TABLE -><P -></P -></DIV -></P -></DIV -><DIV -CLASS="FORMALPARA" -><P -><B ->Color Sample Location. </B -> <DIV -CLASS="INFORMALTABLE" -><P -></P -><A -NAME="AEN2292" -></A -><TABLE -BORDER="0" -FRAME="void" -CLASS="CALSTABLE" -><COL><COL><COL><COL><COL><COL><COL><COL><COL><COL><COL><COL><COL><COL><COL><TBODY -><TR -><TD -> </TD -><TD ->0</TD -><TD -> </TD -><TD ->1</TD -><TD -> </TD -><TD ->2</TD -><TD -> </TD -><TD ->3</TD -><TD -> </TD -><TD ->4</TD -><TD -> </TD -><TD ->5</TD -><TD -> </TD -><TD ->6</TD -><TD -> </TD -><TD ->7</TD -></TR -><TR -><TD ->0</TD -><TD ->Y</TD -><TD -> </TD -><TD ->Y</TD -><TD ->C</TD -><TD ->Y</TD -><TD -> </TD -><TD ->Y</TD -><TD -> </TD -><TD ->Y</TD -><TD -> </TD -><TD ->Y</TD -><TD ->C</TD -><TD ->Y</TD -><TD -> </TD -><TD ->Y</TD -></TR -><TR -><TD ->1</TD -><TD ->Y</TD -><TD -> </TD -><TD ->Y</TD -><TD ->C</TD -><TD ->Y</TD -><TD -> </TD -><TD ->Y</TD -><TD -> </TD -><TD ->Y</TD -><TD -> </TD -><TD ->Y</TD -><TD ->C</TD -><TD ->Y</TD -><TD -> </TD -><TD ->Y</TD -></TR -><TR -><TD ->2</TD -><TD ->Y</TD -><TD -> </TD -><TD ->Y</TD -><TD ->C</TD -><TD ->Y</TD -><TD -> </TD -><TD ->Y</TD -><TD -> </TD -><TD ->Y</TD -><TD -> </TD -><TD ->Y</TD -><TD ->C</TD -><TD ->Y</TD -><TD -> </TD -><TD ->Y</TD -></TR -><TR -><TD ->3</TD -><TD ->Y</TD -><TD -> </TD -><TD ->Y</TD -><TD ->C</TD -><TD ->Y</TD -><TD -> </TD -><TD ->Y</TD -><TD -> </TD -><TD ->Y</TD -><TD -> </TD -><TD ->Y</TD -><TD ->C</TD -><TD ->Y</TD -><TD -> </TD -><TD ->Y</TD -></TR -></TBODY -></TABLE -><P -></P -></DIV -> - </P -></DIV -></DIV -></DIV -><H1 -><A -NAME="PIXFMT-YVU420" -></A -><CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_YVU420</CODE ->, -<CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_YUV420</CODE -></H1 -><DIV -CLASS="REFNAMEDIV" -><A -NAME="AEN2385" -></A -><H2 ->Name</H2 -><CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_YVU420</CODE -> -('YV12'), <CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_YUV420</CODE -> -('YU12') -- Planar formats with ½ horizontal and -vertical chroma resolution, also known as YUV 4:2:0.</DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN2391" -></A -><H2 ->Description</H2 -><P ->These are planar formats, as opposed to a packed format. -The three components are separated into three sub- images or planes. -The Y plane is first. The Y plane has one byte per pixel. For -<CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_YVU420</CODE ->, the Cr plane immediately -follows the Y plane in memory. The Cr plane is half the width and half -the height of the Y plane (and of the image). Each Cr belongs to four -pixels, a two-by-two square of the image. For example, -Cr<SUB ->0</SUB -> belongs to Y'<SUB ->00</SUB ->, -Y'<SUB ->01</SUB ->, Y'<SUB ->10</SUB ->, and -Y'<SUB ->11</SUB ->. Following the Cr plane is the Cb plane, -just like the Cr plane. <CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_YUV420</CODE -> is -the same except the Cb plane comes first, then the Cr plane.</P -><P ->If the Y plane has pad bytes after each row, then the Cr -and Cb planes have half as many pad bytes after their rows. In other -words, two Cx rows (including padding) is exactly as long as one Y row -(including padding).</P -><DIV -CLASS="EXAMPLE" -><A -NAME="AEN2402" -></A -><P -><B ->Example 2-1. <CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_YVU420</CODE -> 4 × 4 -pixel image</B -></P -><DIV -CLASS="FORMALPARA" -><P -><B ->Byte Order. </B ->Each cell is one byte. - <DIV -CLASS="INFORMALTABLE" -><P -></P -><A -NAME="AEN2408" -></A -><TABLE -BORDER="0" -FRAME="void" -CLASS="CALSTABLE" -><COL -WIDTH="2*" -ALIGN="LEFT"><COL><COL><COL><COL><TBODY -><TR -><TD ->start + 0:</TD -><TD ->Y'<SUB ->00</SUB -></TD -><TD ->Y'<SUB ->01</SUB -></TD -><TD ->Y'<SUB ->02</SUB -></TD -><TD ->Y'<SUB ->03</SUB -></TD -></TR -><TR -><TD ->start + 4:</TD -><TD ->Y'<SUB ->10</SUB -></TD -><TD ->Y'<SUB ->11</SUB -></TD -><TD ->Y'<SUB ->12</SUB -></TD -><TD ->Y'<SUB ->13</SUB -></TD -></TR -><TR -><TD ->start + 8:</TD -><TD ->Y'<SUB ->20</SUB -></TD -><TD ->Y'<SUB ->21</SUB -></TD -><TD ->Y'<SUB ->22</SUB -></TD -><TD ->Y'<SUB ->23</SUB -></TD -></TR -><TR -><TD ->start + 12:</TD -><TD ->Y'<SUB ->30</SUB -></TD -><TD ->Y'<SUB ->31</SUB -></TD -><TD ->Y'<SUB ->32</SUB -></TD -><TD ->Y'<SUB ->33</SUB -></TD -></TR -><TR -><TD ->start + 16:</TD -><TD ->Cr<SUB ->00</SUB -></TD -><TD ->Cr<SUB ->01</SUB -></TD -><TD -> </TD -><TD -> </TD -></TR -><TR -><TD ->start + 18:</TD -><TD ->Cr<SUB ->10</SUB -></TD -><TD ->Cr<SUB ->11</SUB -></TD -><TD -> </TD -><TD -> </TD -></TR -><TR -><TD ->start + 20:</TD -><TD ->Cb<SUB ->00</SUB -></TD -><TD ->Cb<SUB ->01</SUB -></TD -><TD -> </TD -><TD -> </TD -></TR -><TR -><TD ->start + 22:</TD -><TD ->Cb<SUB ->10</SUB -></TD -><TD ->Cb<SUB ->11</SUB -></TD -><TD -> </TD -><TD -> </TD -></TR -></TBODY -></TABLE -><P -></P -></DIV -> - </P -></DIV -><DIV -CLASS="FORMALPARA" -><P -><B ->Color Sample Location. </B -> <DIV -CLASS="INFORMALTABLE" -><P -></P -><A -NAME="AEN2479" -></A -><TABLE -BORDER="0" -FRAME="void" -CLASS="CALSTABLE" -><COL><COL><COL><COL><COL><COL><COL><TBODY -><TR -><TD -> </TD -><TD ->0</TD -><TD -> </TD -><TD ->1</TD -><TD -> </TD -><TD ->2</TD -><TD -> </TD -><TD ->3</TD -></TR -><TR -><TD ->0</TD -><TD ->Y</TD -><TD -> </TD -><TD ->Y</TD -><TD -> </TD -><TD ->Y</TD -><TD -> </TD -><TD ->Y</TD -></TR -><TR -><TD -> </TD -><TD -> </TD -><TD ->C</TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD ->C</TD -><TD -> </TD -></TR -><TR -><TD ->1</TD -><TD ->Y</TD -><TD -> </TD -><TD ->Y</TD -><TD -> </TD -><TD ->Y</TD -><TD -> </TD -><TD ->Y</TD -></TR -><TR -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -></TR -><TR -><TD ->2</TD -><TD ->Y</TD -><TD -> </TD -><TD ->Y</TD -><TD -> </TD -><TD ->Y</TD -><TD -> </TD -><TD ->Y</TD -></TR -><TR -><TD -> </TD -><TD -> </TD -><TD ->C</TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD ->C</TD -><TD -> </TD -></TR -><TR -><TD ->3</TD -><TD ->Y</TD -><TD -> </TD -><TD ->Y</TD -><TD -> </TD -><TD ->Y</TD -><TD -> </TD -><TD ->Y</TD -></TR -></TBODY -></TABLE -><P -></P -></DIV -> - </P -></DIV -></DIV -></DIV -><H1 -><A -NAME="PIXFMT-YVU410" -></A -><CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_YVU410</CODE ->, -<CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_YUV410</CODE -></H1 -><DIV -CLASS="REFNAMEDIV" -><A -NAME="AEN2552" -></A -><H2 ->Name</H2 -><CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_YVU410</CODE -> -('YVU9'), <CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_YUV410</CODE -> -('YUV9') -- Planar formats with ¼ horizontal and -vertical chroma resolution, also known as YUV 4:1:0.</DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN2558" -></A -><H2 ->Description</H2 -><P ->These are planar formats, as opposed to a packed format. -The three components are separated into three sub-images or planes. -The Y plane is first. The Y plane has one byte per pixel. For -<CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_YVU410</CODE ->, the Cr plane immediately -follows the Y plane in memory. The Cr plane is ¼ the width and -¼ the height of the Y plane (and of the image). Each Cr belongs -to 16 pixels, a four-by-four square of the image. Following the Cr -plane is the Cb plane, just like the Cr plane. -<CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_YUV410</CODE -> is the same, except the Cb -plane comes first, then the Cr plane.</P -><P ->If the Y plane has pad bytes after each row, then the Cr -and Cb planes have ¼ as many pad bytes after their rows. In -other words, four Cx rows (including padding) are exactly as long as -one Y row (including padding).</P -><DIV -CLASS="EXAMPLE" -><A -NAME="AEN2564" -></A -><P -><B ->Example 2-1. <CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_YVU410</CODE -> 4 × 4 -pixel image</B -></P -><DIV -CLASS="FORMALPARA" -><P -><B ->Byte Order. </B ->Each cell is one byte. - <DIV -CLASS="INFORMALTABLE" -><P -></P -><A -NAME="AEN2570" -></A -><TABLE -BORDER="0" -FRAME="void" -CLASS="CALSTABLE" -><COL -WIDTH="2*" -ALIGN="LEFT"><COL><COL><COL><COL><TBODY -><TR -><TD ->start + 0:</TD -><TD ->Y'<SUB ->00</SUB -></TD -><TD ->Y'<SUB ->01</SUB -></TD -><TD ->Y'<SUB ->02</SUB -></TD -><TD ->Y'<SUB ->03</SUB -></TD -></TR -><TR -><TD ->start + 4:</TD -><TD ->Y'<SUB ->10</SUB -></TD -><TD ->Y'<SUB ->11</SUB -></TD -><TD ->Y'<SUB ->12</SUB -></TD -><TD ->Y'<SUB ->13</SUB -></TD -></TR -><TR -><TD ->start + 8:</TD -><TD ->Y'<SUB ->20</SUB -></TD -><TD ->Y'<SUB ->21</SUB -></TD -><TD ->Y'<SUB ->22</SUB -></TD -><TD ->Y'<SUB ->23</SUB -></TD -></TR -><TR -><TD ->start + 12:</TD -><TD ->Y'<SUB ->30</SUB -></TD -><TD ->Y'<SUB ->31</SUB -></TD -><TD ->Y'<SUB ->32</SUB -></TD -><TD ->Y'<SUB ->33</SUB -></TD -></TR -><TR -><TD ->start + 16:</TD -><TD ->Cr<SUB ->00</SUB -></TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -></TR -><TR -><TD ->start + 17:</TD -><TD ->Cb<SUB ->00</SUB -></TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -></TR -></TBODY -></TABLE -><P -></P -></DIV -> - </P -></DIV -><DIV -CLASS="FORMALPARA" -><P -><B ->Color Sample Location. </B -> <DIV -CLASS="INFORMALTABLE" -><P -></P -><A -NAME="AEN2625" -></A -><TABLE -BORDER="0" -FRAME="void" -CLASS="CALSTABLE" -><COL><COL><COL><COL><COL><COL><COL><TBODY -><TR -><TD -> </TD -><TD ->0</TD -><TD -> </TD -><TD ->1</TD -><TD -> </TD -><TD ->2</TD -><TD -> </TD -><TD ->3</TD -></TR -><TR -><TD ->0</TD -><TD ->Y</TD -><TD -> </TD -><TD ->Y</TD -><TD -> </TD -><TD ->Y</TD -><TD -> </TD -><TD ->Y</TD -></TR -><TR -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -></TR -><TR -><TD ->1</TD -><TD ->Y</TD -><TD -> </TD -><TD ->Y</TD -><TD -> </TD -><TD ->Y</TD -><TD -> </TD -><TD ->Y</TD -></TR -><TR -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD ->C</TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -></TR -><TR -><TD ->2</TD -><TD ->Y</TD -><TD -> </TD -><TD ->Y</TD -><TD -> </TD -><TD ->Y</TD -><TD -> </TD -><TD ->Y</TD -></TR -><TR -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -></TR -><TR -><TD ->3</TD -><TD ->Y</TD -><TD -> </TD -><TD ->Y</TD -><TD -> </TD -><TD ->Y</TD -><TD -> </TD -><TD ->Y</TD -></TR -></TBODY -></TABLE -><P -></P -></DIV -> - </P -></DIV -></DIV -></DIV -><H1 -><A -NAME="PIXFMT-YUV422P" -></A -><CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_YUV422P</CODE -></H1 -><DIV -CLASS="REFNAMEDIV" -><A -NAME="AEN2690" -></A -><H2 ->Name</H2 -><CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_YUV422P</CODE -> -('422P') -- Format with ½ horizontal chroma resolution, -also known as YUV 4:2:2. Planar layout as opposed to -<CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_YUYV</CODE ->.</DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN2695" -></A -><H2 ->Description</H2 -><P ->This format is not commonly used. This is a planar -version of the YUYV format. The three components are separated into -three sub-images or planes. The Y plane is first. The Y plane has one -byte per pixel. The Cb plane immediately follows the Y plane in -memory. The Cb plane is half the width of the Y plane (and of the -image). Each Cb belongs to two pixels. For example, -Cb<SUB ->0</SUB -> belongs to Y'<SUB ->00</SUB ->, -Y'<SUB ->01</SUB ->. Following the Cb plane is the Cr plane, -just like the Cb plane.</P -><P ->If the Y plane has pad bytes after each row, then the Cr -and Cb planes have half as many pad bytes after their rows. In other -words, two Cx rows (including padding) is exactly as long as one Y row -(including padding).</P -><DIV -CLASS="EXAMPLE" -><A -NAME="AEN2702" -></A -><P -><B ->Example 2-1. <CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_YUV422P</CODE -> 4 × 4 -pixel image</B -></P -><DIV -CLASS="FORMALPARA" -><P -><B ->Byte Order. </B ->Each cell is one byte. - <DIV -CLASS="INFORMALTABLE" -><P -></P -><A -NAME="AEN2708" -></A -><TABLE -BORDER="0" -FRAME="void" -CLASS="CALSTABLE" -><COL -WIDTH="2*" -ALIGN="LEFT"><COL><COL><COL><COL><TBODY -><TR -><TD ->start + 0:</TD -><TD ->Y'<SUB ->00</SUB -></TD -><TD ->Y'<SUB ->01</SUB -></TD -><TD ->Y'<SUB ->02</SUB -></TD -><TD ->Y'<SUB ->03</SUB -></TD -></TR -><TR -><TD ->start + 4:</TD -><TD ->Y'<SUB ->10</SUB -></TD -><TD ->Y'<SUB ->11</SUB -></TD -><TD ->Y'<SUB ->12</SUB -></TD -><TD ->Y'<SUB ->13</SUB -></TD -></TR -><TR -><TD ->start + 8:</TD -><TD ->Y'<SUB ->20</SUB -></TD -><TD ->Y'<SUB ->21</SUB -></TD -><TD ->Y'<SUB ->22</SUB -></TD -><TD ->Y'<SUB ->23</SUB -></TD -></TR -><TR -><TD ->start + 12:</TD -><TD ->Y'<SUB ->30</SUB -></TD -><TD ->Y'<SUB ->31</SUB -></TD -><TD ->Y'<SUB ->32</SUB -></TD -><TD ->Y'<SUB ->33</SUB -></TD -></TR -><TR -><TD ->start + 16:</TD -><TD ->Cb<SUB ->00</SUB -></TD -><TD ->Cb<SUB ->01</SUB -></TD -><TD -> </TD -><TD -> </TD -></TR -><TR -><TD ->start + 18:</TD -><TD ->Cb<SUB ->10</SUB -></TD -><TD ->Cb<SUB ->11</SUB -></TD -><TD -> </TD -><TD -> </TD -></TR -><TR -><TD ->start + 20:</TD -><TD ->Cb<SUB ->20</SUB -></TD -><TD ->Cb<SUB ->21</SUB -></TD -><TD -> </TD -><TD -> </TD -></TR -><TR -><TD ->start + 22:</TD -><TD ->Cb<SUB ->30</SUB -></TD -><TD ->Cb<SUB ->31</SUB -></TD -><TD -> </TD -><TD -> </TD -></TR -><TR -><TD ->start + 24:</TD -><TD ->Cr<SUB ->00</SUB -></TD -><TD ->Cr<SUB ->01</SUB -></TD -><TD -> </TD -><TD -> </TD -></TR -><TR -><TD ->start + 26:</TD -><TD ->Cr<SUB ->10</SUB -></TD -><TD ->Cr<SUB ->11</SUB -></TD -><TD -> </TD -><TD -> </TD -></TR -><TR -><TD ->start + 28:</TD -><TD ->Cr<SUB ->20</SUB -></TD -><TD ->Cr<SUB ->21</SUB -></TD -><TD -> </TD -><TD -> </TD -></TR -><TR -><TD ->start + 30:</TD -><TD ->Cr<SUB ->30</SUB -></TD -><TD ->Cr<SUB ->31</SUB -></TD -><TD -> </TD -><TD -> </TD -></TR -></TBODY -></TABLE -><P -></P -></DIV -> - </P -></DIV -><DIV -CLASS="FORMALPARA" -><P -><B ->Color Sample Location. </B -> <DIV -CLASS="INFORMALTABLE" -><P -></P -><A -NAME="AEN2803" -></A -><TABLE -BORDER="0" -FRAME="void" -CLASS="CALSTABLE" -><COL><COL><COL><COL><COL><COL><COL><TBODY -><TR -><TD -> </TD -><TD ->0</TD -><TD -> </TD -><TD ->1</TD -><TD -> </TD -><TD ->2</TD -><TD -> </TD -><TD ->3</TD -></TR -><TR -><TD ->0</TD -><TD ->Y</TD -><TD ->C</TD -><TD ->Y</TD -><TD -> </TD -><TD ->Y</TD -><TD ->C</TD -><TD ->Y</TD -></TR -><TR -><TD ->1</TD -><TD ->Y</TD -><TD ->C</TD -><TD ->Y</TD -><TD -> </TD -><TD ->Y</TD -><TD ->C</TD -><TD ->Y</TD -></TR -><TR -><TD ->2</TD -><TD ->Y</TD -><TD ->C</TD -><TD ->Y</TD -><TD -> </TD -><TD ->Y</TD -><TD ->C</TD -><TD ->Y</TD -></TR -><TR -><TD ->3</TD -><TD ->Y</TD -><TD ->C</TD -><TD ->Y</TD -><TD -> </TD -><TD ->Y</TD -><TD ->C</TD -><TD ->Y</TD -></TR -></TBODY -></TABLE -><P -></P -></DIV -> - </P -></DIV -></DIV -></DIV -><H1 -><A -NAME="PIXFMT-YUV411P" -></A -><CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_YUV411P</CODE -></H1 -><DIV -CLASS="REFNAMEDIV" -><A -NAME="AEN2855" -></A -><H2 ->Name</H2 -><CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_YUV411P</CODE -> -('411P') -- Format with ¼ horizontal chroma resolution, -also known as YUV 4:1:1. Planar layout as opposed to -<CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_Y41P</CODE ->.</DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN2860" -></A -><H2 ->Description</H2 -><P ->This format is not commonly used. This is a planar -format similar to the 4:2:2 planar format except with half as many -chroma. The three components are separated into three sub-images or -planes. The Y plane is first. The Y plane has one byte per pixel. The -Cb plane immediately follows the Y plane in memory. The Cb plane is -¼ the width of the Y plane (and of the image). Each Cb belongs -to 4 pixels all on the same row. For example, -Cb<SUB ->0</SUB -> belongs to Y'<SUB ->00</SUB ->, -Y'<SUB ->01</SUB ->, Y'<SUB ->02</SUB -> and -Y'<SUB ->03</SUB ->. Following the Cb plane is the Cr plane, -just like the Cb plane.</P -><P ->If the Y plane has pad bytes after each row, then the Cr -and Cb planes have ¼ as many pad bytes after their rows. In -other words, four C x rows (including padding) is exactly as long as -one Y row (including padding).</P -><DIV -CLASS="EXAMPLE" -><A -NAME="AEN2869" -></A -><P -><B ->Example 2-1. <CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_YUV411P</CODE -> 4 × 4 -pixel image</B -></P -><DIV -CLASS="FORMALPARA" -><P -><B ->Byte Order. </B ->Each cell is one byte. - <DIV -CLASS="INFORMALTABLE" -><P -></P -><A -NAME="AEN2875" -></A -><TABLE -BORDER="0" -FRAME="void" -CLASS="CALSTABLE" -><COL -WIDTH="2*" -ALIGN="LEFT"><COL><COL><COL><COL><TBODY -><TR -><TD ->start + 0:</TD -><TD ->Y'<SUB ->00</SUB -></TD -><TD ->Y'<SUB ->01</SUB -></TD -><TD ->Y'<SUB ->02</SUB -></TD -><TD ->Y'<SUB ->03</SUB -></TD -></TR -><TR -><TD ->start + 4:</TD -><TD ->Y'<SUB ->10</SUB -></TD -><TD ->Y'<SUB ->11</SUB -></TD -><TD ->Y'<SUB ->12</SUB -></TD -><TD ->Y'<SUB ->13</SUB -></TD -></TR -><TR -><TD ->start + 8:</TD -><TD ->Y'<SUB ->20</SUB -></TD -><TD ->Y'<SUB ->21</SUB -></TD -><TD ->Y'<SUB ->22</SUB -></TD -><TD ->Y'<SUB ->23</SUB -></TD -></TR -><TR -><TD ->start + 12:</TD -><TD ->Y'<SUB ->30</SUB -></TD -><TD ->Y'<SUB ->31</SUB -></TD -><TD ->Y'<SUB ->32</SUB -></TD -><TD ->Y'<SUB ->33</SUB -></TD -></TR -><TR -><TD ->start + 16:</TD -><TD ->Cb<SUB ->00</SUB -></TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -></TR -><TR -><TD ->start + 17:</TD -><TD ->Cb<SUB ->10</SUB -></TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -></TR -><TR -><TD ->start + 18:</TD -><TD ->Cb<SUB ->20</SUB -></TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -></TR -><TR -><TD ->start + 19:</TD -><TD ->Cb<SUB ->30</SUB -></TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -></TR -><TR -><TD ->start + 20:</TD -><TD ->Cr<SUB ->00</SUB -></TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -></TR -><TR -><TD ->start + 21:</TD -><TD ->Cr<SUB ->10</SUB -></TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -></TR -><TR -><TD ->start + 22:</TD -><TD ->Cr<SUB ->20</SUB -></TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -></TR -><TR -><TD ->start + 23:</TD -><TD ->Cr<SUB ->30</SUB -></TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -></TR -></TBODY -></TABLE -><P -></P -></DIV -> - </P -></DIV -><DIV -CLASS="FORMALPARA" -><P -><B ->Color Sample Location. </B -> <DIV -CLASS="INFORMALTABLE" -><P -></P -><A -NAME="AEN2954" -></A -><TABLE -BORDER="0" -FRAME="void" -CLASS="CALSTABLE" -><COL><COL><COL><COL><COL><COL><COL><TBODY -><TR -><TD -> </TD -><TD ->0</TD -><TD -> </TD -><TD ->1</TD -><TD -> </TD -><TD ->2</TD -><TD -> </TD -><TD ->3</TD -></TR -><TR -><TD ->0</TD -><TD ->Y</TD -><TD -> </TD -><TD ->Y</TD -><TD ->C</TD -><TD ->Y</TD -><TD -> </TD -><TD ->Y</TD -></TR -><TR -><TD ->1</TD -><TD ->Y</TD -><TD -> </TD -><TD ->Y</TD -><TD ->C</TD -><TD ->Y</TD -><TD -> </TD -><TD ->Y</TD -></TR -><TR -><TD ->2</TD -><TD ->Y</TD -><TD -> </TD -><TD ->Y</TD -><TD ->C</TD -><TD ->Y</TD -><TD -> </TD -><TD ->Y</TD -></TR -><TR -><TD ->3</TD -><TD ->Y</TD -><TD -> </TD -><TD ->Y</TD -><TD ->C</TD -><TD ->Y</TD -><TD -> </TD -><TD ->Y</TD -></TR -></TBODY -></TABLE -><P -></P -></DIV -> - </P -></DIV -></DIV -></DIV -><H1 -><A -NAME="AEN3002" -></A -><CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_NV12</CODE ->, -<CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_NV21</CODE -></H1 -><DIV -CLASS="REFNAMEDIV" -><A -NAME="AEN3007" -></A -><H2 ->Name</H2 -><CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_NV12</CODE -> -('NV12'), <CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_NV21</CODE -> -('NV21') -- Formats with ½ horizontal and vertical -chroma resolution, also known as YUV 4:2:0. One luminance and one -chrominance plane with alternating chroma samples as opposed to -<CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_YVU420</CODE ->.</DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN3014" -></A -><H2 ->Description</H2 -><P ->These are two-plane versions of the YUV 4:2:0 format. -The three components are separated into two sub-images or planes. The -Y plane is first. The Y plane has one byte per pixel. For -<CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_NV12</CODE ->, a combined CbCr plane -immediately follows the Y plane in memory. The CbCr plane is the same -width, in bytes, as the Y plane (and of the image), but is half as -tall in pixels. Each CbCr pair belongs to four pixels. For example, -Cb<SUB ->0</SUB ->/Cr<SUB ->0</SUB -> belongs to -Y'<SUB ->00</SUB ->, Y'<SUB ->01</SUB ->, -Y'<SUB ->10</SUB ->, Y'<SUB ->11</SUB ->. -<CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_NV21</CODE -> is the same except the Cb and -Cr bytes are swapped, the CrCb plane starts with a Cr byte.</P -><P ->If the Y plane has pad bytes after each row, then the -CbCr plane has as many pad bytes after its rows.</P -><DIV -CLASS="EXAMPLE" -><A -NAME="AEN3026" -></A -><P -><B ->Example 2-1. <CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_NV12</CODE -> 4 × 4 -pixel image</B -></P -><DIV -CLASS="FORMALPARA" -><P -><B ->Byte Order. </B ->Each cell is one byte. - <DIV -CLASS="INFORMALTABLE" -><P -></P -><A -NAME="AEN3032" -></A -><TABLE -BORDER="0" -FRAME="void" -CLASS="CALSTABLE" -><COL -WIDTH="2*" -ALIGN="LEFT"><COL><COL><COL><COL><TBODY -><TR -><TD ->start + 0:</TD -><TD ->Y'<SUB ->00</SUB -></TD -><TD ->Y'<SUB ->01</SUB -></TD -><TD ->Y'<SUB ->02</SUB -></TD -><TD ->Y'<SUB ->03</SUB -></TD -></TR -><TR -><TD ->start + 4:</TD -><TD ->Y'<SUB ->10</SUB -></TD -><TD ->Y'<SUB ->11</SUB -></TD -><TD ->Y'<SUB ->12</SUB -></TD -><TD ->Y'<SUB ->13</SUB -></TD -></TR -><TR -><TD ->start + 8:</TD -><TD ->Y'<SUB ->20</SUB -></TD -><TD ->Y'<SUB ->21</SUB -></TD -><TD ->Y'<SUB ->22</SUB -></TD -><TD ->Y'<SUB ->23</SUB -></TD -></TR -><TR -><TD ->start + 12:</TD -><TD ->Y'<SUB ->30</SUB -></TD -><TD ->Y'<SUB ->31</SUB -></TD -><TD ->Y'<SUB ->32</SUB -></TD -><TD ->Y'<SUB ->33</SUB -></TD -></TR -><TR -><TD ->start + 16:</TD -><TD ->Cb<SUB ->00</SUB -></TD -><TD ->Cr<SUB ->00</SUB -></TD -><TD ->Cb<SUB ->01</SUB -></TD -><TD ->Cr<SUB ->01</SUB -></TD -></TR -><TR -><TD ->start + 20:</TD -><TD ->Cb<SUB ->10</SUB -></TD -><TD ->Cr<SUB ->10</SUB -></TD -><TD ->Cb<SUB ->11</SUB -></TD -><TD ->Cr<SUB ->11</SUB -></TD -></TR -></TBODY -></TABLE -><P -></P -></DIV -> - </P -></DIV -><DIV -CLASS="FORMALPARA" -><P -><B ->Color Sample Location. </B -> <DIV -CLASS="INFORMALTABLE" -><P -></P -><A -NAME="AEN3099" -></A -><TABLE -BORDER="0" -FRAME="void" -CLASS="CALSTABLE" -><COL><COL><COL><COL><COL><COL><COL><TBODY -><TR -><TD -> </TD -><TD ->0</TD -><TD -> </TD -><TD ->1</TD -><TD -> </TD -><TD ->2</TD -><TD -> </TD -><TD ->3</TD -></TR -><TR -><TD ->0</TD -><TD ->Y</TD -><TD -> </TD -><TD ->Y</TD -><TD -> </TD -><TD ->Y</TD -><TD -> </TD -><TD ->Y</TD -></TR -><TR -><TD -> </TD -><TD -> </TD -><TD ->C</TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD ->C</TD -><TD -> </TD -></TR -><TR -><TD ->1</TD -><TD ->Y</TD -><TD -> </TD -><TD ->Y</TD -><TD -> </TD -><TD ->Y</TD -><TD -> </TD -><TD ->Y</TD -></TR -><TR -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -></TR -><TR -><TD ->2</TD -><TD ->Y</TD -><TD -> </TD -><TD ->Y</TD -><TD -> </TD -><TD ->Y</TD -><TD -> </TD -><TD ->Y</TD -></TR -><TR -><TD -> </TD -><TD -> </TD -><TD ->C</TD -><TD -> </TD -><TD -> </TD -><TD -> </TD -><TD ->C</TD -><TD -> </TD -></TR -><TR -><TD ->3</TD -><TD ->Y</TD -><TD -> </TD -><TD ->Y</TD -><TD -> </TD -><TD ->Y</TD -><TD -> </TD -><TD ->Y</TD -></TR -></TBODY -></TABLE -><P -></P -></DIV -> - </P -></DIV -></DIV -></DIV -></DIV -><DIV -CLASS="SECTION" -><HR><H2 -CLASS="SECTION" -><A -NAME="AEN3167" ->2.5. Compressed Formats</A -></H2 -><P ->[to do, see also <A -HREF="#VIDIOC-G-COMP" -><CODE -CLASS="CONSTANT" ->VIDIOC_G_COMP</CODE -></A ->, <A -HREF="#VIDIOC-G-COMP" -><CODE -CLASS="CONSTANT" ->VIDIOC_S_COMP</CODE -></A ->, -<A -HREF="#VIDIOC-G-JPEGCOMP" -><CODE -CLASS="CONSTANT" ->VIDIOC_G_JPEGCOMP</CODE -></A ->, <A -HREF="#VIDIOC-G-JPEGCOMP" -><CODE -CLASS="CONSTANT" ->VIDIOC_S_JPEGCOMP</CODE -></A ->. The only compressed standard -format should be [M]JPEG.]</P -></DIV -><DIV -CLASS="SECTION" -><HR><H2 -CLASS="SECTION" -><A -NAME="PIXFMT-RESERVED" ->2.6. Reserved Format Identifiers</A -></H2 -><P ->These formats are not defined by this specification, they -are just listed for reference and to avoid naming conflicts. If you -want to register your own format, send an e-mail to V4L2 maintainer -Gerd Knorr <A -HREF="http://bytesex.org/" -TARGET="_top" ->http://bytesex.org/</A -> -for inclusion in the <TT -CLASS="FILENAME" ->videodev.h</TT -> file. If you want -to share your format with other developers add a link to your -documentation and send a copy to the maintainer of this document, -Michael Schimek <CODE -CLASS="EMAIL" -><<A -HREF="mailto:mschimek@gmx.at" ->mschimek@gmx.at</A ->></CODE ->, for inclusion in this -section. If you think your format should be listed in a standard -format section please make a proposal on the V4L mailing list: -<A -HREF="https://listman.redhat.com/mailman/listinfo/video4linux-list" -TARGET="_top" ->https://listman.redhat.com/mailman/listinfo/video4linux-list</A ->.</P -><DIV -CLASS="TABLE" -><A -NAME="RESERVED-FORMATS" -></A -><P -><B ->Table 2-4. Reserved Image Formats</B -></P -><TABLE -BORDER="0" -FRAME="void" -WIDTH="100%" -CLASS="CALSTABLE" -><COL -WIDTH="38%" -TITLE="C1"><COL -WIDTH="12%" -TITLE="C2"><COL -WIDTH="50%" -TITLE="C3"><THEAD -><TR -><TH ->Identifier</TH -><TH ->Code</TH -><TH ->Details</TH -></TR -></THEAD -><TBODY -><TR -><TD -> <CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_YYUV</CODE -> - </TD -><TD ->'YYUV'</TD -><TD ->unknown</TD -></TR -><TR -><TD -> <CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_HI240</CODE -> - </TD -><TD ->'HI24'</TD -><TD -> Used by the BTTV driver, <A -HREF="http://bytesex.org/bttv/" -TARGET="_top" ->http://bytesex.org/bttv/</A -> - </TD -></TR -><TR -><TD -> <CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_MJPEG</CODE -> - </TD -><TD ->'MJPG'</TD -><TD ->Used by the Zoran driver</TD -></TR -><TR -><TD -> <CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_JPEG</CODE -> - </TD -><TD ->'JPEG'</TD -><TD ->unknown [?]</TD -></TR -><TR -><TD -> <CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_DV</CODE -> - </TD -><TD ->'dvsd'</TD -><TD ->unknown</TD -></TR -><TR -><TD -> <CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_MPEG</CODE -> - </TD -><TD ->'MPEG'</TD -><TD ->unknown</TD -></TR -><TR -><TD -> <CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_WNVA</CODE -> - </TD -><TD ->'WNVA'</TD -><TD -> Used by the Winnov Videum driver, <A -HREF="http://www.thedirks.org/winnov/" -TARGET="_top" ->http://www.thedirks.org/winnov/</A -> - </TD -></TR -></TBODY -></TABLE -></DIV -></DIV -></DIV -><DIV -CLASS="CHAPTER" -><HR><H1 -><A -NAME="IO" -></A ->Chapter 3. Input/Output</H1 -><P ->The V4L2 API defines several different methods to read from or -write to a device. All drivers exchanging data with applications must -support at least one of them.</P -><P ->The classic I/O method using the <CODE -CLASS="FUNCTION" ->read()</CODE -> -and <CODE -CLASS="FUNCTION" ->write()</CODE -> function is automatically selected -after opening a V4L2 device. When the driver does not support this -method attempts to read or write will fail at any time.</P -><P ->Other methods must be negotiated. To select the streaming I/O -method with memory mapped or user buffers applications call the -<A -HREF="#VIDIOC-REQBUFS" -><CODE -CLASS="CONSTANT" ->VIDIOC_REQBUFS</CODE -></A -> ioctl. The asynchronous I/O method is not defined -yet.</P -><P ->Video overlay can be considered another I/O method, although -the application does not directly receive the image data. It is -selected by initiating video overlay with the <A -HREF="#VIDIOC-G-FMT" -><CODE -CLASS="CONSTANT" ->VIDIOC_S_FMT</CODE -></A -> ioctl. -For more information see <A -HREF="#OVERLAY" ->Section 4.2</A ->.</P -><P ->Generally exactly one I/O method, including overlay, is -associated with each file descriptor. The only exceptions are -applications not exchanging data with a driver ("panel applications", -see <A -HREF="#OPEN" ->Section 1.1</A ->) and drivers permitting simultaneous video capturing -and overlay using the same file descriptor, for compatibility with V4L -and earlier versions of V4L2.</P -><P -><CODE -CLASS="CONSTANT" ->VIDIOC_S_FMT</CODE -> and -<CODE -CLASS="CONSTANT" ->VIDIOC_REQBUFS</CODE -> would permit this to some degree, -but for simplicity drivers need not support switching the I/O method -(after first switching away from read/write) other than by closing -and reopening the device.</P -><P ->The following sections describe the various I/O methods in -more detail.</P -><DIV -CLASS="SECTION" -><HR><H2 -CLASS="SECTION" -><A -NAME="RW" ->3.1. Read/Write</A -></H2 -><P ->Input and output devices support the -<CODE -CLASS="FUNCTION" ->read()</CODE -> and <CODE -CLASS="FUNCTION" ->write()</CODE -> function, -respectively, when the <CODE -CLASS="CONSTANT" ->V4L2_CAP_READWRITE</CODE -> flag in -the <CODE -CLASS="STRUCTFIELD" ->capabilities</CODE -> field of struct <A -HREF="#V4L2-CAPABILITY" ->v4l2_capability</A -> -returned by the <A -HREF="#VIDIOC-QUERYCAP" -><CODE -CLASS="CONSTANT" ->VIDIOC_QUERYCAP</CODE -></A -> ioctl is set.</P -><P ->Drivers may need the CPU to copy the data, but they may also -support DMA to or from user memory, so this I/O method is not -necessarily less efficient than other methods merely exchanging buffer -pointers. It is considered inferior though because no meta-information -like frame counters or timestamps are passed. This information is -necessary to recognize frame dropping and to synchronize with other -data streams. However this is also the simplest I/O method, requiring -little or no setup to exchange data. It permits command line stunts -like this (the <SPAN -CLASS="APPLICATION" ->vidctrl</SPAN -> tool is -fictitious):</P -><DIV -CLASS="INFORMALEXAMPLE" -><P -></P -><A -NAME="AEN3266" -></A -><PRE -CLASS="SCREEN" ->> vidctrl /dev/video --input=0 --format=YUYV --size=352x288 -> dd if=/dev/video of=myimage.422 bs=202752 count=1</PRE -><P -></P -></DIV -><P ->To read from the device applications use the -<A -HREF="#FUNC-READ" -><CODE -CLASS="FUNCTION" ->read()</CODE -></A -> function, to write the <A -HREF="#FUNC-WRITE" -><CODE -CLASS="FUNCTION" ->write()</CODE -></A -> function. -Drivers must implement one I/O method if they -exchange data with applications, but it need not be this.<A -NAME="AEN3273" -HREF="#FTN.AEN3273" -><SPAN -CLASS="footnote" ->[13]</SPAN -></A -> When reading or writing is supported, the driver -must also support the <A -HREF="#FUNC-SELECT" -><CODE -CLASS="FUNCTION" ->select()</CODE -></A -> and <A -HREF="#FUNC-POLL" -><CODE -CLASS="FUNCTION" ->poll()</CODE -></A -> -function.<A -NAME="AEN3279" -HREF="#FTN.AEN3279" -><SPAN -CLASS="footnote" ->[14]</SPAN -></A -></P -></DIV -><DIV -CLASS="SECTION" -><HR><H2 -CLASS="SECTION" -><A -NAME="MMAP" ->3.2. Streaming I/O (Memory Mapping)</A -></H2 -><P ->Input and output devices support this I/O method when the -<CODE -CLASS="CONSTANT" ->V4L2_CAP_STREAMING</CODE -> flag in the -<CODE -CLASS="STRUCTFIELD" ->capabilities</CODE -> field of struct <A -HREF="#V4L2-CAPABILITY" ->v4l2_capability</A -> -returned by the <A -HREF="#VIDIOC-QUERYCAP" -><CODE -CLASS="CONSTANT" ->VIDIOC_QUERYCAP</CODE -></A -> ioctl is set. There are two -streaming methods, to determine if the memory mapping flavor is -supported applications must call the <A -HREF="#VIDIOC-REQBUFS" -><CODE -CLASS="CONSTANT" ->VIDIOC_REQBUFS</CODE -></A -> ioctl.</P -><P ->Streaming is an I/O method where only pointers to buffers -are exchanged between application and driver, the data itself is not -copied. Memory mapping is primarily intended to map buffers in device -memory into the application's address space. Device memory can be for -example the video memory on a graphics card with a video capture -add-on. However, being the most efficient I/O method available for a -long time, many other drivers support streaming as well, allocating -buffers in DMA-able main memory.</P -><P ->A driver can support many sets of buffers. Each set is -identified by a unique buffer type value. The sets are independent and -each set can hold a different type of data. To access different sets -at the same time different file descriptors must be used.<A -NAME="AEN3296" -HREF="#FTN.AEN3296" -><SPAN -CLASS="footnote" ->[15]</SPAN -></A -></P -><P ->To allocate device buffers applications call the -<A -HREF="#VIDIOC-REQBUFS" -><CODE -CLASS="CONSTANT" ->VIDIOC_REQBUFS</CODE -></A -> ioctl with the desired number of buffers and buffer -type, for example <CODE -CLASS="CONSTANT" ->V4L2_BUF_TYPE_VIDEO_CAPTURE</CODE ->. -This ioctl can also be used to change the number of buffers or to free -the allocated memory, provided none of the buffers are still -mapped.</P -><P ->Before applications can access the buffers they must map -them into their address space with the <A -HREF="#FUNC-MMAP" -><CODE -CLASS="FUNCTION" ->mmap()</CODE -></A -> function. The -location of the buffers in device memory can be determined with the -<A -HREF="#VIDIOC-QUERYBUF" -><CODE -CLASS="CONSTANT" ->VIDIOC_QUERYBUF</CODE -></A -> ioctl. The <CODE -CLASS="STRUCTFIELD" ->m.offset</CODE -> and -<CODE -CLASS="STRUCTFIELD" ->length</CODE -> returned in a struct <A -HREF="#V4L2-BUFFER" ->v4l2_buffer</A -> are -passed as sixth and second parameter to the -<CODE -CLASS="FUNCTION" ->mmap()</CODE -> function. The offset and length values -must not be modified. Remember the buffers are allocated in physical -memory, as opposed to virtual memory which can be swapped out to disk. -Applications should free the buffers as soon as possible with the -<A -HREF="#FUNC-MUNMAP" -><CODE -CLASS="FUNCTION" ->munmap()</CODE -></A -> function.</P -><DIV -CLASS="EXAMPLE" -><A -NAME="AEN3316" -></A -><P -><B ->Example 3-1. Mapping buffers</B -></P -><PRE -CLASS="PROGRAMLISTING" ->struct <A -HREF="#V4L2-REQUESTBUFFERS" ->v4l2_requestbuffers</A -> reqbuf; -struct { - void *start; - size_t length; -} *buffers; -unsigned int i; - -memset (&reqbuf, 0, sizeof (reqbuf)); -reqbuf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; -reqbuf.memory = V4L2_MEMORY_MMAP; -reqbuf.count = 20; - -if (-1 == ioctl (fd, <A -HREF="#VIDIOC-REQBUFS" -><CODE -CLASS="CONSTANT" ->VIDIOC_REQBUFS</CODE -></A ->, &reqbuf)) { - if (errno == EINVAL) - printf ("Video capturing or mmap-streaming is not supported\n"); - else - perror ("VIDIOC_REQBUFS"); - - exit (EXIT_FAILURE); -} - -/* We want at least five buffers. */ - -if (reqbuf.count < 5) { - /* You may need to free the buffers here. */ - printf ("Not enough buffer memory\n"); - exit (EXIT_FAILURE); -} - -buffers = calloc (reqbuf.count, sizeof (*buffers)); -assert (buffers != NULL); - -for (i = 0; i < reqbuf.count; i++) { - struct <A -HREF="#V4L2-BUFFER" ->v4l2_buffer</A -> buffer; - - memset (&buffer, 0, sizeof (buffer)); - buffer.type = reqbuf.type; - buffer.memory = V4L2_MEMORY_MMAP; - buffer.index = i; - - if (-1 == ioctl (fd, <A -HREF="#VIDIOC-QUERYBUF" -><CODE -CLASS="CONSTANT" ->VIDIOC_QUERYBUF</CODE -></A ->, &buffer)) { - perror ("VIDIOC_QUERYBUF"); - exit (EXIT_FAILURE); - } - - buffers[i].length = buffer.length; /* remember for munmap() */ - - buffers[i].start = mmap (NULL, buffer.length, - PROT_READ | PROT_WRITE, /* required */ - MAP_SHARED, /* recommended */ - fd, buffer.m.offset); - - if (buffers[i].start == MAP_FAILED) { - /* You may need to unmap and free the so far - mapped buffers here. */ - perror ("mmap"); - exit (EXIT_FAILURE); - } -} - -/* Cleanup. */ - -for (i = 0; i < reqbuf.count; i++) - munmap (buffers[i].start, buffers[i].length); - </PRE -></DIV -><P ->Streaming drivers maintain two buffer queues, an incoming -and an outgoing queue. They separate the synchronous capture or output -operation locked to a video clock from the application which is -subject to random disk or network delays and preemption by -other processes, thereby reducing the probability of data loss. -The queues are organized as FIFOs, buffers will be -output in the order enqueued in the incoming FIFO, and were -captured in the order dequeued from the outgoing FIFO.</P -><P ->The driver may require a minimum number of buffers enqueued -at all times to function, apart of this no limit exists on the number -of buffers applications can enqueue in advance, or dequeue and -process. They can also enqueue in a different order than buffers have -been dequeued, and the driver can <SPAN -CLASS="emphasis" -><I -CLASS="EMPHASIS" ->fill</I -></SPAN -> enqueued -<SPAN -CLASS="emphasis" -><I -CLASS="EMPHASIS" ->empty</I -></SPAN -> buffers in any order. <A -NAME="AEN3329" -HREF="#FTN.AEN3329" -><SPAN -CLASS="footnote" ->[16]</SPAN -></A -> The index number of a buffer (struct <A -HREF="#V4L2-BUFFER" ->v4l2_buffer</A -> -<CODE -CLASS="STRUCTFIELD" ->index</CODE ->) plays no role here, it only -identifies the buffer.</P -><P ->Initially all mapped buffers are in dequeued state, -inaccessible by the driver. For capturing applications it is customary -to first enqueue all mapped buffers, then to start capturing and enter -the read loop. Here the application waits until a filled buffer can be -dequeued, and re-enqueues the buffer when the data is no longer -needed. Output applications fill and enqueue buffers, when enough -buffers are stacked up the output is started with -<CODE -CLASS="CONSTANT" ->VIDIOC_STREAMON</CODE ->. In the write loop, when -the application runs out of free buffers, it must wait until an empty -buffer can be dequeued and reused.</P -><P ->To enqueue and dequeue a buffer applications use the -<A -HREF="#VIDIOC-QBUF" -><CODE -CLASS="CONSTANT" ->VIDIOC_QBUF</CODE -></A -> and <A -HREF="#VIDIOC-QBUF" -><CODE -CLASS="CONSTANT" ->VIDIOC_DQBUF</CODE -></A -> ioctl. The status of a buffer being -mapped, enqueued, full or empty can be determined at any time using the -<A -HREF="#VIDIOC-QUERYBUF" -><CODE -CLASS="CONSTANT" ->VIDIOC_QUERYBUF</CODE -></A -> ioctl. Two methods exist to suspend execution of the -application until one or more buffers can be dequeued. By default -<CODE -CLASS="CONSTANT" ->VIDIOC_DQBUF</CODE -> blocks when no buffer is in the -outgoing queue. When the <CODE -CLASS="CONSTANT" ->O_NONBLOCK</CODE -> flag was -given to the <A -HREF="#FUNC-OPEN" -><CODE -CLASS="FUNCTION" ->open()</CODE -></A -> function, <CODE -CLASS="CONSTANT" ->VIDIOC_DQBUF</CODE -> -returns immediately with an <SPAN -CLASS="ERRORCODE" ->EAGAIN</SPAN -> error code when no buffer is available. The -<A -HREF="#FUNC-SELECT" -><CODE -CLASS="FUNCTION" ->select()</CODE -></A -> or <A -HREF="#FUNC-POLL" -><CODE -CLASS="FUNCTION" ->poll()</CODE -></A -> function are always available.</P -><P ->To start and stop capturing or output applications call the -<A -HREF="#VIDIOC-STREAMON" -><CODE -CLASS="CONSTANT" ->VIDIOC_STREAMON</CODE -></A -> and <A -HREF="#VIDIOC-STREAMON" -><CODE -CLASS="CONSTANT" ->VIDIOC_STREAMOFF</CODE -></A -> ioctl. Note -<CODE -CLASS="CONSTANT" ->VIDIOC_STREAMOFF</CODE -> removes all buffers from both -queues as a side effect. Since there is no notion of doing anything -"now" on a multitasking system, if an application needs to synchronize -with another event it should examine the struct <A -HREF="#V4L2-BUFFER" ->v4l2_buffer</A -> -<CODE -CLASS="STRUCTFIELD" ->timestamp</CODE -> of captured buffers, or set the -field before enqueuing buffers for output.</P -><P ->Drivers implementing memory mapping I/O must -support the <CODE -CLASS="CONSTANT" ->VIDIOC_REQBUFS</CODE ->, -<CODE -CLASS="CONSTANT" ->VIDIOC_QUERYBUF</CODE ->, -<CODE -CLASS="CONSTANT" ->VIDIOC_QBUF</CODE ->, <CODE -CLASS="CONSTANT" ->VIDIOC_DQBUF</CODE ->, -<CODE -CLASS="CONSTANT" ->VIDIOC_STREAMON</CODE -> and -<CODE -CLASS="CONSTANT" ->VIDIOC_STREAMOFF</CODE -> ioctl, the -<CODE -CLASS="FUNCTION" ->mmap()</CODE ->, <CODE -CLASS="FUNCTION" ->munmap()</CODE ->, -<CODE -CLASS="FUNCTION" ->select()</CODE -> and <CODE -CLASS="FUNCTION" ->poll()</CODE -> -function.<A -NAME="AEN3371" -HREF="#FTN.AEN3371" -><SPAN -CLASS="footnote" ->[17]</SPAN -></A -></P -><P ->[capture example]</P -></DIV -><DIV -CLASS="SECTION" -><HR><H2 -CLASS="SECTION" -><A -NAME="USERP" ->3.3. Streaming I/O (User Pointers)</A -></H2 -><P ->Input and output devices support this I/O method when the -<CODE -CLASS="CONSTANT" ->V4L2_CAP_STREAMING</CODE -> flag in the -<CODE -CLASS="STRUCTFIELD" ->capabilities</CODE -> field of struct <A -HREF="#V4L2-CAPABILITY" ->v4l2_capability</A -> -returned by the <A -HREF="#VIDIOC-QUERYCAP" -><CODE -CLASS="CONSTANT" ->VIDIOC_QUERYCAP</CODE -></A -> ioctl is set. If the particular user -pointer method (not only memory mapping) is supported must be -determined by calling the <A -HREF="#VIDIOC-REQBUFS" -><CODE -CLASS="CONSTANT" ->VIDIOC_REQBUFS</CODE -></A -> ioctl.</P -><P ->This I/O method combines advantages of the read/write and -memory mapping methods. Buffers are allocated by the application -itself, and can reside for example in virtual or shared memory. Only -pointers to data are exchanged, these pointers and meta-information -are passed in struct <A -HREF="#V4L2-BUFFER" ->v4l2_buffer</A ->. The driver must be switched -into user pointer I/O mode by calling the <A -HREF="#VIDIOC-REQBUFS" -><CODE -CLASS="CONSTANT" ->VIDIOC_REQBUFS</CODE -></A -> with the -desired buffer type. No buffers are allocated beforehands, -consequently they are not indexed and cannot be queried like mapped -buffers with the <CODE -CLASS="CONSTANT" ->VIDIOC_QUERYBUF</CODE -> ioctl.</P -><DIV -CLASS="EXAMPLE" -><A -NAME="AEN3392" -></A -><P -><B ->Example 3-2. Initiating streaming I/O with user pointers</B -></P -><PRE -CLASS="PROGRAMLISTING" ->struct <A -HREF="#V4L2-REQUESTBUFFERS" ->v4l2_requestbuffers</A -> reqbuf; - -memset (&reqbuf, 0, sizeof (reqbuf)); -reqbuf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; -reqbuf.memory = V4L2_MEMORY_USERPTR; - -if (ioctl (fd, <A -HREF="#VIDIOC-REQBUFS" -><CODE -CLASS="CONSTANT" ->VIDIOC_REQBUFS</CODE -></A ->, &reqbuf) == -1) { - if (errno == EINVAL) - printf ("Video capturing or user pointer streaming is not supported\n"); - else - perror ("VIDIOC_REQBUFS"); - - exit (EXIT_FAILURE); -} - </PRE -></DIV -><P ->Buffer addresses and sizes are passed on the fly with the -<A -HREF="#VIDIOC-QBUF" -><CODE -CLASS="CONSTANT" ->VIDIOC_QBUF</CODE -></A -> ioctl. Although buffers are commonly cycled, -applications can pass different addresses and sizes at each -<CODE -CLASS="CONSTANT" ->VIDIOC_QBUF</CODE -> call. If required by the hardware the -driver swaps memory pages within physical memory to create a -continuous area of memory. This happens transparently to the -application in the virtual memory subsystem of the kernel. When buffer -pages have been swapped out to disk they are brought back and finally -locked in physical memory for DMA.<A -NAME="AEN3402" -HREF="#FTN.AEN3402" -><SPAN -CLASS="footnote" ->[18]</SPAN -></A -></P -><P ->Filled or displayed buffers are dequeued with the -<A -HREF="#VIDIOC-QBUF" -><CODE -CLASS="CONSTANT" ->VIDIOC_DQBUF</CODE -></A -> ioctl. The driver can unlock the memory pages at any -time between the completion of the DMA and this ioctl. The memory is -also unlocked when <A -HREF="#VIDIOC-STREAMON" -><CODE -CLASS="CONSTANT" ->VIDIOC_STREAMOFF</CODE -></A -> is called, <A -HREF="#VIDIOC-REQBUFS" -><CODE -CLASS="CONSTANT" ->VIDIOC_REQBUFS</CODE -></A ->, or -when the device is closed. Applications must take care not to free -buffers without dequeuing. For once, the buffers remain locked until -further, wasting physical memory. Second the driver will not be -notified when the memory is returned to the application's free list -and subsequently reused for other purposes, possibly completing the -requested DMA and overwriting valuable data.</P -><P ->For capturing applications it is customary to enqueue a -number of empty buffers, to start capturing and enter the read loop. -Here the application waits until a filled buffer can be dequeued, and -re-enqueues the buffer when the data is no longer needed. Output -applications fill and enqueue buffers, when enough buffers are stacked -up output is started. In the write loop, when the application -runs out of free buffers it must wait until an empty buffer can be -dequeued and reused. Two methods exist to suspend execution of the -application until one or more buffers can be dequeued. By default -<CODE -CLASS="CONSTANT" ->VIDIOC_DQBUF</CODE -> blocks when no buffer is in the -outgoing queue. When the <CODE -CLASS="CONSTANT" ->O_NONBLOCK</CODE -> flag was -given to the <A -HREF="#FUNC-OPEN" -><CODE -CLASS="FUNCTION" ->open()</CODE -></A -> function, <CODE -CLASS="CONSTANT" ->VIDIOC_DQBUF</CODE -> -returns immediately with an <SPAN -CLASS="ERRORCODE" ->EAGAIN</SPAN -> error code when no buffer is available. The -<A -HREF="#FUNC-SELECT" -><CODE -CLASS="FUNCTION" ->select()</CODE -></A -> or <A -HREF="#FUNC-POLL" -><CODE -CLASS="FUNCTION" ->poll()</CODE -></A -> function are always available.</P -><P ->To start and stop capturing or output applications call the -<A -HREF="#VIDIOC-STREAMON" -><CODE -CLASS="CONSTANT" ->VIDIOC_STREAMON</CODE -></A -> and <A -HREF="#VIDIOC-STREAMON" -><CODE -CLASS="CONSTANT" ->VIDIOC_STREAMOFF</CODE -></A -> ioctl. Note -<CODE -CLASS="CONSTANT" ->VIDIOC_STREAMOFF</CODE -> removes all buffers from both -queues and unlocks all buffers as a side effect. Since there is no -notion of doing anything "now" on a multitasking system, if an -application needs to synchronize with another event it should examine -the struct <A -HREF="#V4L2-BUFFER" ->v4l2_buffer</A -> <CODE -CLASS="STRUCTFIELD" ->timestamp</CODE -> of captured -buffers, or set the field before enqueuing buffers for output.</P -><P ->Drivers implementing user pointer I/O must -support the <CODE -CLASS="CONSTANT" ->VIDIOC_REQBUFS</CODE ->, -<CODE -CLASS="CONSTANT" ->VIDIOC_QBUF</CODE ->, <CODE -CLASS="CONSTANT" ->VIDIOC_DQBUF</CODE ->, -<CODE -CLASS="CONSTANT" ->VIDIOC_STREAMON</CODE -> and -<CODE -CLASS="CONSTANT" ->VIDIOC_STREAMOFF</CODE -> ioctl, the -<CODE -CLASS="FUNCTION" ->select()</CODE -> and <CODE -CLASS="FUNCTION" ->poll()</CODE -> function.<A -NAME="AEN3438" -HREF="#FTN.AEN3438" -><SPAN -CLASS="footnote" ->[19]</SPAN -></A -></P -></DIV -><DIV -CLASS="SECTION" -><HR><H2 -CLASS="SECTION" -><A -NAME="ASYNC" ->3.4. Asynchronous I/O</A -></H2 -><P ->This method is not defined yet.</P -></DIV -><DIV -CLASS="SECTION" -><HR><H2 -CLASS="SECTION" -><A -NAME="BUFFER" ->3.5. Buffers</A -></H2 -><P ->A buffer contains data exchanged by application and -driver using one of the Streaming I/O methods. Only pointers to -buffers are exchanged, the data itself is not copied. These pointers, -together with meta-information like timestamps or field parity, are -stored in a struct <CODE -CLASS="STRUCTNAME" ->v4l2_buffer</CODE ->, argument to -the <A -HREF="#VIDIOC-QUERYBUF" -><CODE -CLASS="CONSTANT" ->VIDIOC_QUERYBUF</CODE -></A ->, <A -HREF="#VIDIOC-QBUF" -><CODE -CLASS="CONSTANT" ->VIDIOC_QBUF</CODE -></A -> and <A -HREF="#VIDIOC-QBUF" -><CODE -CLASS="CONSTANT" ->VIDIOC_DQBUF</CODE -></A -> ioctl.</P -><P ->Nominally timestamps refer to the first data byte transmitted. -In practice however the wide range of hardware covered by the V4L2 API -limits timestamp accuracy. Often an interrupt routine will -sample the system clock shortly after the field or frame was stored -completely in memory. So applications must expect a constant -difference up to one field or frame period plus a small (few scan -lines) random error. The delay and error can be much -larger due to compression or transmission over an external bus when -the frames are not properly stamped by the sender. This is frequently -the case with USB cameras. Here timestamps refer to the instant the -field or frame was received by the driver, not the capture time. These -devices identify by not enumerating any video standards, see <A -HREF="#STANDARD" ->Section 1.7</A ->.</P -><P ->Similar limitations apply to output timestamps. Typically -the video hardware locks to a clock controlling the video timing, the -horizontal and vertical synchronization pulses. At some point in the -line sequence, possibly the vertical blanking, an interrupt routine -samples the system clock, compares against the timestamp and programs -the hardware to repeat the previous field or frame, or to display the -buffer contents.</P -><P ->Apart of limitations of the video device and natural -inaccuracies of all clocks, it should be noted system time itself is -not perfectly stable. It can be affected by power saving cycles, -warped to insert leap seconds, or even turned back or forth by the -system administrator affecting long term measurements. <A -NAME="AEN3460" -HREF="#FTN.AEN3460" -><SPAN -CLASS="footnote" ->[20]</SPAN -></A -></P -><DIV -CLASS="TABLE" -><A -NAME="V4L2-BUFFER" -></A -><P -><B ->Table 3-1. struct <CODE -CLASS="STRUCTNAME" ->v4l2_buffer</CODE -></B -></P -><TABLE -BORDER="0" -FRAME="void" -WIDTH="100%" -CLASS="CALSTABLE" -><COL -WIDTH="50%" -TITLE="C1"><COL><COL><COL -WIDTH="50%" -TITLE="C4"><TBODY -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->index</CODE -></TD -><TD -> </TD -><TD ->Number of the buffer, set by the application. This -field is only used for <A -HREF="#MMAP" ->memory mapping</A -> I/O -and can range from zero to the number of buffers allocated -with the <A -HREF="#VIDIOC-REQBUFS" -><CODE -CLASS="CONSTANT" ->VIDIOC_REQBUFS</CODE -></A -> ioctl (struct <A -HREF="#V4L2-REQUESTBUFFERS" ->v4l2_requestbuffers</A -> <CODE -CLASS="STRUCTFIELD" ->count</CODE ->) minus one.</TD -></TR -><TR -><TD ->enum <A -HREF="#V4L2-BUF-TYPE" ->v4l2_buf_type</A -></TD -><TD -><CODE -CLASS="STRUCTFIELD" ->type</CODE -></TD -><TD -> </TD -><TD ->Type of the buffer, same as struct <A -HREF="#V4L2-FORMAT" ->v4l2_format</A -> -<CODE -CLASS="STRUCTFIELD" ->type</CODE -> or struct <A -HREF="#V4L2-REQUESTBUFFERS" ->v4l2_requestbuffers</A -> -<CODE -CLASS="STRUCTFIELD" ->type</CODE ->, set by the application.</TD -></TR -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->bytesused</CODE -></TD -><TD -> </TD -><TD ->The number of bytes occupied by the data in the -buffer. It depends on the negotiated data format and may change with -each buffer for compressed variable size data like JPEG images. -Drivers must set this field when <CODE -CLASS="STRUCTFIELD" ->type</CODE -> -refers to an input stream, applications when an output stream.</TD -></TR -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->flags</CODE -></TD -><TD -> </TD -><TD ->Flags set by the application or driver, see <A -HREF="#BUFFER-FLAGS" ->Table 3-3</A ->.</TD -></TR -><TR -><TD ->enum <A -HREF="#V4L2-FIELD" ->v4l2_field</A -></TD -><TD -><CODE -CLASS="STRUCTFIELD" ->field</CODE -></TD -><TD -> </TD -><TD ->Indicates the field order of the image in the -buffer, see <A -HREF="#V4L2-FIELD" ->Table 3-8</A ->. This field is not used when -the buffer contains VBI data. Drivers must set it when -<CODE -CLASS="STRUCTFIELD" ->type</CODE -> refers to an input stream, -applications when an output stream.</TD -></TR -><TR -><TD ->struct timeval</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->timestamp</CODE -></TD -><TD -> </TD -><TD -><P ->For input streams this is the -system time (as returned by the <CODE -CLASS="FUNCTION" ->gettimeofday()</CODE -> -function) when the first data byte was captured. For output streams -the data will not be displayed before this time, secondary to the -nominal frame rate determined by the current video standard in -enqueued order. Applications can for example zero this field to -display frames as soon as possible. The driver stores the time at -which the first data byte was actually sent out in the -<CODE -CLASS="STRUCTFIELD" ->timestamp</CODE -> field. This permits -applications to monitor the drift between the video and system -clock.</P -></TD -></TR -><TR -><TD ->struct <A -HREF="#V4L2-TIMECODE" ->v4l2_timecode</A -></TD -><TD -><CODE -CLASS="STRUCTFIELD" ->timecode</CODE -></TD -><TD -> </TD -><TD ->When <CODE -CLASS="STRUCTFIELD" ->type</CODE -> is -<CODE -CLASS="CONSTANT" ->V4L2_BUF_TYPE_VIDEO_CAPTURE</CODE -> and the -<CODE -CLASS="CONSTANT" ->V4L2_BUF_FLAG_TIMECODE</CODE -> flag is set in -<CODE -CLASS="STRUCTFIELD" ->flags</CODE ->, this structure contains a frame -timecode. In <A -HREF="#V4L2-FIELD" ->V4L2_FIELD_ALTERNATE</A -> -mode the top and bottom field contain the same timecode. -Timecodes are intended to help video editing and are typically recorded on -video tapes, but also embedded in compressed formats like MPEG. This -field is independent of the <CODE -CLASS="STRUCTFIELD" ->timestamp</CODE -> and -<CODE -CLASS="STRUCTFIELD" ->sequence</CODE -> fields.</TD -></TR -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->sequence</CODE -></TD -><TD -> </TD -><TD ->Set by the driver, counting the frames in the -sequence.</TD -></TR -><TR -><TD -COLSPAN="4" -><P ->In <A -HREF="#V4L2-FIELD" ->V4L2_FIELD_ALTERNATE</A -> mode the top and -bottom field have the same sequence number. The count starts at zero -and includes dropped or repeated frames. A dropped frame was received -by an input device but could not be stored due to lack of free buffer -space. A repeated frame was displayed again by an output device -because the application did not pass new data in -time.</P -><P ->Note this may count the frames received -e.g. over USB, without taking into account the frames dropped by the -remote hardware due to limited compression throughput or bus -bandwidth. These devices identify by not enumerating any video -standards, see <A -HREF="#STANDARD" ->Section 1.7</A ->.</P -></TD -></TR -><TR -><TD ->enum <A -HREF="#V4L2-MEMORY" ->v4l2_memory</A -></TD -><TD -><CODE -CLASS="STRUCTFIELD" ->memory</CODE -></TD -><TD -> </TD -><TD ->This field must be set by applications and/or drivers -in accordance with the selected I/O method.</TD -></TR -><TR -><TD ->union</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->m</CODE -></TD -><TD -> </TD -><TD -> </TD -></TR -><TR -><TD -> </TD -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->offset</CODE -></TD -><TD ->When <CODE -CLASS="STRUCTFIELD" ->memory</CODE -> is -<CODE -CLASS="CONSTANT" ->V4L2_MEMORY_MMAP</CODE -> this is the offset of the buffer -from the start of the device memory. The value is returned by the -driver and apart of serving as parameter to the <A -HREF="#FUNC-MMAP" -><CODE -CLASS="FUNCTION" ->mmap()</CODE -></A -> function -not useful for applications. See <A -HREF="#MMAP" ->Section 3.2</A -> for details.</TD -></TR -><TR -><TD -> </TD -><TD ->unsigned long</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->userptr</CODE -></TD -><TD ->When <CODE -CLASS="STRUCTFIELD" ->memory</CODE -> is -<CODE -CLASS="CONSTANT" ->V4L2_MEMORY_USERPTR</CODE -> this is a pointer to the -buffer (casted to unsigned long type) in virtual memory, set by the -application. See <A -HREF="#USERP" ->Section 3.3</A -> for details.</TD -></TR -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->length</CODE -></TD -><TD -> </TD -><TD ->Size of the buffer (not the payload) in bytes.</TD -></TR -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->input</CODE -></TD -><TD -> </TD -><TD ->Some video capture drivers support rapid and -synchronous video input changes, a function useful for example in -video surveillance applications. For this purpose applications set the -<CODE -CLASS="CONSTANT" ->V4L2_BUF_FLAG_INPUT</CODE -> flag, and this field to the -number of a video input as in struct <A -HREF="#V4L2-INPUT" ->v4l2_input</A -> field -<CODE -CLASS="STRUCTFIELD" ->index</CODE ->.</TD -></TR -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->reserved</CODE -></TD -><TD -> </TD -><TD ->A place holder for future extensions and custom -(driver defined) buffer types -<CODE -CLASS="CONSTANT" ->V4L2_BUF_TYPE_PRIVATE</CODE -> and higher.</TD -></TR -></TBODY -></TABLE -></DIV -><DIV -CLASS="TABLE" -><A -NAME="V4L2-BUF-TYPE" -></A -><P -><B ->Table 3-2. enum v4l2_buf_type</B -></P -><TABLE -BORDER="0" -FRAME="void" -WIDTH="100%" -CLASS="CALSTABLE" -><COL -WIDTH="38%" -TITLE="C1"><COL -WIDTH="12%" -TITLE="C2"><COL -WIDTH="50%" -TITLE="C3"><TBODY -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_BUF_TYPE_VIDEO_CAPTURE</CODE -></TD -><TD ->1</TD -><TD ->Buffer of a video capture stream, see <A -HREF="#CAPTURE" ->Section 4.1</A ->.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_BUF_TYPE_VIDEO_OUTPUT</CODE -></TD -><TD ->2</TD -><TD ->Buffer of a video output stream, see <A -HREF="#OUTPUT" ->Section 4.3</A ->.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_BUF_TYPE_VIDEO_OVERLAY</CODE -></TD -><TD ->3</TD -><TD ->Buffer for video overlay, see <A -HREF="#OVERLAY" ->Section 4.2</A ->.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_BUF_TYPE_VBI_CAPTURE</CODE -></TD -><TD ->4</TD -><TD ->Buffer of a raw VBI capture stream, see <A -HREF="#RAW-VBI" ->Section 4.6</A ->.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_BUF_TYPE_VBI_OUTPUT</CODE -></TD -><TD ->5</TD -><TD ->Buffer of a raw VBI output stream, see <A -HREF="#RAW-VBI" ->Section 4.6</A ->.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_BUF_TYPE_PRIVATE</CODE -></TD -><TD ->0x80</TD -><TD ->This and higher values are reserved for custom -(driver defined) buffer types.</TD -></TR -></TBODY -></TABLE -></DIV -><DIV -CLASS="TABLE" -><A -NAME="BUFFER-FLAGS" -></A -><P -><B ->Table 3-3. Buffer Flags</B -></P -><TABLE -BORDER="0" -FRAME="void" -WIDTH="100%" -CLASS="CALSTABLE" -><COL -WIDTH="38%" -TITLE="C1"><COL -WIDTH="12%" -TITLE="C2"><COL -WIDTH="50%" -TITLE="C3"><TBODY -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_BUF_FLAG_MAPPED</CODE -></TD -><TD ->0x0001</TD -><TD ->The buffer resides in device memory and has been mapped -into the application's address space, see <A -HREF="#MMAP" ->Section 3.2</A -> for details. -Drivers set or clear this flag when the -<A -HREF="#VIDIOC-QUERYBUF" ->VIDIOC_QUERYBUF</A ->, <A -HREF="#VIDIOC-QBUF" ->VIDIOC_QBUF</A -> or <A -HREF="#VIDIOC-QBUF" ->VIDIOC_DQBUF</A -> ioctl is called. Set by the driver.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_BUF_FLAG_QUEUED</CODE -></TD -><TD ->0x0002</TD -><TD ->Internally drivers maintain two buffer queues, an -incoming and outgoing queue. When this flag is set, the buffer is -currently on the incoming queue. It automatically moves to the -outgoing queue after the buffer has been filled (capture devices) or -displayed (output devices). Drivers set or clear this flag when the -<CODE -CLASS="CONSTANT" ->VIDIOC_QUERYBUF</CODE -> ioctl is called. After -(successful) calling the <CODE -CLASS="CONSTANT" ->VIDIOC_QBUF </CODE ->ioctl it is -always set and after <CODE -CLASS="CONSTANT" ->VIDIOC_DQBUF</CODE -> always -cleared.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_BUF_FLAG_DONE</CODE -></TD -><TD ->0x0004</TD -><TD ->When this flag is set, the buffer is currently on -the outgoing queue, ready to be dequeued from the driver. Drivers set -or clear this flag when the <CODE -CLASS="CONSTANT" ->VIDIOC_QUERYBUF</CODE -> ioctl -is called. After calling the <CODE -CLASS="CONSTANT" ->VIDIOC_QBUF</CODE -> or -<CODE -CLASS="CONSTANT" ->VIDIOC_DQBUF</CODE -> it is always cleared. Of course a -buffer cannot be on both queues at the same time, the -<CODE -CLASS="CONSTANT" ->V4L2_BUF_FLAG_QUEUED</CODE -> and -<CODE -CLASS="CONSTANT" ->V4L2_BUF_FLAG_DONE</CODE -> flag are mutually exclusive. -They can be both cleared however, then the buffer is in "dequeued" -state, in the application domain to say so.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_BUF_FLAG_KEYFRAME</CODE -></TD -><TD ->0x0008</TD -><TD ->Drivers set or clear this flag when calling the -<CODE -CLASS="CONSTANT" ->VIDIOC_DQBUF</CODE -> ioctl. It may be set by video -capture devices when the buffer contains a compressed image which is a -key frame (or field), i.e. can be decompressed on its own.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_BUF_FLAG_PFRAME</CODE -></TD -><TD ->0x0010</TD -><TD ->Similar to <CODE -CLASS="CONSTANT" ->V4L2_BUF_FLAG_KEYFRAME</CODE -> -this flags predicted frames or fields which contain only differences to a -previous key frame.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_BUF_FLAG_BFRAME</CODE -></TD -><TD ->0x0020</TD -><TD ->Similar to <CODE -CLASS="CONSTANT" ->V4L2_BUF_FLAG_PFRAME</CODE -> - this is a bidirectional predicted frame or field. [ooc tbd]</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_BUF_FLAG_TIMECODE</CODE -></TD -><TD ->0x0100</TD -><TD ->The <CODE -CLASS="STRUCTFIELD" ->timecode</CODE -> field is valid. -Drivers set or clear this flag when the <CODE -CLASS="CONSTANT" ->VIDIOC_DQBUF</CODE -> -ioctl is called.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_BUF_FLAG_INPUT</CODE -></TD -><TD ->0x0200</TD -><TD ->The <CODE -CLASS="STRUCTFIELD" ->input</CODE -> field is valid. -Applications set or clear this flag before calling the -<CODE -CLASS="CONSTANT" ->VIDIOC_QBUF</CODE -> ioctl.</TD -></TR -></TBODY -></TABLE -></DIV -><DIV -CLASS="TABLE" -><A -NAME="V4L2-MEMORY" -></A -><P -><B ->Table 3-4. enum v4l2_memory</B -></P -><TABLE -BORDER="0" -FRAME="void" -WIDTH="100%" -CLASS="CALSTABLE" -><COL -WIDTH="38%" -TITLE="C1"><COL -WIDTH="12%" -TITLE="C2"><COL -WIDTH="50%" -TITLE="C3"><TBODY -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_MEMORY_MMAP</CODE -></TD -><TD ->1</TD -><TD ->The buffer is used for <A -HREF="#MMAP" ->memory -mapping</A -> I/O.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_MEMORY_USERPTR</CODE -></TD -><TD ->2</TD -><TD ->The buffer is used for <A -HREF="#USERP" ->user -pointer</A -> I/O.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_MEMORY_OVERLAY</CODE -></TD -><TD ->3</TD -><TD ->[to do]</TD -></TR -></TBODY -></TABLE -></DIV -><DIV -CLASS="SECTION" -><HR><H3 -CLASS="SECTION" -><A -NAME="AEN3738" ->3.5.1. Timecodes</A -></H3 -><P ->The <CODE -CLASS="STRUCTNAME" ->v4l2_timecode</CODE -> structure is -designed to hold a <A -HREF="#SMPTE12M" -><ABBR -CLASS="ABBREV" ->SMPTE12M</ABBR -></A -> or similar timecode. -(struct <CODE -CLASS="STRUCTNAME" ->timeval</CODE -> timestamps are stored in -struct <A -HREF="#V4L2-BUFFER" ->v4l2_buffer</A -> field <CODE -CLASS="STRUCTFIELD" ->timestamp</CODE ->.)</P -><DIV -CLASS="TABLE" -><A -NAME="V4L2-TIMECODE" -></A -><P -><B ->Table 3-5. struct <CODE -CLASS="STRUCTNAME" ->v4l2_timecode</CODE -></B -></P -><TABLE -BORDER="0" -FRAME="void" -WIDTH="100%" -CLASS="CALSTABLE" -><COL -WIDTH="25%" -TITLE="C1"><COL -WIDTH="25%" -TITLE="C2"><COL -WIDTH="50%" -TITLE="C3"><TBODY -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->type</CODE -></TD -><TD ->Frame rate the timecodes are based on, see <A -HREF="#TIMECODE-TYPE" ->Table 3-6</A ->.</TD -></TR -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->flags</CODE -></TD -><TD ->Timecode flags, see <A -HREF="#TIMECODE-FLAGS" ->Table 3-7</A ->.</TD -></TR -><TR -><TD ->__u8</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->frames</CODE -></TD -><TD ->Frame count, 0 ... 23/24/29/49/59, depending on the - type of timecode.</TD -></TR -><TR -><TD ->__u8</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->seconds</CODE -></TD -><TD ->Seconds count, 0 ... 59. This is a binary, not BCD number.</TD -></TR -><TR -><TD ->__u8</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->minutes</CODE -></TD -><TD ->Minutes count, 0 ... 59. This is a binary, not BCD number.</TD -></TR -><TR -><TD ->__u8</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->hours</CODE -></TD -><TD ->Hours count, 0 ... 29. This is a binary, not BCD number.</TD -></TR -><TR -><TD ->__u8</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->userbits</CODE ->[4]</TD -><TD ->The "user group" bits from the timecode.</TD -></TR -></TBODY -></TABLE -></DIV -><DIV -CLASS="TABLE" -><A -NAME="TIMECODE-TYPE" -></A -><P -><B ->Table 3-6. Timecode Types</B -></P -><TABLE -BORDER="0" -FRAME="void" -WIDTH="100%" -CLASS="CALSTABLE" -><COL -WIDTH="38%" -TITLE="C1"><COL -WIDTH="12%" -TITLE="C2"><COL -WIDTH="50%" -TITLE="C3"><TBODY -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_TC_TYPE_24FPS</CODE -></TD -><TD ->1</TD -><TD ->24 frames per second, i. e. film.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_TC_TYPE_25FPS</CODE -></TD -><TD ->2</TD -><TD ->25 frames per second, i.e. PAL or SECAM video.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_TC_TYPE_30FPS</CODE -></TD -><TD ->3</TD -><TD ->30 frames per second, i.e. NTSC video.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_TC_TYPE_50FPS</CODE -></TD -><TD ->4</TD -><TD -> </TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_TC_TYPE_60FPS</CODE -></TD -><TD ->5</TD -><TD -> </TD -></TR -></TBODY -></TABLE -></DIV -><DIV -CLASS="TABLE" -><A -NAME="TIMECODE-FLAGS" -></A -><P -><B ->Table 3-7. Timecode Flags</B -></P -><TABLE -BORDER="0" -FRAME="void" -WIDTH="100%" -CLASS="CALSTABLE" -><COL -WIDTH="38%" -TITLE="C1"><COL -WIDTH="12%" -TITLE="C2"><COL -WIDTH="50%" -TITLE="C3"><TBODY -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_TC_FLAG_DROPFRAME</CODE -></TD -><TD ->0x0001</TD -><TD ->Indicates "drop frame" semantics for counting frames -in 29.97 fps material. When set, frame numbers 0 and 1 at the start of -each minute, except minutes 0, 10, 20, 30, 40, 50 are omitted from the -count.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_TC_FLAG_COLORFRAME</CODE -></TD -><TD ->0x0002</TD -><TD ->The "color frame" flag.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_TC_USERBITS_field</CODE -></TD -><TD ->0x000C</TD -><TD ->Field mask for the "binary group flags".</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_TC_USERBITS_USERDEFINED</CODE -></TD -><TD ->0x0000</TD -><TD ->Unspecified format.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_TC_USERBITS_8BITCHARS</CODE -></TD -><TD ->0x0008</TD -><TD ->8-bit ISO characters.</TD -></TR -></TBODY -></TABLE -></DIV -></DIV -></DIV -><DIV -CLASS="SECTION" -><HR><H2 -CLASS="SECTION" -><A -NAME="FIELD-ORDER" ->3.6. Field Order</A -></H2 -><P ->We have to distinguish between progressive and interlaced -video. Progressive video transmits all lines of a video image -sequentially. Interlaced video divides an image into two fields, -containing only the odd and even lines of the image, respectively. -Alternating the so called odd and even field are transmitted, and due -to a small delay between fields a cathode ray TV displays the lines -interleaved, yielding the original frame. This curious technique was -invented because at refresh rates similar to film the image would -fade out too quickly. Transmitting fields reduces the flicker without -the necessity of doubling the frame rate and with it the bandwidth -required for each channel.</P -><P ->It is important to understand a video camera does not expose -one frame at a time, merely transmitting the frames separated into -fields. The fields are in fact captured at two different instances in -time. An object on screen may well move between one field and the -next. For applications analysing motion it is of paramount importance -to recognize which field of a frame is older, the <SPAN -CLASS="emphasis" -><I -CLASS="EMPHASIS" ->temporal -order</I -></SPAN ->.</P -><P ->When the driver provides or accepts images field by field -rather than interleaved, it is also important applications understand -how the fields combine to frames. We distinguish between top and -bottom fields, the <SPAN -CLASS="emphasis" -><I -CLASS="EMPHASIS" ->spatial order</I -></SPAN ->: The first line -of the top field is the first line of an interlaced frame, the first -line of the bottom field is the second line of that frame.</P -><P ->However because fields were captured one after the other, -arguing whether a frame commences with the top or bottom field is -pointless. Any two successive top and bottom, or bottom and top fields -yield a valid frame. Only when the source was progressive to begin -with, e. g. when transferring film to video, two fields may come from -the same frame, creating a natural order.</P -><P ->Counter to intuition the top field is not necessarily the -older field. Whether the older field contains the top or bottom lines -is a convention determined by the video standard. Hence the -distinction between temporal and spatial order of fields. The diagrams -below should make this clearer.</P -><P ->All video capture and output devices must report the current -field order. Some drivers may permit the selection of a different -order, to this end applications initialize the -<CODE -CLASS="STRUCTFIELD" ->field</CODE -> field of struct <A -HREF="#V4L2-PIX-FORMAT" ->v4l2_pix_format</A -> before -calling the <A -HREF="#VIDIOC-G-FMT" -><CODE -CLASS="CONSTANT" ->VIDIOC_S_FMT</CODE -></A -> ioctl. If this is not desired it should -have the value <CODE -CLASS="CONSTANT" ->V4L2_FIELD_ANY</CODE -> (0).</P -><DIV -CLASS="TABLE" -><A -NAME="V4L2-FIELD" -></A -><P -><B ->Table 3-8. enum v4l2_field</B -></P -><TABLE -BORDER="0" -FRAME="void" -WIDTH="100%" -CLASS="CALSTABLE" -><COL -WIDTH="38%" -TITLE="C1"><COL -WIDTH="12%" -TITLE="C2"><COL -WIDTH="50%" -TITLE="C3"><TBODY -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_FIELD_ANY</CODE -></TD -><TD ->0</TD -><TD ->Applications request this field order when any -one of the <CODE -CLASS="CONSTANT" ->V4L2_FIELD_NONE</CODE ->, -<CODE -CLASS="CONSTANT" ->V4L2_FIELD_TOP</CODE ->, -<CODE -CLASS="CONSTANT" ->V4L2_FIELD_BOTTOM</CODE ->, or -<CODE -CLASS="CONSTANT" ->V4L2_FIELD_INTERLACED</CODE -> formats is acceptable. -Drivers choose depending on hardware capabilities or e. g. the -requested image size, and return the actual field order. struct <A -HREF="#V4L2-BUFFER" ->v4l2_buffer</A -> -<CODE -CLASS="STRUCTFIELD" ->field</CODE -> can never be -<CODE -CLASS="CONSTANT" ->V4L2_FIELD_ANY</CODE ->.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_FIELD_NONE</CODE -></TD -><TD ->1</TD -><TD ->Images are in progressive format, not interlaced. -The driver may also indicate this order when it cannot distinguish -between <CODE -CLASS="CONSTANT" ->V4L2_FIELD_TOP</CODE -> and -<CODE -CLASS="CONSTANT" ->V4L2_FIELD_BOTTOM</CODE ->.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_FIELD_TOP</CODE -></TD -><TD ->2</TD -><TD ->Images consist of the top field only.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_FIELD_BOTTOM</CODE -></TD -><TD ->3</TD -><TD ->Images consist of the bottom field only. -Applications may wish to prevent a device from capturing interlaced -images because they will have "comb" or "feathering" artefacts around -moving objects.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_FIELD_INTERLACED</CODE -></TD -><TD ->4</TD -><TD ->Images contain both fields, interleaved line by -line. The temporal order of the fields (whether the top or bottom -field is first transmitted) depends on the current video standard. -M/NTSC transmits the bottom field first, all other standards the top -field first.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_FIELD_SEQ_TB</CODE -></TD -><TD ->5</TD -><TD ->Images contain both fields, the top field lines -are stored first in memory, immediately followed by the bottom field -lines. Fields are always stored in temporal order, the older one first -in memory. Image sizes refer to the frame, not fields.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_FIELD_SEQ_BT</CODE -></TD -><TD ->6</TD -><TD ->Images contain both fields, the bottom field -lines are stored first in memory, immediately followed by the top -field lines. Fields are always stored in temporal order, the older one -first in memory. Image sizes refer to the frame, not fields.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_FIELD_ALTERNATE</CODE -></TD -><TD ->7</TD -><TD ->The two fields of a frame are passed in separate -buffers, in temporal order, i. e. the older one first. To indicate the field -parity (whether the current field is a top or bottom field) the driver -or application, depending on data direction, must set struct <A -HREF="#V4L2-BUFFER" ->v4l2_buffer</A -> -<CODE -CLASS="STRUCTFIELD" ->field</CODE -> to -<CODE -CLASS="CONSTANT" ->V4L2_FIELD_TOP</CODE -> or -<CODE -CLASS="CONSTANT" ->V4L2_FIELD_BOTTOM</CODE ->. Any two successive fields pair -to build a frame. If fields are successive, without any dropped fields -between them (fields can drop individually), can be determined from -the struct <A -HREF="#V4L2-BUFFER" ->v4l2_buffer</A -> <CODE -CLASS="STRUCTFIELD" ->sequence</CODE -> field. Image -sizes refer to the frame, not fields. This format cannot be selected -when using the read/write I/O method.</TD -></TR -></TBODY -></TABLE -></DIV -><DIV -CLASS="FIGURE" -><A -NAME="FIELDSEQ-TB" -></A -><P -><B ->Figure 3-1. Field Order, Top Field First Transmitted</B -></P -><DIV -CLASS="MEDIAOBJECT" -><P -><IMG -SRC="fieldseq_tb.gif"></P -></DIV -></DIV -><DIV -CLASS="FIGURE" -><A -NAME="FIELDSEQ-BT" -></A -><P -><B ->Figure 3-2. Field Order, Bottom Field First Transmitted</B -></P -><DIV -CLASS="MEDIAOBJECT" -><P -><IMG -SRC="fieldseq_bt.gif"></P -></DIV -></DIV -></DIV -></DIV -><DIV -CLASS="CHAPTER" -><HR><H1 -><A -NAME="DEVICES" -></A ->Chapter 4. Device Types</H1 -><DIV -CLASS="SECTION" -><H2 -CLASS="SECTION" -><A -NAME="CAPTURE" ->4.1. Video Capture Interface</A -></H2 -><P ->Video capture devices sample an analog video signal and store -the digitized images in memory. Today nearly all devices can capture -at full 25 or 30 frames/second. With this interface applications can -control the capture process and move images from the driver into user -space.</P -><P ->Conventionally V4L2 video capture devices are accessed through -character device special files named <TT -CLASS="FILENAME" ->/dev/video</TT -> -and <TT -CLASS="FILENAME" ->/dev/video0</TT -> to -<TT -CLASS="FILENAME" ->/dev/video63</TT -> with major number 81 and minor -numbers 0 to 63. <TT -CLASS="FILENAME" ->/dev/video</TT -> is typically a -symbolic link to the preferred video capture device.</P -><DIV -CLASS="SECTION" -><HR><H3 -CLASS="SECTION" -><A -NAME="AEN3960" ->4.1.1. Querying Capabilities</A -></H3 -><P ->Devices supporting the video capture interface set the -<CODE -CLASS="CONSTANT" ->V4L2_CAP_VIDEO_CAPTURE</CODE -> flag in the -<CODE -CLASS="STRUCTFIELD" ->capabilities</CODE -> field of struct <A -HREF="#V4L2-CAPABILITY" ->v4l2_capability</A -> -returned by the <A -HREF="#VIDIOC-QUERYCAP" -><CODE -CLASS="CONSTANT" ->VIDIOC_QUERYCAP</CODE -></A ->. As secondary device functions they -may also support the <A -HREF="#OVERLAY" ->video overlay</A -> -(<CODE -CLASS="CONSTANT" ->V4L2_CAP_VIDEO_OVERLAY</CODE ->) and the <A -HREF="#RAW-VBI" ->raw VBI capture</A -> -(<CODE -CLASS="CONSTANT" ->V4L2_CAP_VBI_CAPTURE</CODE ->) interface. At least one of -the read/write or streaming I/O methods must be supported. Tuners and -audio inputs are optional.</P -></DIV -><DIV -CLASS="SECTION" -><HR><H3 -CLASS="SECTION" -><A -NAME="AEN3972" ->4.1.2. Supplemental Functions</A -></H3 -><P ->Video capture devices shall support <A -HREF="#AUDIO" ->audio input</A ->, <A -HREF="#TUNER" ->tuner</A ->, <A -HREF="#CONTROL" ->controls</A ->, -<A -HREF="#CROP" ->cropping and scaling</A -> and <A -HREF="#STREAMING-PAR" ->streaming parameter</A -> ioctls as needed. -The <A -HREF="#VIDEO" ->video input</A -> and <A -HREF="#STANDARD" ->video standard</A -> ioctls must be supported by -all video capture devices.</P -></DIV -><DIV -CLASS="SECTION" -><HR><H3 -CLASS="SECTION" -><A -NAME="AEN3982" ->4.1.3. Image Format Negotiation</A -></H3 -><P ->The result of a capture operation is determined by -cropping and image format parameters. The former select an area of the -video picture to capture, the latter how images are stored in memory, -i. e. in RGB or YUV format, the number of bits per pixel or width and -height. Together they also define how images are scaled in the -process.</P -><P ->As usual these parameters are <SPAN -CLASS="emphasis" -><I -CLASS="EMPHASIS" ->not</I -></SPAN -> -reset at <CODE -CLASS="FUNCTION" ->open()</CODE -> time to permit Unix tool chains, -programming a device and then reading from it as if it was a plain -file. Well written V4L2 applications ensure they really get what they -want, including cropping and scaling.</P -><P ->Cropping initialization at minimum requires to reset the -parameters to defaults. An example is given in <A -HREF="#CROP" ->Section 1.10</A ->.</P -><P ->To query the current image format applications set the -<CODE -CLASS="STRUCTFIELD" ->type</CODE -> field of a struct <A -HREF="#V4L2-FORMAT" ->v4l2_format</A -> to -<CODE -CLASS="CONSTANT" ->V4L2_BUF_TYPE_VIDEO_CAPTURE</CODE -> and call the -<A -HREF="#VIDIOC-G-FMT" -><CODE -CLASS="CONSTANT" ->VIDIOC_G_FMT</CODE -></A -> ioctl with a pointer to this structure. Drivers fill -the struct <A -HREF="#V4L2-PIX-FORMAT" ->v4l2_pix_format</A -> <CODE -CLASS="STRUCTFIELD" ->pix</CODE -> member of the -<CODE -CLASS="STRUCTFIELD" ->fmt</CODE -> union.</P -><P ->To request different parameters applications set the -<CODE -CLASS="STRUCTFIELD" ->type</CODE -> field of a struct <A -HREF="#V4L2-FORMAT" ->v4l2_format</A -> as above and -initialize all fields of the struct <A -HREF="#V4L2-PIX-FORMAT" ->v4l2_pix_format</A -> -<CODE -CLASS="STRUCTFIELD" ->vbi</CODE -> member of the -<CODE -CLASS="STRUCTFIELD" ->fmt</CODE -> union, or better just modify the -results of <CODE -CLASS="CONSTANT" ->VIDIOC_G_FMT</CODE ->, and call the -<A -HREF="#VIDIOC-G-FMT" -><CODE -CLASS="CONSTANT" ->VIDIOC_S_FMT</CODE -></A -> ioctl with a pointer to this structure. Drivers may -adjust the parameters and finally return the actual parameters as -<CODE -CLASS="CONSTANT" ->VIDIOC_G_FMT</CODE -> does.</P -><P ->Like <CODE -CLASS="CONSTANT" ->VIDIOC_S_FMT</CODE -> the -<A -HREF="#VIDIOC-G-FMT" -><CODE -CLASS="CONSTANT" ->VIDIOC_TRY_FMT</CODE -></A -> ioctl can be used to learn about hardware limitations -without disabling I/O or possibly time consuming hardware -preparations.</P -><P ->The contents of struct <A -HREF="#V4L2-PIX-FORMAT" ->v4l2_pix_format</A -> are discussed in <A -HREF="#PIXFMT" ->Chapter 2</A ->. See also the specification of the -<CODE -CLASS="CONSTANT" ->VIDIOC_G_FMT</CODE ->, <CODE -CLASS="CONSTANT" ->VIDIOC_S_FMT</CODE -> -and <CODE -CLASS="CONSTANT" ->VIDIOC_TRY_FMT</CODE -> ioctls for details. Video -capture devices must implement both the -<CODE -CLASS="CONSTANT" ->VIDIOC_G_FMT</CODE -> and -<CODE -CLASS="CONSTANT" ->VIDIOC_S_FMT</CODE -> ioctl, even if -<CODE -CLASS="CONSTANT" ->VIDIOC_S_FMT</CODE -> ignores all requests and always -returns default parameters as <CODE -CLASS="CONSTANT" ->VIDIOC_G_FMT</CODE -> does. -<CODE -CLASS="CONSTANT" ->VIDIOC_TRY_FMT</CODE -> is optional.</P -></DIV -><DIV -CLASS="SECTION" -><HR><H3 -CLASS="SECTION" -><A -NAME="AEN4024" ->4.1.4. Reading Images</A -></H3 -><P ->A video capture device may support the <A -HREF="#RW" ->read() function</A -> and/or streaming (<A -HREF="#MMAP" ->memory mapping</A -> or <A -HREF="#USERP" ->user pointer</A ->) I/O. See <A -HREF="#IO" ->Chapter 3</A -> for details.</P -></DIV -></DIV -><DIV -CLASS="SECTION" -><HR><H2 -CLASS="SECTION" -><A -NAME="OVERLAY" ->4.2. Video Overlay Interface</A -></H2 -><FONT -COLOR="RED" ->Also known as Frame Buffer Overlay or Previewing</FONT -><P ->Video overlay devices have the ability to genlock (TV-)video -into the (VGA-)video signal of a graphics card, or to store captured -images directly in video memory of a graphics card, typically with -clipping. This can be considerable more efficient than capturing -images and displaying them by other means. In the old days when only -nuclear power plants needed cooling towers this used to be the only -way to put live video into a window.</P -><P ->Video overlay devices are accessed through the same character -special files as <A -HREF="#CAPTURE" ->video capture</A -> devices. -Note the default function of a <TT -CLASS="FILENAME" ->/dev/video</TT -> device -is video capturing. The overlay function is only available after -calling the <A -HREF="#VIDIOC-G-FMT" -><CODE -CLASS="CONSTANT" ->VIDIOC_S_FMT</CODE -></A -> ioctl.</P -><P ->The driver may support simultaneous overlay and capturing -using the read/write and streaming I/O methods. If so, operation at -the nominal frame rate of the video standard is not guaranteed. Frames -may be directed away from overlay to capture, or one field may be used -for overlay and the other for capture if the capture parameters permit -this.</P -><P ->Applications should use different file descriptors for -capturing and overlay. This must be supported by all drivers capable -of simultaneous capturing and overlay. Optionally these drivers may -also permit capturing and overlay with a single file descriptor for -compatibility with V4L and earlier versions of V4L2.<A -NAME="AEN4042" -HREF="#FTN.AEN4042" -><SPAN -CLASS="footnote" ->[21]</SPAN -></A -></P -><DIV -CLASS="SECTION" -><HR><H3 -CLASS="SECTION" -><A -NAME="AEN4048" ->4.2.1. Querying Capabilities</A -></H3 -><P ->Devices supporting the video overlay interface set the -<CODE -CLASS="CONSTANT" ->V4L2_CAP_VIDEO_OVERLAY</CODE -> flag in the -<CODE -CLASS="STRUCTFIELD" ->capabilities</CODE -> field of struct <A -HREF="#V4L2-CAPABILITY" ->v4l2_capability</A -> -returned by the <A -HREF="#VIDIOC-QUERYCAP" -><CODE -CLASS="CONSTANT" ->VIDIOC_QUERYCAP</CODE -></A ->. The overlay I/O method specified -below must be supported. Tuners and audio inputs are optional.</P -></DIV -><DIV -CLASS="SECTION" -><HR><H3 -CLASS="SECTION" -><A -NAME="AEN4056" ->4.2.2. Supplemental Functions</A -></H3 -><P ->Video overlay devices shall support <A -HREF="#AUDIO" ->audio input</A ->, <A -HREF="#TUNER" ->tuner</A ->, <A -HREF="#CONTROL" ->controls</A ->, -<A -HREF="#CROP" ->cropping and scaling</A -> and <A -HREF="#STREAMING-PAR" ->streaming parameter</A -> ioctls as needed. -The <A -HREF="#VIDEO" ->video input</A -> and <A -HREF="#STANDARD" ->video standard</A -> ioctls must be supported by -all video overlay devices.</P -></DIV -><DIV -CLASS="SECTION" -><HR><H3 -CLASS="SECTION" -><A -NAME="AEN4066" ->4.2.3. Setup</A -></H3 -><P ->Before overlay can commence applications must program the -driver with frame buffer parameters, namely the address and size of -the frame buffer and the image format, for example RGB 5:6:5. The -<A -HREF="#VIDIOC-G-FBUF" -><CODE -CLASS="CONSTANT" ->VIDIOC_G_FBUF</CODE -></A -> and <A -HREF="#VIDIOC-G-FBUF" -><CODE -CLASS="CONSTANT" ->VIDIOC_S_FBUF</CODE -></A -> ioctls are available to get -and set these parameters, respectively. The -<CODE -CLASS="CONSTANT" ->VIDIOC_S_FBUF</CODE -> ioctl is privileged because it -allows to set up DMA into physical memory, bypassing the memory -protection mechanisms of the kernel. Only the superuser can change the -frame buffer address and size. Users are not supposed to run TV -applications as root or with SUID bit set. A small helper application -with suitable privileges should query the graphics system and program -the V4L2 driver at the appropriate time.</P -><P ->Some devices add the video overlay to the output signal -of the graphics card. In this case the frame buffer is not modified by -the video device, and the frame buffer address and pixel format are -not needed by the driver. The <CODE -CLASS="CONSTANT" ->VIDIOC_S_FBUF</CODE -> ioctl -is not privileged. An application can check for this type of device by -calling the <CODE -CLASS="CONSTANT" ->VIDIOC_G_FBUF</CODE -> ioctl.</P -><P ->A driver may support any (or none) of three clipping -methods:<P -></P -><OL -TYPE="1" -><LI -><P ->Chroma-keying displays the overlaid image only where -pixels in the primary graphics surface assume a certain color.</P -></LI -><LI -><P ->A bitmap can be specified where each bit corresponds -to a pixel in the overlaid image. When the bit is set, the -corresponding video pixel is displayed, otherwise a pixel of the -graphics surface.</P -></LI -><LI -><P ->A list of clipping rectangles can be specified. In -these regions <SPAN -CLASS="emphasis" -><I -CLASS="EMPHASIS" ->no</I -></SPAN -> video is displayed, so the -graphics surface can be seen here.</P -></LI -></OL -></P -><P ->When simultaneous capturing and overlay is supported and -the hardware prohibits different image and frame buffer formats, the -format requested first takes precedence. The attempt to capture -(<A -HREF="#VIDIOC-G-FMT" -><CODE -CLASS="CONSTANT" ->VIDIOC_S_FMT</CODE -></A ->) or overlay (<A -HREF="#VIDIOC-G-FBUF" -><CODE -CLASS="CONSTANT" ->VIDIOC_S_FBUF</CODE -></A ->) may fail with an -<SPAN -CLASS="ERRORCODE" ->EBUSY</SPAN -> error code or return accordingly modified parameters..</P -></DIV -><DIV -CLASS="SECTION" -><HR><H3 -CLASS="SECTION" -><A -NAME="AEN4092" ->4.2.4. Overlay Window</A -></H3 -><P ->The overlaid image is determined by cropping and overlay -window parameters. The former select an area of the video picture to -capture, the latter how images are overlaid and clipped. Cropping -initialization at minimum requires to reset the parameters to -defaults. An example is given in <A -HREF="#CROP" ->Section 1.10</A ->.</P -><P ->The overlay window is described by a struct <A -HREF="#V4L2-WINDOW" ->v4l2_window</A ->. It -defines the size of the image, its position over the graphics surface -and the clipping to be applied. To get the current parameters applications -set the <CODE -CLASS="STRUCTFIELD" ->type</CODE -> field of a struct <A -HREF="#V4L2-FORMAT" ->v4l2_format</A -> to -<CODE -CLASS="CONSTANT" ->V4L2_BUF_TYPE_VIDEO_OVERLAY</CODE -> and call the -<A -HREF="#VIDIOC-G-FMT" -><CODE -CLASS="CONSTANT" ->VIDIOC_G_FMT</CODE -></A -> ioctl. The driver fills the -<CODE -CLASS="STRUCTNAME" ->v4l2_window</CODE -> substructure named -<CODE -CLASS="STRUCTFIELD" ->win</CODE ->. Retrieving a previously programmed -clipping list or bitmap is not possible.</P -><P ->To program the overlay window applications set the -<CODE -CLASS="STRUCTFIELD" ->type</CODE -> field of a struct <A -HREF="#V4L2-FORMAT" ->v4l2_format</A -> to -<CODE -CLASS="CONSTANT" ->V4L2_BUF_TYPE_VIDEO_OVERLAY</CODE ->, initialize the -<CODE -CLASS="STRUCTFIELD" ->win</CODE -> substructure and call the -<A -HREF="#VIDIOC-G-FMT" -><CODE -CLASS="CONSTANT" ->VIDIOC_S_FMT</CODE -></A -> ioctl. The driver adjusts the parameters against -hardware limits and returns the actual parameters as -<CODE -CLASS="CONSTANT" ->VIDIOC_G_FMT</CODE -> does. Like -<CODE -CLASS="CONSTANT" ->VIDIOC_S_FMT</CODE ->, the <A -HREF="#VIDIOC-G-FMT" -><CODE -CLASS="CONSTANT" ->VIDIOC_TRY_FMT</CODE -></A -> ioctl can be -used to learn about driver capabilities without actually changing -driver state. Unlike <CODE -CLASS="CONSTANT" ->VIDIOC_S_FMT</CODE -> this also works -after the overlay has been enabled.</P -><P ->The scaling factor of the overlaid image is implied by the -width and height given in struct <A -HREF="#V4L2-WINDOW" ->v4l2_window</A -> and the size of the cropping -rectangle. For more information see <A -HREF="#CROP" ->Section 1.10</A ->.</P -><P ->When simultaneous capturing and overlay is supported and -the hardware prohibits different image and window sizes, the size -requested first takes precedence. The attempt to capture or overlay as -well (<A -HREF="#VIDIOC-G-FMT" -><CODE -CLASS="CONSTANT" ->VIDIOC_S_FMT</CODE -></A ->) may fail with an <SPAN -CLASS="ERRORCODE" ->EBUSY</SPAN -> error code or return accordingly -modified parameters.</P -><DIV -CLASS="TABLE" -><A -NAME="V4L2-WINDOW" -></A -><P -><B ->Table 4-1. struct <CODE -CLASS="STRUCTNAME" ->v4l2_window</CODE -></B -></P -><TABLE -BORDER="0" -FRAME="void" -WIDTH="100%" -CLASS="CALSTABLE" -><COL -WIDTH="25%" -TITLE="C1"><COL -WIDTH="25%" -TITLE="C2"><COL -WIDTH="50%" -TITLE="C3"><TBODY -><TR -><TD ->struct <A -HREF="#V4L2-RECT" ->v4l2_rect</A -></TD -><TD -><CODE -CLASS="STRUCTFIELD" ->w</CODE -></TD -><TD ->Size and position of the window relative to the -top, left corner of the frame buffer defined with <A -HREF="#VIDIOC-G-FBUF" -><CODE -CLASS="CONSTANT" ->VIDIOC_S_FBUF</CODE -></A ->. The -window can extend the frame buffer width and height, the -<CODE -CLASS="STRUCTFIELD" ->x</CODE -> and <CODE -CLASS="STRUCTFIELD" ->y</CODE -> -coordinates can be negative, and it can lie completely outside the -frame buffer. The driver clips the window accordingly, or if that is -not possible, modifies its size and/or position.</TD -></TR -><TR -><TD ->enum <A -HREF="#V4L2-FIELD" ->v4l2_field</A -></TD -><TD -><CODE -CLASS="STRUCTFIELD" ->field</CODE -></TD -><TD ->Applications set this field to determine which -video field shall be overlaid, typically one of -<CODE -CLASS="CONSTANT" ->V4L2_FIELD_ANY</CODE -> (0), -<CODE -CLASS="CONSTANT" ->V4L2_FIELD_TOP</CODE ->, -<CODE -CLASS="CONSTANT" ->V4L2_FIELD_BOTTOM</CODE -> or -<CODE -CLASS="CONSTANT" ->V4L2_FIELD_INTERLACED</CODE ->. Drivers may have to choose -a different field order and return the actual setting here.</TD -></TR -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->chromakey</CODE -></TD -><TD ->When chroma-keying has been negotiated with -<A -HREF="#VIDIOC-G-FBUF" -><CODE -CLASS="CONSTANT" ->VIDIOC_S_FBUF</CODE -></A -> applications set this field to the desired host order -RGB32 value for the chroma key. [host order? alpha channel?]</TD -></TR -><TR -><TD ->struct <A -HREF="#V4L2-CLIP" ->v4l2_clip</A -> *</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->clips</CODE -></TD -><TD ->When chroma-keying has <SPAN -CLASS="emphasis" -><I -CLASS="EMPHASIS" ->not</I -></SPAN -> -been negotiated and <A -HREF="#VIDIOC-G-FBUF" -><CODE -CLASS="CONSTANT" ->VIDIOC_G_FBUF</CODE -></A -> indicated this capability, -applications can set this field to point to the first in a list of -clipping rectangles.</TD -></TR -><TR -><TD -COLSPAN="3" ->Like the window coordinates -<CODE -CLASS="STRUCTFIELD" ->w</CODE ->, clipping rectangles are defined relative -to the top, left corner of the frame buffer. However clipping -rectangles must not extend the frame buffer width and height, and they -must not overlap. If possible applications should merge adjacent -rectangles. Whether this must create x-y or y-x bands, or the order of -rectangles, is not defined. When clip lists are not supported the -driver ignores this field. Its contents after calling <A -HREF="#VIDIOC-G-FMT" -><CODE -CLASS="CONSTANT" ->VIDIOC_S_FMT</CODE -></A -> -are undefined.</TD -></TR -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->clipcount</CODE -></TD -><TD ->When the application set the -<CODE -CLASS="STRUCTFIELD" ->clips</CODE -> field, this field must contain the -number of clipping rectangles in the list. When clip lists are not -supported the driver ignores this field, its contents after calling -<CODE -CLASS="CONSTANT" ->VIDIOC_S_FMT</CODE -> are undefined. When clip lists are -supported but no clipping is desired this field must be set to -zero.</TD -></TR -><TR -><TD ->void *</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->bitmap</CODE -></TD -><TD ->When chroma-keying has -<SPAN -CLASS="emphasis" -><I -CLASS="EMPHASIS" ->not</I -></SPAN -> been negotiated and <A -HREF="#VIDIOC-G-FBUF" -><CODE -CLASS="CONSTANT" ->VIDIOC_G_FBUF</CODE -></A -> indicated -this capability, applications can set this field to point to a -clipping bit mask.</TD -></TR -><TR -><TD -COLSPAN="3" -><P ->It must be of the same size -as the window, <CODE -CLASS="STRUCTFIELD" ->w.width</CODE -> and -<CODE -CLASS="STRUCTFIELD" ->w.height</CODE ->. Each bit corresponds to a pixel -in the overlaid image, which is displayed only when the bit is -<SPAN -CLASS="emphasis" -><I -CLASS="EMPHASIS" ->set</I -></SPAN ->. Pixel coordinates translate to bits like: -<PRE -CLASS="PROGRAMLISTING" ->((__u8 *) <CODE -CLASS="STRUCTFIELD" ->bitmap</CODE ->)[<CODE -CLASS="STRUCTFIELD" ->w.width</CODE -> * y + x / 8] & (1 << (x & 7))</PRE -></P -><P ->where <CODE -CLASS="STRUCTFIELD" ->0</CODE -> ≤ x < -<CODE -CLASS="STRUCTFIELD" ->w.width</CODE -> and <CODE -CLASS="STRUCTFIELD" ->0</CODE -> ≤ -y <<CODE -CLASS="STRUCTFIELD" ->w.height</CODE ->.<SUP ->a</SUP -></P -><P ->When a clipping -bit mask is not supported the driver ignores this field, its contents -after calling <A -HREF="#VIDIOC-G-FMT" -><CODE -CLASS="CONSTANT" ->VIDIOC_S_FMT</CODE -></A -> are undefined. When a bit mask is supported -but no clipping is desired this field must be set to -<CODE -CLASS="CONSTANT" ->NULL</CODE ->.</P -><P ->Applications need not create a -clip list or bit mask. When they pass both, or despite negotiating -chroma-keying, the results are undefined. Regardless of the chosen -method, the clipping abilities of the hardware may be limited in -quantity or quality. The results when these limits are exceeded are -undefined.<SUP ->b</SUP -></P -></TD -></TR -></TBODY -><TR -><TD -COLSPAN="3" ->Notes:<BR><A -NAME="FTN.AEN4203" ->a. </A ->Should we require - <CODE -CLASS="STRUCTFIELD" ->w.width</CODE -> to be a multiple of - eight?<BR><A -NAME="FTN.AEN4211" ->b. </A ->When the image is written into frame buffer -memory it will be undesirable if the driver clips out less pixels -than expected, because the application and graphics system are not -aware these regions need to be refreshed. The driver should clip out -more pixels or not write the image at all.<BR></TD -></TR -></TABLE -></DIV -><DIV -CLASS="TABLE" -><A -NAME="V4L2-CLIP" -></A -><P -><B ->Table 4-2. struct <CODE -CLASS="STRUCTNAME" ->v4l2_clip</CODE -><A -NAME="AEN4216" -HREF="#FTN.AEN4216" -><SPAN -CLASS="footnote" ->[22]</SPAN -></A -></B -></P -><TABLE -BORDER="0" -FRAME="void" -WIDTH="100%" -CLASS="CALSTABLE" -><COL -WIDTH="25%" -TITLE="C1"><COL -WIDTH="25%" -TITLE="C2"><COL -WIDTH="50%" -TITLE="C3"><TBODY -><TR -><TD ->struct <A -HREF="#V4L2-RECT" ->v4l2_rect</A -></TD -><TD -><CODE -CLASS="STRUCTFIELD" ->c</CODE -></TD -><TD ->Coordinates of the clipping rectangle, relative to -the top, left corner of the frame buffer. Only window pixels -<SPAN -CLASS="emphasis" -><I -CLASS="EMPHASIS" ->outside</I -></SPAN -> all clipping rectangles are -displayed.</TD -></TR -><TR -><TD ->struct <A -HREF="#V4L2-CLIP" ->v4l2_clip</A -> *</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->next</CODE -></TD -><TD ->Pointer to the next clipping rectangle in the list, -NULL when this is the last rectangle.</TD -></TR -></TBODY -></TABLE -></DIV -><DIV -CLASS="TABLE" -><A -NAME="V4L2-RECT" -></A -><P -><B ->Table 4-3. struct <CODE -CLASS="STRUCTNAME" ->v4l2_rect</CODE -></B -></P -><TABLE -BORDER="0" -FRAME="void" -WIDTH="100%" -CLASS="CALSTABLE" -><COL -WIDTH="25%" -TITLE="C1"><COL -WIDTH="25%" -TITLE="C2"><COL -WIDTH="50%" -TITLE="C3"><TBODY -><TR -><TD ->__s32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->left</CODE -></TD -><TD ->Horizontal offset of the top, left corner of the -rectangle, in pixels.</TD -></TR -><TR -><TD ->__s32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->top</CODE -></TD -><TD ->Vertical offset of the top, left corner of the -rectangle, in pixels. Offsets increase to the right and down.</TD -></TR -><TR -><TD ->__s32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->width</CODE -></TD -><TD ->Width of the rectangle, in pixels.</TD -></TR -><TR -><TD ->__s32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->height</CODE -></TD -><TD ->Height of the rectangle, in pixels. Width and -height cannot be negative, the fields are signed for hysterical -reasons. </TD -></TR -></TBODY -></TABLE -></DIV -></DIV -><DIV -CLASS="SECTION" -><HR><H3 -CLASS="SECTION" -><A -NAME="AEN4266" ->4.2.5. Enabling Overlay</A -></H3 -><P ->To start or stop the frame buffer overlay applications call -the <A -HREF="#VIDIOC-OVERLAY" -><CODE -CLASS="CONSTANT" ->VIDIOC_OVERLAY</CODE -></A -> ioctl.</P -></DIV -></DIV -><DIV -CLASS="SECTION" -><HR><H2 -CLASS="SECTION" -><A -NAME="OUTPUT" ->4.3. Video Output Interface</A -></H2 -><P ->Video output devices encode stills or image sequences as -analog video signal. With this interface applications can -control the encoding process and move images from user space to -the driver.</P -><P ->Conventionally V4L2 video output devices are accessed through -character device special files named <TT -CLASS="FILENAME" ->/dev/vout</TT -> and -<TT -CLASS="FILENAME" ->/dev/vout0</TT -> to <TT -CLASS="FILENAME" ->/dev/voutN</TT ->. No -minor numbers were recommended yet. <TT -CLASS="FILENAME" ->/dev/vout</TT -> is -typically a symbolic link to the preferred video output device.</P -><DIV -CLASS="SECTION" -><HR><H3 -CLASS="SECTION" -><A -NAME="AEN4279" ->4.3.1. Querying Capabilities</A -></H3 -><P ->Devices supporting the video output interface set the -<CODE -CLASS="CONSTANT" ->V4L2_CAP_VIDEO_OUTPUT</CODE -> flag in the -<CODE -CLASS="STRUCTFIELD" ->capabilities</CODE -> field of struct <A -HREF="#V4L2-CAPABILITY" ->v4l2_capability</A -> -returned by the <A -HREF="#VIDIOC-QUERYCAP" -><CODE -CLASS="CONSTANT" ->VIDIOC_QUERYCAP</CODE -></A ->. As secondary device functions they -may also support the <A -HREF="#RAW-VBI" ->raw VBI output</A -> -(<CODE -CLASS="CONSTANT" ->V4L2_CAP_VBI_OUTPUT</CODE ->) interface. At least one of -the read/write or streaming I/O methods must be supported. Modulators -and audio outputs are optional.</P -></DIV -><DIV -CLASS="SECTION" -><HR><H3 -CLASS="SECTION" -><A -NAME="AEN4289" ->4.3.2. Supplemental Functions</A -></H3 -><P ->Video output devices shall support <A -HREF="#AUDIO" ->audio output</A ->, <A -HREF="#TUNER" ->modulator</A ->, <A -HREF="#CONTROL" ->controls</A ->, -<A -HREF="#CROP" ->cropping and scaling</A -> and <A -HREF="#STREAMING-PAR" ->streaming parameter</A -> ioctls as needed. -The <A -HREF="#VIDEO" ->video output</A -> and <A -HREF="#STANDARD" ->video standard</A -> ioctls must be supported by -all video output devices.</P -></DIV -><DIV -CLASS="SECTION" -><HR><H3 -CLASS="SECTION" -><A -NAME="AEN4299" ->4.3.3. Image Format Negotiation</A -></H3 -><P ->The output is determined by cropping and image format -parameters. The former select an area of the video picture where the -image will appear, the latter how images are stored in memory, i. e. in -RGB or YUV format, the number of bits per pixel or width and height. -Together they also define how images are scaled in the process.</P -><P ->As usual these parameters are <SPAN -CLASS="emphasis" -><I -CLASS="EMPHASIS" ->not</I -></SPAN -> -reset at <CODE -CLASS="FUNCTION" ->open()</CODE -> time to permit Unix tool chains, -programming a device and then writing to it as if it was a plain -file. Well written V4L2 applications ensure they really get what they -want, including cropping and scaling.</P -><P ->Cropping initialization at minimum requires to reset the -parameters to defaults. An example is given in <A -HREF="#CROP" ->Section 1.10</A ->.</P -><P ->To query the current image format applications set the -<CODE -CLASS="STRUCTFIELD" ->type</CODE -> field of a struct <A -HREF="#V4L2-FORMAT" ->v4l2_format</A -> to -<CODE -CLASS="CONSTANT" ->V4L2_BUF_TYPE_VIDEO_OUTPUT</CODE -> and call the -<A -HREF="#VIDIOC-G-FMT" -><CODE -CLASS="CONSTANT" ->VIDIOC_G_FMT</CODE -></A -> ioctl with a pointer to this structure. Drivers fill -the struct <A -HREF="#V4L2-PIX-FORMAT" ->v4l2_pix_format</A -> <CODE -CLASS="STRUCTFIELD" ->pix</CODE -> member of the -<CODE -CLASS="STRUCTFIELD" ->fmt</CODE -> union.</P -><P ->To request different parameters applications set the -<CODE -CLASS="STRUCTFIELD" ->type</CODE -> field of a struct <A -HREF="#V4L2-FORMAT" ->v4l2_format</A -> as above and -initialize all fields of the struct <A -HREF="#V4L2-PIX-FORMAT" ->v4l2_pix_format</A -> -<CODE -CLASS="STRUCTFIELD" ->vbi</CODE -> member of the -<CODE -CLASS="STRUCTFIELD" ->fmt</CODE -> union, or better just modify the -results of <CODE -CLASS="CONSTANT" ->VIDIOC_G_FMT</CODE ->, and call the -<A -HREF="#VIDIOC-G-FMT" -><CODE -CLASS="CONSTANT" ->VIDIOC_S_FMT</CODE -></A -> ioctl with a pointer to this structure. Drivers may -adjust the parameters and finally return the actual parameters as -<CODE -CLASS="CONSTANT" ->VIDIOC_G_FMT</CODE -> does.</P -><P ->Like <CODE -CLASS="CONSTANT" ->VIDIOC_S_FMT</CODE -> the -<A -HREF="#VIDIOC-G-FMT" -><CODE -CLASS="CONSTANT" ->VIDIOC_TRY_FMT</CODE -></A -> ioctl can be used to learn about hardware limitations -without disabling I/O or possibly time consuming hardware -preparations.</P -><P ->The contents of struct <A -HREF="#V4L2-PIX-FORMAT" ->v4l2_pix_format</A -> are discussed in <A -HREF="#PIXFMT" ->Chapter 2</A ->. See also the specification of the -<CODE -CLASS="CONSTANT" ->VIDIOC_G_FMT</CODE ->, <CODE -CLASS="CONSTANT" ->VIDIOC_S_FMT</CODE -> -and <CODE -CLASS="CONSTANT" ->VIDIOC_TRY_FMT</CODE -> ioctls for details. Video -output devices must implement both the -<CODE -CLASS="CONSTANT" ->VIDIOC_G_FMT</CODE -> and -<CODE -CLASS="CONSTANT" ->VIDIOC_S_FMT</CODE -> ioctl, even if -<CODE -CLASS="CONSTANT" ->VIDIOC_S_FMT</CODE -> ignores all requests and always -returns default parameters as <CODE -CLASS="CONSTANT" ->VIDIOC_G_FMT</CODE -> does. -<CODE -CLASS="CONSTANT" ->VIDIOC_TRY_FMT</CODE -> is optional.</P -></DIV -><DIV -CLASS="SECTION" -><HR><H3 -CLASS="SECTION" -><A -NAME="AEN4341" ->4.3.4. Writing Images</A -></H3 -><P ->A video output device may support the <A -HREF="#RW" ->write() function</A -> and/or streaming (<A -HREF="#MMAP" ->memory mapping</A -> or <A -HREF="#USERP" ->user pointer</A ->) I/O. See <A -HREF="#IO" ->Chapter 3</A -> for details.</P -></DIV -></DIV -><DIV -CLASS="SECTION" -><HR><H2 -CLASS="SECTION" -><A -NAME="CODEC" ->4.4. Codec Interface</A -></H2 -><DIV -CLASS="NOTE" -><BLOCKQUOTE -CLASS="NOTE" -><P -><B ->Suspended: </B ->This interface has been be suspended from the V4L2 API -implemented in Linux 2.6 until we have more experience with codec -device interfaces.</P -></BLOCKQUOTE -></DIV -><P ->A V4L2 codec can compress, decompress, transform, or -otherwise convert video data from one format into another format, in -memory. Applications send data to be converted to the driver through -the <CODE -CLASS="FUNCTION" ->write()</CODE -> call, and receive the converted data -through the <CODE -CLASS="FUNCTION" ->read()</CODE -> call. For efficiency, a driver -may also support streaming I/O.</P -><P ->[to do]</P -></DIV -><DIV -CLASS="SECTION" -><HR><H2 -CLASS="SECTION" -><A -NAME="EFFECT" ->4.5. Effect Devices Interface</A -></H2 -><DIV -CLASS="NOTE" -><BLOCKQUOTE -CLASS="NOTE" -><P -><B ->Suspended: </B ->This interface has been be suspended from the V4L2 API -implemented in Linux 2.6 until we have more experience with effect -device interfaces.</P -></BLOCKQUOTE -></DIV -><P ->A V4L2 video effect device can do image effects, -filtering, or combine two or more images or image streams. For example -video transitions or wipes. Applications send data to be processed and -receive the result data either with <CODE -CLASS="FUNCTION" ->read()</CODE -> and -<CODE -CLASS="FUNCTION" ->write()</CODE -> functions, or through the streaming I/O -mechanism.</P -><P ->[to do]</P -></DIV -><DIV -CLASS="SECTION" -><HR><H2 -CLASS="SECTION" -><A -NAME="RAW-VBI" ->4.6. Raw VBI Data Interface</A -></H2 -><P ->VBI is an abbreviation of "Vertical Blanking Interval", a gap -in the sequence of lines of an analog video signal. During VBI -no picture information is transmitted, allowing some time while the -electron beam of a cathode ray tube TV returns to the top of the -screen. Using an oscilloscope you will find here the vertical -synchronization pulses and short data packages ASK -modulated<A -NAME="AEN4369" -HREF="#FTN.AEN4369" -><SPAN -CLASS="footnote" ->[23]</SPAN -></A -> -onto the video signal. These are transmissions of services such as -Teletext or Closed Caption.</P -><P ->Subject of this interface type is raw VBI data, as sampled off -a video signal, or to be added to a signal for output. -The data format is similar to uncompressed video images, a number of -lines times a number of samples per line, we call this a VBI image.</P -><P ->Conventionally V4L2 VBI devices are accessed through character -device special files named <TT -CLASS="FILENAME" ->/dev/vbi</TT -> and -<TT -CLASS="FILENAME" ->/dev/vbi0</TT -> to <TT -CLASS="FILENAME" ->/dev/vbi15</TT -> with -major number 81 and minor numbers 224 to 239. -<TT -CLASS="FILENAME" ->/dev/vbi</TT -> is typically a symbolic link to the -preferred VBI device. This convention applies to both input and output -devices.</P -><P ->To address the problems of finding related video and VBI -devices VBI capturing is also available as device function under -<TT -CLASS="FILENAME" ->/dev/video</TT ->, VBI output under -<TT -CLASS="FILENAME" ->/dev/vout</TT ->. To capture raw VBI data from these -devices applications must call the <A -HREF="#VIDIOC-G-FMT" -><CODE -CLASS="CONSTANT" ->VIDIOC_S_FMT</CODE -></A -> ioctl. Accessed as -<TT -CLASS="FILENAME" ->/dev/vbi</TT ->, raw VBI capturing or output is -the default device function.</P -><DIV -CLASS="SECTION" -><HR><H3 -CLASS="SECTION" -><A -NAME="AEN4383" ->4.6.1. Querying Capabilities</A -></H3 -><P ->Devices supporting the raw VBI capturing or output API set -the <CODE -CLASS="CONSTANT" ->V4L2_CAP_VBI_CAPTURE</CODE -> or -<CODE -CLASS="CONSTANT" ->V4L2_CAP_VBI_OUTPUT</CODE -> flags, respectively, in the -<CODE -CLASS="STRUCTFIELD" ->capabilities</CODE -> field of struct <A -HREF="#V4L2-CAPABILITY" ->v4l2_capability</A -> -returned by the <A -HREF="#VIDIOC-QUERYCAP" -><CODE -CLASS="CONSTANT" ->VIDIOC_QUERYCAP</CODE -></A ->. At least one of the -read/write, streaming or asynchronous I/O methods must be -supported. VBI devices may or may not have a tuner or modulator.</P -></DIV -><DIV -CLASS="SECTION" -><HR><H3 -CLASS="SECTION" -><A -NAME="AEN4392" ->4.6.2. Supplemental Functions</A -></H3 -><P ->VBI devices shall support <A -HREF="#VIDEO" ->video -input or output</A ->, <A -HREF="#TUNER" ->tuner or -modulator</A ->, and <A -HREF="#CONTROL" ->controls</A -> ioctls -as needed. The <A -HREF="#STANDARD" ->video standard</A -> ioctls provide -information vital to program a VBI device, therefore must be -supported.</P -></DIV -><DIV -CLASS="SECTION" -><HR><H3 -CLASS="SECTION" -><A -NAME="AEN4399" ->4.6.3. Raw VBI Format Negotiation</A -></H3 -><P ->Raw VBI sampling abilities can vary, in particular the -sampling frequency. To properly interpret the data V4L2 specifies an -ioctl to query the sampling parameters. Moreover, to allow for some -flexibility applications can also suggest different parameters.</P -><P ->As usual these parameters are <SPAN -CLASS="emphasis" -><I -CLASS="EMPHASIS" ->not</I -></SPAN -> -reset at <CODE -CLASS="FUNCTION" ->open()</CODE -> time to permit Unix tool chains, -programming a device and then reading from it as if it was a plain -file. Well written V4L2 applications should always ensure they really -get what they want, requesting reasonable parameters and then checking -if the actual parameters are suitable.</P -><P ->To query the current raw VBI capture parameters -applications set the <CODE -CLASS="STRUCTFIELD" ->type</CODE -> field of a -struct <A -HREF="#V4L2-FORMAT" ->v4l2_format</A -> to <CODE -CLASS="CONSTANT" ->V4L2_BUF_TYPE_VBI_CAPTURE</CODE -> or -<CODE -CLASS="CONSTANT" ->V4L2_BUF_TYPE_VBI_OUTPUT</CODE ->, and call the -<A -HREF="#VIDIOC-G-FMT" -><CODE -CLASS="CONSTANT" ->VIDIOC_G_FMT</CODE -></A -> ioctl with a pointer to this structure. Drivers fill -the struct <A -HREF="#V4L2-VBI-FORMAT" ->v4l2_vbi_format</A -> <CODE -CLASS="STRUCTFIELD" ->vbi</CODE -> member of the -<CODE -CLASS="STRUCTFIELD" ->fmt</CODE -> union.</P -><P ->To request different parameters applications set the -<CODE -CLASS="STRUCTFIELD" ->type</CODE -> field of a struct <A -HREF="#V4L2-FORMAT" ->v4l2_format</A -> as above and -initialize all fields of the struct <A -HREF="#V4L2-VBI-FORMAT" ->v4l2_vbi_format</A -> -<CODE -CLASS="STRUCTFIELD" ->vbi</CODE -> member of the -<CODE -CLASS="STRUCTFIELD" ->fmt</CODE -> union, or better just modify the -results of <CODE -CLASS="CONSTANT" ->VIDIOC-G-FMT</CODE ->, and call the -<A -HREF="#VIDIOC-G-FMT" -><CODE -CLASS="CONSTANT" ->VIDIOC_S_FMT</CODE -></A -> ioctl with a pointer to this structure. Drivers return -an <SPAN -CLASS="ERRORCODE" ->EINVAL</SPAN -> error code only when the given parameters are ambiguous, otherwise -they modify the parameters according to the hardware capabilites and -return the actual parameters. When the driver allocates resources at -this point, it may return an <SPAN -CLASS="ERRORCODE" ->EBUSY</SPAN -> error code to indicate the returned -parameters are valid but the required resources are currently not -available. That may happen for instance when the video and VBI areas -to capture would overlap, or when the driver supports multiple opens -and another process already requested VBI capturing or output. Anyway, -applications must expect other resource allocation points which may -return <SPAN -CLASS="ERRORCODE" ->EBUSY</SPAN ->, at the <A -HREF="#VIDIOC-STREAMON" -><CODE -CLASS="CONSTANT" ->VIDIOC_STREAMON</CODE -></A -> ioctl -and the first read(), write() and select() call.</P -><P ->VBI devices must implement both the -<CODE -CLASS="CONSTANT" ->VIDIOC_G_FMT</CODE -> and -<CODE -CLASS="CONSTANT" ->VIDIOC_S_FMT</CODE -> ioctl, even if -<CODE -CLASS="CONSTANT" ->VIDIOC_S_FMT</CODE -> ignores all requests and always -returns default parameters as <CODE -CLASS="CONSTANT" ->VIDIOC_G_FMT</CODE -> does. -<CODE -CLASS="CONSTANT" ->VIDIOC_TRY_FMT</CODE -> is optional.</P -><DIV -CLASS="TABLE" -><A -NAME="V4L2-VBI-FORMAT" -></A -><P -><B ->Table 4-4. struct <CODE -CLASS="STRUCTNAME" ->v4l2_vbi_format</CODE -></B -></P -><TABLE -BORDER="0" -FRAME="void" -WIDTH="100%" -CLASS="CALSTABLE" -><COL -WIDTH="25%" -TITLE="C1"><COL -WIDTH="25%" -TITLE="C2"><COL -WIDTH="50%" -TITLE="C3"><TBODY -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->sampling_rate</CODE -></TD -><TD ->Samples per second, i. e. unit 1 Hz.</TD -></TR -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->offset</CODE -></TD -><TD -><P ->Horizontal offset of the VBI image, -relative to the leading edge of the line synchronization pulse and -counted in samples: The first sample in the VBI image will be located -<CODE -CLASS="STRUCTFIELD" ->offset</CODE -> / -<CODE -CLASS="STRUCTFIELD" ->sampling_rate</CODE -> seconds following the leading -edge. See also <A -HREF="#VBI-HSYNC" ->Figure 4-1</A ->.</P -></TD -></TR -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->samples_per_line</CODE -></TD -><TD -> </TD -></TR -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->sample_format</CODE -></TD -><TD -><P ->Defines the sample format as in <A -HREF="#PIXFMT" ->Chapter 2</A ->, a four-character-code.<SUP ->a</SUP -> Usually this is -<CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_GREY</CODE ->, i. e. each sample -consists of 8 bits with lower values oriented towards the black level. -Do not assume any other correlation of values with the signal level. -For example, the MSB does not necessarily indicate if the signal is -'high' or 'low' because 128 may not be the mean value of the -signal. Drivers shall not convert the sample format by software.</P -></TD -></TR -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->start</CODE ->[2]</TD -><TD ->This is the scanning system line number -associated with the first line of the VBI image, of the first and the -second field respectively. See <A -HREF="#VBI-525" ->Figure 4-2</A -> and -<A -HREF="#VBI-625" ->Figure 4-3</A -> for valid values. VBI input drivers can -return start values 0 if the hardware cannot reliable identify -scanning lines, VBI acquisition may not require this -information.</TD -></TR -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->count</CODE ->[2]</TD -><TD ->The number of lines in the first and second -field image, respectively.</TD -></TR -><TR -><TD -COLSPAN="3" -><P ->Drivers should be as -flexibility as possible. For example, it may be possible to extend or -move the VBI capture window down to the picture area, implementing a -'full field mode' to capture data service transmissions embedded in -the picture.</P -><P ->An application can set the first or second -<CODE -CLASS="STRUCTFIELD" ->count</CODE -> value to zero if no data is required -from the respective field; <CODE -CLASS="STRUCTFIELD" ->count</CODE ->[1] if the -scanning system is progressive, i. e. not interlaced. The -corresponding start value shall be ignored by the application and -driver. Anyway, drivers may not support single field capturing and -return both count values non-zero.</P -><P ->Both -<CODE -CLASS="STRUCTFIELD" ->count</CODE -> values set to zero, or line numbers -outside the bounds depicted in <A -HREF="#VBI-525" ->Figure 4-2</A -> and <A -HREF="#VBI-625" ->Figure 4-3</A ->, or a field image covering -lines of two fields, are invalid and shall not be returned by the -driver.</P -><P ->To initialize the <CODE -CLASS="STRUCTFIELD" ->start</CODE -> -and <CODE -CLASS="STRUCTFIELD" ->count</CODE -> fields, applications must first -determine the current video standard selection. The <A -HREF="#V4L2-STD-ID" ->v4l2_std_id</A -> or -the <CODE -CLASS="STRUCTFIELD" ->framelines</CODE -> field of struct <A -HREF="#V4L2-STANDARD" ->v4l2_standard</A -> can -be evaluated for this purpose.</P -></TD -></TR -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->flags</CODE -></TD -><TD ->See <A -HREF="#VBIFMT-FLAGS" ->Table 4-5</A -> below. Currently -only drivers set flags, applications must set this field to -zero.</TD -></TR -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->reserved</CODE ->[2]</TD -><TD ->This array is reserved for future extensions. -Drivers and applications must set it to zero.</TD -></TR -></TBODY -><TR -><TD -COLSPAN="3" ->Notes:<BR><A -NAME="FTN.AEN4470" ->a. </A ->A few devices may be unable to -sample VBI data at all but can extend the video capture window to the -VBI region.<BR></TD -></TR -></TABLE -></DIV -><DIV -CLASS="TABLE" -><A -NAME="VBIFMT-FLAGS" -></A -><P -><B ->Table 4-5. Raw VBI Format Flags</B -></P -><TABLE -BORDER="0" -FRAME="void" -WIDTH="100%" -CLASS="CALSTABLE" -><COL -WIDTH="38%" -TITLE="C1"><COL -WIDTH="12%" -TITLE="C2"><COL -WIDTH="50%" -TITLE="C3"><TBODY -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_VBI_UNSYNC</CODE -></TD -><TD ->0x0001</TD -><TD -><P ->This flag indicates hardware which does not -properly distinguish between fields. Normally the VBI image stores the -first field (lower scanning line numbers) first in memory. This may be -a top or bottom field depending on the video standard. When this flag -is set the first or second field may be stored first, however the -fields are still in correct temporal order with the older field first -in memory.<SUP ->a</SUP -></P -></TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_VBI_INTERLACED</CODE -></TD -><TD ->0x0002</TD -><TD ->By default the two field images will be passed -sequentially; all lines of the first field followed by all lines of -the second field (compare <A -HREF="#FIELD-ORDER" ->Section 3.6</A -> -<CODE -CLASS="CONSTANT" ->V4L2_FIELD_SEQ_TB</CODE -> and -<CODE -CLASS="CONSTANT" ->V4L2_FIELD_SEQ_BT</CODE ->, whether the top or bottom -field is first in memory depends on the video standard). When this -flag is set, the two fields are interlaced (cf. -<CODE -CLASS="CONSTANT" ->V4L2_FIELD_INTERLACED</CODE ->). The first line of the -first field followed by the first line of the second field, then the -two second lines, and so on. Such a layout may be necessary when the -hardware has been programmed to capture or output interlaced video -images and is unable to separate the fields for VBI capturing at -the same time. For simplicity setting this flag implies that both -<CODE -CLASS="STRUCTFIELD" ->count</CODE -> values are equal and non-zero.</TD -></TR -></TBODY -><TR -><TD -COLSPAN="3" ->Notes:<BR><A -NAME="FTN.AEN4526" ->a. </A ->Most VBI services transmit on both fields, but -some have different semantics depending on the field number. These -cannot be reliable decoded or encoded when -<CODE -CLASS="CONSTANT" ->V4L2_VBI_UNSYNC</CODE -> is set.<BR></TD -></TR -></TABLE -></DIV -><DIV -CLASS="FIGURE" -><A -NAME="VBI-HSYNC" -></A -><P -><B ->Figure 4-1. Line synchronization</B -></P -><DIV -CLASS="MEDIAOBJECT" -><P -><IMG -SRC="vbi_hsync.gif"></P -></DIV -></DIV -><DIV -CLASS="FIGURE" -><A -NAME="VBI-525" -></A -><P -><B ->Figure 4-2. ITU-R 525 line numbering (M/NTSC and M/PAL)</B -></P -><DIV -CLASS="MEDIAOBJECT" -><P -><IMG -SRC="vbi_525.gif"><DIV -CLASS="CAPTION" -><P ->(1) For the purpose of this specification field 2 -starts in line 264 and not 263.5 because half line capturing is not -supported.</P -></DIV -></P -></DIV -></DIV -><DIV -CLASS="FIGURE" -><A -NAME="VBI-625" -></A -><P -><B ->Figure 4-3. ITU-R 625 line numbering</B -></P -><DIV -CLASS="MEDIAOBJECT" -><P -><IMG -SRC="vbi_625.gif"><DIV -CLASS="CAPTION" -><P ->(1) For the purpose of this specification field 2 -starts in line 314 and not 313.5 because half line capturing is not -supported.</P -></DIV -></P -></DIV -></DIV -><P ->Remember the VBI image format depends on the selected -video standard, therefore the application must choose a new standard or -query the current standard first. Attempts to read or write data ahead -of format negotiation, or after switching the video standard which may -invalidate the negotiated VBI parameters, should be refused by the -driver. A format change during active I/O is not permitted.</P -></DIV -><DIV -CLASS="SECTION" -><HR><H3 -CLASS="SECTION" -><A -NAME="AEN4571" ->4.6.4. Reading and writing VBI images</A -></H3 -><P ->To assure synchronization with the field number and easier -implementation, the smallest unit of data passed at a time is one -frame, consisting of two fields of VBI images immediately following in -memory.</P -><P ->The total size of a frame computes as follows:</P -><PRE -CLASS="PROGRAMLISTING" ->(<CODE -CLASS="STRUCTFIELD" ->count</CODE ->[0] + <CODE -CLASS="STRUCTFIELD" ->count</CODE ->[1]) * -<CODE -CLASS="STRUCTFIELD" ->samples_per_line</CODE -> * sample size in bytes</PRE -><P ->The sample size is most likely always one byte, -applications must check the <CODE -CLASS="STRUCTFIELD" ->sample_format</CODE -> -field though, to function properly with other drivers.</P -><P ->A VBI device may support <A -HREF="#RW" ->read/write</A -> and/or streaming (<A -HREF="#MMAP" ->memory mapping</A -> or <A -HREF="#USERP" ->user pointer</A ->) I/O. The latter bears the -possibility of synchronizing video and -VBI data by using buffer timestamps.</P -><P ->Remember the <A -HREF="#VIDIOC-STREAMON" -><CODE -CLASS="CONSTANT" ->VIDIOC_STREAMON</CODE -></A -> ioctl and the first read(), -write() and select() call can be resource allocation points returning -an <SPAN -CLASS="ERRORCODE" ->EBUSY</SPAN -> error code if the required hardware resources are temporarily -unavailable, for example the device is already in use by another -process.</P -></DIV -></DIV -><DIV -CLASS="SECTION" -><HR><H2 -CLASS="SECTION" -><A -NAME="SLICED" ->4.7. Sliced VBI Data Interface</A -></H2 -><DIV -CLASS="NOTE" -><BLOCKQUOTE -CLASS="NOTE" -><P -><B ->Proposal: </B ->This interface is not yet implemented in v4l2.</P -></BLOCKQUOTE -></DIV -><P ->Sliced VBI data is VBI data after demodulation by hardware -decoders. Kernel drivers shall not convert to or from raw VBI data by -software. The data is passed as short packets of fixed size covering -one scan line each. The number of packets per frame is variable.</P -><P ->Sliced VBI input and output devices are accessed through the -same character special files as raw VBI devices. Note the default -function of a <TT -CLASS="FILENAME" ->/dev/vbi</TT -> device is raw VBI -capturing or output. The sliced VBI function is only available after -calling the <A -HREF="#VIDIOC-G-FMT" -><CODE -CLASS="CONSTANT" ->VIDIOC_S_FMT</CODE -></A -> ioctl.</P -><DIV -CLASS="SECTION" -><HR><H3 -CLASS="SECTION" -><A -NAME="AEN4599" ->4.7.1. Querying Capabilities</A -></H3 -><P ->Devices supporting the sliced VBI capturing or output API -set the <CODE -CLASS="CONSTANT" ->V4L2_CAP_SLICED_VBI_CAPTURE</CODE -> or -<CODE -CLASS="CONSTANT" ->V4L2_CAP_SLICED_VBI_OUTPUT</CODE -> flags in the -<CODE -CLASS="STRUCTFIELD" ->capabilities</CODE -> field of struct <A -HREF="#V4L2-CAPABILITY" ->v4l2_capability</A -> -returned by the <A -HREF="#VIDIOC-QUERYCAP" -><CODE -CLASS="CONSTANT" ->VIDIOC_QUERYCAP</CODE -></A ->. At least one of the read/write, -streaming or asynchronous I/O methods must be supported. VBI devices -may have a tuner or modulator.</P -></DIV -><DIV -CLASS="SECTION" -><HR><H3 -CLASS="SECTION" -><A -NAME="AEN4608" ->4.7.2. Supplemental Functions</A -></H3 -><P ->VBI devices shall support <A -HREF="#VIDEO" ->video -input or output</A ->, <A -HREF="#TUNER" ->tuner or -modulator</A ->, and <A -HREF="#CONTROL" ->controls</A -> ioctls -as needed. The <A -HREF="#STANDARD" ->video standard</A -> provide -information vital to program a VBI device, therefore must be -supported.</P -></DIV -><DIV -CLASS="SECTION" -><HR><H3 -CLASS="SECTION" -><A -NAME="AEN4615" ->4.7.3. Sliced VBI Format Negotiation</A -></H3 -><P ->To determine which data services are supported by the -hardware and which are desired by the application, the driver and application have to -negotiate the sliced VBI data format.</P -><P ->After setting the <CODE -CLASS="STRUCTFIELD" ->type</CODE -> field of -struct <A -HREF="#V4L2-FORMAT" ->v4l2_format</A -> to <CODE -CLASS="CONSTANT" ->V4L2_BUF_TYPE_SLICED_VBI_CAPTURE</CODE -> -or <CODE -CLASS="CONSTANT" ->V4L2_BUF_TYPE_SLICED_VBI_OUTPUT</CODE ->, a -<A -HREF="#VIDIOC-G-FMT" -><CODE -CLASS="CONSTANT" ->VIDIOC_G_FMT</CODE -></A -> fills the struct <CODE -CLASS="STRUCTNAME" ->v4l2_sliced_vbi_format</CODE -> -<CODE -CLASS="STRUCTFIELD" ->sliced</CODE -> member of the -<CODE -CLASS="STRUCTFIELD" ->fmt</CODE -> union of a struct <A -HREF="#V4L2-FORMAT" ->v4l2_format</A ->.</P -><P ->Applications can request different parameters by -initializing or modifying the <CODE -CLASS="STRUCTFIELD" ->sliced</CODE -> member -and calling the <A -HREF="#VIDIOC-G-FMT" -><CODE -CLASS="CONSTANT" ->VIDIOC_S_FMT</CODE -></A -> ioctl with a pointer to the -<CODE -CLASS="STRUCTNAME" ->v4l2_format</CODE -> structure. <SPAN -CLASS="emphasis" -><I -CLASS="EMPHASIS" ->All fields -of struct <CODE -CLASS="STRUCTNAME" ->v4l2_vbi_format</CODE -> must be -initialized</I -></SPAN ->. Drivers return an <SPAN -CLASS="ERRORCODE" ->EINVAL</SPAN -> error code only when -the given parameters are ambiguous, otherwise they modify the -parameters according to the hardware capabilites. When the driver -allocates resources at this point, it may return an <SPAN -CLASS="ERRORCODE" ->EBUSY</SPAN -> error code to -indicate the returned parameters are valid but the required resources -are currently not available. Applications must expect other resource -allocation points which may return <SPAN -CLASS="ERRORCODE" ->EBUSY</SPAN -> at the -<A -HREF="#VIDIOC-STREAMON" -><CODE -CLASS="CONSTANT" ->VIDIOC_STREAMON</CODE -></A -> ioctl and the first read(), write() and select() -call. Different file descriptors must be used to pass raw and sliced -VBI data simultaneously, if this is supported by the driver.</P -><DIV -CLASS="TABLE" -><A -NAME="V4L2-SLICED-VBI-FORMAT" -></A -><P -><B ->Table 4-6. struct <CODE -CLASS="STRUCTNAME" ->v4l2_sliced_vbi_format</CODE -></B -></P -><TABLE -BORDER="0" -FRAME="void" -WIDTH="100%" -CLASS="CALSTABLE" -><COL -WIDTH="25%" -TITLE="C1"><COL -WIDTH="25%" -TITLE="C2"><COL -WIDTH="50%" -TITLE="C3"><TBODY -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->service_set</CODE -></TD -><TD ->A set of symbols defining which types of data -packets are passed. See <A -HREF="#SLICED-VBI-TYPES" ->Table 4-8</A -> for details.</TD -></TR -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->packet_size</CODE -></TD -><TD -><P ->The size of each type of packet is fixed, -however when different types of packets are exchanged between driver -and application their size can vary. This value defines the size of -the largest packet (struct <A -HREF="#V4L2-SLICED-DATA" ->v4l2_sliced_data</A ->) that will be -passed, smaller packets must be padded accordingly. When the -architecture requires special alignment of __u32 quantities the driver -shall round up <CODE -CLASS="STRUCTFIELD" ->packet_size </CODE -> as -necessary.</P -></TD -></TR -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->io_size</CODE -></TD -><TD ->Maximum number of bytes passed by one <CODE -CLASS="FUNCTION" ->read()</CODE -> or -<CODE -CLASS="FUNCTION" ->write()</CODE -> call, and the buffer size in bytes for the <A -HREF="#VIDIOC-QBUF" -><CODE -CLASS="CONSTANT" ->VIDIOC_QBUF</CODE -></A -> and -<A -HREF="#VIDIOC-QBUF" -><CODE -CLASS="CONSTANT" ->VIDIOC_DQBUF</CODE -></A -> ioctl. Usually this will be -<CODE -CLASS="STRUCTFIELD" ->packet_size</CODE -> times the number of scan lines -potentially containing the data in question. On input, applications -should set this field to zero and accept the value proposed by the -driver.</TD -></TR -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->reserved</CODE -></TD -><TD ->Applications and drivers must set this field to -zero.</TD -></TR -></TBODY -></TABLE -></DIV -><DIV -CLASS="TABLE" -><A -NAME="V4L2-SLICED-DATA" -></A -><P -><B ->Table 4-7. struct <CODE -CLASS="STRUCTNAME" ->v4l2_sliced_data</CODE -></B -></P -><TABLE -BORDER="0" -FRAME="void" -WIDTH="100%" -CLASS="CALSTABLE" -><COL -WIDTH="38%" -TITLE="C1"><COL -WIDTH="12%" -TITLE="C2"><COL -WIDTH="50%" -TITLE="C3"><TBODY -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->id</CODE -></TD -><TD ->One of the symbols in <A -HREF="#SLICED-VBI-TYPES" ->Table 4-8</A -> defining the type of data in this packet. A -value of zero indicates an empty packet with no payload, in this case -<CODE -CLASS="STRUCTFIELD" ->line</CODE -> and <CODE -CLASS="STRUCTFIELD" ->data</CODE -> -are undefined.</TD -></TR -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->line</CODE -></TD -><TD ->The scanning system line number this data has -been captured from, or shall be inserted at. See <A -HREF="#VBI-525" ->Figure 4-2</A -> -and <A -HREF="#VBI-625" ->Figure 4-3</A -> for valid values. Sliced VBI input drivers -can set the line number of all packets to <CODE -CLASS="CONSTANT" ->0</CODE -> if -the hardware cannot reliable identify scan lines.</TD -></TR -><TR -><TD ->__u8</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->data</CODE ->[]</TD -><TD ->The packet payload. See <A -HREF="#SLICED-VBI-TYPES" ->Table 4-8</A -> for the contents and number of bytes passed -for each data type. The contents of padding bytes following up to -<CODE -CLASS="STRUCTFIELD" ->packet_size</CODE -> is undefined.</TD -></TR -></TBODY -></TABLE -></DIV -><DIV -CLASS="TABLE" -><A -NAME="SLICED-VBI-TYPES" -></A -><P -><B ->Table 4-8. Sliced VBI data formats</B -></P -><TABLE -BORDER="1" -WIDTH="100%" -CLASS="CALSTABLE" -><COL><COL><COL><COL><THEAD -><TR -><TH ->Symbol</TH -><TH ->Reference</TH -><TH ->Lines, usually</TH -><TH ->Payload</TH -></TR -></THEAD -><TBODY -><TR -><TD ->V4L2_SLICED_TELETEXT_B (Teletext System B)</TD -><TD -><A -HREF="#TELETEXT" -><ABBR -CLASS="ABBREV" ->TELETEXT</ABBR -></A -></TD -><TD ->PAL/SECAM line 6-22, 318-335</TD -><TD ->Last 42 of the 45 byte Teletext packet, that is -without clock run-in and framing code, lsb first transmitted.</TD -></TR -><TR -><TD ->V4L2_SLICED_VPS</TD -><TD -><A -HREF="#VPS" -><ABBR -CLASS="ABBREV" ->VPS</ABBR -></A -></TD -><TD ->PAL line 16</TD -><TD ->Byte number 3 to 15 according to Figure 9 of ETS -300 231, lsb first transmitted.</TD -></TR -><TR -><TD ->V4L2_SLICED_CAPTION_625</TD -><TD -><A -HREF="#EIA608" -><ABBR -CLASS="ABBREV" ->EIA608</ABBR -></A -></TD -><TD ->PAL line 22 (?)</TD -><TD ->First and second byte including parity bit, lsb -first transmitted.</TD -></TR -><TR -><TD ->V4L2_SLICED_WSS_625</TD -><TD -><A -HREF="#WSS" -><ABBR -CLASS="ABBREV" ->WSS</ABBR -></A -></TD -><TD ->PAL/SECAM line 23</TD -><TD -><PRE -CLASS="SCREEN" ->Byte 0 1 - msb lsb msb lsb -Bit 7 6 5 4 3 2 1 0 x x 13 12 11 10 9</PRE -></TD -></TR -><TR -><TD ->V4L2_SLICED_CAPTION_525</TD -><TD -><A -HREF="#EIA608" -><ABBR -CLASS="ABBREV" ->EIA608</ABBR -></A -></TD -><TD ->NTSC line 21, 284</TD -><TD ->First and second byte including parity bit, lsb -first transmitted.</TD -></TR -><TR -><TD ->V4L2_SLICED_RESERVED</TD -><TD -> </TD -><TD ->undefined</TD -><TD ->undefined</TD -></TR -></TBODY -></TABLE -></DIV -><P ->Remember the VBI image format depends on the selected -video standard, therefore the application must choose a new standard or -query the current standard first. Attempts to read or write data ahead -of format negotiation, or after switching the video standard which may -invalidate the negotiated VBI parameters, should be refused by the -driver. A format change is not permitted during active i/o.</P -></DIV -><DIV -CLASS="SECTION" -><HR><H3 -CLASS="SECTION" -><A -NAME="AEN4760" ->4.7.4. Reading and writing sliced VBI data</A -></H3 -><P ->The smallest unit of data passed at a time is one sliced -data packet. Within the bounds of <CODE -CLASS="STRUCTFIELD" ->io_size</CODE -> -multiple packets can (and should) be passed, but no more than one -frame at a time (to keep the processing time low, for example from -reception to display of subtitles). Packets are always passed in -ascending line number order, without duplicate line numbers. If the -line numbers are unknown the driver must pass the packets in -transmitted order. Empty packets with <CODE -CLASS="STRUCTFIELD" ->id</CODE -> -set to zero can be inserted anywhere.</P -><P ->To assure synchronization and to distinguish from frame -dropping, when one frame does not contain any data in question one or -more empty packets must be passed. In streaming I/O mode one buffer of -<CODE -CLASS="STRUCTFIELD" ->io_size</CODE -> shall coincide with one video -frame. The <CODE -CLASS="STRUCTFIELD" ->id</CODE -> of unused packets must be -zero.</P -><P ->A sliced VBI device may support <A -HREF="#RW" ->read/write</A -> and/or streaming (<A -HREF="#MMAP" ->memory mapping</A -> or <A -HREF="#USERP" ->user pointer</A ->) I/O. The latter bears the -possibility of synchronizing video and VBI data by using buffer -timestamps.</P -><P ->Remember the <A -HREF="#VIDIOC-STREAMON" -><CODE -CLASS="CONSTANT" ->VIDIOC_STREAMON</CODE -></A -> ioctl and the first read(), -write() and select() call can be resource allocation points returning -an <SPAN -CLASS="ERRORCODE" ->EBUSY</SPAN -> error code if the required hardware resources are temporarily -unavailable, for example the device is already in use by another -process.</P -></DIV -></DIV -><DIV -CLASS="SECTION" -><HR><H2 -CLASS="SECTION" -><A -NAME="TTX" ->4.8. Teletext Interface</A -></H2 -><P ->This interface aims at devices receiving and demodulating -Teletext data [<A -HREF="#TELETEXT" -><ABBR -CLASS="ABBREV" ->TELETEXT</ABBR -></A ->], evaluating the -Teletext packages and storing formatted pages in cache memory. Such -devices are usually implemented as microcontrollers with serial -interface (I<SUP ->2</SUP ->C) and can be found on older -TV cards, dedicated Teletext decoding cards and home-brew devices -connected to the PC parallel port.</P -><P ->The Teletext API was designed by Martin Buck. It is defined in -the kernel header file <TT -CLASS="FILENAME" ->linux/videotext.h</TT ->, the -specification is available from <A -HREF="http://home.pages.de/~videotext/" -TARGET="_top" ->http://home.pages.de/~videotext/</A ->. (Videotext is the name of -the German public television Teletext service.) Conventional character -device file names are <TT -CLASS="FILENAME" ->/dev/vtx</TT -> and -<TT -CLASS="FILENAME" ->/dev/vttuner</TT ->, with device number 83, 0 and 83, 16 -respectively. A similar interface exists for the Philips SAA5249 -Teletext decoder [specification?] with character device file names -<TT -CLASS="FILENAME" ->/dev/tlkN</TT ->, device number 102, N.</P -><P ->Eventually the Teletext API was integrated into the V4L API -with character device file names <TT -CLASS="FILENAME" ->/dev/vtx0</TT -> to -<TT -CLASS="FILENAME" ->/dev/vtx31</TT ->, device major number 81, minor numbers -192 to 223. For reference the V4L Teletext API specification is -reproduced here in full: "Teletext interfaces talk the existing VTX -API." Teletext devices with major number 83 and 102 will be removed in -Linux 2.6.</P -><P ->There are no plans to replace the Teletext API or to integrate -it into V4L2. Please write to the Video4Linux mailing list: <A -HREF="https://listman.redhat.com/mailman/listinfo/video4linux-list" -TARGET="_top" ->https://listman.redhat.com/mailman/listinfo/video4linux-list</A -> -when the need arises.</P -></DIV -><DIV -CLASS="SECTION" -><HR><H2 -CLASS="SECTION" -><A -NAME="RADIO" ->4.9. Radio Interface</A -></H2 -><P ->This interface is intended for AM and FM (analog) radio -receivers.</P -><P ->Conventionally V4L2 radio devices are accessed through -character device special files named <TT -CLASS="FILENAME" ->/dev/radio</TT -> -and <TT -CLASS="FILENAME" ->/dev/radio0</TT -> to -<TT -CLASS="FILENAME" ->/dev/radio63</TT -> with major number 81 and minor -numbers 64 to 127.</P -><DIV -CLASS="SECTION" -><HR><H3 -CLASS="SECTION" -><A -NAME="AEN4799" ->4.9.1. Querying Capabilities</A -></H3 -><P ->Devices supporting the radio interface set the -<CODE -CLASS="CONSTANT" ->V4L2_CAP_RADIO</CODE -> and -<CODE -CLASS="CONSTANT" ->V4L2_CAP_TUNER</CODE -> flag in the -<CODE -CLASS="STRUCTFIELD" ->capabilities</CODE -> field of struct <A -HREF="#V4L2-CAPABILITY" ->v4l2_capability</A -> -returned by the <A -HREF="#VIDIOC-QUERYCAP" -><CODE -CLASS="CONSTANT" ->VIDIOC_QUERYCAP</CODE -></A -> ioctl. Other combinations of -capability flags are reserved for future extensions.</P -></DIV -><DIV -CLASS="SECTION" -><HR><H3 -CLASS="SECTION" -><A -NAME="AEN4808" ->4.9.2. Supplemental Functions</A -></H3 -><P ->Radio devices can support <A -HREF="#CONTROL" ->controls</A ->, and must support the <A -HREF="#TUNER" ->tuner</A -> ioctls.</P -><P ->They do not support the video input or output, audio input -or output, video standard, cropping and scaling, compression and -streaming parameter, or overlay ioctls. All other ioctls and I/O -methods are reserved for future extensions.</P -></DIV -><DIV -CLASS="SECTION" -><HR><H3 -CLASS="SECTION" -><A -NAME="AEN4814" ->4.9.3. Programming</A -></H3 -><P ->Radio devices may have a couple audio controls (as discussed -in <A -HREF="#CONTROL" ->Section 1.8</A ->) such as a volume control, possibly custom -controls. Further all radio devices have one tuner (these are -discussed in <A -HREF="#TUNER" ->Section 1.6</A ->) with index number zero to select -the radio frequency and to determine if a monaural or FM stereo -program is received. Drivers switch automatically between AM and FM -depending on the selected frequency. The <A -HREF="#VIDIOC-G-TUNER" -><CODE -CLASS="CONSTANT" ->VIDIOC_G_TUNER</CODE -></A -> ioctl -reports the supported frequency range.</P -></DIV -></DIV -><DIV -CLASS="SECTION" -><HR><H2 -CLASS="SECTION" -><A -NAME="RDS" ->4.10. RDS Interface</A -></H2 -><P ->The Radio Data System transmits supplementary -information in binary format, for example the station name or travel -information, on a inaudible audio subcarrier of a radio program. This -interface aims at devices capable of receiving and decoding RDS -information.</P -><P ->The V4L API defines its RDS API as follows.</P -><P ->From radio devices supporting it, RDS data can be -read with the <CODE -CLASS="FUNCTION" ->read()</CODE -> function. The data is packed -in groups of three, as follows:<P -></P -><OL -TYPE="1" -><LI -><P ->First Octet Least Significant Byte of RDS -Block</P -></LI -><LI -><P ->Second Octet Most Significant Byte of RDS -Block</P -></LI -><LI -><P ->Third Octet Bit 7: Error bit. Indicates that an -uncorrectable error occurred during reception of this block. Bit 6: -Corrected bit. Indicates that an error was corrected for this data -block. Bits 5-3: Received Offset. Indicates the offset received by the -sync system. Bits 2-0: Offset Name. Indicates the offset applied to -this data.</P -></LI -></OL -></P -><P ->It was argued <SPAN -CLASS="COMMENT" ->video4linux-list@redhat.com -on 12 Nov 2002, subject "RDS/RBDS"</SPAN -> the RDS API should be -extended before integration into V4L2, no new API has been devised yet. -Please write to the Video4Linux mailing list for discussion: <A -HREF="https://listman.redhat.com/mailman/listinfo/video4linux-list" -TARGET="_top" ->https://listman.redhat.com/mailman/listinfo/video4linux-list</A ->. -Meanwhile no V4L2 driver should set the -<CODE -CLASS="CONSTANT" ->V4L2_CAP_RDS_CAPTURE</CODE -> capability flag.</P -></DIV -></DIV -><DIV -CLASS="REFERENCE" -><A -NAME="USER-FUNC" -></A -><DIV -CLASS="TITLEPAGE" -><H1 -CLASS="TITLE" ->I. Function Reference</H1 -><DIV -CLASS="TOC" -><DL -><DT -><B ->Table of Contents</B -></DT -><DT -><A -HREF="#FUNC-CLOSE" ->close</A -> -- Close a V4L2 device</DT -><DT -><A -HREF="#FUNC-IOCTL" ->ioctl</A -> -- Program a V4L2 device</DT -><DT -><A -HREF="#VIDIOC-CROPCAP" ->ioctl VIDIOC_CROPCAP</A -> -- Information about the video cropping and scaling abilities.</DT -><DT -><A -HREF="#VIDIOC-ENUMAUDIO" ->ioctl VIDIOC_ENUMAUDIO</A -> -- Enumerate audio inputs</DT -><DT -><A -HREF="#VIDIOC-ENUMAUDIOOUT" ->ioctl VIDIOC_ENUMAUDOUT</A -> -- Enumerate audio outputs</DT -><DT -><A -HREF="#VIDIOC-ENUM-FMT" ->ioctl VIDIOC_ENUM_FMT</A -> -- Enumerate image formats</DT -><DT -><A -HREF="#VIDIOC-ENUMINPUT" ->ioctl VIDIOC_ENUMINPUT</A -> -- Enumerate video inputs</DT -><DT -><A -HREF="#VIDIOC-ENUMOUTPUT" ->ioctl VIDIOC_ENUMOUTPUT</A -> -- Enumerate video outputs</DT -><DT -><A -HREF="#VIDIOC-ENUMSTD" ->ioctl VIDIOC_ENUMSTD</A -> -- Enumerate supported video standards</DT -><DT -><A -HREF="#VIDIOC-G-AUDIO" ->ioctl VIDIOC_G_AUDIO, VIDIOC_S_AUDIO</A -> -- Query or select the current audio input and its -attributes</DT -><DT -><A -HREF="#VIDIOC-G-AUDIOOUT" ->ioctl VIDIOC_G_AUDOUT, VIDIOC_S_AUDOUT</A -> -- Query or select the current audio output</DT -><DT -><A -HREF="#VIDIOC-G-COMP" ->ioctl VIDIOC_G_COMP, VIDIOC_S_COMP</A -> -- Get or set compression parameters</DT -><DT -><A -HREF="#VIDIOC-G-CROP" ->ioctl VIDIOC_G_CROP, VIDIOC_S_CROP</A -> -- Get or set the current cropping rectangle</DT -><DT -><A -HREF="#VIDIOC-G-CTRL" ->ioctl VIDIOC_G_CTRL, VIDIOC_S_CTRL</A -> -- Get or set the value of a control</DT -><DT -><A -HREF="#VIDIOC-G-FBUF" ->ioctl VIDIOC_G_FBUF, VIDIOC_S_FBUF</A -> -- Get or set frame buffer overlay parameters.</DT -><DT -><A -HREF="#VIDIOC-G-FMT" ->ioctl VIDIOC_G_FMT, VIDIOC_S_FMT, VIDIOC_TRY_FMT</A -> -- Get or set the data format, try a format.</DT -><DT -><A -HREF="#VIDIOC-G-FREQUENCY" ->ioctl VIDIOC_G_FREQUENCY, VIDIOC_S_FREQUENCY</A -> -- Get or set tuner or modulator radio -frequency</DT -><DT -><A -HREF="#VIDIOC-G-INPUT" ->ioctl VIDIOC_G_INPUT, VIDIOC_S_INPUT</A -> -- Query or select the current video input</DT -><DT -><A -HREF="#VIDIOC-G-JPEGCOMP" ->ioctl VIDIOC_G_JPEGCOMP, VIDIOC_S_JPEGCOMP</A -> -- </DT -><DT -><A -HREF="#VIDIOC-G-MODULATOR" ->ioctl VIDIOC_G_MODULATOR, VIDIOC_S_MODULATOR</A -> -- Get or set modulator attributes</DT -><DT -><A -HREF="#VIDIOC-G-OUTPUT" ->ioctl VIDIOC_G_OUTPUT, VIDIOC_S_OUTPUT</A -> -- Query or select the current video output</DT -><DT -><A -HREF="#VIDIOC-G-PARM" ->ioctl VIDIOC_G_PARM, VIDIOC_S_PARM</A -> -- Get or set streaming parameters</DT -><DT -><A -HREF="#VIDIOC-G-PRIORITY" ->ioctl VIDIOC_G_PRIORITY, VIDIOC_S_PRIORITY</A -> -- Query or request the access priority associated with a -file descriptor</DT -><DT -><A -HREF="#VIDIOC-G-STD" ->ioctl VIDIOC_G_STD, VIDIOC_S_STD</A -> -- Query or select the video standard of the current input</DT -><DT -><A -HREF="#VIDIOC-G-TUNER" ->ioctl VIDIOC_G_TUNER, VIDIOC_S_TUNER</A -> -- Get or set tuner attributes</DT -><DT -><A -HREF="#VIDIOC-OVERLAY" ->ioctl VIDIOC_OVERLAY</A -> -- Start or stop video overlay</DT -><DT -><A -HREF="#VIDIOC-QBUF" ->ioctl VIDIOC_QBUF, VIDIOC_DQBUF</A -> -- Exchange a buffer with the driver</DT -><DT -><A -HREF="#VIDIOC-QUERYBUF" ->ioctl VIDIOC_QUERYBUF</A -> -- Query the status of a buffer</DT -><DT -><A -HREF="#VIDIOC-QUERYCAP" ->ioctl VIDIOC_QUERYCAP</A -> -- Query device capabilities</DT -><DT -><A -HREF="#VIDIOC-QUERYCTRL" ->ioctl VIDIOC_QUERYCTRL, VIDIOC_QUERYMENU</A -> -- Enumerate controls and menu control items</DT -><DT -><A -HREF="#VIDIOC-QUERYSTD" ->ioctl VIDIOC_QUERYSTD</A -> -- Sense the video standard received by the current input</DT -><DT -><A -HREF="#VIDIOC-REQBUFS" ->ioctl VIDIOC_REQBUFS</A -> -- Initiate Memory Mapping or User Pointer I/O</DT -><DT -><A -HREF="#VIDIOC-STREAMON" ->ioctl VIDIOC_STREAMON, VIDIOC_STREAMOFF</A -> -- Start or stop streaming I/O.</DT -><DT -><A -HREF="#FUNC-MMAP" ->mmap</A -> -- Map device memory into application address space</DT -><DT -><A -HREF="#FUNC-MUNMAP" ->munmap</A -> -- Unmap device memory</DT -><DT -><A -HREF="#FUNC-OPEN" ->open</A -> -- Open a V4L2 device</DT -><DT -><A -HREF="#FUNC-POLL" ->poll</A -> -- Wait for some event on a file descriptor</DT -><DT -><A -HREF="#FUNC-READ" ->read</A -> -- Read from a V4L2 device</DT -><DT -><A -HREF="#FUNC-SELECT" ->select</A -> -- Synchronous I/O multiplexing</DT -><DT -><A -HREF="#FUNC-WRITE" ->write</A -> -- Write to a V4L2 device</DT -></DL -></DIV -></DIV -><H1 -><A -NAME="FUNC-CLOSE" -></A ->close</H1 -><DIV -CLASS="REFNAMEDIV" -><A -NAME="AEN4841" -></A -><H2 ->Name</H2 ->close -- Close a V4L2 device</DIV -><DIV -CLASS="REFSYNOPSISDIV" -><A -NAME="AEN4844" -></A -><H2 ->Synopsis</H2 -><DIV -CLASS="FUNCSYNOPSIS" -><P -></P -><A -NAME="AEN4845" -></A -><PRE -CLASS="FUNCSYNOPSISINFO" ->#include <unistd.h></PRE -><P -><CODE -><CODE -CLASS="FUNCDEF" ->int close</CODE ->(int fd);</CODE -></P -><P -></P -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN4852" -></A -><H2 ->Arguments</H2 -><P -></P -><DIV -CLASS="VARIABLELIST" -><DL -><DT -><VAR -CLASS="PARAMETER" ->fd</VAR -></DT -><DD -><P ->File descriptor returned by <A -HREF="#FUNC-OPEN" -><CODE -CLASS="FUNCTION" ->open()</CODE -></A ->.</P -></DD -></DL -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN4862" -></A -><H2 ->Description</H2 -><P ->Closes the device. Any I/O in progress is terminated and -resources associated with the file descriptor are freed. However data -format parameters, current input or output, control values or other -properties remain unchanged.</P -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN4865" -></A -><H2 ->Return Value</H2 -><P ->The function returns <SPAN -CLASS="RETURNVALUE" ->0</SPAN -> on -success, <SPAN -CLASS="RETURNVALUE" ->-1</SPAN -> on failure and the -<VAR -CLASS="VARNAME" ->errno</VAR -> is set appropriately. Possible error -codes:</P -><P -></P -><DIV -CLASS="VARIABLELIST" -><DL -><DT -><SPAN -CLASS="ERRORCODE" ->EBADF</SPAN -></DT -><DD -><P -><VAR -CLASS="PARAMETER" ->fd</VAR -> is not a valid open file -descriptor.</P -></DD -></DL -></DIV -></DIV -><H1 -><A -NAME="FUNC-IOCTL" -></A ->ioctl</H1 -><DIV -CLASS="REFNAMEDIV" -><A -NAME="AEN4879" -></A -><H2 ->Name</H2 ->ioctl -- Program a V4L2 device</DIV -><DIV -CLASS="REFSYNOPSISDIV" -><A -NAME="AEN4882" -></A -><H2 ->Synopsis</H2 -><DIV -CLASS="FUNCSYNOPSIS" -><P -></P -><A -NAME="AEN4883" -></A -><PRE -CLASS="FUNCSYNOPSISINFO" ->#include <sys/ioctl.h></PRE -><P -><CODE -><CODE -CLASS="FUNCDEF" ->int ioctl</CODE ->(int fd, int request, void *argp);</CODE -></P -><P -></P -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN4894" -></A -><H2 ->Arguments</H2 -><P -></P -><DIV -CLASS="VARIABLELIST" -><DL -><DT -><VAR -CLASS="PARAMETER" ->fd</VAR -></DT -><DD -><P ->File descriptor returned by <A -HREF="#FUNC-OPEN" -><CODE -CLASS="FUNCTION" ->open()</CODE -></A ->.</P -></DD -><DT -><VAR -CLASS="PARAMETER" ->request</VAR -></DT -><DD -><P ->V4L2 ioctl request code as defined in the <A -HREF="#VIDEODEV" ->videodev.h</A -> header file, for example -VIDIOC_QUERYCAP.</P -></DD -><DT -><VAR -CLASS="PARAMETER" ->argp</VAR -></DT -><DD -><P ->Pointer to a function parameter, usually a structure.</P -></DD -></DL -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN4915" -></A -><H2 ->Description</H2 -><P ->The <CODE -CLASS="FUNCTION" ->ioctl()</CODE -> function is used to program -V4L2 devices. The argument <VAR -CLASS="PARAMETER" ->fd</VAR -> must be an open -file descriptor. An ioctl <VAR -CLASS="PARAMETER" ->request</VAR -> has encoded -in it whether the argument is an input, output or read/write -parameter, and the size of the argument <VAR -CLASS="PARAMETER" ->argp</VAR -> in -bytes. Macros and defines specifying V4L2 ioctl requests are located -in the <A -HREF="#VIDEODEV" ->videodev.h</A -> header file. -Applications should use their own copy, not include the version in the -kernel sources on the system they compile on. All V4L2 ioctl requests, -their respective function and parameters are specified in <A -HREF="#USER-FUNC" ->Reference I, <I ->Function Reference</I -></A ->.</P -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN4924" -></A -><H2 ->Return Value</H2 -><P ->On success the <CODE -CLASS="FUNCTION" ->ioctl()</CODE -> function returns -<SPAN -CLASS="RETURNVALUE" ->0</SPAN -> and does not reset the -<VAR -CLASS="VARNAME" ->errno</VAR -> variable. On failure -<SPAN -CLASS="RETURNVALUE" ->-1</SPAN -> is returned, when the ioctl takes an -output or read/write parameter it remains unmodified, and the -<VAR -CLASS="VARNAME" ->errno</VAR -> variable is set appropriately. See below for -possible error codes. Generic errors like <SPAN -CLASS="ERRORCODE" ->EBADF</SPAN -> -or <SPAN -CLASS="ERRORCODE" ->EFAULT</SPAN -> are not listed in the sections -discussing individual ioctl requests.</P -><P ->Note ioctls may return undefined error codes. Since errors -may have side effects such as a driver reset applications should -abort on unexpected errors.</P -><P -></P -><DIV -CLASS="VARIABLELIST" -><DL -><DT -><SPAN -CLASS="ERRORCODE" ->EBADF</SPAN -></DT -><DD -><P -><VAR -CLASS="PARAMETER" ->fd</VAR -> is not a valid open file -descriptor.</P -></DD -><DT -><SPAN -CLASS="ERRORCODE" ->EBUSY</SPAN -></DT -><DD -><P ->The property cannot be changed right now. Typically -this error code is returned when I/O is in progress or the driver -supports multiple opens and another process locked the property.</P -></DD -><DT -><SPAN -CLASS="ERRORCODE" ->EFAULT</SPAN -></DT -><DD -><P -><VAR -CLASS="PARAMETER" ->argp</VAR -> references an inaccessible -memory area.</P -></DD -><DT -><SPAN -CLASS="ERRORCODE" ->ENOTTY</SPAN -></DT -><DD -><P -><VAR -CLASS="PARAMETER" ->fd</VAR -> is not associated with a -character special device.</P -></DD -><DT -><SPAN -CLASS="ERRORCODE" ->EINVAL</SPAN -></DT -><DD -><P ->The <VAR -CLASS="PARAMETER" ->request</VAR -> or the data pointed -to by <VAR -CLASS="PARAMETER" ->argp</VAR -> is not valid. This is a very common -error code, see the individual ioctl requests listed in <A -HREF="#USER-FUNC" ->Reference I, <I ->Function Reference</I -></A -> for actual causes.</P -></DD -><DT -><SPAN -CLASS="ERRORCODE" ->ENOMEM</SPAN -></DT -><DD -><P ->Insufficient memory to complete the request.</P -></DD -><DT -><SPAN -CLASS="ERRORCODE" ->ERANGE</SPAN -></DT -><DD -><P ->The application attempted to set a control with the -<A -HREF="#VIDIOC-G-CTRL" -><CODE -CLASS="CONSTANT" ->VIDIOC_S_CTRL</CODE -></A -> ioctl to a value which is out of bounds.</P -></DD -></DL -></DIV -></DIV -><H1 -><A -NAME="VIDIOC-CROPCAP" -></A ->ioctl VIDIOC_CROPCAP</H1 -><DIV -CLASS="REFNAMEDIV" -><A -NAME="AEN4980" -></A -><H2 ->Name</H2 ->ioctl VIDIOC_CROPCAP -- Information about the video cropping and scaling abilities.</DIV -><DIV -CLASS="REFSYNOPSISDIV" -><A -NAME="AEN4983" -></A -><H2 ->Synopsis</H2 -><DIV -CLASS="FUNCSYNOPSIS" -><P -></P -><A -NAME="AEN4984" -></A -><P -><CODE -><CODE -CLASS="FUNCDEF" ->int ioctl</CODE ->(int fd, int request, struct v4l2_cropcap -*argp);</CODE -></P -><P -></P -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN4994" -></A -><H2 ->Arguments</H2 -><P -></P -><DIV -CLASS="VARIABLELIST" -><DL -><DT -><VAR -CLASS="PARAMETER" ->fd</VAR -></DT -><DD -><P ->File descriptor returned by <A -HREF="#FUNC-OPEN" -><CODE -CLASS="FUNCTION" ->open()</CODE -></A ->.</P -></DD -><DT -><VAR -CLASS="PARAMETER" ->request</VAR -></DT -><DD -><P ->VIDIOC_CROPCAP</P -></DD -><DT -><VAR -CLASS="PARAMETER" ->argp</VAR -></DT -><DD -><P -></P -></DD -></DL -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN5014" -></A -><H2 ->Description</H2 -><P ->Applications use this function to query the cropping -limits, the pixel aspect of images and to calculate scale factors. -They set the <CODE -CLASS="STRUCTFIELD" ->type</CODE -> field of a v4l2_cropcap -structure to the respective buffer (stream) type and call the -<CODE -CLASS="CONSTANT" ->VIDIOC_CROPCAP</CODE -> ioctl with a pointer to this -structure. Drivers fill the rest of the structure. The results are -constant except when switching the video standard. Remember this -switch can occur implicit when switching the video input or -output.</P -><DIV -CLASS="TABLE" -><A -NAME="V4L2-CROPCAP" -></A -><P -><B ->Table 1. struct <CODE -CLASS="STRUCTNAME" ->v4l2_cropcap</CODE -></B -></P -><TABLE -BORDER="0" -FRAME="void" -WIDTH="100%" -CLASS="CALSTABLE" -><COL -WIDTH="25%" -TITLE="C1"><COL -WIDTH="25%" -TITLE="C2"><COL -WIDTH="50%" -TITLE="C3"><TBODY -><TR -><TD ->enum <A -HREF="#V4L2-BUF-TYPE" ->v4l2_buf_type</A -></TD -><TD -><CODE -CLASS="STRUCTFIELD" ->type</CODE -></TD -><TD ->Type of the data stream, set by the application. -Only these types are valid here: -<CODE -CLASS="CONSTANT" ->V4L2_BUF_TYPE_VIDEO_CAPTURE</CODE ->, -<CODE -CLASS="CONSTANT" ->V4L2_BUF_TYPE_VIDEO_OUTPUT</CODE ->, -<CODE -CLASS="CONSTANT" ->V4L2_BUF_TYPE_VIDEO_OVERLAY</CODE ->, and custom (driver -defined) types with code <CODE -CLASS="CONSTANT" ->V4L2_BUF_TYPE_PRIVATE</CODE -> -and higher.</TD -></TR -><TR -><TD ->struct <A -HREF="#V4L2-RECT-CROP" ->v4l2_rect</A -></TD -><TD -><CODE -CLASS="STRUCTFIELD" ->bounds</CODE -></TD -><TD ->Defines the window within capturing or output is -possible, this may exclude for example the horizontal and vertical -blanking areas. The cropping rectangle cannot exceed these limits. -Width and height are defined in pixels, the driver writer is free to -choose origin and units of the coordinate system in the analog -domain.</TD -></TR -><TR -><TD ->struct <A -HREF="#V4L2-RECT-CROP" ->v4l2_rect</A -></TD -><TD -><CODE -CLASS="STRUCTFIELD" ->defrect</CODE -></TD -><TD ->Default cropping rectangle, it shall cover the -"whole picture". Assuming pixel aspect 1/1 this could be for example a -640 × 480 rectangle for NTSC, a -768 × 576 rectangle for PAL and SECAM centered over -the active picture area. The same co-ordinate system as for - <CODE -CLASS="STRUCTFIELD" ->bounds</CODE -> is used.</TD -></TR -><TR -><TD ->struct <A -HREF="#V4L2-FRACT" ->v4l2_fract</A -></TD -><TD -><CODE -CLASS="STRUCTFIELD" ->pixelaspect</CODE -></TD -><TD -><P ->This is the pixel aspect (y / x) when no -scaling is applied, the ratio of the actual sampling -frequency and the frequency required to get square -pixels.</P -><P ->When cropping coordinates refer to square pixels, -the driver sets <CODE -CLASS="STRUCTFIELD" ->pixelaspect</CODE -> to 1/1. Other -common values are 54/59 for PAL and SECAM, 11/10 for NTSC sampled -according to [<A -HREF="#ITU601" -><ABBR -CLASS="ABBREV" ->ITU601</ABBR -></A ->].</P -></TD -></TR -></TBODY -></TABLE -></DIV -><DIV -CLASS="TABLE" -><A -NAME="V4L2-RECT-CROP" -></A -><P -><B ->Table 2. struct <CODE -CLASS="STRUCTNAME" ->v4l2_rect</CODE -></B -></P -><TABLE -BORDER="0" -FRAME="void" -WIDTH="100%" -CLASS="CALSTABLE" -><COL -WIDTH="25%" -TITLE="C1"><COL -WIDTH="25%" -TITLE="C2"><COL -WIDTH="50%" -TITLE="C3"><TBODY -><TR -><TD ->__s32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->left</CODE -></TD -><TD ->Horizontal offset of the top, left corner of the -rectangle, in pixels.</TD -></TR -><TR -><TD ->__s32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->top</CODE -></TD -><TD ->Vertical offset of the top, left corner of the -rectangle, in pixels.</TD -></TR -><TR -><TD ->__s32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->width</CODE -></TD -><TD ->Width of the rectangle, in pixels.</TD -></TR -><TR -><TD ->__s32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->height</CODE -></TD -><TD ->Height of the rectangle, in pixels. Width -and height cannot be negative, the fields are signed for -hysterical reasons. <P -CLASS="COMMENT" ->video4linux-list@redhat.com -on 22 Oct 2002 subject "Re:[V4L][patches!] Re:v4l2/kernel-2.5"</P -></TD -></TR -></TBODY -></TABLE -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN5091" -></A -><H2 ->Return Value</H2 -><P ->On success <SPAN -CLASS="RETURNVALUE" ->0</SPAN -> is returned, on -error <SPAN -CLASS="RETURNVALUE" ->-1</SPAN -> and <VAR -CLASS="VARNAME" ->errno</VAR -> is -set appropriately:</P -><P -></P -><DIV -CLASS="VARIABLELIST" -><DL -><DT -><SPAN -CLASS="ERRORCODE" ->EINVAL</SPAN -></DT -><DD -><P ->The struct <A -HREF="#V4L2-CROPCAP" ->v4l2_cropcap</A -> <CODE -CLASS="STRUCTFIELD" ->type</CODE -> is -invalid or the ioctl is not supported. This is not permitted for -video capture, output and overlay devices, which must support -<CODE -CLASS="CONSTANT" ->VIDIOC_CROPCAP</CODE ->.</P -></DD -></DL -></DIV -></DIV -><H1 -><A -NAME="VIDIOC-ENUMAUDIO" -></A ->ioctl VIDIOC_ENUMAUDIO</H1 -><DIV -CLASS="REFNAMEDIV" -><A -NAME="AEN5107" -></A -><H2 ->Name</H2 ->ioctl VIDIOC_ENUMAUDIO -- Enumerate audio inputs</DIV -><DIV -CLASS="REFSYNOPSISDIV" -><A -NAME="AEN5110" -></A -><H2 ->Synopsis</H2 -><DIV -CLASS="FUNCSYNOPSIS" -><P -></P -><A -NAME="AEN5111" -></A -><P -><CODE -><CODE -CLASS="FUNCDEF" ->int ioctl</CODE ->(int fd, int request, struct v4l2_audio *argp);</CODE -></P -><P -></P -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN5121" -></A -><H2 ->Arguments</H2 -><P -></P -><DIV -CLASS="VARIABLELIST" -><DL -><DT -><VAR -CLASS="PARAMETER" ->fd</VAR -></DT -><DD -><P ->File descriptor returned by <A -HREF="#FUNC-OPEN" -><CODE -CLASS="FUNCTION" ->open()</CODE -></A ->.</P -></DD -><DT -><VAR -CLASS="PARAMETER" ->request</VAR -></DT -><DD -><P ->VIDIOC_ENUMAUDIO</P -></DD -><DT -><VAR -CLASS="PARAMETER" ->argp</VAR -></DT -><DD -><P -></P -></DD -></DL -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN5141" -></A -><H2 ->Description</H2 -><P ->To query the attributes of an audio input applications -initialize the <CODE -CLASS="STRUCTFIELD" ->index</CODE -> field and zero out the -<CODE -CLASS="STRUCTFIELD" ->reserved</CODE -> array of a struct <A -HREF="#V4L2-AUDIO" ->v4l2_audio</A -> -and call the <CODE -CLASS="CONSTANT" ->VIDIOC_ENUMAUDIO</CODE -> ioctl with a pointer -to this structure. Drivers fill the rest of the structure or return an -<SPAN -CLASS="ERRORCODE" ->EINVAL</SPAN -> error code when the index is out of bounds. To enumerate all audio -inputs applications shall begin at index zero, incrementing by one -until the driver returns <SPAN -CLASS="ERRORCODE" ->EINVAL</SPAN ->.</P -><P ->See <A -HREF="#VIDIOC-G-AUDIO" ->ioctl VIDIOC_G_AUDIO, VIDIOC_S_AUDIO</A -> for a description of -struct <A -HREF="#V4L2-AUDIO" ->v4l2_audio</A ->.</P -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN5153" -></A -><H2 ->Return Value</H2 -><P ->On success <SPAN -CLASS="RETURNVALUE" ->0</SPAN -> is returned, on -error <SPAN -CLASS="RETURNVALUE" ->-1</SPAN -> and <VAR -CLASS="VARNAME" ->errno</VAR -> is -set appropriately:</P -><P -></P -><DIV -CLASS="VARIABLELIST" -><DL -><DT -><SPAN -CLASS="ERRORCODE" ->EINVAL</SPAN -></DT -><DD -><P ->The number of the audio input is out of bounds, or -there are no audio inputs at all and this ioctl is not -supported.</P -></DD -></DL -></DIV -></DIV -><H1 -><A -NAME="VIDIOC-ENUMAUDIOOUT" -></A ->ioctl VIDIOC_ENUMAUDOUT</H1 -><DIV -CLASS="REFNAMEDIV" -><A -NAME="AEN5166" -></A -><H2 ->Name</H2 ->ioctl VIDIOC_ENUMAUDOUT -- Enumerate audio outputs</DIV -><DIV -CLASS="REFSYNOPSISDIV" -><A -NAME="AEN5169" -></A -><H2 ->Synopsis</H2 -><DIV -CLASS="FUNCSYNOPSIS" -><P -></P -><A -NAME="AEN5170" -></A -><P -><CODE -><CODE -CLASS="FUNCDEF" ->int ioctl</CODE ->(int fd, int request, struct v4l2_audioout *argp);</CODE -></P -><P -></P -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN5180" -></A -><H2 ->Arguments</H2 -><P -></P -><DIV -CLASS="VARIABLELIST" -><DL -><DT -><VAR -CLASS="PARAMETER" ->fd</VAR -></DT -><DD -><P ->File descriptor returned by <A -HREF="#FUNC-OPEN" -><CODE -CLASS="FUNCTION" ->open()</CODE -></A ->.</P -></DD -><DT -><VAR -CLASS="PARAMETER" ->request</VAR -></DT -><DD -><P ->VIDIOC_ENUMAUDOUT</P -></DD -><DT -><VAR -CLASS="PARAMETER" ->argp</VAR -></DT -><DD -><P -></P -></DD -></DL -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN5200" -></A -><H2 ->Description</H2 -><P ->To query the attributes of an audio output applications -initialize the <CODE -CLASS="STRUCTFIELD" ->index</CODE -> field and zero out the -<CODE -CLASS="STRUCTFIELD" ->reserved</CODE -> array of a struct <A -HREF="#V4L2-AUDIOOUT" ->v4l2_audioout</A -> and -call the <CODE -CLASS="CONSTANT" ->VIDIOC_G_AUDOUT</CODE -> ioctl with a pointer -to this structure. Drivers fill the rest of the structure or return an -<SPAN -CLASS="ERRORCODE" ->EINVAL</SPAN -> error code when the index is out of bounds. To enumerate all audio -outputs applications shall begin at index zero, incrementing by one -until the driver returns <SPAN -CLASS="ERRORCODE" ->EINVAL</SPAN ->.</P -><P ->Note connectors on a TV card to loop back the received audio -signal to a sound card are not audio outputs in this sense.</P -><P ->See <A -HREF="#VIDIOC-G-AUDIOOUT" ->ioctl VIDIOC_G_AUDOUT, VIDIOC_S_AUDOUT</A -> for a description of -struct <A -HREF="#V4L2-AUDIOOUT" ->v4l2_audioout</A ->.</P -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN5213" -></A -><H2 ->Return Value</H2 -><P ->On success <SPAN -CLASS="RETURNVALUE" ->0</SPAN -> is returned, on -error <SPAN -CLASS="RETURNVALUE" ->-1</SPAN -> and <VAR -CLASS="VARNAME" ->errno</VAR -> is -set appropriately:</P -><P -></P -><DIV -CLASS="VARIABLELIST" -><DL -><DT -><SPAN -CLASS="ERRORCODE" ->EINVAL</SPAN -></DT -><DD -><P ->The number of the audio output is out of bounds, or -there are no audio outputs at all and this ioctl is not -supported.</P -></DD -></DL -></DIV -></DIV -><H1 -><A -NAME="VIDIOC-ENUM-FMT" -></A ->ioctl VIDIOC_ENUM_FMT</H1 -><DIV -CLASS="REFNAMEDIV" -><A -NAME="AEN5226" -></A -><H2 ->Name</H2 ->ioctl VIDIOC_ENUM_FMT -- Enumerate image formats</DIV -><DIV -CLASS="REFSYNOPSISDIV" -><A -NAME="AEN5229" -></A -><H2 ->Synopsis</H2 -><DIV -CLASS="FUNCSYNOPSIS" -><P -></P -><A -NAME="AEN5230" -></A -><P -><CODE -><CODE -CLASS="FUNCDEF" ->int ioctl</CODE ->(int fd, int request, struct v4l2_fmtdesc -*argp);</CODE -></P -><P -></P -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN5240" -></A -><H2 ->Arguments</H2 -><P -></P -><DIV -CLASS="VARIABLELIST" -><DL -><DT -><VAR -CLASS="PARAMETER" ->fd</VAR -></DT -><DD -><P ->File descriptor returned by <A -HREF="#FUNC-OPEN" -><CODE -CLASS="FUNCTION" ->open()</CODE -></A ->.</P -></DD -><DT -><VAR -CLASS="PARAMETER" ->request</VAR -></DT -><DD -><P ->VIDIOC_ENUM_FMT</P -></DD -><DT -><VAR -CLASS="PARAMETER" ->argp</VAR -></DT -><DD -><P -></P -></DD -></DL -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN5260" -></A -><H2 ->Description</H2 -><P ->To enumerate image formats applications initialize the -<CODE -CLASS="STRUCTFIELD" ->type</CODE -> and <CODE -CLASS="STRUCTFIELD" ->index</CODE -> -field of struct <A -HREF="#V4L2-FMTDESC" ->v4l2_fmtdesc</A -> and call the -<CODE -CLASS="CONSTANT" ->VIDIOC_ENUM_FMT</CODE -> ioctl with a pointer to this -structure. Drivers fill the rest of the structure or return an -<SPAN -CLASS="ERRORCODE" ->EINVAL</SPAN -> error code. All formats are enumerable by beginning at index zero and -incrementing by one until <SPAN -CLASS="ERRORCODE" ->EINVAL</SPAN -> is -returned.</P -><DIV -CLASS="TABLE" -><A -NAME="V4L2-FMTDESC" -></A -><P -><B ->Table 1. struct <CODE -CLASS="STRUCTNAME" ->v4l2_fmtdesc</CODE -></B -></P -><TABLE -BORDER="0" -FRAME="void" -WIDTH="100%" -CLASS="CALSTABLE" -><COL -WIDTH="25%" -TITLE="C1"><COL -WIDTH="25%" -TITLE="C2"><COL -WIDTH="50%" -TITLE="C3"><TBODY -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->index</CODE -></TD -><TD ->Number of the format in the enumeration, set by -the application. This is in no way related to the <CODE -CLASS="STRUCTFIELD" ->pixelformat</CODE -> field.</TD -></TR -><TR -><TD ->enum <A -HREF="#V4L2-BUF-TYPE" ->v4l2_buf_type</A -></TD -><TD -><CODE -CLASS="STRUCTFIELD" ->type</CODE -></TD -><TD ->Type of the data stream, set by the application. -Only these types are valid here: -<CODE -CLASS="CONSTANT" ->V4L2_BUF_TYPE_VIDEO_CAPTURE</CODE ->, -<CODE -CLASS="CONSTANT" ->V4L2_BUF_TYPE_VIDEO_OUTPUT</CODE ->, -<CODE -CLASS="CONSTANT" ->V4L2_BUF_TYPE_VIDEO_OVERLAY</CODE ->, and custom (driver -defined) types with code <CODE -CLASS="CONSTANT" ->V4L2_BUF_TYPE_PRIVATE</CODE -> -and higher.</TD -></TR -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->flags</CODE -></TD -><TD ->See <A -HREF="#FMTDESC-FLAGS" ->Table 2</A -></TD -></TR -><TR -><TD ->__u8</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->description</CODE ->[32]</TD -><TD ->Description of the format, a NUL-terminated ASCII -string. This information is intended for the user, for example: "YUV -4:2:2".</TD -></TR -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->pixelformat</CODE -></TD -><TD ->The image format identifier. This is a -four character code as computed by the v4l2_fourcc() -macro:</TD -></TR -><TR -><TD -COLSPAN="3" -><P -><PRE -CLASS="PROGRAMLISTING" ->#define v4l2_fourcc(a,b,c,d) (((__u32)(a)<<0)|((__u32)(b)<<8)|((__u32)(c)<<16)|((__u32)(d)<<24))</PRE -></P -><P ->Several image formats are already -defined by this specification in <A -HREF="#PIXFMT" ->Chapter 2</A ->. Note these -codes are not the same as those used in the Windows world.</P -></TD -></TR -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->reserved</CODE ->[4]</TD -><TD ->Reserved for future extensions. Drivers must set -the array to zero.</TD -></TR -></TBODY -></TABLE -></DIV -><DIV -CLASS="TABLE" -><A -NAME="FMTDESC-FLAGS" -></A -><P -><B ->Table 2. Image Format Description Flags</B -></P -><TABLE -BORDER="0" -FRAME="void" -WIDTH="100%" -CLASS="CALSTABLE" -><COL -WIDTH="38%" -TITLE="C1"><COL -WIDTH="12%" -TITLE="C2"><COL -WIDTH="50%" -TITLE="C3"><TBODY -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_FMT_FLAG_COMPRESSED</CODE -></TD -><TD ->0x0001</TD -><TD ->This is a compressed format.</TD -></TR -></TBODY -></TABLE -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN5334" -></A -><H2 ->Return Value</H2 -><P ->On success <SPAN -CLASS="RETURNVALUE" ->0</SPAN -> is returned, on -error <SPAN -CLASS="RETURNVALUE" ->-1</SPAN -> and <VAR -CLASS="VARNAME" ->errno</VAR -> is -set appropriately:</P -><P -></P -><DIV -CLASS="VARIABLELIST" -><DL -><DT -><SPAN -CLASS="ERRORCODE" ->EINVAL</SPAN -></DT -><DD -><P ->The struct <A -HREF="#V4L2-FMTDESC" ->v4l2_fmtdesc</A -> <CODE -CLASS="STRUCTFIELD" ->type</CODE -> -is not supported or the <CODE -CLASS="STRUCTFIELD" ->index</CODE -> is out of -bounds.</P -></DD -></DL -></DIV -></DIV -><H1 -><A -NAME="VIDIOC-ENUMINPUT" -></A ->ioctl VIDIOC_ENUMINPUT</H1 -><DIV -CLASS="REFNAMEDIV" -><A -NAME="AEN5350" -></A -><H2 ->Name</H2 ->ioctl VIDIOC_ENUMINPUT -- Enumerate video inputs</DIV -><DIV -CLASS="REFSYNOPSISDIV" -><A -NAME="AEN5353" -></A -><H2 ->Synopsis</H2 -><DIV -CLASS="FUNCSYNOPSIS" -><P -></P -><A -NAME="AEN5354" -></A -><P -><CODE -><CODE -CLASS="FUNCDEF" ->int ioctl</CODE ->(int fd, int request, struct v4l2_input -*argp);</CODE -></P -><P -></P -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN5364" -></A -><H2 ->Arguments</H2 -><P -></P -><DIV -CLASS="VARIABLELIST" -><DL -><DT -><VAR -CLASS="PARAMETER" ->fd</VAR -></DT -><DD -><P ->File descriptor returned by <A -HREF="#FUNC-OPEN" -><CODE -CLASS="FUNCTION" ->open()</CODE -></A ->.</P -></DD -><DT -><VAR -CLASS="PARAMETER" ->request</VAR -></DT -><DD -><P ->VIDIOC_ENUMINPUT</P -></DD -><DT -><VAR -CLASS="PARAMETER" ->argp</VAR -></DT -><DD -><P -></P -></DD -></DL -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN5384" -></A -><H2 ->Description</H2 -><P ->To query the attributes of a video input applications -initialize the <CODE -CLASS="STRUCTFIELD" ->index</CODE -> field of struct <A -HREF="#V4L2-INPUT" ->v4l2_input</A -> -and call the <CODE -CLASS="CONSTANT" ->VIDIOC_ENUMINPUT</CODE -> ioctl with a -pointer to this structure. Drivers fill the rest of the structure or -return an <SPAN -CLASS="ERRORCODE" ->EINVAL</SPAN -> error code when the index is out of bounds. To enumerate all -inputs applications shall begin at index zero, incrementing by one -until the driver returns <SPAN -CLASS="ERRORCODE" ->EINVAL</SPAN ->.</P -><DIV -CLASS="TABLE" -><A -NAME="V4L2-INPUT" -></A -><P -><B ->Table 1. struct <CODE -CLASS="STRUCTNAME" ->v4l2_input</CODE -></B -></P -><TABLE -BORDER="0" -FRAME="void" -WIDTH="100%" -CLASS="CALSTABLE" -><COL -WIDTH="25%" -TITLE="C1"><COL -WIDTH="25%" -TITLE="C2"><COL -WIDTH="50%" -TITLE="C3"><TBODY -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->index</CODE -></TD -><TD ->Identifies the input, set by the -application.</TD -></TR -><TR -><TD ->__u8</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->name</CODE ->[32]</TD -><TD ->Name of the video input, a NUL-terminated ASCII -string, for example: "Vin (Composite 2)". This information is intended -for the user, preferably the connector label on the device itself.</TD -></TR -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->type</CODE -></TD -><TD ->Type of the input, see <A -HREF="#INPUT-TYPE" ->Table 2</A ->.</TD -></TR -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->audioset</CODE -></TD -><TD ->Video inputs combine with zero or more audio -inputs. For example one composite video connectors may exist, but two -audio connectors. On the other hand, video from a tuner will likely -combine only with audio from the same tuner. Devices with N audio -inputs number them 0 … N-1 with N ≤ 32. Each bit position of -<CODE -CLASS="STRUCTFIELD" ->audioset</CODE -> represents one audio input. For -details on audio inputs and how to switch see <A -HREF="#AUDIO" ->Section 1.5</A ->.</TD -></TR -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->tuner</CODE -></TD -><TD ->Capture devices can have zero or more tuners (RF -demodulators). When the <CODE -CLASS="STRUCTFIELD" ->type</CODE -> is set to -<CODE -CLASS="CONSTANT" ->V4L2_INPUT_TYPE_TUNER</CODE -> this is an RF connector and -this field identifies the tuner. It corresponds to -struct <A -HREF="#V4L2-TUNER" ->v4l2_tuner</A -> field <CODE -CLASS="STRUCTFIELD" ->index</CODE ->. For details on -tuners see <A -HREF="#TUNER" ->Section 1.6</A ->.</TD -></TR -><TR -><TD -><A -HREF="#V4L2-STD-ID" ->v4l2_std_id</A -></TD -><TD -><CODE -CLASS="STRUCTFIELD" ->std</CODE -></TD -><TD ->Every video input supports one or more different -video standards. This field is a set of all supported standards. For -details on video standards and how to switch see <A -HREF="#STANDARD" ->Section 1.7</A ->.</TD -></TR -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->status</CODE -></TD -><TD ->This field provides status information about the -input. See <A -HREF="#INPUT-STATUS" ->Table 3</A -> for flags. -<CODE -CLASS="STRUCTFIELD" ->status</CODE -> is only valid when this is the -current input.</TD -></TR -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->reserved</CODE ->[4]</TD -><TD ->Reserved for future extensions. Drivers must set -the array to zero.</TD -></TR -></TBODY -></TABLE -></DIV -><DIV -CLASS="TABLE" -><A -NAME="INPUT-TYPE" -></A -><P -><B ->Table 2. Input Types</B -></P -><TABLE -BORDER="0" -FRAME="void" -WIDTH="100%" -CLASS="CALSTABLE" -><COL -WIDTH="38%" -TITLE="C1"><COL -WIDTH="12%" -TITLE="C2"><COL -WIDTH="50%" -TITLE="C3"><TBODY -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_INPUT_TYPE_TUNER</CODE -></TD -><TD ->1</TD -><TD ->This input uses a tuner (RF demodulator).</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_INPUT_TYPE_CAMERA</CODE -></TD -><TD ->2</TD -><TD ->Analog baseband input, for example CVBS / -Composite Video, S-Video, RGB.</TD -></TR -></TBODY -></TABLE -></DIV -><DIV -CLASS="TABLE" -><A -NAME="INPUT-STATUS" -></A -><P -><B ->Table 3. Input Status Flags</B -></P -><TABLE -BORDER="0" -FRAME="void" -WIDTH="100%" -CLASS="CALSTABLE" -><COL -WIDTH="33%" -TITLE="C1"><COL -WIDTH="33%" -ALIGN="CENTER" -TITLE="C2"><COL -WIDTH="33%" -TITLE="C3"><TBODY -><TR -><TD -COLSPAN="3" -ALIGN="LEFT" ->General</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_IN_ST_NO_POWER</CODE -></TD -><TD ->0x00000001</TD -><TD ->Attached device is off.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_IN_ST_NO_SIGNAL</CODE -></TD -><TD ->0x00000002</TD -><TD -> </TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_IN_ST_NO_COLOR</CODE -></TD -><TD ->0x00000004</TD -><TD -> </TD -></TR -><TR -><TD -COLSPAN="3" -ALIGN="LEFT" ->Analog Video</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_IN_ST_NO_H_LOCK</CODE -></TD -><TD ->0x00000100</TD -><TD ->No horizontal sync lock.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_IN_ST_COLOR_KILL</CODE -></TD -><TD ->0x00000200</TD -><TD ->The color killer is a circuit that shuts off the -color decoding when it cannot find the color burst. This flag -indicates if the color killer is <SPAN -CLASS="emphasis" -><I -CLASS="EMPHASIS" ->enabled</I -></SPAN ->, while -<CODE -CLASS="CONSTANT" ->V4L2_IN_ST_NO_COLOR</CODE -> is set when no color is -<SPAN -CLASS="emphasis" -><I -CLASS="EMPHASIS" ->detected</I -></SPAN ->.</TD -></TR -><TR -><TD -COLSPAN="3" -ALIGN="LEFT" ->Digital Video</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_IN_ST_NO_SYNC</CODE -></TD -><TD ->0x00010000</TD -><TD ->No synchronization lock.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_IN_ST_NO_EQU</CODE -></TD -><TD ->0x00020000</TD -><TD ->No equalizer lock.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_IN_ST_NO_CARRIER</CODE -></TD -><TD ->0x00040000</TD -><TD ->Carrier recovery failed.</TD -></TR -><TR -><TD -COLSPAN="3" -ALIGN="LEFT" ->VCR and Set-Top Box</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_IN_ST_MACROVISION</CODE -></TD -><TD ->0x01000000</TD -><TD ->Macrovision is an analog copy protection system -mangling the video signal to confuse video recorders. When this -flag is set Macrovision protection has been detected.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_IN_ST_NO_ACCESS</CODE -></TD -><TD ->0x02000000</TD -><TD ->Conditional access denied.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_IN_ST_VTR</CODE -></TD -><TD ->0x04000000</TD -><TD ->VTR time constant. [?]</TD -></TR -></TBODY -></TABLE -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN5545" -></A -><H2 ->Return Value</H2 -><P ->On success <SPAN -CLASS="RETURNVALUE" ->0</SPAN -> is returned, on -error <SPAN -CLASS="RETURNVALUE" ->-1</SPAN -> and <VAR -CLASS="VARNAME" ->errno</VAR -> is -set appropriately:</P -><P -></P -><DIV -CLASS="VARIABLELIST" -><DL -><DT -><SPAN -CLASS="ERRORCODE" ->EINVAL</SPAN -></DT -><DD -><P ->The struct <A -HREF="#V4L2-INPUT" ->v4l2_input</A -> <CODE -CLASS="STRUCTFIELD" ->index</CODE -> is -out of bounds.</P -></DD -></DL -></DIV -></DIV -><H1 -><A -NAME="VIDIOC-ENUMOUTPUT" -></A ->ioctl VIDIOC_ENUMOUTPUT</H1 -><DIV -CLASS="REFNAMEDIV" -><A -NAME="AEN5560" -></A -><H2 ->Name</H2 ->ioctl VIDIOC_ENUMOUTPUT -- Enumerate video outputs</DIV -><DIV -CLASS="REFSYNOPSISDIV" -><A -NAME="AEN5563" -></A -><H2 ->Synopsis</H2 -><DIV -CLASS="FUNCSYNOPSIS" -><P -></P -><A -NAME="AEN5564" -></A -><P -><CODE -><CODE -CLASS="FUNCDEF" ->int ioctl</CODE ->(int fd, int request, struct v4l2_output *argp);</CODE -></P -><P -></P -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN5574" -></A -><H2 ->Arguments</H2 -><P -></P -><DIV -CLASS="VARIABLELIST" -><DL -><DT -><VAR -CLASS="PARAMETER" ->fd</VAR -></DT -><DD -><P ->File descriptor returned by <A -HREF="#FUNC-OPEN" -><CODE -CLASS="FUNCTION" ->open()</CODE -></A ->.</P -></DD -><DT -><VAR -CLASS="PARAMETER" ->request</VAR -></DT -><DD -><P ->VIDIOC_ENUMOUTPUT</P -></DD -><DT -><VAR -CLASS="PARAMETER" ->argp</VAR -></DT -><DD -><P -></P -></DD -></DL -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN5594" -></A -><H2 ->Description</H2 -><P ->To query the attributes of a video outputs applications -initialize the <CODE -CLASS="STRUCTFIELD" ->index</CODE -> field of struct <A -HREF="#V4L2-OUTPUT" ->v4l2_output</A -> -and call the <CODE -CLASS="CONSTANT" ->VIDIOC_ENUMOUTPUT</CODE -> ioctl with a -pointer to this structure. Drivers fill the rest of the structure or -return an <SPAN -CLASS="ERRORCODE" ->EINVAL</SPAN -> error code when the index is out of bounds. To enumerate all -outputs applications shall begin at index zero, incrementing by one -until the driver returns <SPAN -CLASS="ERRORCODE" ->EINVAL</SPAN ->.</P -><DIV -CLASS="TABLE" -><A -NAME="V4L2-OUTPUT" -></A -><P -><B ->Table 1. struct <CODE -CLASS="STRUCTNAME" ->v4l2_output</CODE -></B -></P -><TABLE -BORDER="0" -FRAME="void" -WIDTH="100%" -CLASS="CALSTABLE" -><COL -WIDTH="25%" -TITLE="C1"><COL -WIDTH="25%" -TITLE="C2"><COL -WIDTH="50%" -TITLE="C3"><TBODY -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->index</CODE -></TD -><TD ->Identifies the output, set by the -application.</TD -></TR -><TR -><TD ->__u8</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->name</CODE ->[32]</TD -><TD ->Name of the video output, a NUL-terminated ASCII -string, for example: "Vout". This information is intended for the -user, preferably the connector label on the device itself.</TD -></TR -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->type</CODE -></TD -><TD ->Type of the output, see <A -HREF="#OUTPUT-TYPE" ->Table 2</A ->.</TD -></TR -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->audioset</CODE -></TD -><TD ->Video outputs combine with zero or more audio -outputs. For example one composite video connectors may exist, but two -audio connectors. On the other hand, video to a modulator will likely -combine only with audio to the same modulator. Devices with N audio -outputs number them 0 … N-1 with N ≤ 32. Each bit position of -<CODE -CLASS="STRUCTFIELD" ->audioset</CODE -> represents one audio output. For -details on audio outputs and how to switch see <A -HREF="#AUDIO" ->Section 1.5</A ->.</TD -></TR -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->modulator</CODE -></TD -><TD ->Output devices can have zero or more RF modulators. -When the <CODE -CLASS="STRUCTFIELD" ->type</CODE -> is -<CODE -CLASS="CONSTANT" ->V4L2_OUTPUT_TYPE_MODULATOR</CODE -> this is an RF -connector and this field identifies the modulator. It corresponds to -struct <A -HREF="#V4L2-MODULATOR" ->v4l2_modulator</A -> field <CODE -CLASS="STRUCTFIELD" ->index</CODE ->. For details -on modulators see <A -HREF="#TUNER" ->Section 1.6</A ->.</TD -></TR -><TR -><TD -><A -HREF="#V4L2-STD-ID" ->v4l2_std_id</A -></TD -><TD -><CODE -CLASS="STRUCTFIELD" ->std</CODE -></TD -><TD ->Every video output supports one or more different -video standards. This field is a set of all supported standards. For -details on video standards and how to switch see <A -HREF="#STANDARD" ->Section 1.7</A ->.</TD -></TR -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->reserved</CODE ->[4]</TD -><TD ->Reserved for future extensions. Drivers must set -the array to zero.</TD -></TR -></TBODY -></TABLE -></DIV -><DIV -CLASS="TABLE" -><A -NAME="OUTPUT-TYPE" -></A -><P -><B ->Table 2. Output Type</B -></P -><TABLE -BORDER="0" -FRAME="void" -WIDTH="100%" -CLASS="CALSTABLE" -><COL -WIDTH="38%" -TITLE="C1"><COL -WIDTH="12%" -TITLE="C2"><COL -WIDTH="50%" -TITLE="C3"><TBODY -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_OUTPUT_TYPE_MODULATOR</CODE -></TD -><TD ->1</TD -><TD ->This output is an analog TV modulator.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_OUTPUT_TYPE_ANALOG</CODE -></TD -><TD ->2</TD -><TD ->Analog baseband output, for example Composite / -CVBS, S-Video, RGB.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_OUTPUT_TYPE_ANALOGVGAOVERLAY</CODE -></TD -><TD ->3</TD -><TD ->[?]</TD -></TR -></TBODY -></TABLE -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN5679" -></A -><H2 ->Return Value</H2 -><P ->On success <SPAN -CLASS="RETURNVALUE" ->0</SPAN -> is returned, on -error <SPAN -CLASS="RETURNVALUE" ->-1</SPAN -> and <VAR -CLASS="VARNAME" ->errno</VAR -> is -set appropriately:</P -><P -></P -><DIV -CLASS="VARIABLELIST" -><DL -><DT -><SPAN -CLASS="ERRORCODE" ->EINVAL</SPAN -></DT -><DD -><P ->The struct <A -HREF="#V4L2-OUTPUT" ->v4l2_output</A -> <CODE -CLASS="STRUCTFIELD" ->index</CODE -> -is out of bounds.</P -></DD -></DL -></DIV -></DIV -><H1 -><A -NAME="VIDIOC-ENUMSTD" -></A ->ioctl VIDIOC_ENUMSTD</H1 -><DIV -CLASS="REFNAMEDIV" -><A -NAME="AEN5694" -></A -><H2 ->Name</H2 ->ioctl VIDIOC_ENUMSTD -- Enumerate supported video standards</DIV -><DIV -CLASS="REFSYNOPSISDIV" -><A -NAME="AEN5697" -></A -><H2 ->Synopsis</H2 -><DIV -CLASS="FUNCSYNOPSIS" -><P -></P -><A -NAME="AEN5698" -></A -><P -><CODE -><CODE -CLASS="FUNCDEF" ->int ioctl</CODE ->(int fd, int request, struct v4l2_standard *argp);</CODE -></P -><P -></P -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN5708" -></A -><H2 ->Arguments</H2 -><P -></P -><DIV -CLASS="VARIABLELIST" -><DL -><DT -><VAR -CLASS="PARAMETER" ->fd</VAR -></DT -><DD -><P ->File descriptor returned by <A -HREF="#FUNC-OPEN" -><CODE -CLASS="FUNCTION" ->open()</CODE -></A ->.</P -></DD -><DT -><VAR -CLASS="PARAMETER" ->request</VAR -></DT -><DD -><P ->VIDIOC_ENUMSTD</P -></DD -><DT -><VAR -CLASS="PARAMETER" ->argp</VAR -></DT -><DD -><P -></P -></DD -></DL -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN5728" -></A -><H2 ->Description</H2 -><P ->To query the attributes of a video standard, -especially a custom (driver defined) one, applications initialize the -<CODE -CLASS="STRUCTFIELD" ->index</CODE -> field of struct <A -HREF="#V4L2-STANDARD" ->v4l2_standard</A -> and call the -<CODE -CLASS="CONSTANT" ->VIDIOC_ENUMSTD</CODE -> ioctl with a pointer to this -structure. Drivers fill the rest of the structure or return an -<SPAN -CLASS="ERRORCODE" ->EINVAL</SPAN -> error code when the index is out of bounds. To enumerate all standards -applications shall begin at index zero, incrementing by one until the -driver returns <SPAN -CLASS="ERRORCODE" ->EINVAL</SPAN ->. Drivers may enumerate a -different set of standards after switching the video input or -output.<A -NAME="AEN5736" -HREF="#FTN.AEN5736" -><SPAN -CLASS="footnote" ->[24]</SPAN -></A -></P -><DIV -CLASS="TABLE" -><A -NAME="V4L2-STANDARD" -></A -><P -><B ->Table 1. struct <CODE -CLASS="STRUCTNAME" ->v4l2_standard</CODE -></B -></P -><TABLE -BORDER="0" -FRAME="void" -WIDTH="100%" -CLASS="CALSTABLE" -><COL -WIDTH="25%" -TITLE="C1"><COL -WIDTH="25%" -TITLE="C2"><COL -WIDTH="50%" -TITLE="C3"><TBODY -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->index</CODE -></TD -><TD ->Number of the video standard, set by the -application.</TD -></TR -><TR -><TD -><A -HREF="#V4L2-STD-ID" ->v4l2_std_id</A -></TD -><TD -><CODE -CLASS="STRUCTFIELD" ->id</CODE -></TD -><TD ->The bits in this field identify the standard as -one of the common standards listed in <A -HREF="#V4L2-STD-ID" ->Table 3</A ->, -or if bits 32 to 63 are set as custom standards. Multiple bits can be -set if the hardware does not distinguish between these standards, -however separate indices do not indicate the opposite. The -<CODE -CLASS="STRUCTFIELD" ->id</CODE -> must be unique. No other enumerated -<CODE -CLASS="STRUCTNAME" ->v4l2_standard</CODE -> structure, for this input or -output anyway, can contain the same set of bits.</TD -></TR -><TR -><TD ->__u8</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->name</CODE ->[24]</TD -><TD ->Name of the standard, a NUL-terminated ASCII -string, for example: "PAL-B/G", "NTSC Japan". This information is -intended for the user.</TD -></TR -><TR -><TD ->struct <A -HREF="#V4L2-FRACT" ->v4l2_fract</A -></TD -><TD -><CODE -CLASS="STRUCTFIELD" ->frameperiod</CODE -></TD -><TD ->The frame period (not field period) is numerator -/ denominator. For example M/NTSC has a frame period of 1001 / -30000 seconds.</TD -></TR -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->framelines</CODE -></TD -><TD ->Total lines per frame including blanking, -e. g. 625 for B/PAL.</TD -></TR -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->reserved</CODE ->[4]</TD -><TD ->Reserved for future extensions. Drivers must set -the array to zero.</TD -></TR -></TBODY -></TABLE -></DIV -><DIV -CLASS="TABLE" -><A -NAME="V4L2-FRACT" -></A -><P -><B ->Table 2. struct <CODE -CLASS="STRUCTNAME" ->v4l2_fract</CODE -></B -></P -><TABLE -BORDER="0" -FRAME="void" -WIDTH="100%" -CLASS="CALSTABLE" -><COL -WIDTH="25%" -TITLE="C1"><COL -WIDTH="25%" -TITLE="C2"><COL -WIDTH="50%" -TITLE="C3"><TBODY -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->numerator</CODE -></TD -><TD -> </TD -></TR -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->denominator</CODE -></TD -><TD -> </TD -></TR -></TBODY -></TABLE -></DIV -><DIV -CLASS="TABLE" -><A -NAME="V4L2-STD-ID" -></A -><P -><B ->Table 3. typedef <CODE -CLASS="STRUCTNAME" ->v4l2_std_id</CODE -></B -></P -><TABLE -BORDER="0" -FRAME="void" -WIDTH="100%" -CLASS="CALSTABLE" -><COL -WIDTH="25%" -TITLE="C1"><COL -WIDTH="25%" -TITLE="C2"><COL -WIDTH="50%" -TITLE="C3"><TBODY -><TR -><TD ->__u64</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->v4l2_std_id</CODE -></TD -><TD ->This type is a set, each bit representing -another video standard as listed below and in <A -HREF="#VIDEO-STANDARDS" ->Table 4</A ->.</TD -></TR -><TR -><TD -COLSPAN="3" -><P -><CODE -CLASS="CONSTANT" ->V4L2_STD_PAL_60</CODE -> is a -hybrid standard with 525 lines, 60 Hz refresh rate, but PAL -color modulation. Some PAL video recorders can play back NTSC tapes in this -mode for display on 50/60 Hz agnostic PAL TVs.</P -><P -><CODE -CLASS="CONSTANT" ->V4L2_STD_ATSC_8_VSB</CODE -> and -<CODE -CLASS="CONSTANT" ->V4L2_STD_ATSC_16_VSB</CODE -> are the U.S. terrestrial -digital TV standards. The present V4L2 API makes no provisions for -digital TV reception, so no driver will report these standards -yet. See also the Linux DVB API at -<A -HREF="http://linuxtv.org" -TARGET="_top" ->http://linuxtv.org</A ->.</P -><P ->Bit -32 to 63 are reserved for custom (driver defined) video -standards.</P -></TD -></TR -></TBODY -></TABLE -></DIV -><P -><PRE -CLASS="PROGRAMLISTING" ->#define V4L2_STD_PAL_B ((v4l2_std_id)0x00000001) -#define V4L2_STD_PAL_B1 ((v4l2_std_id)0x00000002) -#define V4L2_STD_PAL_G ((v4l2_std_id)0x00000004) -#define V4L2_STD_PAL_H ((v4l2_std_id)0x00000008) -#define V4L2_STD_PAL_I ((v4l2_std_id)0x00000010) -#define V4L2_STD_PAL_D ((v4l2_std_id)0x00000020) -#define V4L2_STD_PAL_D1 ((v4l2_std_id)0x00000040) -#define V4L2_STD_PAL_K ((v4l2_std_id)0x00000080) - -#define V4L2_STD_PAL_M ((v4l2_std_id)0x00000100) -#define V4L2_STD_PAL_N ((v4l2_std_id)0x00000200) -#define V4L2_STD_PAL_Nc ((v4l2_std_id)0x00000400) -#define V4L2_STD_PAL_60 ((v4l2_std_id)0x00000800) - -#define V4L2_STD_NTSC_M ((v4l2_std_id)0x00001000) -#define V4L2_STD_NTSC_M_JP ((v4l2_std_id)0x00002000) - -#define V4L2_STD_SECAM_B ((v4l2_std_id)0x00010000) -#define V4L2_STD_SECAM_D ((v4l2_std_id)0x00020000) -#define V4L2_STD_SECAM_G ((v4l2_std_id)0x00040000) -#define V4L2_STD_SECAM_H ((v4l2_std_id)0x00080000) -#define V4L2_STD_SECAM_K ((v4l2_std_id)0x00100000) -#define V4L2_STD_SECAM_K1 ((v4l2_std_id)0x00200000) -#define V4L2_STD_SECAM_L ((v4l2_std_id)0x00400000) - -/* ATSC/HDTV */ -#define V4L2_STD_ATSC_8_VSB ((v4l2_std_id)0x01000000) -#define V4L2_STD_ATSC_16_VSB ((v4l2_std_id)0x02000000) - -#define V4L2_STD_PAL_BG (V4L2_STD_PAL_B |\ - V4L2_STD_PAL_B1 |\ - V4L2_STD_PAL_G) -#define V4L2_STD_PAL_DK (V4L2_STD_PAL_D |\ - V4L2_STD_PAL_D1 |\ - V4L2_STD_PAL_K) -#define V4L2_STD_PAL (V4L2_STD_PAL_BG |\ - V4L2_STD_PAL_DK |\ - V4L2_STD_PAL_H |\ - V4L2_STD_PAL_I) -#define V4L2_STD_NTSC (V4L2_STD_NTSC_M |\ - V4L2_STD_NTSC_M_JP) -#define V4L2_STD_SECAM (V4L2_STD_SECAM_B |\ - V4L2_STD_SECAM_D |\ - V4L2_STD_SECAM_G |\ - V4L2_STD_SECAM_H |\ - V4L2_STD_SECAM_K |\ - V4L2_STD_SECAM_K1 |\ - V4L2_STD_SECAM_L) - -#define V4L2_STD_525_60 (V4L2_STD_PAL_M |\ - V4L2_STD_PAL_60 |\ - V4L2_STD_NTSC) -#define V4L2_STD_625_50 (V4L2_STD_PAL |\ - V4L2_STD_PAL_N |\ - V4L2_STD_PAL_Nc |\ - V4L2_STD_SECAM) - -#define V4L2_STD_UNKNOWN 0 -#define V4L2_STD_ALL (V4L2_STD_525_60 |\ - V4L2_STD_625_50)</PRE -></P -><DIV -CLASS="TABLE" -><A -NAME="VIDEO-STANDARDS" -></A -><P -><B ->Table 4. Video Standards (based on [<A -HREF="#ITU470" -><ABBR -CLASS="ABBREV" ->ITU470</ABBR -></A ->])</B -></P -><TABLE -BORDER="1" -RULES="all" -WIDTH="100%" -CLASS="CALSTABLE" -><COL -WIDTH="12%" -ALIGN="LEFT" -TITLE="C1"><COL -WIDTH="12%" -TITLE="C2"><COL -WIDTH="12%" -TITLE="C3"><COL -WIDTH="12%" -TITLE="C4"><COL -WIDTH="12%" -TITLE="C5"><COL><COL -WIDTH="12%" -TITLE="C7"><COL><COL -WIDTH="12%" -TITLE="C9"><COL><COL><COL -WIDTH="12%" -TITLE="C12"><THEAD -><TR -><TH ->Characteristics</TH -><TH -><P ->M/NTSC<SUP ->a</SUP -></P -></TH -><TH ->M/PAL</TH -><TH -><P ->N/PAL<SUP ->b</SUP -></P -></TH -><TH -ALIGN="CENTER" ->B, B1, G/PAL</TH -><TH -ALIGN="CENTER" ->D, D1, K/PAL</TH -><TH -ALIGN="CENTER" ->H/PAL</TH -><TH -ALIGN="CENTER" ->I/PAL</TH -><TH -ALIGN="CENTER" ->B, G/SECAM</TH -><TH -ALIGN="CENTER" ->D, K/SECAM</TH -><TH -ALIGN="CENTER" ->K1/SECAM</TH -><TH -ALIGN="CENTER" ->L/SECAM</TH -></TR -></THEAD -><TBODY -><TR -><TD ->Frame lines</TD -><TD -COLSPAN="2" -ALIGN="CENTER" ->525</TD -><TD -COLSPAN="9" -ALIGN="CENTER" ->625</TD -></TR -><TR -><TD ->Frame period (s)</TD -><TD -COLSPAN="2" -ALIGN="CENTER" ->1001/30000</TD -><TD -COLSPAN="9" -ALIGN="CENTER" ->1/25</TD -></TR -><TR -><TD ->Chrominance sub-carrier frequency (Hz)</TD -><TD ->3579545 ± 10</TD -><TD ->3579611.49 ± 10</TD -><TD ->4433618.75 ± 5 (3582056.25 -± 5)</TD -><TD -COLSPAN="3" -ALIGN="CENTER" ->4433618.75 ± 5</TD -><TD ->4433618.75 ± 1</TD -><TD -COLSPAN="4" -ALIGN="CENTER" ->f<SUB ->OR</SUB -> = -4406250 ± 2000, f<SUB ->OB</SUB -> = 4250000 -± 2000</TD -></TR -><TR -><TD ->Nominal radio-frequency channel bandwidth -(MHz)</TD -><TD ->6</TD -><TD ->6</TD -><TD ->6</TD -><TD ->B: 7; B1, G: 8</TD -><TD ->8</TD -><TD ->8</TD -><TD ->8</TD -><TD ->8</TD -><TD ->8</TD -><TD ->8</TD -><TD ->8</TD -></TR -><TR -><TD ->Sound carrier relative to vision carrier -(MHz)</TD -><TD ->+ 4.5</TD -><TD ->+ 4.5</TD -><TD ->+ 4.5</TD -><TD -><P ->+ 5.5 ± 0.001 -<SUP ->c</SUP -> <SUP ->d</SUP -> <SUP ->e</SUP -> <SUP ->f</SUP -></P -></TD -><TD ->+ 6.5 ± 0.001</TD -><TD ->+ 5.5</TD -><TD ->+ 5.9996 ± 0.0005</TD -><TD ->+ 5.5 ± 0.001</TD -><TD ->+ 6.5 ± 0.001</TD -><TD ->+ 6.5</TD -><TD -><P ->+ 6.5 <SUP ->g</SUP -></P -></TD -></TR -></TBODY -><TR -><TD -COLSPAN="12" ->Notes:<BR><A -NAME="FTN.AEN5849" ->a. </A ->Japan uses a standard -similar to M/NTSC -(V4L2_STD_NTSC_M_JP).<BR><A -NAME="FTN.AEN5854" ->b. </A -> The values in -brackets apply to the combination N/PAL a.k.a. -N<SUB ->C</SUB -> used in Argentina -(V4L2_STD_PAL_Nc).<BR><A -NAME="FTN.AEN5904" ->c. </A ->In the Federal Republic of Germany, Austria, Italy, -the Netherlands, Slovakia and Switzerland a system of two sound -carriers is used, the frequency of the second carrier being -242.1875 kHz above the frequency of the first sound carrier. For -stereophonic sound transmissions a similar system is used in -Australia.<BR><A -NAME="FTN.AEN5906" ->d. </A ->New Zealand uses a sound -carrier displaced 5.4996 ± 0.0005 MHz from the vision -carrier.<BR><A -NAME="FTN.AEN5908" ->e. </A ->In Denmark, Finland, New -Zealand, Sweden and Spain a system of two sound carriers is used. In -Iceland, Norway and Poland the same system is being introduced. The -second carrier is 5.85 MHz above the vision carrier and is DQPSK -modulated with 728 kbit/s sound and data multiplex. (NICAM -system)<BR><A -NAME="FTN.AEN5910" ->f. </A ->In the United Kingdom, a -system of two sound carriers is used. The second sound carrier is -6.552 MHz above the vision carrier and is DQPSK modulated with a -728 kbit/s sound and data multiplex able to carry two sound -channels. (NICAM system)<BR><A -NAME="FTN.AEN5920" ->g. </A ->In France, a -digital carrier 5.85 MHz away from the vision carrier may be used in -addition to the main sound carrier. It is modulated in differentially -encoded QPSK with a 728 kbit/s sound and data multiplexer capable of -carrying two sound channels. (NICAM -system)<BR></TD -></TR -></TABLE -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN5922" -></A -><H2 ->Return Value</H2 -><P ->On success <SPAN -CLASS="RETURNVALUE" ->0</SPAN -> is returned, on -error <SPAN -CLASS="RETURNVALUE" ->-1</SPAN -> and <VAR -CLASS="VARNAME" ->errno</VAR -> is -set appropriately:</P -><P -></P -><DIV -CLASS="VARIABLELIST" -><DL -><DT -><SPAN -CLASS="ERRORCODE" ->EINVAL</SPAN -></DT -><DD -><P ->The struct <A -HREF="#V4L2-STANDARD" ->v4l2_standard</A -> <CODE -CLASS="STRUCTFIELD" ->index</CODE -> -is out of bounds.</P -></DD -></DL -></DIV -></DIV -><H1 -><A -NAME="VIDIOC-G-AUDIO" -></A ->ioctl VIDIOC_G_AUDIO, VIDIOC_S_AUDIO</H1 -><DIV -CLASS="REFNAMEDIV" -><A -NAME="AEN5939" -></A -><H2 ->Name</H2 ->ioctl VIDIOC_G_AUDIO, ioctl VIDIOC_S_AUDIO -- Query or select the current audio input and its -attributes</DIV -><DIV -CLASS="REFSYNOPSISDIV" -><A -NAME="AEN5943" -></A -><H2 ->Synopsis</H2 -><DIV -CLASS="FUNCSYNOPSIS" -><P -></P -><A -NAME="AEN5944" -></A -><P -><CODE -><CODE -CLASS="FUNCDEF" ->int ioctl</CODE ->(int fd, int request, struct v4l2_audio *argp);</CODE -></P -><P -></P -></DIV -><DIV -CLASS="FUNCSYNOPSIS" -><P -></P -><A -NAME="AEN5954" -></A -><P -><CODE -><CODE -CLASS="FUNCDEF" ->int ioctl</CODE ->(int fd, int request, const struct v4l2_audio *argp);</CODE -></P -><P -></P -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN5964" -></A -><H2 ->Arguments</H2 -><P -></P -><DIV -CLASS="VARIABLELIST" -><DL -><DT -><VAR -CLASS="PARAMETER" ->fd</VAR -></DT -><DD -><P ->File descriptor returned by <A -HREF="#FUNC-OPEN" -><CODE -CLASS="FUNCTION" ->open()</CODE -></A ->.</P -></DD -><DT -><VAR -CLASS="PARAMETER" ->request</VAR -></DT -><DD -><P ->VIDIOC_G_AUDIO, VIDIOC_S_AUDIO</P -></DD -><DT -><VAR -CLASS="PARAMETER" ->argp</VAR -></DT -><DD -><P -></P -></DD -></DL -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN5984" -></A -><H2 ->Description</H2 -><P ->To query the current audio input applications zero out the -<CODE -CLASS="STRUCTFIELD" ->reserved</CODE -> array of a struct <A -HREF="#V4L2-AUDIO" ->v4l2_audio</A -> -and call the <CODE -CLASS="CONSTANT" ->VIDIOC_G_AUDIO</CODE -> ioctl with a pointer -to this structure. Drivers fill the rest of the structure or return an -<SPAN -CLASS="ERRORCODE" ->EINVAL</SPAN -> error code when the device has no audio inputs, or none which combine -with the current video input.</P -><P ->Audio inputs have one writable property, the audio mode. To -select the current audio input <SPAN -CLASS="emphasis" -><I -CLASS="EMPHASIS" ->and</I -></SPAN -> change the -audio mode, applications initialize the -<CODE -CLASS="STRUCTFIELD" ->index</CODE -> and <CODE -CLASS="STRUCTFIELD" ->mode</CODE -> -fields, and the -<CODE -CLASS="STRUCTFIELD" ->reserved</CODE -> array of a -<CODE -CLASS="STRUCTNAME" ->v4l2_audio</CODE -> structure and call the -<CODE -CLASS="CONSTANT" ->VIDIOC_S_AUDIO</CODE -> ioctl. Drivers may switch to a -different audio mode if the request cannot be satisfied. However, this -is a write-only ioctl, it does not return the actual new audio -mode.</P -><DIV -CLASS="TABLE" -><A -NAME="V4L2-AUDIO" -></A -><P -><B ->Table 1. struct <CODE -CLASS="STRUCTNAME" ->v4l2_audio</CODE -></B -></P -><TABLE -BORDER="0" -FRAME="void" -WIDTH="100%" -CLASS="CALSTABLE" -><COL -WIDTH="25%" -TITLE="C1"><COL -WIDTH="25%" -TITLE="C2"><COL -WIDTH="50%" -TITLE="C3"><TBODY -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->index</CODE -></TD -><TD ->Identifies the audio input, set by the -driver or application.</TD -></TR -><TR -><TD ->__u8</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->name</CODE ->[32]</TD -><TD ->Name of the audio input, a NUL-terminated ASCII -string, for example: "Line In". This information is intended for the -user, preferably the connector label on the device itself.</TD -></TR -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->capability</CODE -></TD -><TD ->Audio capability flags, see <A -HREF="#AUDIO-CAPABILITY" ->Table 2</A ->.</TD -></TR -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->mode</CODE -></TD -><TD ->Audio mode set by drivers and applications (on - <CODE -CLASS="CONSTANT" ->VIDIOC_S_AUDIO</CODE -> ioctl), see <A -HREF="#AUDIO-MODE" ->Table 3</A ->.</TD -></TR -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->reserved</CODE ->[2]</TD -><TD ->Reserved for future extensions. Drivers and -applications must set the array to zero.</TD -></TR -></TBODY -></TABLE -></DIV -><DIV -CLASS="TABLE" -><A -NAME="AUDIO-CAPABILITY" -></A -><P -><B ->Table 2. Audio Capability Flags</B -></P -><TABLE -BORDER="0" -FRAME="void" -WIDTH="100%" -CLASS="CALSTABLE" -><COL -WIDTH="38%" -TITLE="C1"><COL -WIDTH="12%" -TITLE="C2"><COL -WIDTH="50%" -TITLE="C3"><TBODY -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_AUDCAP_STEREO</CODE -></TD -><TD ->0x00001</TD -><TD ->This is a stereo input. The flag is intended to -automatically disable stereo recording etc. when the signal is always -monaural. The API provides no means to detect if stereo is -<SPAN -CLASS="emphasis" -><I -CLASS="EMPHASIS" ->received</I -></SPAN ->, unless the audio input belongs to a -tuner.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_AUDCAP_AVL</CODE -></TD -><TD ->0x00002</TD -><TD ->Automatic Volume Level mode is supported.</TD -></TR -></TBODY -></TABLE -></DIV -><DIV -CLASS="TABLE" -><A -NAME="AUDIO-MODE" -></A -><P -><B ->Table 3. Audio Modes</B -></P -><TABLE -BORDER="0" -FRAME="void" -WIDTH="100%" -CLASS="CALSTABLE" -><COL -WIDTH="38%" -TITLE="C1"><COL -WIDTH="12%" -TITLE="C2"><COL -WIDTH="50%" -TITLE="C3"><TBODY -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_AUDMODE_AVL</CODE -></TD -><TD ->0x00001</TD -><TD ->AVL mode is on.</TD -></TR -></TBODY -></TABLE -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN6067" -></A -><H2 ->Return Value</H2 -><P ->On success <SPAN -CLASS="RETURNVALUE" ->0</SPAN -> is returned, on -error <SPAN -CLASS="RETURNVALUE" ->-1</SPAN -> and <VAR -CLASS="VARNAME" ->errno</VAR -> is -set appropriately:</P -><P -></P -><DIV -CLASS="VARIABLELIST" -><DL -><DT -><SPAN -CLASS="ERRORCODE" ->EINVAL</SPAN -></DT -><DD -><P ->No audio inputs combine with the current video input, -or the number of the selected audio input is out of bounds or it does -not combine, or there are no audio inputs at all and the ioctl is not -supported.</P -></DD -><DT -><SPAN -CLASS="ERRORCODE" ->EBUSY</SPAN -></DT -><DD -><P ->I/O is in progress, the input cannot be -switched.</P -></DD -></DL -></DIV -></DIV -><H1 -><A -NAME="VIDIOC-G-AUDIOOUT" -></A ->ioctl VIDIOC_G_AUDOUT, VIDIOC_S_AUDOUT</H1 -><DIV -CLASS="REFNAMEDIV" -><A -NAME="AEN6087" -></A -><H2 ->Name</H2 ->ioctl VIDIOC_G_AUDOUT, ioctl VIDIOC_S_AUDOUT -- Query or select the current audio output</DIV -><DIV -CLASS="REFSYNOPSISDIV" -><A -NAME="AEN6091" -></A -><H2 ->Synopsis</H2 -><DIV -CLASS="FUNCSYNOPSIS" -><P -></P -><A -NAME="AEN6092" -></A -><P -><CODE -><CODE -CLASS="FUNCDEF" ->int ioctl</CODE ->(int fd, int request, struct v4l2_audioout *argp);</CODE -></P -><P -></P -></DIV -><DIV -CLASS="FUNCSYNOPSIS" -><P -></P -><A -NAME="AEN6102" -></A -><P -><CODE -><CODE -CLASS="FUNCDEF" ->int ioctl</CODE ->(int fd, int request, const struct v4l2_audioout *argp);</CODE -></P -><P -></P -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN6112" -></A -><H2 ->Arguments</H2 -><P -></P -><DIV -CLASS="VARIABLELIST" -><DL -><DT -><VAR -CLASS="PARAMETER" ->fd</VAR -></DT -><DD -><P ->File descriptor returned by <A -HREF="#FUNC-OPEN" -><CODE -CLASS="FUNCTION" ->open()</CODE -></A ->.</P -></DD -><DT -><VAR -CLASS="PARAMETER" ->request</VAR -></DT -><DD -><P ->VIDIOC_G_AUDOUT, VIDIOC_S_AUDOUT</P -></DD -><DT -><VAR -CLASS="PARAMETER" ->argp</VAR -></DT -><DD -><P -></P -></DD -></DL -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN6132" -></A -><H2 ->Description</H2 -><P ->To query the current audio output applications zero out the -<CODE -CLASS="STRUCTFIELD" ->reserved</CODE -> array of a struct <A -HREF="#V4L2-AUDIOOUT" ->v4l2_audioout</A -> and -call the <CODE -CLASS="CONSTANT" ->VIDIOC_G_AUDOUT</CODE -> ioctl with a pointer -to this structure. Drivers fill the rest of the structure or return an -<SPAN -CLASS="ERRORCODE" ->EINVAL</SPAN -> error code when the device has no audio inputs, or none which combine -with the current video output.</P -><P ->Audio outputs have no writable properties. Nevertheless, to -select the current audio output applications can initialize the -<CODE -CLASS="STRUCTFIELD" ->index</CODE -> field and -<CODE -CLASS="STRUCTFIELD" ->reserved</CODE -> array (which in the future may -contain writable properties) of a -<CODE -CLASS="STRUCTNAME" ->v4l2_audioout</CODE -> structure and call the -<CODE -CLASS="CONSTANT" ->VIDIOC_S_AUDOUT</CODE -> ioctl. Drivers switch to the -requested output or return the <SPAN -CLASS="ERRORCODE" ->EINVAL</SPAN -> error code when the index is out of -bounds. This is a write-only ioctl, it does not return the current -audio output attributes as <CODE -CLASS="CONSTANT" ->VIDIOC_G_AUDOUT</CODE -> -does.</P -><P ->Note connectors on a TV card to loop back the received audio -signal to a sound card are not audio outputs in this sense.</P -><DIV -CLASS="TABLE" -><A -NAME="V4L2-AUDIOOUT" -></A -><P -><B ->Table 1. struct <CODE -CLASS="STRUCTNAME" ->v4l2_audioout</CODE -></B -></P -><TABLE -BORDER="0" -FRAME="void" -WIDTH="100%" -CLASS="CALSTABLE" -><COL -WIDTH="25%" -TITLE="C1"><COL -WIDTH="25%" -TITLE="C2"><COL -WIDTH="50%" -TITLE="C3"><TBODY -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->index</CODE -></TD -><TD ->Identifies the audio output, set by the -driver or application.</TD -></TR -><TR -><TD ->__u8</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->name</CODE ->[32]</TD -><TD ->Name of the audio output, a NUL-terminated ASCII -string, for example: "Line Out". This information is intended for the -user, preferably the connector label on the device itself.</TD -></TR -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->capability</CODE -></TD -><TD ->Audio capability flags, none defined yet. Drivers -must set this field to zero.</TD -></TR -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->mode</CODE -></TD -><TD ->Audio mode, none defined yet. Drivers and -applications (on <CODE -CLASS="CONSTANT" ->VIDIOC_S_AUDOUT</CODE ->) must set this -field to zero.</TD -></TR -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->reserved</CODE ->[2]</TD -><TD ->Reserved for future extensions. Drivers and -applications must set the array to zero.</TD -></TR -></TBODY -></TABLE -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN6182" -></A -><H2 ->Return Value</H2 -><P ->On success <SPAN -CLASS="RETURNVALUE" ->0</SPAN -> is returned, on -error <SPAN -CLASS="RETURNVALUE" ->-1</SPAN -> and <VAR -CLASS="VARNAME" ->errno</VAR -> is -set appropriately:</P -><P -></P -><DIV -CLASS="VARIABLELIST" -><DL -><DT -><SPAN -CLASS="ERRORCODE" ->EINVAL</SPAN -></DT -><DD -><P ->No audio outputs combine with the current video -output, or the number of the selected audio output is out of bounds or -it does not combine, or there are no audio outputs at all and the -ioctl is not supported.</P -></DD -><DT -><SPAN -CLASS="ERRORCODE" ->EBUSY</SPAN -></DT -><DD -><P ->I/O is in progress, the output cannot be -switched.</P -></DD -></DL -></DIV -></DIV -><H1 -><A -NAME="VIDIOC-G-COMP" -></A ->ioctl VIDIOC_G_COMP, VIDIOC_S_COMP</H1 -><DIV -CLASS="REFNAMEDIV" -><A -NAME="AEN6202" -></A -><H2 ->Name</H2 ->ioctl VIDIOC_G_COMP, ioctl VIDIOC_S_COMP -- Get or set compression parameters</DIV -><DIV -CLASS="REFSYNOPSISDIV" -><A -NAME="AEN6206" -></A -><H2 ->Synopsis</H2 -><DIV -CLASS="FUNCSYNOPSIS" -><P -></P -><A -NAME="AEN6207" -></A -><P -><CODE -><CODE -CLASS="FUNCDEF" ->int ioctl</CODE ->(int fd, int request, v4l2_compression *argp);</CODE -></P -><P -></P -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN6217" -></A -><H2 ->Arguments</H2 -><P -></P -><DIV -CLASS="VARIABLELIST" -><DL -><DT -><VAR -CLASS="PARAMETER" ->fd</VAR -></DT -><DD -><P ->File descriptor returned by <A -HREF="#FUNC-OPEN" -><CODE -CLASS="FUNCTION" ->open()</CODE -></A ->.</P -></DD -><DT -><VAR -CLASS="PARAMETER" ->request</VAR -></DT -><DD -><P ->VIDIOC_G_COMP, VIDIOC_S_COMP</P -></DD -><DT -><VAR -CLASS="PARAMETER" ->argp</VAR -></DT -><DD -><P -></P -></DD -></DL -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN6237" -></A -><H2 ->Description</H2 -><P ->[to do]</P -><DIV -CLASS="TABLE" -><A -NAME="V4L2-COMPRESSION" -></A -><P -><B ->Table 1. struct <CODE -CLASS="STRUCTNAME" ->v4l2_compression</CODE -></B -></P -><TABLE -BORDER="0" -FRAME="void" -WIDTH="100%" -CLASS="CALSTABLE" -><COL -WIDTH="25%" -TITLE="C1"><COL -WIDTH="25%" -TITLE="C2"><COL -WIDTH="50%" -TITLE="C3"><TBODY -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->quality</CODE -></TD -><TD -> </TD -></TR -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->keyframerate</CODE -></TD -><TD -> </TD -></TR -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->pframerate</CODE -></TD -><TD -> </TD -></TR -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->reserved</CODE ->[5]</TD -><TD -> </TD -></TR -></TBODY -></TABLE -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN6269" -></A -><H2 ->Return Value</H2 -><P ->On success <SPAN -CLASS="RETURNVALUE" ->0</SPAN -> is returned, on -error <SPAN -CLASS="RETURNVALUE" ->-1</SPAN -> and <VAR -CLASS="VARNAME" ->errno</VAR -> is -set appropriately:</P -><P -></P -><DIV -CLASS="VARIABLELIST" -><DL -><DT -><SPAN -CLASS="ERRORCODE" ->EINVAL</SPAN -></DT -><DD -><P ->This ioctl is not supported</P -></DD -></DL -></DIV -></DIV -><H1 -><A -NAME="VIDIOC-G-CROP" -></A ->ioctl VIDIOC_G_CROP, VIDIOC_S_CROP</H1 -><DIV -CLASS="REFNAMEDIV" -><A -NAME="AEN6284" -></A -><H2 ->Name</H2 ->ioctl VIDIOC_G_CROP, ioctl VIDIOC_S_CROP -- Get or set the current cropping rectangle</DIV -><DIV -CLASS="REFSYNOPSISDIV" -><A -NAME="AEN6288" -></A -><H2 ->Synopsis</H2 -><DIV -CLASS="FUNCSYNOPSIS" -><P -></P -><A -NAME="AEN6289" -></A -><P -><CODE -><CODE -CLASS="FUNCDEF" ->int ioctl</CODE ->(int fd, int request, struct v4l2_crop *argp);</CODE -></P -><P -></P -></DIV -><DIV -CLASS="FUNCSYNOPSIS" -><P -></P -><A -NAME="AEN6299" -></A -><P -><CODE -><CODE -CLASS="FUNCDEF" ->int ioctl</CODE ->(int fd, int request, const struct v4l2_crop *argp);</CODE -></P -><P -></P -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN6309" -></A -><H2 ->Arguments</H2 -><P -></P -><DIV -CLASS="VARIABLELIST" -><DL -><DT -><VAR -CLASS="PARAMETER" ->fd</VAR -></DT -><DD -><P ->File descriptor returned by <A -HREF="#FUNC-OPEN" -><CODE -CLASS="FUNCTION" ->open()</CODE -></A ->.</P -></DD -><DT -><VAR -CLASS="PARAMETER" ->request</VAR -></DT -><DD -><P ->VIDIOC_G_CROP, VIDIOC_S_CROP</P -></DD -><DT -><VAR -CLASS="PARAMETER" ->argp</VAR -></DT -><DD -><P -></P -></DD -></DL -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN6329" -></A -><H2 ->Description</H2 -><P ->To query the cropping rectangle size and position -applications set the <CODE -CLASS="STRUCTFIELD" ->type</CODE -> field of a -<CODE -CLASS="STRUCTNAME" ->v4l2_crop</CODE -> structure to the respective buffer -(stream) type and call the <CODE -CLASS="CONSTANT" ->VIDIOC_G_CROP</CODE -> ioctl -with a pointer to this structure. The driver fills the rest of the -structure or returns the <SPAN -CLASS="ERRORCODE" ->EINVAL</SPAN -> error code if cropping is not supported.</P -><P ->To change the cropping rectangle applications initialize the -<CODE -CLASS="STRUCTFIELD" ->type</CODE -> and struct <A -HREF="#V4L2-RECT" ->v4l2_rect</A -> substructure named -<CODE -CLASS="STRUCTFIELD" ->c</CODE -> of a v4l2_crop structure and call the -<CODE -CLASS="CONSTANT" ->VIDIOC_S_CROP</CODE -> ioctl with a pointer to this -structure.</P -><P ->The driver first adjusts the requested dimensions against -hardware limits, i. e. the bounds given by the capture/output window, -and it rounds to the closest possible values of horizontal and -vertical offset, width and height. In particular the driver must round -the vertical offset of the cropping rectangle to frame lines modulo -two, such that the field order cannot be confused.</P -><P ->Second the driver adjusts the image size (the opposite -rectangle of the scaling process, source or target depending on the -data direction) to the closest size possible while maintaining the -current horizontal and vertical scaling factor.</P -><P ->Finally the driver programs the hardware with the actual -cropping and image parameters. <CODE -CLASS="CONSTANT" ->VIDIOC_S_CROP</CODE -> is a -write-only ioctl, it does not return the actual parameters. To query -them applications must call <CODE -CLASS="CONSTANT" ->VIDIOC_G_CROP</CODE -> and -<A -HREF="#VIDIOC-G-FMT" -><CODE -CLASS="CONSTANT" ->VIDIOC_G_FMT</CODE -></A ->. When the parameters are unsuitable the application may -modify the cropping or image parameters and repeat the cycle until -satisfactory parameters have been negotiated.</P -><P ->When cropping is not supported then no parameters are -changed and <CODE -CLASS="CONSTANT" ->VIDIOC_S_CROP</CODE -> returns the -<SPAN -CLASS="ERRORCODE" ->EINVAL</SPAN -> error code.</P -><DIV -CLASS="TABLE" -><A -NAME="V4L2-CROP" -></A -><P -><B ->Table 1. struct <CODE -CLASS="STRUCTNAME" ->v4l2_crop</CODE -></B -></P -><TABLE -BORDER="0" -FRAME="void" -WIDTH="100%" -CLASS="CALSTABLE" -><COL -WIDTH="25%" -TITLE="C1"><COL -WIDTH="25%" -TITLE="C2"><COL -WIDTH="50%" -TITLE="C3"><TBODY -><TR -><TD ->enum <A -HREF="#V4L2-BUF-TYPE" ->v4l2_buf_type</A -></TD -><TD -><CODE -CLASS="STRUCTFIELD" ->type</CODE -></TD -><TD ->Type of the data stream, set by the application. -Only these types are valid here: <CODE -CLASS="CONSTANT" ->V4L2_BUF_TYPE_VIDEO_CAPTURE</CODE ->, -<CODE -CLASS="CONSTANT" ->V4L2_BUF_TYPE_VIDEO_OUTPUT</CODE ->, -<CODE -CLASS="CONSTANT" ->V4L2_BUF_TYPE_VIDEO_OVERLAY</CODE ->, and custom (driver -defined) types with code <CODE -CLASS="CONSTANT" ->V4L2_BUF_TYPE_PRIVATE</CODE -> -and higher.</TD -></TR -><TR -><TD ->struct <A -HREF="#V4L2-RECT" ->v4l2_rect</A -></TD -><TD -><CODE -CLASS="STRUCTFIELD" ->c</CODE -></TD -><TD ->Cropping rectangle. The same co-ordinate system as -for struct <A -HREF="#V4L2-CROPCAP" ->v4l2_cropcap</A -> <CODE -CLASS="STRUCTFIELD" ->bounds</CODE -> is used.</TD -></TR -></TBODY -></TABLE -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN6378" -></A -><H2 ->Return Value</H2 -><P ->On success <SPAN -CLASS="RETURNVALUE" ->0</SPAN -> is returned, on -error <SPAN -CLASS="RETURNVALUE" ->-1</SPAN -> and <VAR -CLASS="VARNAME" ->errno</VAR -> is -set appropriately:</P -><P -></P -><DIV -CLASS="VARIABLELIST" -><DL -><DT -><SPAN -CLASS="ERRORCODE" ->EINVAL</SPAN -></DT -><DD -><P ->Cropping is not supported.</P -></DD -></DL -></DIV -></DIV -><H1 -><A -NAME="VIDIOC-G-CTRL" -></A ->ioctl VIDIOC_G_CTRL, VIDIOC_S_CTRL</H1 -><DIV -CLASS="REFNAMEDIV" -><A -NAME="AEN6393" -></A -><H2 ->Name</H2 ->ioctl VIDIOC_G_CTRL, ioctl VIDIOC_S_CTRL -- Get or set the value of a control</DIV -><DIV -CLASS="REFSYNOPSISDIV" -><A -NAME="AEN6397" -></A -><H2 ->Synopsis</H2 -><DIV -CLASS="FUNCSYNOPSIS" -><P -></P -><A -NAME="AEN6398" -></A -><P -><CODE -><CODE -CLASS="FUNCDEF" ->int ioctl</CODE ->(int fd, int request, struct v4l2_control -*argp);</CODE -></P -><P -></P -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN6408" -></A -><H2 ->Arguments</H2 -><P -></P -><DIV -CLASS="VARIABLELIST" -><DL -><DT -><VAR -CLASS="PARAMETER" ->fd</VAR -></DT -><DD -><P ->File descriptor returned by <A -HREF="#FUNC-OPEN" -><CODE -CLASS="FUNCTION" ->open()</CODE -></A ->.</P -></DD -><DT -><VAR -CLASS="PARAMETER" ->request</VAR -></DT -><DD -><P ->VIDIOC_G_CTRL, VIDIOC_S_CTRL</P -></DD -><DT -><VAR -CLASS="PARAMETER" ->argp</VAR -></DT -><DD -><P -></P -></DD -></DL -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN6428" -></A -><H2 ->Description</H2 -><P ->To get the current value of a control applications -initialize the <CODE -CLASS="STRUCTFIELD" ->id</CODE -> field of a struct -<CODE -CLASS="STRUCTNAME" ->v4l2_control</CODE -> and call the -<CODE -CLASS="CONSTANT" ->VIDIOC_G_CTRL</CODE -> ioctl with a pointer to this -structure. To change the value of a control applications initialize -the <CODE -CLASS="STRUCTFIELD" ->id</CODE -> and <CODE -CLASS="STRUCTFIELD" ->value</CODE -> -fields of a struct <CODE -CLASS="STRUCTNAME" ->v4l2_control</CODE -> and call the -<CODE -CLASS="CONSTANT" ->VIDIOC_S_CTRL</CODE -> ioctl.</P -><P ->When the <CODE -CLASS="STRUCTFIELD" ->id</CODE -> is invalid drivers -return an <SPAN -CLASS="ERRORCODE" ->EINVAL</SPAN -> error code. When the <CODE -CLASS="STRUCTFIELD" ->value</CODE -> is out -of bounds drivers can choose to take the closest valid value or return -an <SPAN -CLASS="ERRORCODE" ->ERANGE</SPAN -> error code, whatever seems more appropriate. However, -<CODE -CLASS="CONSTANT" ->VIDIOC_S_CTRL</CODE -> is a write-only ioctl, it does not -return the actual new value.</P -><DIV -CLASS="TABLE" -><A -NAME="V4L2-CONTROL" -></A -><P -><B ->Table 1. struct <CODE -CLASS="STRUCTNAME" ->v4l2_control</CODE -></B -></P -><TABLE -BORDER="0" -FRAME="void" -WIDTH="100%" -CLASS="CALSTABLE" -><COL -WIDTH="25%" -TITLE="C1"><COL -WIDTH="25%" -TITLE="C2"><COL -WIDTH="50%" -TITLE="C3"><TBODY -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->id</CODE -></TD -><TD ->Identifies the control, set by the -application.</TD -></TR -><TR -><TD ->__s32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->value</CODE -></TD -><TD ->New value or current value.</TD -></TR -></TBODY -></TABLE -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN6463" -></A -><H2 ->Return Value</H2 -><P ->On success <SPAN -CLASS="RETURNVALUE" ->0</SPAN -> is returned, on -error <SPAN -CLASS="RETURNVALUE" ->-1</SPAN -> and <VAR -CLASS="VARNAME" ->errno</VAR -> is -set appropriately:</P -><P -></P -><DIV -CLASS="VARIABLELIST" -><DL -><DT -><SPAN -CLASS="ERRORCODE" ->EINVAL</SPAN -></DT -><DD -><P ->The struct <A -HREF="#V4L2-CONTROL" ->v4l2_control</A -> <CODE -CLASS="STRUCTFIELD" ->id</CODE -> is -invalid.</P -></DD -><DT -><SPAN -CLASS="ERRORCODE" ->ERANGE</SPAN -></DT -><DD -><P ->The struct <A -HREF="#V4L2-CONTROL" ->v4l2_control</A -> <CODE -CLASS="STRUCTFIELD" ->value</CODE -> -is out of bounds.</P -></DD -><DT -><SPAN -CLASS="ERRORCODE" ->EBUSY</SPAN -></DT -><DD -><P ->The control is temporarily not changeable, possibly -because another applications took over control of the device function -this control belongs to.</P -></DD -></DL -></DIV -></DIV -><H1 -><A -NAME="VIDIOC-G-FBUF" -></A ->ioctl VIDIOC_G_FBUF, VIDIOC_S_FBUF</H1 -><DIV -CLASS="REFNAMEDIV" -><A -NAME="AEN6492" -></A -><H2 ->Name</H2 ->ioctl VIDIOC_G_FBUF, ioctl VIDIOC_S_FBUF -- Get or set frame buffer overlay parameters.</DIV -><DIV -CLASS="REFSYNOPSISDIV" -><A -NAME="AEN6496" -></A -><H2 ->Synopsis</H2 -><DIV -CLASS="FUNCSYNOPSIS" -><P -></P -><A -NAME="AEN6497" -></A -><P -><CODE -><CODE -CLASS="FUNCDEF" ->int ioctl</CODE ->(int fd, int request, struct v4l2_framebuffer *argp);</CODE -></P -><P -></P -></DIV -><DIV -CLASS="FUNCSYNOPSIS" -><P -></P -><A -NAME="AEN6507" -></A -><P -><CODE -><CODE -CLASS="FUNCDEF" ->int ioctl</CODE ->(int fd, int request, const struct v4l2_framebuffer *argp);</CODE -></P -><P -></P -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN6517" -></A -><H2 ->Arguments</H2 -><P -></P -><DIV -CLASS="VARIABLELIST" -><DL -><DT -><VAR -CLASS="PARAMETER" ->fd</VAR -></DT -><DD -><P ->File descriptor returned by <A -HREF="#FUNC-OPEN" -><CODE -CLASS="FUNCTION" ->open()</CODE -></A ->.</P -></DD -><DT -><VAR -CLASS="PARAMETER" ->request</VAR -></DT -><DD -><P ->VIDIOC_G_FBUF, VIDIOC_S_FBUF</P -></DD -><DT -><VAR -CLASS="PARAMETER" ->argp</VAR -></DT -><DD -><P -></P -></DD -></DL -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN6537" -></A -><H2 ->Description</H2 -><P ->The <CODE -CLASS="CONSTANT" ->VIDIOC_G_FBUF</CODE -> and -<CODE -CLASS="CONSTANT" ->VIDIOC_S_FBUF</CODE -> ioctl are used to get and set the -frame buffer parameters for <A -HREF="#OVERLAY" ->video overlay</A ->.</P -><P ->To get the current parameters applications call the -<CODE -CLASS="CONSTANT" ->VIDIOC_G_FBUF</CODE -> ioctl with a pointer to a -<CODE -CLASS="STRUCTNAME" ->v4l2_framebuffer</CODE -> structure, the driver fills -all fields of the structure or returns the <SPAN -CLASS="ERRORCODE" ->EINVAL</SPAN -> error code when overlay is -not supported. To set the parameters applications initialize the -<CODE -CLASS="STRUCTFIELD" ->flags</CODE -> field, -<CODE -CLASS="STRUCTFIELD" ->base</CODE -> unless the overlay is of -<CODE -CLASS="CONSTANT" ->V4L2_FBUF_CAP_EXTERNOVERLAY</CODE -> type, and the -struct <A -HREF="#V4L2-PIX-FORMAT" ->v4l2_pix_format</A -> <CODE -CLASS="STRUCTFIELD" ->fmt</CODE -> substructure. The driver -accordingly prepares for overlay or returns an error code.</P -><P ->When the driver does <SPAN -CLASS="emphasis" -><I -CLASS="EMPHASIS" ->not</I -></SPAN -> support -<CODE -CLASS="CONSTANT" ->V4L2_FBUF_CAP_EXTERNOVERLAY</CODE ->, i. e. it will -write into video memory, the <CODE -CLASS="CONSTANT" ->VIDIOC_S_FBUF</CODE -> ioctl -is a privileged function and only the superuser can change the frame -buffer parameters.</P -><DIV -CLASS="TABLE" -><A -NAME="V4L2-FRAMEBUFFER" -></A -><P -><B ->Table 1. struct <CODE -CLASS="STRUCTNAME" ->v4l2_framebuffer</CODE -></B -></P -><TABLE -BORDER="0" -FRAME="void" -WIDTH="100%" -CLASS="CALSTABLE" -><COL -WIDTH="50%" -TITLE="C1"><COL><COL><COL -WIDTH="50%" -TITLE="C4"><TBODY -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->capability</CODE -></TD -><TD -> </TD -><TD ->Overlay capability flags set by the driver, see -<A -HREF="#FRAMEBUFFER-CAP" ->Table 2</A ->.</TD -></TR -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->flags</CODE -></TD -><TD -> </TD -><TD ->Overlay control flags set by application and -driver, see <A -HREF="#FRAMEBUFFER-FLAGS" ->Table 3</A -></TD -></TR -><TR -><TD ->void *</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->base</CODE -></TD -><TD -> </TD -><TD -><P ->Physical base address of the frame buffer, -the address of the pixel at coordinates (0; 0) in the frame buffer. -This field is not used when <CODE -CLASS="CONSTANT" ->VIDIOC_G_FBUF</CODE -> sets -the <CODE -CLASS="CONSTANT" ->V4L2_FBUF_CAP_EXTERNOVERLAY</CODE -> flag in the -<CODE -CLASS="STRUCTFIELD" ->capability</CODE -> field.<SUP ->a</SUP -></P -></TD -></TR -><TR -><TD ->struct <A -HREF="#V4L2-PIX-FORMAT" ->v4l2_pix_format</A -></TD -><TD -><CODE -CLASS="STRUCTFIELD" ->fmt</CODE -></TD -><TD -> </TD -><TD ->Physical layout of the frame buffer. The -<CODE -CLASS="STRUCTNAME" ->v4l2_pix_format</CODE -> structure is defined in <A -HREF="#PIXFMT" ->Chapter 2</A ->, for clarification the fields and expected values -are listed below.</TD -></TR -><TR -><TD -> </TD -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->width</CODE -></TD -><TD ->Width of the frame buffer in pixels.</TD -></TR -><TR -><TD -> </TD -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->height</CODE -></TD -><TD ->Height of the frame buffer in pixels. When the -driver <SPAN -CLASS="emphasis" -><I -CLASS="EMPHASIS" ->clears</I -></SPAN -> -<CODE -CLASS="CONSTANT" ->V4L2_FBUF_CAP_EXTERNOVERLAY</CODE ->, the visible portion -of the frame buffer can be smaller than width and height.</TD -></TR -><TR -><TD -> </TD -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->pixelformat</CODE -></TD -><TD ->The pixel format of the graphics surface, set by -the application. Usually this is an RGB format (for example RGB 5:6:5) -but YUV formats are also permitted. The behavior of the driver when -requesting a compressed format is undefined. See <A -HREF="#PIXFMT" ->Chapter 2</A -> for information on pixel formats. This field is not -used when the driver sets -<CODE -CLASS="CONSTANT" ->V4L2_FBUF_CAP_EXTERNOVERLAY</CODE ->.</TD -></TR -><TR -><TD -> </TD -><TD ->enum <A -HREF="#V4L2-FIELD" ->v4l2_field</A -></TD -><TD -><CODE -CLASS="STRUCTFIELD" ->field</CODE -></TD -><TD ->Ignored. The field order is selected with the -<A -HREF="#VIDIOC-G-FMT" -><CODE -CLASS="CONSTANT" ->VIDIOC_S_FMT</CODE -></A -> ioctl using struct <A -HREF="#V4L2-WINDOW" ->v4l2_window</A ->.</TD -></TR -><TR -><TD -> </TD -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->bytesperline</CODE -></TD -><TD ->Distance in bytes between the leftmost pixels in two -adjacent lines.</TD -></TR -><TR -><TD -COLSPAN="4" -><P ->Both applications and drivers -can set this field to request padding bytes at the end of each line. -Drivers however may ignore the value requested by the application, -returning <CODE -CLASS="STRUCTFIELD" ->width</CODE -> times bytes per pixel or a -larger value required by the hardware. That implies applications can -just set this field to zero to get a reasonable -default.</P -><P ->Video hardware may access padding bytes, -therefore they must reside in accessible memory. Consider cases where -padding bytes after the last line of an image cross a system page -boundary. Input devices may write padding bytes, the value is -undefined. Output devices ignore the contents of padding -bytes.</P -><P ->When the image format is planar the -<CODE -CLASS="STRUCTFIELD" ->bytesperline</CODE -> value applies to the largest -plane and is divided by the same factor as the -<CODE -CLASS="STRUCTFIELD" ->width</CODE -> field for any smaller planes. For -example the Cb and Cr planes of a YUV 4:2:0 image have half as many -padding bytes following each line as the Y plane. To avoid ambiguities -drivers must return a <CODE -CLASS="STRUCTFIELD" ->bytesperline</CODE -> value -rounded up to a multiple of the scale factor.</P -><P ->This -field is not used when the driver sets -<CODE -CLASS="CONSTANT" ->V4L2_FBUF_CAP_EXTERNOVERLAY</CODE ->.</P -></TD -></TR -><TR -><TD -> </TD -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->sizeimage</CODE -></TD -><TD -><P ->Applications must initialize this field. -Together with <CODE -CLASS="STRUCTFIELD" ->base</CODE -> it defines the frame -buffer memory accessible by the driver.</P -><P ->The field is not -used when the driver sets -<CODE -CLASS="CONSTANT" ->V4L2_FBUF_CAP_EXTERNOVERLAY</CODE ->.</P -></TD -></TR -><TR -><TD -> </TD -><TD ->enum <A -HREF="#V4L2-COLORSPACE" ->v4l2_colorspace</A -></TD -><TD -><CODE -CLASS="STRUCTFIELD" ->colorspace</CODE -></TD -><TD ->This information supplements the -<CODE -CLASS="STRUCTFIELD" ->pixelformat</CODE -> and must be set by the driver, -see <A -HREF="#COLORSPACES" ->Section 2.2</A ->.</TD -></TR -><TR -><TD -> </TD -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->priv</CODE -></TD -><TD ->Reserved for additional information about custom -(driver defined) formats. When not used drivers and applications must -set this field to zero.</TD -></TR -></TBODY -><TR -><TD -COLSPAN="4" ->Notes:<BR><A -NAME="FTN.AEN6588" ->a. </A ->A -physical base address may not suit all platforms. GK notes in theory -we should pass something like PCI device + memory region + offset -instead. If you encounter problems please discuss on the Video4Linux -mailing list: <A -HREF="https://listman.redhat.com/mailman/listinfo/video4linux-list" -TARGET="_top" ->https://listman.redhat.com/mailman/listinfo/video4linux-list</A ->.<BR></TD -></TR -></TABLE -></DIV -><DIV -CLASS="TABLE" -><A -NAME="FRAMEBUFFER-CAP" -></A -><P -><B ->Table 2. Frame Buffer Capability Flags</B -></P -><TABLE -BORDER="0" -FRAME="void" -WIDTH="100%" -CLASS="CALSTABLE" -><COL -WIDTH="38%" -TITLE="C1"><COL -WIDTH="12%" -TITLE="C2"><COL -WIDTH="50%" -TITLE="C3"><TBODY -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_FBUF_CAP_EXTERNOVERLAY</CODE -></TD -><TD ->0x0001</TD -><TD ->The video is overlaid externally onto the -video signal of the graphics card.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_FBUF_CAP_CHROMAKEY</CODE -></TD -><TD ->0x0002</TD -><TD ->The device supports clipping by chroma-keying the -image into the display.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_FBUF_CAP_LIST_CLIPPING</CODE -></TD -><TD ->0x0004</TD -><TD ->The device supports clipping using a list of clip -rectangles.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_FBUF_CAP_BITMAP_CLIPPING</CODE -></TD -><TD ->0x0008</TD -><TD ->The device supports clipping using a bit mask.</TD -></TR -></TBODY -></TABLE -></DIV -><DIV -CLASS="TABLE" -><A -NAME="FRAMEBUFFER-FLAGS" -></A -><P -><B ->Table 3. Frame Buffer Flags</B -></P -><TABLE -BORDER="0" -FRAME="void" -WIDTH="100%" -CLASS="CALSTABLE" -><COL -WIDTH="38%" -TITLE="C1"><COL -WIDTH="12%" -TITLE="C2"><COL -WIDTH="50%" -TITLE="C3"><TBODY -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_FBUF_FLAG_PRIMARY</CODE -></TD -><TD ->0x0001</TD -><TD ->The frame buffer is the primary graphics surface. -In other words, the overlay is destructive, the video hardware will -write the image into visible graphics memory as opposed to merely -displaying the image in place of the original display contents.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_FBUF_FLAG_OVERLAY</CODE -></TD -><TD ->0x0002</TD -><TD ->The frame buffer is an overlay surface the same -size as the capture. [?]</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_FBUF_FLAG_CHROMAKEY</CODE -></TD -><TD ->0x0004</TD -><TD ->Use chromakey (when -<CODE -CLASS="CONSTANT" ->V4L2_FBUF_CAP_CHROMAKEY</CODE -> indicates this -capability). The other clipping methods are negotiated with the -<A -HREF="#VIDIOC-G-FMT" -><CODE -CLASS="CONSTANT" ->VIDIOC_S_FMT</CODE -></A -> ioctl, see also <A -HREF="#OVERLAY" ->Section 4.2</A ->.</TD -></TR -></TBODY -></TABLE -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN6729" -></A -><H2 ->Return Value</H2 -><P ->On success <SPAN -CLASS="RETURNVALUE" ->0</SPAN -> is returned, on -error <SPAN -CLASS="RETURNVALUE" ->-1</SPAN -> and <VAR -CLASS="VARNAME" ->errno</VAR -> is -set appropriately:</P -><P -></P -><DIV -CLASS="VARIABLELIST" -><DL -><DT -><SPAN -CLASS="ERRORCODE" ->EACCES</SPAN -></DT -><DD -><P -><CODE -CLASS="CONSTANT" ->VIDIOC_S_FBUF</CODE -> can only be called -by a privileged user.</P -></DD -><DT -><SPAN -CLASS="ERRORCODE" ->EBUSY</SPAN -></DT -><DD -><P ->The frame buffer parameters cannot be changed at this -time because overlay is already enabled, or capturing is enabled -and the hardware cannot capture and overlay simultaneously.</P -></DD -><DT -><SPAN -CLASS="ERRORCODE" ->EINVAL</SPAN -></DT -><DD -><P ->The ioctl is not supported or the -<CODE -CLASS="CONSTANT" ->VIDIOC_S_FBUF</CODE -> parameters are unsuitable.</P -></DD -></DL -></DIV -></DIV -><H1 -><A -NAME="VIDIOC-G-FMT" -></A ->ioctl VIDIOC_G_FMT, VIDIOC_S_FMT, VIDIOC_TRY_FMT</H1 -><DIV -CLASS="REFNAMEDIV" -><A -NAME="AEN6756" -></A -><H2 ->Name</H2 ->ioctl VIDIOC_G_FMT, ioctl VIDIOC_S_FMT, ioctl VIDIOC_TRY_FMT -- Get or set the data format, try a format.</DIV -><DIV -CLASS="REFSYNOPSISDIV" -><A -NAME="AEN6761" -></A -><H2 ->Synopsis</H2 -><DIV -CLASS="FUNCSYNOPSIS" -><P -></P -><A -NAME="AEN6762" -></A -><P -><CODE -><CODE -CLASS="FUNCDEF" ->int ioctl</CODE ->(int fd, int request, struct v4l2_format -*argp);</CODE -></P -><P -></P -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN6772" -></A -><H2 ->Arguments</H2 -><P -></P -><DIV -CLASS="VARIABLELIST" -><DL -><DT -><VAR -CLASS="PARAMETER" ->fd</VAR -></DT -><DD -><P ->File descriptor returned by <A -HREF="#FUNC-OPEN" -><CODE -CLASS="FUNCTION" ->open()</CODE -></A ->.</P -></DD -><DT -><VAR -CLASS="PARAMETER" ->request</VAR -></DT -><DD -><P ->VIDIOC_G_FMT, VIDIOC_S_FMT, VIDIOC_TRY_FMT</P -></DD -><DT -><VAR -CLASS="PARAMETER" ->argp</VAR -></DT -><DD -><P -></P -></DD -></DL -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN6792" -></A -><H2 ->Description</H2 -><P ->These ioctls are used to negotiate the format of data -(typically image format) exchanged between driver and -application.</P -><P ->To query the current parameters applications set the -<CODE -CLASS="STRUCTFIELD" ->type</CODE -> field of a struct -<CODE -CLASS="STRUCTNAME" ->v4l2_format</CODE -> to the respective buffer (stream) -type. For example video capture devices use -<CODE -CLASS="CONSTANT" ->V4L2_BUF_TYPE_VIDEO_CAPTURE</CODE ->. When the application -calls the <CODE -CLASS="CONSTANT" ->VIDIOC_G_FMT</CODE -> ioctl with a pointer to -this structure the driver fills the respective member of the -<CODE -CLASS="STRUCTFIELD" ->fmt</CODE -> union. In case of video capture devices -that is the struct <A -HREF="#V4L2-PIX-FORMAT" ->v4l2_pix_format</A -> <CODE -CLASS="STRUCTFIELD" ->pix</CODE -> member. -When the requested buffer type is not supported drivers return an -<SPAN -CLASS="ERRORCODE" ->EINVAL</SPAN -> error code.</P -><P ->To change the current format parameters applications -initialize the <CODE -CLASS="STRUCTFIELD" ->type</CODE -> field and all -fields of the respective <CODE -CLASS="STRUCTFIELD" ->fmt</CODE -> -union member. For details see the documentation of the various devices -types in <A -HREF="#DEVICES" ->Chapter 4</A ->. Good practice is to query the -current parameters first, and to -modify only those parameters not suitable for the application. When -the application calls the <CODE -CLASS="CONSTANT" ->VIDIOC_S_FMT</CODE -> ioctl -with a pointer to a <CODE -CLASS="STRUCTNAME" ->v4l2_format</CODE -> structure -the driver checks -and adjusts the parameters against hardware abilities. Drivers -should not return an error code unless the input is ambiguous, this is -a mechanism to fathom device capabilities and to approach parameters -acceptable for both the application and driver. On success the driver -may program the hardware, allocate resources and generally prepare for -data exchange. -Finally the <CODE -CLASS="CONSTANT" ->VIDIOC_S_FMT</CODE -> ioctl returns the -current format parameters as <CODE -CLASS="CONSTANT" ->VIDIOC_G_FMT</CODE -> does. -Very simple, inflexible devices may even ignore all input and always -return the default parameters. However all V4L2 devices exchanging -data with the application must implement the -<CODE -CLASS="CONSTANT" ->VIDIOC_G_FMT</CODE -> and -<CODE -CLASS="CONSTANT" ->VIDIOC_S_FMT</CODE -> ioctl. When the requested buffer -type is not supported drivers return an <SPAN -CLASS="ERRORCODE" ->EINVAL</SPAN -> error code on a -<CODE -CLASS="CONSTANT" ->VIDIOC_S_FMT</CODE -> attempt. When I/O is already in -progress or the resource is not available for other reasons drivers -return the <SPAN -CLASS="ERRORCODE" ->EBUSY</SPAN -> error code.</P -><P ->The <CODE -CLASS="CONSTANT" ->VIDIOC_TRY_FMT</CODE -> ioctl is equivalent -to <CODE -CLASS="CONSTANT" ->VIDIOC_S_FMT</CODE -> with one exception: it does not -change driver state. It can also be called at any time, never -returning <SPAN -CLASS="ERRORCODE" ->EBUSY</SPAN ->. This function is provided to -negotiate parameters, to learn about hardware limitations, without -disabling I/O or possibly time consuming hardware preparations. -Although strongly recommended drivers are not required to implement -this ioctl.</P -><DIV -CLASS="TABLE" -><A -NAME="V4L2-FORMAT" -></A -><P -><B ->Table 1. struct <CODE -CLASS="STRUCTNAME" ->v4l2_format</CODE -></B -></P -><TABLE -BORDER="0" -FRAME="void" -WIDTH="100%" -CLASS="CALSTABLE" -><COL -WIDTH="25%" -TITLE="C1"><COL -WIDTH="25%" -TITLE="C2"><COL -WIDTH="25%" -TITLE="C3"><COL -WIDTH="25%" -TITLE="C4"><TBODY -><TR -><TD ->enum <A -HREF="#V4L2-BUF-TYPE" ->v4l2_buf_type</A -></TD -><TD -><CODE -CLASS="STRUCTFIELD" ->type</CODE -></TD -><TD -> </TD -><TD ->Type of the data stream, see <A -HREF="#V4L2-BUF-TYPE" ->Table 3-2</A ->.</TD -></TR -><TR -><TD ->union</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->fmt</CODE -></TD -><TD -> </TD -><TD -> </TD -></TR -><TR -><TD -> </TD -><TD ->struct <A -HREF="#V4L2-PIX-FORMAT" ->v4l2_pix_format</A -></TD -><TD -><CODE -CLASS="STRUCTFIELD" ->pix</CODE -></TD -><TD ->Definition of an image format, see <A -HREF="#PIXFMT" ->Chapter 2</A ->, used by video capture and output -devices.</TD -></TR -><TR -><TD -> </TD -><TD ->struct <A -HREF="#V4L2-WINDOW" ->v4l2_window</A -></TD -><TD -><CODE -CLASS="STRUCTFIELD" ->win</CODE -></TD -><TD ->Definition of an overlaid image, see <A -HREF="#OVERLAY" ->Section 4.2</A ->, used by video overlay devices.</TD -></TR -><TR -><TD -> </TD -><TD ->struct <A -HREF="#V4L2-VBI-FORMAT" ->v4l2_vbi_format</A -></TD -><TD -><CODE -CLASS="STRUCTFIELD" ->vbi</CODE -></TD -><TD ->Raw VBI capture or output parameters. This is -discussed in more detail in <A -HREF="#RAW-VBI" ->Section 4.6</A ->. Used by raw VBI -capture and output devices.</TD -></TR -><TR -><TD -> </TD -><TD ->__u8</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->raw_data</CODE ->[200]</TD -><TD ->Place holder for future extensions and custom -(driver defined) formats with <CODE -CLASS="STRUCTFIELD" ->type</CODE -> -<CODE -CLASS="CONSTANT" ->V4L2_BUF_TYPE_PRIVATE</CODE -> and higher.</TD -></TR -></TBODY -></TABLE -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN6874" -></A -><H2 ->Return Value</H2 -><P ->On success <SPAN -CLASS="RETURNVALUE" ->0</SPAN -> is returned, on -error <SPAN -CLASS="RETURNVALUE" ->-1</SPAN -> and <VAR -CLASS="VARNAME" ->errno</VAR -> is -set appropriately:</P -><P -></P -><DIV -CLASS="VARIABLELIST" -><DL -><DT -><SPAN -CLASS="ERRORCODE" ->EBUSY</SPAN -></DT -><DD -><P ->The data format cannot be changed at this -time, for example because I/O is already in progress.</P -></DD -><DT -><SPAN -CLASS="ERRORCODE" ->EINVAL</SPAN -></DT -><DD -><P ->The struct <A -HREF="#V4L2-FORMAT" ->v4l2_format</A -> <CODE -CLASS="STRUCTFIELD" ->type</CODE -> -field is invalid, the requested buffer type not supported, or -<CODE -CLASS="CONSTANT" ->VIDIOC_TRY_FMT</CODE -> was called and is not -supported with this buffer type.</P -></DD -></DL -></DIV -></DIV -><H1 -><A -NAME="VIDIOC-G-FREQUENCY" -></A ->ioctl VIDIOC_G_FREQUENCY, VIDIOC_S_FREQUENCY</H1 -><DIV -CLASS="REFNAMEDIV" -><A -NAME="AEN6897" -></A -><H2 ->Name</H2 ->ioctl VIDIOC_G_FREQUENCY, ioctl VIDIOC_S_FREQUENCY -- Get or set tuner or modulator radio -frequency</DIV -><DIV -CLASS="REFSYNOPSISDIV" -><A -NAME="AEN6901" -></A -><H2 ->Synopsis</H2 -><DIV -CLASS="FUNCSYNOPSIS" -><P -></P -><A -NAME="AEN6902" -></A -><P -><CODE -><CODE -CLASS="FUNCDEF" ->int ioctl</CODE ->(int fd, int request, struct v4l2_frequency -*argp);</CODE -></P -><P -></P -></DIV -><DIV -CLASS="FUNCSYNOPSIS" -><P -></P -><A -NAME="AEN6912" -></A -><P -><CODE -><CODE -CLASS="FUNCDEF" ->int ioctl</CODE ->(int fd, int request, const struct v4l2_frequency -*argp);</CODE -></P -><P -></P -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN6922" -></A -><H2 ->Arguments</H2 -><P -></P -><DIV -CLASS="VARIABLELIST" -><DL -><DT -><VAR -CLASS="PARAMETER" ->fd</VAR -></DT -><DD -><P ->File descriptor returned by <A -HREF="#FUNC-OPEN" -><CODE -CLASS="FUNCTION" ->open()</CODE -></A ->.</P -></DD -><DT -><VAR -CLASS="PARAMETER" ->request</VAR -></DT -><DD -><P ->VIDIOC_G_FREQUENCY, VIDIOC_S_FREQUENCY</P -></DD -><DT -><VAR -CLASS="PARAMETER" ->argp</VAR -></DT -><DD -><P -></P -></DD -></DL -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN6942" -></A -><H2 ->Description</H2 -><P ->To get the current tuner or modulator radio frequency -applications set the <CODE -CLASS="STRUCTFIELD" ->tuner</CODE -> field of a -struct <A -HREF="#V4L2-FREQUENCY" ->v4l2_frequency</A -> to the respective tuner or modulator number (only -input devices have tuners, only output devices have modulators), zero -out the <CODE -CLASS="STRUCTFIELD" ->reserved</CODE -> array and -call the <CODE -CLASS="CONSTANT" ->VIDIOC_G_FREQUENCY</CODE -> ioctl with a pointer -to this structure. The driver stores the current frequency in the -<CODE -CLASS="STRUCTFIELD" ->frequency</CODE -> field.</P -><P ->To change the current tuner or modulator radio frequency -applications initialize the <CODE -CLASS="STRUCTFIELD" ->tuner</CODE -> and -<CODE -CLASS="STRUCTFIELD" ->frequency</CODE -> fields, and the -<CODE -CLASS="STRUCTFIELD" ->reserved</CODE -> array of a struct <A -HREF="#V4L2-FREQUENCY" ->v4l2_frequency</A -> and -call the <CODE -CLASS="CONSTANT" ->VIDIOC_S_FREQUENCY</CODE -> ioctl with a pointer -to this structure. When the requested frequency is not possible the -driver assumes the closest possible value. However, -<CODE -CLASS="CONSTANT" ->VIDIOC_S_FREQUENCY</CODE -> is a write-only ioctl, it does -not return the actual new frequency.</P -><DIV -CLASS="TABLE" -><A -NAME="V4L2-FREQUENCY" -></A -><P -><B ->Table 1. struct <CODE -CLASS="STRUCTNAME" ->v4l2_frequency</CODE -></B -></P -><TABLE -BORDER="0" -FRAME="void" -WIDTH="100%" -CLASS="CALSTABLE" -><COL -WIDTH="25%" -TITLE="C1"><COL -WIDTH="25%" -TITLE="C2"><COL -WIDTH="50%" -TITLE="C3"><TBODY -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->tuner</CODE -></TD -><TD ->The tuner or modulator index number. This is the -same value as in the struct <A -HREF="#V4L2-INPUT" ->v4l2_input</A -> <CODE -CLASS="STRUCTFIELD" ->tuner</CODE -> -field and the struct <A -HREF="#V4L2-TUNER" ->v4l2_tuner</A -> <CODE -CLASS="STRUCTFIELD" ->index</CODE -> field, or -the struct <A -HREF="#V4L2-OUTPUT" ->v4l2_output</A -> <CODE -CLASS="STRUCTFIELD" ->modulator</CODE -> field and the -struct <A -HREF="#V4L2-MODULATOR" ->v4l2_modulator</A -> <CODE -CLASS="STRUCTFIELD" ->index</CODE -> field.</TD -></TR -><TR -><TD ->enum <A -HREF="#V4L2-TUNER-TYPE" ->v4l2_tuner_type</A -></TD -><TD -><CODE -CLASS="STRUCTFIELD" ->type</CODE -></TD -><TD ->The tuner type. This is the same value as in the -struct <A -HREF="#V4L2-TUNER" ->v4l2_tuner</A -> <CODE -CLASS="STRUCTFIELD" ->type</CODE -> field. The field is not -applicable to modulators, i. e. ignored by drivers.</TD -></TR -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->frequency</CODE -></TD -><TD ->Tuning frequency in units of 62.5 kHz, or if the -struct <A -HREF="#V4L2-TUNER" ->v4l2_tuner</A -> or struct <A -HREF="#V4L2-MODULATOR" ->v4l2_modulator</A -> <CODE -CLASS="STRUCTFIELD" ->capabilities</CODE -> flag -<CODE -CLASS="CONSTANT" ->V4L2_TUNER_CAP_LOW</CODE -> is set, in units of 62.5 -Hz.</TD -></TR -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->reserved</CODE ->[8];</TD -><TD ->Reserved for future extensions. Drivers and - applications must set the array to zero.</TD -></TR -></TBODY -></TABLE -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN7001" -></A -><H2 ->Return Value</H2 -><P ->On success <SPAN -CLASS="RETURNVALUE" ->0</SPAN -> is returned, on -error <SPAN -CLASS="RETURNVALUE" ->-1</SPAN -> and <VAR -CLASS="VARNAME" ->errno</VAR -> is -set appropriately:</P -><P -></P -><DIV -CLASS="VARIABLELIST" -><DL -><DT -><SPAN -CLASS="ERRORCODE" ->EINVAL</SPAN -></DT -><DD -><P ->The <CODE -CLASS="STRUCTFIELD" ->tuner</CODE -> field is out of -bounds.</P -></DD -></DL -></DIV -></DIV -><H1 -><A -NAME="VIDIOC-G-INPUT" -></A ->ioctl VIDIOC_G_INPUT, VIDIOC_S_INPUT</H1 -><DIV -CLASS="REFNAMEDIV" -><A -NAME="AEN7017" -></A -><H2 ->Name</H2 ->ioctl VIDIOC_G_INPUT, ioctl VIDIOC_S_INPUT -- Query or select the current video input</DIV -><DIV -CLASS="REFSYNOPSISDIV" -><A -NAME="AEN7021" -></A -><H2 ->Synopsis</H2 -><DIV -CLASS="FUNCSYNOPSIS" -><P -></P -><A -NAME="AEN7022" -></A -><P -><CODE -><CODE -CLASS="FUNCDEF" ->int ioctl</CODE ->(int fd, int request, int *argp);</CODE -></P -><P -></P -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN7032" -></A -><H2 ->Arguments</H2 -><P -></P -><DIV -CLASS="VARIABLELIST" -><DL -><DT -><VAR -CLASS="PARAMETER" ->fd</VAR -></DT -><DD -><P ->File descriptor returned by <A -HREF="#FUNC-OPEN" -><CODE -CLASS="FUNCTION" ->open()</CODE -></A ->.</P -></DD -><DT -><VAR -CLASS="PARAMETER" ->request</VAR -></DT -><DD -><P ->VIDIOC_G_INPUT, VIDIOC_S_INPUT</P -></DD -><DT -><VAR -CLASS="PARAMETER" ->argp</VAR -></DT -><DD -><P -></P -></DD -></DL -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN7052" -></A -><H2 ->Description</H2 -><P ->To query the current video input applications call the -<CODE -CLASS="CONSTANT" ->VIDIOC_G_INPUT</CODE -> ioctl with a pointer to an integer -where the driver stores the number of the input, as in the -struct <A -HREF="#V4L2-INPUT" ->v4l2_input</A -> <CODE -CLASS="STRUCTFIELD" ->index</CODE -> field. This ioctl will -fail only when there are no video inputs, returning -<SPAN -CLASS="ERRORCODE" ->EINVAL</SPAN ->.</P -><P ->To select a video input applications store the number of the -desired input in an integer and call the -<CODE -CLASS="CONSTANT" ->VIDIOC_S_INPUT</CODE -> ioctl with a pointer to this -integer. Side effects are possible. For example inputs may support -different video standards, so the driver may implicitly switch the -current standard. It is good practice to select an input before -querying or negotiating any other parameters.</P -><P ->Information about video inputs is available using the -<A -HREF="#VIDIOC-ENUMINPUT" -><CODE -CLASS="CONSTANT" ->VIDIOC_ENUMINPUT</CODE -></A -> ioctl.</P -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN7064" -></A -><H2 ->Return Value</H2 -><P ->On success <SPAN -CLASS="RETURNVALUE" ->0</SPAN -> is returned, on -error <SPAN -CLASS="RETURNVALUE" ->-1</SPAN -> and <VAR -CLASS="VARNAME" ->errno</VAR -> is -set appropriately:</P -><P -></P -><DIV -CLASS="VARIABLELIST" -><DL -><DT -><SPAN -CLASS="ERRORCODE" ->EINVAL</SPAN -></DT -><DD -><P ->The number of the video input is out of bounds, or -there are no video inputs at all and this ioctl is not -supported.</P -></DD -><DT -><SPAN -CLASS="ERRORCODE" ->EBUSY</SPAN -></DT -><DD -><P ->I/O is in progress, the input cannot be -switched.</P -></DD -></DL -></DIV -></DIV -><H1 -><A -NAME="VIDIOC-G-JPEGCOMP" -></A ->ioctl VIDIOC_G_JPEGCOMP, VIDIOC_S_JPEGCOMP</H1 -><DIV -CLASS="REFNAMEDIV" -><A -NAME="AEN7084" -></A -><H2 ->Name</H2 ->ioctl VIDIOC_G_JPEGCOMP, ioctl VIDIOC_S_JPEGCOMP -- </DIV -><DIV -CLASS="REFSYNOPSISDIV" -><A -NAME="AEN7088" -></A -><H2 ->Synopsis</H2 -><DIV -CLASS="FUNCSYNOPSIS" -><P -></P -><A -NAME="AEN7089" -></A -><P -><CODE -><CODE -CLASS="FUNCDEF" ->int ioctl</CODE ->(int fd, int request, v4l2_jpegcompression *argp);</CODE -></P -><P -></P -></DIV -><DIV -CLASS="FUNCSYNOPSIS" -><P -></P -><A -NAME="AEN7099" -></A -><P -><CODE -><CODE -CLASS="FUNCDEF" ->int ioctl</CODE ->(int fd, int request, const v4l2_jpegcompression *argp);</CODE -></P -><P -></P -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN7109" -></A -><H2 ->Arguments</H2 -><P -></P -><DIV -CLASS="VARIABLELIST" -><DL -><DT -><VAR -CLASS="PARAMETER" ->fd</VAR -></DT -><DD -><P ->File descriptor returned by <A -HREF="#FUNC-OPEN" -><CODE -CLASS="FUNCTION" ->open()</CODE -></A ->.</P -></DD -><DT -><VAR -CLASS="PARAMETER" ->request</VAR -></DT -><DD -><P ->VIDIOC_G_JPEGCOMP, VIDIOC_S_JPEGCOMP</P -></DD -><DT -><VAR -CLASS="PARAMETER" ->argp</VAR -></DT -><DD -><P -></P -></DD -></DL -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN7129" -></A -><H2 ->Description</H2 -><P ->[to do]</P -><P ->Ronald Bultje elaborates:</P -><P ->APP is some application-specific information. The -application can set it itself, and it'll be stored in the JPEG-encoded -fields (e.g. interlacing information for in an AVI or so). COM is the -same, but it's comments, like 'encoded by me' or so.</P -><P ->jpeg_markers describes whether the huffman tables, -quantization tables and the restart interval information (all -JPEG-specific stuff) should be stored in the JPEG-encoded fields. -These define how the JPEG field is encoded. If you omit them, -applications assume you've used standard encoding. You usually do want -to add them.</P -><P -CLASS="COMMENT" ->NB VIDIOC_S_JPEGCOMP is w/o.</P -><DIV -CLASS="TABLE" -><A -NAME="V4L2-JPEGCOMPRESSION" -></A -><P -><B ->Table 1. struct <CODE -CLASS="STRUCTNAME" ->v4l2_jpegcompression</CODE -></B -></P -><TABLE -BORDER="0" -FRAME="void" -WIDTH="100%" -CLASS="CALSTABLE" -><COL -WIDTH="25%" -TITLE="C1"><COL -WIDTH="25%" -TITLE="C2"><COL -WIDTH="50%" -TITLE="C3"><TBODY -><TR -><TD ->int</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->quality</CODE -></TD -><TD -> </TD -></TR -><TR -><TD ->int</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->APPn</CODE -></TD -><TD -> </TD -></TR -><TR -><TD ->int</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->APP_len</CODE -></TD -><TD -> </TD -></TR -><TR -><TD ->char</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->APP_data</CODE ->[60]</TD -><TD -> </TD -></TR -><TR -><TD ->int</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->COM_len</CODE -></TD -><TD -> </TD -></TR -><TR -><TD ->char</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->COM_data</CODE ->[60]</TD -><TD -> </TD -></TR -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->jpeg_markers</CODE -></TD -><TD ->See <A -HREF="#JPEG-MARKERS" ->Table 2</A ->.</TD -></TR -></TBODY -></TABLE -></DIV -><DIV -CLASS="TABLE" -><A -NAME="JPEG-MARKERS" -></A -><P -><B ->Table 2. JPEG Markers Flags</B -></P -><TABLE -BORDER="0" -FRAME="void" -WIDTH="100%" -CLASS="CALSTABLE" -><COL -WIDTH="38%" -TITLE="C1"><COL -WIDTH="12%" -TITLE="C2"><COL -WIDTH="50%" -TITLE="C3"><TBODY -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_JPEG_MARKER_DHT</CODE -></TD -><TD ->(1<<3)</TD -><TD ->Define Huffman Tables</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_JPEG_MARKER_DQT</CODE -></TD -><TD ->(1<<4)</TD -><TD ->Define Quantization Tables</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_JPEG_MARKER_DRI</CODE -></TD -><TD ->(1<<5)</TD -><TD ->Define Restart Interval</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_JPEG_MARKER_COM</CODE -></TD -><TD ->(1<<6)</TD -><TD ->Comment segment</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_JPEG_MARKER_APP</CODE -></TD -><TD ->(1<<7)</TD -><TD ->App segment, driver will always use APP0</TD -></TR -></TBODY -></TABLE -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN7214" -></A -><H2 ->Return Value</H2 -><P ->On success <SPAN -CLASS="RETURNVALUE" ->0</SPAN -> is returned, on -error <SPAN -CLASS="RETURNVALUE" ->-1</SPAN -> and <VAR -CLASS="VARNAME" ->errno</VAR -> is -set appropriately:</P -><P -></P -><DIV -CLASS="VARIABLELIST" -><DL -><DT -><SPAN -CLASS="ERRORCODE" ->EINVAL</SPAN -></DT -><DD -><P ->This ioctl is not supported.</P -></DD -></DL -></DIV -></DIV -><H1 -><A -NAME="VIDIOC-G-MODULATOR" -></A ->ioctl VIDIOC_G_MODULATOR, VIDIOC_S_MODULATOR</H1 -><DIV -CLASS="REFNAMEDIV" -><A -NAME="AEN7229" -></A -><H2 ->Name</H2 ->ioctl VIDIOC_G_MODULATOR, ioctl VIDIOC_S_MODULATOR -- Get or set modulator attributes</DIV -><DIV -CLASS="REFSYNOPSISDIV" -><A -NAME="AEN7233" -></A -><H2 ->Synopsis</H2 -><DIV -CLASS="FUNCSYNOPSIS" -><P -></P -><A -NAME="AEN7234" -></A -><P -><CODE -><CODE -CLASS="FUNCDEF" ->int ioctl</CODE ->(int fd, int request, struct v4l2_modulator -*argp);</CODE -></P -><P -></P -></DIV -><DIV -CLASS="FUNCSYNOPSIS" -><P -></P -><A -NAME="AEN7244" -></A -><P -><CODE -><CODE -CLASS="FUNCDEF" ->int ioctl</CODE ->(int fd, int request, const struct v4l2_modulator -*argp);</CODE -></P -><P -></P -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN7254" -></A -><H2 ->Arguments</H2 -><P -></P -><DIV -CLASS="VARIABLELIST" -><DL -><DT -><VAR -CLASS="PARAMETER" ->fd</VAR -></DT -><DD -><P ->File descriptor returned by <A -HREF="#FUNC-OPEN" -><CODE -CLASS="FUNCTION" ->open()</CODE -></A ->.</P -></DD -><DT -><VAR -CLASS="PARAMETER" ->request</VAR -></DT -><DD -><P ->VIDIOC_G_MODULATOR, VIDIOC_S_MODULATOR</P -></DD -><DT -><VAR -CLASS="PARAMETER" ->argp</VAR -></DT -><DD -><P -></P -></DD -></DL -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN7274" -></A -><H2 ->Description</H2 -><P ->To query the attributes of a modulator applications initialize -the <CODE -CLASS="STRUCTFIELD" ->index</CODE -> field and zero out the -<CODE -CLASS="STRUCTFIELD" ->reserved</CODE -> array of a struct <A -HREF="#V4L2-MODULATOR" ->v4l2_modulator</A -> and -call the <CODE -CLASS="CONSTANT" ->VIDIOC_G_MODULATOR</CODE -> ioctl with a pointer -to this structure. Drivers fill the rest of the structure or return an -<SPAN -CLASS="ERRORCODE" ->EINVAL</SPAN -> error code when the index is out of bounds. To enumerate all modulators -applications shall begin at index zero, incrementing by one until the -driver returns <SPAN -CLASS="ERRORCODE" ->EINVAL</SPAN ->.</P -><P ->Modulators have two writable properties, an audio -modulation set and the radio frequency. To change the modulated audio -subprograms, applications initialize the <CODE -CLASS="STRUCTFIELD" ->index</CODE -> and <CODE -CLASS="STRUCTFIELD" ->txsubchans</CODE -> fields and the -<CODE -CLASS="STRUCTFIELD" ->reserved</CODE -> array and call the -<CODE -CLASS="CONSTANT" ->VIDIOC_S_MODULATOR</CODE -> ioctl. Drivers may choose a -different audio modulation if the request cannot be satisfied. However -this is a write-only ioctl, it does not return the actual audio -modulation selected.</P -><P ->To change the radio frequency the <A -HREF="#VIDIOC-G-FREQUENCY" -><CODE -CLASS="CONSTANT" ->VIDIOC_S_FREQUENCY</CODE -></A -> ioctl -is available.</P -><DIV -CLASS="TABLE" -><A -NAME="V4L2-MODULATOR" -></A -><P -><B ->Table 1. struct <CODE -CLASS="STRUCTNAME" ->v4l2_modulator</CODE -></B -></P -><TABLE -BORDER="0" -FRAME="void" -WIDTH="100%" -CLASS="CALSTABLE" -><COL -WIDTH="25%" -TITLE="C1"><COL -WIDTH="25%" -TITLE="C2"><COL -WIDTH="50%" -TITLE="C3"><TBODY -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->index</CODE -></TD -><TD ->Identifies the modulator, set by the -application.</TD -></TR -><TR -><TD ->__u8</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->name</CODE ->[32]</TD -><TD ->Name of the modulator, a NUL-terminated ASCII -string. This information is intended for the user.</TD -></TR -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->capability</CODE -></TD -><TD ->Modulator capability flags. No flags are defined -for this field, the tuner flags in struct <A -HREF="#V4L2-TUNER" ->v4l2_tuner</A -> -are used accordingly. The audio flags indicate the ability -to encode audio subprograms. They will <SPAN -CLASS="emphasis" -><I -CLASS="EMPHASIS" ->not</I -></SPAN -> -change for example with the current video standard.</TD -></TR -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->rangelow</CODE -></TD -><TD ->The lowest tunable frequency in units of 62.5 -KHz, or if the <CODE -CLASS="STRUCTFIELD" ->capability</CODE -> flag -<CODE -CLASS="CONSTANT" ->V4L2_TUNER_CAP_LOW</CODE -> is set, in units of 62.5 -Hz.</TD -></TR -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->rangehigh</CODE -></TD -><TD ->The highest tunable frequency in units of 62.5 -KHz, or if the <CODE -CLASS="STRUCTFIELD" ->capability</CODE -> flag -<CODE -CLASS="CONSTANT" ->V4L2_TUNER_CAP_LOW</CODE -> is set, in units of 62.5 -Hz.</TD -></TR -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->txsubchans</CODE -></TD -><TD ->With this field applications can determine how -audio sub-carriers shall be modulated. It contains a set of flags as -defined in <A -HREF="#MODULATOR-TXSUBCHANS" ->Table 2</A ->. Note the tuner -<CODE -CLASS="STRUCTFIELD" ->rxsubchans</CODE -> flags are reused, but the -semantics are different. Video output devices are assumed to have an -analog or PCM audio input with 1-3 channels. The -<CODE -CLASS="STRUCTFIELD" ->txsubchans</CODE -> flags select one or more -channels for modulation, together with some audio subprogram -indicator, for example a stereo pilot tone.</TD -></TR -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->reserved</CODE ->[4]</TD -><TD ->Reserved for future extensions. Drivers and -applications must set the array to zero.</TD -></TR -></TBODY -></TABLE -></DIV -><DIV -CLASS="TABLE" -><A -NAME="MODULATOR-TXSUBCHANS" -></A -><P -><B ->Table 2. Modulator Audio Transmission Flags</B -></P -><TABLE -BORDER="0" -FRAME="void" -WIDTH="100%" -CLASS="CALSTABLE" -><COL -WIDTH="38%" -TITLE="C1"><COL -WIDTH="12%" -TITLE="C2"><COL -WIDTH="50%" -TITLE="C3"><TBODY -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_TUNER_SUB_MONO</CODE -></TD -><TD ->0x0001</TD -><TD ->Modulate channel 1 as mono audio, when the input -has more channels, a down-mix of channel 1 and 2. This flag does not -combine with <CODE -CLASS="CONSTANT" ->V4L2_TUNER_SUB_STEREO</CODE -> or -<CODE -CLASS="CONSTANT" ->V4L2_TUNER_SUB_LANG1</CODE ->.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_TUNER_SUB_STEREO</CODE -></TD -><TD ->0x0002</TD -><TD ->Modulate channel 1 and 2 as left and right -channel of a stereo audio signal. When the input has only one channel -or two channels and <CODE -CLASS="CONSTANT" ->V4L2_TUNER_SUB_SAP</CODE -> is also -set, channel 1 is encoded as left and right channel. This flag does -not combine with <CODE -CLASS="CONSTANT" ->V4L2_TUNER_SUB_MONO </CODE -> or -<CODE -CLASS="CONSTANT" ->V4L2_TUNER_SUB_LANG1</CODE ->. When the driver does not -support stereo audio it shall fall back to mono.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_TUNER_SUB_LANG1</CODE -></TD -><TD ->0x0008</TD -><TD ->Modulate channel 1 and 2 as primary and secondary -language of a bilingual audio signal. When the input has only one -channel it is used for both languages. It is not possible to encode -the primary or secondary language only. This flag does not combine -with <CODE -CLASS="CONSTANT" ->V4L2_TUNER_SUB_MONO </CODE -> or -<CODE -CLASS="CONSTANT" ->V4L2_TUNER_SUB_STEREO</CODE ->. If the hardware does not -support the respective audio matrix, or the current video standard -does not permit bilingual audio the -<CODE -CLASS="CONSTANT" ->VIDIOC_S_MODULATOR</CODE -> ioctl shall return an <SPAN -CLASS="ERRORCODE" ->EINVAL</SPAN -> error code -and the driver shall fall back to mono or stereo mode. -<A -HREF="#FTN.TUNER-AUDIO-CAP" -><SPAN -CLASS="footnote" ->[a]</SPAN -></A -></TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_TUNER_SUB_LANG2</CODE -></TD -><TD ->0x0004</TD -><TD ->Same effect as -<CODE -CLASS="CONSTANT" ->V4L2_TUNER_SUB_LANG1</CODE ->. -<A -HREF="#FTN.TUNER-AUDIO-CAP" -><SPAN -CLASS="footnote" ->[a]</SPAN -></A -></TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_TUNER_SUB_SAP</CODE -></TD -><TD ->0x0004</TD -><TD ->When combined with <CODE -CLASS="CONSTANT" ->V4L2_TUNER_SUB_MONO</CODE -> the first channel is encoded as mono audio, the last -channel as Second Audio Program. When the input has only one channel -it is used for both audio tracks. When the input has three channels -the mono track is a down-mix of channel 1 and 2. When combined with -<CODE -CLASS="CONSTANT" ->V4L2_TUNER_SUB_STEREO </CODE -> channel 1 and 2 are -encoded as left and right stereo audio, channel 3 as Second Audio -Program. When the input has only two channels, the first is encoded as -left and right channel and the second as SAP. When the input has only -one channel it is used for all audio tracks. It is not possible to -encode a Second Audio Program only. This flag must combine with -<CODE -CLASS="CONSTANT" ->V4L2_TUNER_SUB_MONO</CODE -> or -<CODE -CLASS="CONSTANT" ->V4L2_TUNER_SUB_STEREO</CODE ->. If the hardware does not -support the respective audio matrix, or the current video standard -does not permit SAP the <CODE -CLASS="CONSTANT" -> VIDIOC_S_MODULATOR</CODE -> ioctl -shall return an <SPAN -CLASS="ERRORCODE" ->EINVAL</SPAN -> error code and driver shall fall back to mono or stereo -mode.<A -HREF="#FTN.TUNER-AUDIO-CAP" -><SPAN -CLASS="footnote" ->[a]</SPAN -></A -></TD -></TR -></TBODY -></TABLE -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN7396" -></A -><H2 ->Return Value</H2 -><P ->On success 0 is returned, on error -1 and -<VAR -CLASS="VARNAME" ->errno</VAR -> is set appropriately:</P -><P -></P -><DIV -CLASS="VARIABLELIST" -><DL -><DT -><SPAN -CLASS="ERRORCODE" ->EINVAL</SPAN -></DT -><DD -><P ->The struct <A -HREF="#V4L2-MODULATOR" ->v4l2_modulator</A -> -<CODE -CLASS="STRUCTFIELD" ->index</CODE -> is out of bounds.</P -></DD -></DL -></DIV -></DIV -><H1 -><A -NAME="VIDIOC-G-OUTPUT" -></A ->ioctl VIDIOC_G_OUTPUT, VIDIOC_S_OUTPUT</H1 -><DIV -CLASS="REFNAMEDIV" -><A -NAME="AEN7411" -></A -><H2 ->Name</H2 ->ioctl VIDIOC_G_OUTPUT, ioctl VIDIOC_S_OUTPUT -- Query or select the current video output</DIV -><DIV -CLASS="REFSYNOPSISDIV" -><A -NAME="AEN7415" -></A -><H2 ->Synopsis</H2 -><DIV -CLASS="FUNCSYNOPSIS" -><P -></P -><A -NAME="AEN7416" -></A -><P -><CODE -><CODE -CLASS="FUNCDEF" ->int ioctl</CODE ->(int fd, int request, int *argp);</CODE -></P -><P -></P -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN7426" -></A -><H2 ->Arguments</H2 -><P -></P -><DIV -CLASS="VARIABLELIST" -><DL -><DT -><VAR -CLASS="PARAMETER" ->fd</VAR -></DT -><DD -><P ->File descriptor returned by <A -HREF="#FUNC-OPEN" -><CODE -CLASS="FUNCTION" ->open()</CODE -></A ->.</P -></DD -><DT -><VAR -CLASS="PARAMETER" ->request</VAR -></DT -><DD -><P ->VIDIOC_G_OUTPUT, VIDIOC_S_OUTPUT</P -></DD -><DT -><VAR -CLASS="PARAMETER" ->argp</VAR -></DT -><DD -><P -></P -></DD -></DL -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN7446" -></A -><H2 ->Description</H2 -><P ->To query the current video output applications call the -<CODE -CLASS="CONSTANT" ->VIDIOC_G_OUTPUT</CODE -> ioctl with a pointer to an integer -where the driver stores the number of the output, as in the -struct <A -HREF="#V4L2-OUTPUT" ->v4l2_output</A -> <CODE -CLASS="STRUCTFIELD" ->index</CODE -> field. This ioctl -will fail only when there are no video outputs, returning the -<SPAN -CLASS="ERRORCODE" ->EINVAL</SPAN -> error code.</P -><P ->To select a video output applications store the number of the -desired output in an integer and call the -<CODE -CLASS="CONSTANT" ->VIDIOC_S_OUTPUT</CODE -> ioctl with a pointer to this integer. -Side effects are possible. For example outputs may support different -video standards, so the driver may implicitly switch the current -standard. It is good practice to select an output before querying or -negotiating any other parameters.</P -><P ->Information about video outputs is available using the -<A -HREF="#VIDIOC-ENUMOUTPUT" -><CODE -CLASS="CONSTANT" ->VIDIOC_ENUMOUTPUT</CODE -></A -> ioctl.</P -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN7458" -></A -><H2 ->Return Value</H2 -><P ->On success <SPAN -CLASS="RETURNVALUE" ->0</SPAN -> is returned, on -error <SPAN -CLASS="RETURNVALUE" ->-1</SPAN -> and <VAR -CLASS="VARNAME" ->errno</VAR -> is -set appropriately:</P -><P -></P -><DIV -CLASS="VARIABLELIST" -><DL -><DT -><SPAN -CLASS="ERRORCODE" ->EINVAL</SPAN -></DT -><DD -><P ->The number of the video output is out of bounds, or -there are no video outputs at all and this ioctl is not -supported.</P -></DD -><DT -><SPAN -CLASS="ERRORCODE" ->EBUSY</SPAN -></DT -><DD -><P ->I/O is in progress, the output cannot be -switched.</P -></DD -></DL -></DIV -></DIV -><H1 -><A -NAME="VIDIOC-G-PARM" -></A ->ioctl VIDIOC_G_PARM, VIDIOC_S_PARM</H1 -><DIV -CLASS="REFNAMEDIV" -><A -NAME="AEN7478" -></A -><H2 ->Name</H2 ->ioctl VIDIOC_G_PARM, ioctl VIDIOC_S_PARM -- Get or set streaming parameters</DIV -><DIV -CLASS="REFSYNOPSISDIV" -><A -NAME="AEN7482" -></A -><H2 ->Synopsis</H2 -><DIV -CLASS="FUNCSYNOPSIS" -><P -></P -><A -NAME="AEN7483" -></A -><P -><CODE -><CODE -CLASS="FUNCDEF" ->int ioctl</CODE ->(int fd, int request, v4l2_streamparm *argp);</CODE -></P -><P -></P -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN7493" -></A -><H2 ->Arguments</H2 -><P -></P -><DIV -CLASS="VARIABLELIST" -><DL -><DT -><VAR -CLASS="PARAMETER" ->fd</VAR -></DT -><DD -><P ->File descriptor returned by <A -HREF="#FUNC-OPEN" -><CODE -CLASS="FUNCTION" ->open()</CODE -></A ->.</P -></DD -><DT -><VAR -CLASS="PARAMETER" ->request</VAR -></DT -><DD -><P ->VIDIOC_G_PARM, VIDIOC_S_PARM</P -></DD -><DT -><VAR -CLASS="PARAMETER" ->argp</VAR -></DT -><DD -><P -></P -></DD -></DL -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN7513" -></A -><H2 ->Description</H2 -><P ->[to do]</P -><P -><CODE -CLASS="CONSTANT" ->VIDIOC_S_PARM</CODE -> is a write-only ioctl, - it does not return the actual parameters.</P -><DIV -CLASS="TABLE" -><A -NAME="V4L2-STREAMPARM" -></A -><P -><B ->Table 1. struct <CODE -CLASS="STRUCTNAME" ->v4l2_streamparm</CODE -></B -></P -><TABLE -BORDER="0" -FRAME="void" -WIDTH="100%" -CLASS="CALSTABLE" -><COL -WIDTH="50%" -TITLE="C1"><COL><COL><TBODY -><TR -><TD ->enum <A -HREF="#V4L2-BUF-TYPE" ->v4l2_buf_type</A -></TD -><TD -><CODE -CLASS="STRUCTFIELD" ->type</CODE -></TD -><TD -> </TD -><TD ->The buffer (stream) type, same as struct <A -HREF="#V4L2-FORMAT" ->v4l2_format</A -> -<CODE -CLASS="STRUCTFIELD" ->type</CODE ->, set by the application.</TD -></TR -><TR -><TD ->union</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->parm</CODE -></TD -><TD -> </TD -><TD -> </TD -></TR -><TR -><TD -> </TD -><TD ->struct <A -HREF="#V4L2-CAPTUREPARM" ->v4l2_captureparm</A -></TD -><TD -><CODE -CLASS="STRUCTFIELD" ->capture</CODE -></TD -><TD ->Parameters for capture devices, used when -<CODE -CLASS="STRUCTFIELD" ->type</CODE -> is -<CODE -CLASS="CONSTANT" ->V4L2_BUF_TYPE_VIDEO_CAPTURE</CODE ->.</TD -></TR -><TR -><TD -> </TD -><TD ->struct <A -HREF="#V4L2-OUTPUTPARM" ->v4l2_outputparm</A -></TD -><TD -><CODE -CLASS="STRUCTFIELD" ->output</CODE -></TD -><TD ->Parameters for output devices, used when -<CODE -CLASS="STRUCTFIELD" ->type</CODE -> is -<CODE -CLASS="CONSTANT" ->V4L2_BUF_TYPE_VIDEO_OUTPUT</CODE ->.</TD -></TR -><TR -><TD -> </TD -><TD ->__u8</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->raw_data</CODE ->[200]</TD -><TD ->A place holder for future extensions and custom -(driver defined) buffer types <CODE -CLASS="CONSTANT" ->V4L2_BUF_TYPE_PRIVATE</CODE -> and -higher.</TD -></TR -></TBODY -></TABLE -></DIV -><DIV -CLASS="TABLE" -><A -NAME="V4L2-CAPTUREPARM" -></A -><P -><B ->Table 2. struct <CODE -CLASS="STRUCTNAME" ->v4l2_captureparm</CODE -></B -></P -><TABLE -BORDER="0" -FRAME="void" -WIDTH="100%" -CLASS="CALSTABLE" -><COL -WIDTH="25%" -TITLE="C1"><COL -WIDTH="25%" -TITLE="C2"><COL -WIDTH="50%" -TITLE="C3"><TBODY -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->capability</CODE -></TD -><TD ->See <A -HREF="#PARM-CAPS" ->Table 4</A ->.</TD -></TR -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->capturemode</CODE -></TD -><TD ->Set by drivers and applications, see <A -HREF="#PARM-FLAGS" ->Table 5</A ->.</TD -></TR -><TR -><TD ->struct <A -HREF="#V4L2-FRACT" ->v4l2_fract</A -></TD -><TD -><CODE -CLASS="STRUCTFIELD" ->timeperframe</CODE -></TD -><TD -><P ->This is is the desired period between -successive frames captured by the driver, expressed in 0.1 µs -units. The field is intended to skip frames on the driver side, saving -I/O bandwidth.</P -><P ->Applications store here the desired frame -period, drivers return the actual frame period, which must be greater -or equal to the nominal frame period determined by the current video -standard (struct <A -HREF="#V4L2-STANDARD" ->v4l2_standard</A -> <CODE -CLASS="STRUCTFIELD" ->frameperiod</CODE -> -field). Changing the video standard (also implicitly by switching the -video input) may reset this parameter to the nominal frame period. To -reset manually applications can just set this field to -zero.</P -><P ->Drivers support this function only when they set the -<CODE -CLASS="CONSTANT" ->V4L2_CAP_TIMEPERFRAME</CODE -> flag in the -<CODE -CLASS="STRUCTFIELD" ->capability</CODE -> field.</P -></TD -></TR -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->extendedmode</CODE -></TD -><TD ->Custom (driver specific) streaming parameters. When -unused, applications and drivers must set this field to zero. -Applications using this field should check the driver name and -version, see <A -HREF="#QUERYCAP" ->Section 1.2</A ->.</TD -></TR -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->readbuffers</CODE -></TD -><TD ->Applications set this field to the desired number - of buffers used internally by the driver in <A -HREF="#FUNC-READ" -><CODE -CLASS="FUNCTION" ->read()</CODE -></A -> - mode. Drivers return the actual number of buffers. When an application requests - zero buffers, drivers should just return the current - setting rather than the minimum or an error code. For - details see <A -HREF="#RW" ->Section 3.1</A ->.</TD -></TR -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->reserved</CODE ->[4]</TD -><TD ->Reserved for future extensions. Drivers and -applications must set the array to zero.</TD -></TR -></TBODY -></TABLE -></DIV -><DIV -CLASS="TABLE" -><A -NAME="V4L2-OUTPUTPARM" -></A -><P -><B ->Table 3. struct <CODE -CLASS="STRUCTNAME" ->v4l2_outputparm</CODE -></B -></P -><TABLE -BORDER="0" -FRAME="void" -WIDTH="100%" -CLASS="CALSTABLE" -><COL -WIDTH="25%" -TITLE="C1"><COL -WIDTH="25%" -TITLE="C2"><COL -WIDTH="50%" -TITLE="C3"><TBODY -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->capability</CODE -></TD -><TD ->See <A -HREF="#PARM-CAPS" ->Table 4</A ->.</TD -></TR -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->outputmode</CODE -></TD -><TD ->Set by drivers and applications, see <A -HREF="#PARM-FLAGS" ->Table 5</A ->.</TD -></TR -><TR -><TD ->struct <A -HREF="#V4L2-FRACT" ->v4l2_fract</A -></TD -><TD -><CODE -CLASS="STRUCTFIELD" ->timeperframe</CODE -></TD -><TD ->This is is the desired period between -successive frames output by the driver, expressed in 0.1 µs -units.</TD -></TR -><TR -><TD -COLSPAN="3" -><P ->The field is intended to -repeat frames on the driver side in <A -HREF="#FUNC-WRITE" -><CODE -CLASS="FUNCTION" ->write()</CODE -></A -> mode (in streaming -mode timestamps can be used to throttle the output), saving I/O -bandwidth.</P -><P ->Applications store here the desired frame -period, drivers return the actual frame period, which must be greater -or equal to the nominal frame period determined by the current video -standard (struct <A -HREF="#V4L2-STANDARD" ->v4l2_standard</A -> <CODE -CLASS="STRUCTFIELD" ->frameperiod</CODE -> -field). Changing the video standard (also implicitly by switching the -video output) may reset this parameter to the nominal frame period. To -reset manually applications can just set this field to -zero.</P -><P ->Drivers support this function only when they set the -<CODE -CLASS="CONSTANT" ->V4L2_CAP_TIMEPERFRAME</CODE -> flag in the -<CODE -CLASS="STRUCTFIELD" ->capability</CODE -> field.</P -></TD -></TR -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->extendedmode</CODE -></TD -><TD ->Custom (driver specific) streaming parameters. When -unused, applications and drivers must set this field to zero. -Applications using this field should check the driver name and -version, see <A -HREF="#QUERYCAP" ->Section 1.2</A ->.</TD -></TR -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->writebuffers</CODE -></TD -><TD ->Applications set this field to the desired number -of buffers used internally by the driver in -<CODE -CLASS="FUNCTION" ->write()</CODE -> mode. Drivers return the actual number of -buffers. When an application requests zero buffers, drivers should -just return the current setting rather than the minimum or an error -code. For details see <A -HREF="#RW" ->Section 3.1</A ->.</TD -></TR -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->reserved</CODE ->[4]</TD -><TD ->Reserved for future extensions. Drivers and -applications must set the array to zero.</TD -></TR -></TBODY -></TABLE -></DIV -><DIV -CLASS="TABLE" -><A -NAME="PARM-CAPS" -></A -><P -><B ->Table 4. Streaming Parameters Capabilites</B -></P -><TABLE -BORDER="0" -FRAME="void" -WIDTH="100%" -CLASS="CALSTABLE" -><COL -WIDTH="38%" -TITLE="C1"><COL -WIDTH="12%" -TITLE="C2"><COL -WIDTH="50%" -TITLE="C3"><TBODY -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_CAP_TIMEPERFRAME</CODE -></TD -><TD ->0x1000</TD -><TD ->The frame skipping/repeating controlled by the -<CODE -CLASS="STRUCTFIELD" ->timeperframe</CODE -> field is supported.</TD -></TR -></TBODY -></TABLE -></DIV -><DIV -CLASS="TABLE" -><A -NAME="PARM-FLAGS" -></A -><P -><B ->Table 5. Capture Parameters Flags</B -></P -><TABLE -BORDER="0" -FRAME="void" -WIDTH="100%" -CLASS="CALSTABLE" -><COL -WIDTH="38%" -TITLE="C1"><COL -WIDTH="12%" -TITLE="C2"><COL -WIDTH="50%" -TITLE="C3"><TBODY -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_MODE_HIGHQUALITY</CODE -></TD -><TD ->0x0001</TD -><TD -><P ->High quality imaging mode. High quality mode -is intended for still imaging applications. The idea is to get the -best possible image quality that the hardware can deliver. It is not -defined how the driver writer may achieve that; it will depend on the -hardware and the ingenuity of the driver writer. High quality mode is -a different mode from the the regular motion video capture modes. In -high quality mode:<P -></P -><UL -><LI -><P ->The driver may be able to capture higher -resolutions than for motion capture.</P -></LI -><LI -><P ->The driver may support fewer pixel formats -than motion capture (e.g. true color).</P -></LI -><LI -><P ->The driver may capture and arithmetically -combine multiple successive fields or frames to remove color edge -artifacts and reduce the noise in the video data.</P -></LI -><LI -><P ->The driver may capture images in slices like -a scanner in order to handle larger format images than would otherwise -be possible. </P -></LI -><LI -><P ->An image capture operation may be -significantly slower than motion capture. </P -></LI -><LI -><P ->Moving objects in the image might have -excessive motion blur. </P -></LI -><LI -><P ->Capture might only work through the -<CODE -CLASS="FUNCTION" ->read()</CODE -> call.</P -></LI -></UL -></P -></TD -></TR -></TBODY -></TABLE -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN7719" -></A -><H2 ->Return Value</H2 -><P ->On success <SPAN -CLASS="RETURNVALUE" ->0</SPAN -> is returned, on -error <SPAN -CLASS="RETURNVALUE" ->-1</SPAN -> and <VAR -CLASS="VARNAME" ->errno</VAR -> is -set appropriately:</P -><P -></P -><DIV -CLASS="VARIABLELIST" -><DL -><DT -><SPAN -CLASS="ERRORCODE" ->EINVAL</SPAN -></DT -><DD -><P ->This ioctl is not supported.</P -></DD -></DL -></DIV -></DIV -><H1 -><A -NAME="VIDIOC-G-PRIORITY" -></A ->ioctl VIDIOC_G_PRIORITY, VIDIOC_S_PRIORITY</H1 -><DIV -CLASS="REFNAMEDIV" -><A -NAME="AEN7734" -></A -><H2 ->Name</H2 ->ioctl VIDIOC_G_PRIORITY, ioctl VIDIOC_S_PRIORITY -- Query or request the access priority associated with a -file descriptor</DIV -><DIV -CLASS="REFSYNOPSISDIV" -><A -NAME="AEN7738" -></A -><H2 ->Synopsis</H2 -><DIV -CLASS="FUNCSYNOPSIS" -><P -></P -><A -NAME="AEN7739" -></A -><P -><CODE -><CODE -CLASS="FUNCDEF" ->int ioctl</CODE ->(int fd, int request, enum v4l2_priority *argp);</CODE -></P -><P -></P -></DIV -><DIV -CLASS="FUNCSYNOPSIS" -><P -></P -><A -NAME="AEN7749" -></A -><P -><CODE -><CODE -CLASS="FUNCDEF" ->int ioctl</CODE ->(int fd, int request, const enum v4l2_priority *argp);</CODE -></P -><P -></P -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN7759" -></A -><H2 ->Arguments</H2 -><P -></P -><DIV -CLASS="VARIABLELIST" -><DL -><DT -><VAR -CLASS="PARAMETER" ->fd</VAR -></DT -><DD -><P ->File descriptor returned by <A -HREF="#FUNC-OPEN" -><CODE -CLASS="FUNCTION" ->open()</CODE -></A ->.</P -></DD -><DT -><VAR -CLASS="PARAMETER" ->request</VAR -></DT -><DD -><P ->VIDIOC_G_PRIORITY, VIDIOC_S_PRIORITY</P -></DD -><DT -><VAR -CLASS="PARAMETER" ->argp</VAR -></DT -><DD -><P ->Pointer to an enum v4l2_priority type.</P -></DD -></DL -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN7779" -></A -><H2 ->Description</H2 -><P ->To query the current access priority -applications call the <CODE -CLASS="CONSTANT" ->VIDIOC_G_PRIORITY</CODE -> ioctl -with a pointer to an enum v4l2_priority variable where the driver stores -the current priority.</P -><P ->To request an access priority applications store the -desired priority in an enum v4l2_priority variable and call -<CODE -CLASS="CONSTANT" ->VIDIOC_S_PRIORITY</CODE -> ioctl with a pointer to this -variable.</P -><DIV -CLASS="TABLE" -><A -NAME="V4L2-PRIORITY" -></A -><P -><B ->Table 1. enum v4l2_priority</B -></P -><TABLE -BORDER="0" -FRAME="void" -WIDTH="100%" -CLASS="CALSTABLE" -><COL -WIDTH="38%" -TITLE="C1"><COL -WIDTH="12%" -TITLE="C2"><COL -WIDTH="50%" -TITLE="C3"><TBODY -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_PRIORITY_UNSET</CODE -></TD -><TD ->0</TD -><TD -> </TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_PRIORITY_BACKGROUND</CODE -></TD -><TD ->1</TD -><TD ->Lowest priority, usually applications running in -background, for example monitoring VBI transmissions. A proxy -application running in user space will be necessary if multiple -applications want to read from a device at this priority.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_PRIORITY_INTERACTIVE</CODE -></TD -><TD ->2</TD -><TD -> </TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_PRIORITY_DEFAULT</CODE -></TD -><TD ->2</TD -><TD ->Medium priority, usually applications started and -interactively controlled by the user. For example TV viewers, Teletext -browsers, or just "panel" applications to change the channel or video -controls. This is the default priority unless an application requests -another.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_PRIORITY_RECORD</CODE -></TD -><TD ->3</TD -><TD ->Highest priority. Only one file descriptor can have -this priority, it blocks any other fd from changing device properties. -Usually applications which must not be interrupted, like video -recording.</TD -></TR -></TBODY -></TABLE -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN7818" -></A -><H2 ->Return Value</H2 -><P ->On success <SPAN -CLASS="RETURNVALUE" ->0</SPAN -> is returned, on -error <SPAN -CLASS="RETURNVALUE" ->-1</SPAN -> and <VAR -CLASS="VARNAME" ->errno</VAR -> is -set appropriately:</P -><P -></P -><DIV -CLASS="VARIABLELIST" -><DL -><DT -><SPAN -CLASS="ERRORCODE" ->EINVAL</SPAN -></DT -><DD -><P ->The requested priority value is invalid, or the -driver does not support access priorities.</P -></DD -><DT -><SPAN -CLASS="ERRORCODE" ->EBUSY</SPAN -></DT -><DD -><P ->Another application already requested higher -priority.</P -></DD -></DL -></DIV -></DIV -><H1 -><A -NAME="VIDIOC-G-STD" -></A ->ioctl VIDIOC_G_STD, VIDIOC_S_STD</H1 -><DIV -CLASS="REFNAMEDIV" -><A -NAME="AEN7838" -></A -><H2 ->Name</H2 ->ioctl VIDIOC_G_STD, ioctl VIDIOC_S_STD -- Query or select the video standard of the current input</DIV -><DIV -CLASS="REFSYNOPSISDIV" -><A -NAME="AEN7842" -></A -><H2 ->Synopsis</H2 -><DIV -CLASS="FUNCSYNOPSIS" -><P -></P -><A -NAME="AEN7843" -></A -><P -><CODE -><CODE -CLASS="FUNCDEF" ->int ioctl</CODE ->(int fd, int request, v4l2_std_id -*argp);</CODE -></P -><P -></P -></DIV -><DIV -CLASS="FUNCSYNOPSIS" -><P -></P -><A -NAME="AEN7853" -></A -><P -><CODE -><CODE -CLASS="FUNCDEF" ->int ioctl</CODE ->(int fd, int request, const v4l2_std_id -*argp);</CODE -></P -><P -></P -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN7863" -></A -><H2 ->Arguments</H2 -><P -></P -><DIV -CLASS="VARIABLELIST" -><DL -><DT -><VAR -CLASS="PARAMETER" ->fd</VAR -></DT -><DD -><P ->File descriptor returned by <A -HREF="#FUNC-OPEN" -><CODE -CLASS="FUNCTION" ->open()</CODE -></A ->.</P -></DD -><DT -><VAR -CLASS="PARAMETER" ->request</VAR -></DT -><DD -><P ->VIDIOC_G_STD, VIDIOC_S_STD</P -></DD -><DT -><VAR -CLASS="PARAMETER" ->argp</VAR -></DT -><DD -><P -></P -></DD -></DL -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN7883" -></A -><H2 ->Description</H2 -><P ->To query and select the current video standard applications -use the <CODE -CLASS="CONSTANT" ->VIDIOC_G_STD</CODE -> and <CODE -CLASS="CONSTANT" ->VIDIOC_S_STD</CODE -> ioctls which take a pointer to a -<A -HREF="#V4L2-STD-ID" ->v4l2_std_id</A -> type as argument. <CODE -CLASS="CONSTANT" ->VIDIOC_G_STD</CODE -> can -return a single flag or a set of flags as in struct <A -HREF="#V4L2-STANDARD" ->v4l2_standard</A -> field -<CODE -CLASS="STRUCTFIELD" ->id</CODE ->. The flags must be unambiguous such -that they appear in only one enumerated <CODE -CLASS="STRUCTNAME" ->v4l2_standard</CODE -> structure.</P -><P -><CODE -CLASS="CONSTANT" ->VIDIOC_S_STD</CODE -> accepts one or more -flags, being a write-only ioctl it does not return the actual new standard as -<CODE -CLASS="CONSTANT" ->VIDIOC_G_STD</CODE -> does. When no flags are given or -the current input does not support the requested standard the driver -returns an <SPAN -CLASS="ERRORCODE" ->EINVAL</SPAN -> error code. When the standard set is ambiguous drivers may -return <SPAN -CLASS="ERRORCODE" ->EINVAL</SPAN -> or choose any of the requested -standards.</P -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN7898" -></A -><H2 ->Return Value</H2 -><P ->On success <SPAN -CLASS="RETURNVALUE" ->0</SPAN -> is returned, on -error <SPAN -CLASS="RETURNVALUE" ->-1</SPAN -> and <VAR -CLASS="VARNAME" ->errno</VAR -> is -set appropriately:</P -><P -></P -><DIV -CLASS="VARIABLELIST" -><DL -><DT -><SPAN -CLASS="ERRORCODE" ->EINVAL</SPAN -></DT -><DD -><P ->This ioctl is not supported, or the -<CODE -CLASS="CONSTANT" ->VIDIOC_S_STD</CODE -> parameter was unsuitable.</P -></DD -></DL -></DIV -></DIV -><H1 -><A -NAME="VIDIOC-G-TUNER" -></A ->ioctl VIDIOC_G_TUNER, VIDIOC_S_TUNER</H1 -><DIV -CLASS="REFNAMEDIV" -><A -NAME="AEN7914" -></A -><H2 ->Name</H2 ->ioctl VIDIOC_G_TUNER, ioctl VIDIOC_S_TUNER -- Get or set tuner attributes</DIV -><DIV -CLASS="REFSYNOPSISDIV" -><A -NAME="AEN7918" -></A -><H2 ->Synopsis</H2 -><DIV -CLASS="FUNCSYNOPSIS" -><P -></P -><A -NAME="AEN7919" -></A -><P -><CODE -><CODE -CLASS="FUNCDEF" ->int ioctl</CODE ->(int fd, int request, struct v4l2_tuner -*argp);</CODE -></P -><P -></P -></DIV -><DIV -CLASS="FUNCSYNOPSIS" -><P -></P -><A -NAME="AEN7929" -></A -><P -><CODE -><CODE -CLASS="FUNCDEF" ->int ioctl</CODE ->(int fd, int request, const struct v4l2_tuner -*argp);</CODE -></P -><P -></P -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN7939" -></A -><H2 ->Arguments</H2 -><P -></P -><DIV -CLASS="VARIABLELIST" -><DL -><DT -><VAR -CLASS="PARAMETER" ->fd</VAR -></DT -><DD -><P ->File descriptor returned by <A -HREF="#FUNC-OPEN" -><CODE -CLASS="FUNCTION" ->open()</CODE -></A ->.</P -></DD -><DT -><VAR -CLASS="PARAMETER" ->request</VAR -></DT -><DD -><P ->VIDIOC_G_TUNER, VIDIOC_S_TUNER</P -></DD -><DT -><VAR -CLASS="PARAMETER" ->argp</VAR -></DT -><DD -><P -></P -></DD -></DL -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN7959" -></A -><H2 ->Description</H2 -><P ->To query the attributes of a tuner applications initialize the -<CODE -CLASS="STRUCTFIELD" ->index</CODE -> field and zero out the -<CODE -CLASS="STRUCTFIELD" ->reserved</CODE -> array of a struct <A -HREF="#V4L2-TUNER" ->v4l2_tuner</A -> and call the -<CODE -CLASS="CONSTANT" ->VIDIOC_G_TUNER</CODE -> ioctl with a pointer to this -structure. Drivers fill the rest of the structure or return an -<SPAN -CLASS="ERRORCODE" ->EINVAL</SPAN -> error code when the index is out of bounds. To enumerate all tuners -applications shall begin at index zero, incrementing by one until the -driver returns <SPAN -CLASS="ERRORCODE" ->EINVAL</SPAN ->.</P -><P ->Tuners have two writable properties, the audio mode and -the radio frequency. To switch the audio mode, applications initialize -the <CODE -CLASS="STRUCTFIELD" ->index</CODE -> and -<CODE -CLASS="STRUCTFIELD" ->audmode</CODE -> fields and the -<CODE -CLASS="STRUCTFIELD" ->reserved</CODE -> array and call the -<CODE -CLASS="CONSTANT" ->VIDIOC_S_TUNER</CODE -> ioctl. This will -<SPAN -CLASS="emphasis" -><I -CLASS="EMPHASIS" ->not</I -></SPAN -> change the currently selected tuner, -which is determined by the current video input. Drivers may choose a -different audio mode if the request cannot be satisfied. Since this -is a write-only ioctl it does not return the actual audio mode -selected.</P -><P ->To change the radio frequency the <A -HREF="#VIDIOC-G-FREQUENCY" -><CODE -CLASS="CONSTANT" ->VIDIOC_S_FREQUENCY</CODE -></A -> ioctl -is available.</P -><DIV -CLASS="TABLE" -><A -NAME="V4L2-TUNER" -></A -><P -><B ->Table 1. struct <CODE -CLASS="STRUCTNAME" ->v4l2_tuner</CODE -></B -></P -><TABLE -BORDER="0" -FRAME="void" -WIDTH="100%" -CLASS="CALSTABLE" -><COL -WIDTH="25%" -TITLE="C1"><COL -WIDTH="25%" -TITLE="C2"><COL -WIDTH="50%" -TITLE="C3"><TBODY -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->index</CODE -></TD -><TD ->Identifies the tuner, set by the -application.</TD -></TR -><TR -><TD ->__u8</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->name</CODE ->[32]</TD -><TD -><P ->Name of the tuner, a NUL-terminated ASCII -string. This information is intended for the user.<SUP ->a</SUP -></P -></TD -></TR -><TR -><TD ->enum <A -HREF="#V4L2-TUNER-TYPE" ->v4l2_tuner_type</A -></TD -><TD -><CODE -CLASS="STRUCTFIELD" ->type</CODE -></TD -><TD ->Type of the tuner, see <A -HREF="#V4L2-TUNER-TYPE" ->Table 2</A ->.</TD -></TR -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->capability</CODE -></TD -><TD -><P ->Tuner capability flags, see <A -HREF="#TUNER-CAPABILITY" ->Table 3</A ->. Audio flags indicate -the ability to decode audio subprograms. They will -<SPAN -CLASS="emphasis" -><I -CLASS="EMPHASIS" ->not</I -></SPAN -> change for example with the current video -standard.</P -><P ->When the structure refers to a radio tuner only -the <CODE -CLASS="CONSTANT" ->V4L2_TUNER_CAP_LOW</CODE -> and -<CODE -CLASS="CONSTANT" ->V4L2_TUNER_CAP_STEREO</CODE -> flags can be -set.</P -></TD -></TR -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->rangelow</CODE -></TD -><TD ->The lowest tunable frequency in units of 62.5 -KHz, or if the <CODE -CLASS="STRUCTFIELD" ->capability</CODE -> flag -<CODE -CLASS="CONSTANT" ->V4L2_TUNER_CAP_LOW</CODE -> is set, in units of 62.5 -Hz.</TD -></TR -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->rangehigh</CODE -></TD -><TD ->The highest tunable frequency in units of 62.5 -KHz, or if the <CODE -CLASS="STRUCTFIELD" ->capability</CODE -> flag -<CODE -CLASS="CONSTANT" ->V4L2_TUNER_CAP_LOW</CODE -> is set, in units of 62.5 -Hz.</TD -></TR -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->rxsubchans</CODE -></TD -><TD -><P ->Some tuners can report the audio subprograms -received by analyzing audio carriers, pilot tones or other indicators. -The <CODE -CLASS="STRUCTFIELD" ->rxsubchans</CODE -> field contains flags defined -in <A -HREF="#TUNER-RXSUBCHANS" ->Table 4</A ->, which are set by the driver to -indicate the audio subprograms the hardware <SPAN -CLASS="emphasis" -><I -CLASS="EMPHASIS" ->may</I -></SPAN -> -currently receive.</P -></TD -></TR -><TR -><TD -COLSPAN="3" -><P ->Only those flags can be set -here which are also set in the <CODE -CLASS="STRUCTFIELD" ->capability</CODE -> -field. When the detection is inconclusive the flags of all possible -audio subprograms must be set. When the driver cannot detect the audio -subprograms at all, this field must contain the same audio flags as -<CODE -CLASS="STRUCTFIELD" ->capability </CODE ->.<SUP ->b</SUP -></P -><P ->For example when two audio -channels are detected but the hardware cannot distinguish between -stereo and bilingual mode all the -<CODE -CLASS="CONSTANT" ->V4L2_TUNER_SUB_STEREO</CODE ->, -<CODE -CLASS="CONSTANT" ->V4L2_TUNER_SUB_LANG1</CODE ->, and -<CODE -CLASS="CONSTANT" ->V4L2_TUNER_SUB_LANG2</CODE -> flags may be set.</P -><P ->When the structure refers to a radio tuner only the -<CODE -CLASS="CONSTANT" ->V4L2_TUNER_SUB_MONO</CODE -> and -<CODE -CLASS="CONSTANT" ->V4L2_TUNER_SUB_STEREO</CODE -> flag can be -set.</P -><P ->The field is valid only when this is the tuner of the -current video input or a radio tuner.</P -></TD -></TR -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->audmode</CODE -></TD -><TD -><P ->The selected audio mode, see <A -HREF="#TUNER-AUDMODE" ->Table 5</A -> for valid values. The audio mode -does not affect audio subprogram detection, and it does not change -automatically. See <A -HREF="#TUNER-MATRIX" ->Table 6</A -> for possible results -when the selected and received audio programs do not -match.</P -><P ->When the structure refers to a radio tuner only the -<CODE -CLASS="CONSTANT" ->V4L2_TUNER_MODE_MONO</CODE -> and -<CODE -CLASS="CONSTANT" ->V4L2_TUNER_MODE_STEREO</CODE -> are valid -values.</P -><P ->Currently this is the only field of struct -<CODE -CLASS="STRUCTNAME" ->v4l2_tuner</CODE -> applications can change.</P -></TD -></TR -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->signal</CODE -></TD -><TD ->The signal strength if known, supposedly ranging -from 0 to 65535. Higher values indicate a better signal.</TD -></TR -><TR -><TD ->__s32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->afc</CODE -></TD -><TD ->Automatic frequency control: When the -<CODE -CLASS="STRUCTFIELD" ->afc</CODE -> value is negative, the frequency is too -low, when positive too high. [need example what to do when it never -settles at zero, i. e. range is what?]</TD -></TR -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->reserved</CODE ->[4]</TD -><TD ->Reserved for future extensions. Drivers and -applications must set the array to zero.</TD -></TR -></TBODY -><TR -><TD -COLSPAN="3" ->Notes:<BR><A -NAME="FTN.AEN7997" ->a. </A ->Video inputs already have a name, the purpose -of this field is not quite clear.<BR><A -NAME="FTN.AEN8045" ->b. </A ->Purpose of -<CODE -CLASS="STRUCTFIELD" ->rxsubchans</CODE -> is to eliminate choice, i. e. -those audio subprograms the driver knows for sure are not received -right now.<BR></TD -></TR -></TABLE -></DIV -><DIV -CLASS="TABLE" -><A -NAME="V4L2-TUNER-TYPE" -></A -><P -><B ->Table 2. enum v4l2_tuner_type</B -></P -><TABLE -BORDER="0" -FRAME="void" -WIDTH="100%" -CLASS="CALSTABLE" -><COL -WIDTH="38%" -TITLE="C1"><COL -WIDTH="12%" -TITLE="C2"><COL -WIDTH="50%" -TITLE="C3"><TBODY -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_TUNER_RADIO</CODE -></TD -><TD ->1</TD -><TD -> </TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_TUNER_ANALOG_TV</CODE -></TD -><TD ->2</TD -><TD -> </TD -></TR -></TBODY -></TABLE -></DIV -><DIV -CLASS="TABLE" -><A -NAME="TUNER-CAPABILITY" -></A -><P -><B ->Table 3. Tuner and Modulator Capability Flags</B -></P -><TABLE -BORDER="0" -FRAME="void" -WIDTH="100%" -CLASS="CALSTABLE" -><COL -WIDTH="38%" -TITLE="C1"><COL -WIDTH="12%" -TITLE="C2"><COL -WIDTH="50%" -TITLE="C3"><TBODY -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_TUNER_CAP_LOW</CODE -></TD -><TD ->0x0001</TD -><TD ->When set frequencies are expressed in units of -62.5 Hz, otherwise in units of 62.5 kHz.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_TUNER_CAP_NORM</CODE -></TD -><TD ->0x0002</TD -><TD ->This is a multi-standard tuner; the video -standard can or must be switched. (B/G PAL tuners for example are -typically not considered multi-standard because the video standard is -automatically selected depending on the frequency band.) The supported -video standards are reported in the respective struct <A -HREF="#V4L2-INPUT" ->v4l2_input</A -> field -<CODE -CLASS="STRUCTFIELD" ->std</CODE ->. For details on video standards and how -to switch see <A -HREF="#STANDARD" ->Section 1.7</A ->.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_TUNER_CAP_STEREO</CODE -></TD -><TD ->0x0010</TD -><TD ->Stereo audio reception is supported.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_TUNER_CAP_LANG1</CODE -></TD -><TD ->0x0040</TD -><TD ->Reception of a primary language (of two) is -supported.<A -HREF="#FTN.TUNER-AUDIO-CAP" -><SPAN -CLASS="footnote" ->[a]</SPAN -></A -></TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_TUNER_CAP_LANG2</CODE -></TD -><TD ->0x0020</TD -><TD ->Reception of a secondary language is -supported.<A -HREF="#FTN.TUNER-AUDIO-CAP" -><SPAN -CLASS="footnote" ->[a]</SPAN -></A -></TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_TUNER_CAP_SAP</CODE -></TD -><TD ->0x0020</TD -><TD -><P ->Reception of the Secondary Audio Program -(typically a secondary language of the current program) is supported. -Note the <CODE -CLASS="CONSTANT" ->V4L2_TUNER_CAP_LANG2</CODE -> and -<CODE -CLASS="CONSTANT" ->V4L2_TUNER_CAP_SAP</CODE -> flags are synonyms. <SUP ->a</SUP -></P -></TD -></TR -></TBODY -><TR -><TD -COLSPAN="3" ->Notes:<BR><A -NAME="FTN.TUNER-AUDIO-CAP" ->a. </A ->The LANG1/LANG2 -nomenclature refers to audio systems transmitting different languages -monaural on two audio subcarriers ("bilingual mode"), otherwise the -left and right stereo channel. Similar the NICAM digital audio system -with two audio channels, transmitted on a second audio subcarrier -while the main AM/FM audio carrier provides mono or primary language -audio for older TV sets. SAP is a feature of the U.S. BTSC audio -system, which consists of up to three audio subcarriers. Unlike LANG2 -SAP is a separate mono audio track besides the primary mono or stereo -audio track.<BR>The <CODE -CLASS="CONSTANT" ->V4L2_TUNER_CAP_SAP</CODE -> -capability flag applies when the tuner supports the M/NTSC video -standard. <CODE -CLASS="CONSTANT" ->V4L2_TUNER_SUB_SAP</CODE -> and -<CODE -CLASS="CONSTANT" ->V4L2_TUNER_MODE_SAP</CODE -> apply when the M/NTSC video -standard is currently selected.<BR></TD -></TR -></TABLE -></DIV -><DIV -CLASS="TABLE" -><A -NAME="TUNER-RXSUBCHANS" -></A -><P -><B ->Table 4. Tuner Audio Reception Flags</B -></P -><TABLE -BORDER="0" -FRAME="void" -WIDTH="100%" -CLASS="CALSTABLE" -><COL -WIDTH="38%" -TITLE="C1"><COL -WIDTH="12%" -TITLE="C2"><COL -WIDTH="50%" -TITLE="C3"><TBODY -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_TUNER_SUB_MONO</CODE -></TD -><TD ->0x0001</TD -><TD ->The tuner receives a mono audio signal.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_TUNER_SUB_STEREO</CODE -></TD -><TD ->0x0002</TD -><TD ->The tuner receives a stereo audio signal.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_TUNER_SUB_LANG1</CODE -></TD -><TD ->0x0008</TD -><TD ->The tuner receives the primary language of a -bilingual audio signal. This flag is not supposed to be set when the -tuner receives Mono + SAP or Stereo + SAP audio.<A -HREF="#FTN.TUNER-AUDIO-CAP" -><SPAN -CLASS="footnote" ->[a]</SPAN -></A -></TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_TUNER_SUB_LANG2</CODE -></TD -><TD ->0x0004</TD -><TD ->The tuner receives the secondary language of a -bilingual audio signal.<A -HREF="#FTN.TUNER-AUDIO-CAP" -><SPAN -CLASS="footnote" ->[a]</SPAN -></A -></TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_TUNER_SUB_SAP</CODE -></TD -><TD ->0x0004</TD -><TD ->The tuner receives a Second Audio Program. Note -the <CODE -CLASS="CONSTANT" ->V4L2_TUNER_SUB_LANG2</CODE -> and -<CODE -CLASS="CONSTANT" ->V4L2_TUNER_SUB_SAP</CODE -> flags are -synonyms.<A -HREF="#FTN.TUNER-AUDIO-CAP" -><SPAN -CLASS="footnote" ->[a]</SPAN -></A -></TD -></TR -></TBODY -></TABLE -></DIV -><DIV -CLASS="TABLE" -><A -NAME="TUNER-AUDMODE" -></A -><P -><B ->Table 5. Tuner Audio Modes</B -></P -><TABLE -BORDER="0" -FRAME="void" -WIDTH="100%" -CLASS="CALSTABLE" -><COL -WIDTH="38%" -TITLE="C1"><COL -WIDTH="12%" -TITLE="C2"><COL -WIDTH="50%" -TITLE="C3"><TBODY -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_TUNER_MODE_MONO</CODE -></TD -><TD ->0</TD -><TD ->Play mono audio. When the tuner receives a stereo -signal this a down-mix of the left and right channel. When the tuner -receives a bilingual or SAP signal this mode selects the primary -language.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_TUNER_MODE_STEREO</CODE -></TD -><TD ->1</TD -><TD ->Play stereo audio. When the tuner receives -bilingual audio it may play different languages on the left and right -channel or the primary language on both channels. When it receives no -stereo signal or does not support stereo reception the driver shall -fall back to mono mode.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_TUNER_MODE_LANG1</CODE -></TD -><TD ->3</TD -><TD ->Play the primary language, mono or -stereo.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_TUNER_MODE_LANG2</CODE -></TD -><TD ->2</TD -><TD ->Play the secondary language, mono. When the tuner -receives no bilingual audio or SAP, or their reception is not -supported the driver shall fall back to mono or stereo mode.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_TUNER_MODE_SAP</CODE -></TD -><TD ->2</TD -><TD ->Play the Second Audio Program. When the tuner -receives no bilingual audio or SAP, or their reception is not -supported the driver shall fall back to mono or stereo mode. Note the -<CODE -CLASS="CONSTANT" ->V4L2_TUNER_MODE_LANG2</CODE -> and -<CODE -CLASS="CONSTANT" ->V4L2_TUNER_MODE_SAP</CODE -> identifiers are -synonyms.<A -HREF="#FTN.TUNER-AUDIO-CAP" -><SPAN -CLASS="footnote" ->[a]</SPAN -></A -></TD -></TR -></TBODY -></TABLE -></DIV -><DIV -CLASS="TABLE" -><A -NAME="TUNER-MATRIX" -></A -><P -><B ->Table 6. Tuner Audio Matrix</B -></P -><TABLE -BORDER="1" -FRAME="border" -WIDTH="100%" -CLASS="CALSTABLE" -><COL -WIDTH="33%" -ALIGN="LEFT"><COL -WIDTH="33%" -TITLE="C2"><COL><COL><COL -WIDTH="33%" -TITLE="C5"><THEAD -><TR -><TH -> </TH -><TH -COLSPAN="4" -ALIGN="CENTER" ->Selected</TH -></TR -><TR -><TH ->Received</TH -><TH ->Mono</TH -><TH ->Stereo</TH -><TH ->Language 1</TH -><TH ->Language 2 / SAP</TH -></TR -></THEAD -><TBODY -><TR -><TD ->Mono</TD -><TD ->Mono</TD -><TD ->Mono/Mono</TD -><TD ->Mono</TD -><TD ->Mono</TD -></TR -><TR -><TD ->Stereo</TD -><TD ->L+R</TD -><TD ->L/R</TD -><TD ->Undefined: L/L or L+R Mono or -L/R Stereo</TD -><TD ->Undefined: R/R or L+R Mono or -L/R Stereo</TD -></TR -><TR -><TD ->Mono/Stereo + SAP (BTSC only)</TD -><TD ->-</TD -><TD ->-</TD -><TD ->Main audio program, mono or stereo</TD -><TD ->SAP Mono</TD -></TR -><TR -><TD ->Bilingual (two carrier systems only)</TD -><TD ->Language 1</TD -><TD ->Undefined: Lang1/Lang1 or Lang1/Lang2</TD -><TD ->Language 1 Mono</TD -><TD ->Language 2 Mono</TD -></TR -></TBODY -></TABLE -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN8271" -></A -><H2 ->Return Value</H2 -><P ->On success <SPAN -CLASS="RETURNVALUE" ->0</SPAN -> is returned, on -error <SPAN -CLASS="RETURNVALUE" ->-1</SPAN -> and <VAR -CLASS="VARNAME" ->errno</VAR -> is -set appropriately:</P -><P -></P -><DIV -CLASS="VARIABLELIST" -><DL -><DT -><SPAN -CLASS="ERRORCODE" ->EINVAL</SPAN -></DT -><DD -><P ->The struct <A -HREF="#V4L2-TUNER" ->v4l2_tuner</A -> <CODE -CLASS="STRUCTFIELD" ->index</CODE -> is -out of bounds.</P -></DD -></DL -></DIV -></DIV -><H1 -><A -NAME="VIDIOC-OVERLAY" -></A ->ioctl VIDIOC_OVERLAY</H1 -><DIV -CLASS="REFNAMEDIV" -><A -NAME="AEN8288" -></A -><H2 ->Name</H2 ->ioctl VIDIOC_OVERLAY -- Start or stop video overlay</DIV -><DIV -CLASS="REFSYNOPSISDIV" -><A -NAME="AEN8291" -></A -><H2 ->Synopsis</H2 -><DIV -CLASS="FUNCSYNOPSIS" -><P -></P -><A -NAME="AEN8292" -></A -><P -><CODE -><CODE -CLASS="FUNCDEF" ->int ioctl</CODE ->(int fd, int request, const int *argp);</CODE -></P -><P -></P -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN8302" -></A -><H2 ->Arguments</H2 -><P -></P -><DIV -CLASS="VARIABLELIST" -><DL -><DT -><VAR -CLASS="PARAMETER" ->fd</VAR -></DT -><DD -><P ->File descriptor returned by <A -HREF="#FUNC-OPEN" -><CODE -CLASS="FUNCTION" ->open()</CODE -></A ->.</P -></DD -><DT -><VAR -CLASS="PARAMETER" ->request</VAR -></DT -><DD -><P ->VIDIOC_OVERLAY</P -></DD -><DT -><VAR -CLASS="PARAMETER" ->argp</VAR -></DT -><DD -><P -></P -></DD -></DL -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN8322" -></A -><H2 ->Description</H2 -><P ->This ioctl is part of the <A -HREF="#OVERLAY" ->video - overlay</A -> I/O method. Applications call - <CODE -CLASS="CONSTANT" ->VIDIOC_OVERLAY</CODE -> to start or stop the - overlay. It takes a pointer to an integer which must be set to - zero by the application to stop overlay, to one to start.</P -><P ->Drivers do not support <A -HREF="#VIDIOC-STREAMON" -><CODE -CLASS="CONSTANT" ->VIDIOC_STREAMON</CODE -></A -> or -<A -HREF="#VIDIOC-STREAMON" -><CODE -CLASS="CONSTANT" ->VIDIOC_STREAMOFF</CODE -></A -> with <CODE -CLASS="CONSTANT" ->V4L2_BUF_TYPE_VIDEO_OVERLAY</CODE ->.</P -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN8333" -></A -><H2 ->Return Value</H2 -><P ->On success <SPAN -CLASS="RETURNVALUE" ->0</SPAN -> is returned, on -error <SPAN -CLASS="RETURNVALUE" ->-1</SPAN -> and <VAR -CLASS="VARNAME" ->errno</VAR -> is -set appropriately:</P -><P -></P -><DIV -CLASS="VARIABLELIST" -><DL -><DT -><SPAN -CLASS="ERRORCODE" ->EINVAL</SPAN -></DT -><DD -><P ->Video overlay is not supported, or the -parameters have not been set up. See <A -HREF="#OVERLAY" ->Section 4.2</A -> for the necessary steps.</P -></DD -></DL -></DIV -></DIV -><H1 -><A -NAME="VIDIOC-QBUF" -></A ->ioctl VIDIOC_QBUF, VIDIOC_DQBUF</H1 -><DIV -CLASS="REFNAMEDIV" -><A -NAME="AEN8349" -></A -><H2 ->Name</H2 ->ioctl VIDIOC_QBUF, ioctl VIDIOC_DQBUF -- Exchange a buffer with the driver</DIV -><DIV -CLASS="REFSYNOPSISDIV" -><A -NAME="AEN8353" -></A -><H2 ->Synopsis</H2 -><DIV -CLASS="FUNCSYNOPSIS" -><P -></P -><A -NAME="AEN8354" -></A -><P -><CODE -><CODE -CLASS="FUNCDEF" ->int ioctl</CODE ->(int fd, int request, struct v4l2_buffer *argp);</CODE -></P -><P -></P -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN8364" -></A -><H2 ->Arguments</H2 -><P -></P -><DIV -CLASS="VARIABLELIST" -><DL -><DT -><VAR -CLASS="PARAMETER" ->fd</VAR -></DT -><DD -><P ->File descriptor returned by <A -HREF="#FUNC-OPEN" -><CODE -CLASS="FUNCTION" ->open()</CODE -></A ->.</P -></DD -><DT -><VAR -CLASS="PARAMETER" ->request</VAR -></DT -><DD -><P ->VIDIOC_QBUF, VIDIOC_DQBUF</P -></DD -><DT -><VAR -CLASS="PARAMETER" ->argp</VAR -></DT -><DD -><P -></P -></DD -></DL -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN8384" -></A -><H2 ->Description</H2 -><P ->Applications call the <CODE -CLASS="CONSTANT" ->VIDIOC_QBUF</CODE -> ioctl -to enqueue an empty (capturing) or filled (output) buffer in the -driver's incoming queue. The semantics depend on the selected I/O -method.</P -><P ->To enqueue a <A -HREF="#MMAP" ->memory mapped</A -> -buffer applications set the <CODE -CLASS="STRUCTFIELD" ->type</CODE -> field of a -struct <A -HREF="#V4L2-BUFFER" ->v4l2_buffer</A -> to the same buffer type as previously struct <A -HREF="#V4L2-FORMAT" ->v4l2_format</A -> -<CODE -CLASS="STRUCTFIELD" ->type</CODE -> and struct <A -HREF="#V4L2-REQUESTBUFFERS" ->v4l2_requestbuffers</A -> -<CODE -CLASS="STRUCTFIELD" ->type</CODE ->, the <CODE -CLASS="STRUCTFIELD" ->memory</CODE -> -field to <CODE -CLASS="CONSTANT" ->V4L2_MEMORY_MMAP</CODE -> and the -<CODE -CLASS="STRUCTFIELD" ->index</CODE -> field. Valid index numbers range from -zero to the number of buffers allocated with <A -HREF="#VIDIOC-REQBUFS" -><CODE -CLASS="CONSTANT" ->VIDIOC_REQBUFS</CODE -></A -> -(struct <A -HREF="#V4L2-REQUESTBUFFERS" ->v4l2_requestbuffers</A -> <CODE -CLASS="STRUCTFIELD" ->count</CODE ->) minus one. The -contents of the struct <CODE -CLASS="STRUCTNAME" ->v4l2_buffer</CODE -> returned -by a <A -HREF="#VIDIOC-QUERYBUF" -><CODE -CLASS="CONSTANT" ->VIDIOC_QUERYBUF</CODE -></A -> ioctl will do as well. When the buffer is -intended for output (<CODE -CLASS="STRUCTFIELD" ->type</CODE -> is -<CODE -CLASS="CONSTANT" ->V4L2_BUF_TYPE_VIDEO_OUTPUT</CODE -> or -<CODE -CLASS="CONSTANT" ->V4L2_BUF_TYPE_VBI_OUTPUT</CODE ->) applications must also -initialize the <CODE -CLASS="STRUCTFIELD" ->bytesused</CODE ->, -<CODE -CLASS="STRUCTFIELD" ->field</CODE -> and -<CODE -CLASS="STRUCTFIELD" ->timestamp</CODE -> fields. See <A -HREF="#BUFFER" ->Section 3.5</A -> for details. When -<CODE -CLASS="CONSTANT" ->VIDIOC_QBUF</CODE -> is called with a pointer to this -structure the driver sets the -<CODE -CLASS="CONSTANT" ->V4L2_BUF_FLAG_MAPPED</CODE -> and -<CODE -CLASS="CONSTANT" ->V4L2_BUF_FLAG_QUEUED</CODE -> flags and clears the -<CODE -CLASS="CONSTANT" ->V4L2_BUF_FLAG_DONE</CODE -> flag in the -<CODE -CLASS="STRUCTFIELD" ->flags</CODE -> field, or it returns an -<SPAN -CLASS="ERRORCODE" ->EINVAL</SPAN -> error code.</P -><P ->To enqueue a <A -HREF="#USERP" ->user pointer</A -> -buffer applications set the <CODE -CLASS="STRUCTFIELD" ->type</CODE -> field of a -struct <A -HREF="#V4L2-BUFFER" ->v4l2_buffer</A -> to the same buffer type as previously struct <A -HREF="#V4L2-FORMAT" ->v4l2_format</A -> -<CODE -CLASS="STRUCTFIELD" ->type</CODE -> and struct <A -HREF="#V4L2-REQUESTBUFFERS" ->v4l2_requestbuffers</A -> -<CODE -CLASS="STRUCTFIELD" ->type</CODE ->, the <CODE -CLASS="STRUCTFIELD" ->memory</CODE -> -field to <CODE -CLASS="CONSTANT" ->V4L2_MEMORY_USERPTR</CODE -> and the -<CODE -CLASS="STRUCTFIELD" ->m.userptr</CODE -> field to the address of the -buffer and <CODE -CLASS="STRUCTFIELD" ->length</CODE -> to its size. When the -buffer is intended for output additional fields must be set as above. -When <CODE -CLASS="CONSTANT" ->VIDIOC_QBUF</CODE -> is called with a pointer to this -structure the driver sets the <CODE -CLASS="CONSTANT" ->V4L2_BUF_FLAG_QUEUED</CODE -> -flag and clears the <CODE -CLASS="CONSTANT" ->V4L2_BUF_FLAG_MAPPED</CODE -> and -<CODE -CLASS="CONSTANT" ->V4L2_BUF_FLAG_DONE</CODE -> flags in the -<CODE -CLASS="STRUCTFIELD" ->flags</CODE -> field, or it returns an error code. -This ioctl locks the memory pages of the buffer in physical memory, -they cannot be swapped out to disk. Buffers remain locked until -dequeued, until the <A -HREF="#VIDIOC-STREAMON" -><CODE -CLASS="CONSTANT" ->VIDIOC_STREAMOFF</CODE -></A -> or <A -HREF="#VIDIOC-REQBUFS" -><CODE -CLASS="CONSTANT" ->VIDIOC_REQBUFS</CODE -></A -> ioctl are -called, or until the device is closed.</P -><P ->Applications call the <CODE -CLASS="CONSTANT" ->VIDIOC_DQBUF</CODE -> -ioctl to dequeue a filled (capturing) or displayed (output) buffer -from the driver's outgoing queue. They just set the -<CODE -CLASS="STRUCTFIELD" ->type</CODE -> and <CODE -CLASS="STRUCTFIELD" ->memory</CODE -> -fields of a struct <A -HREF="#V4L2-BUFFER" ->v4l2_buffer</A -> as above, when <CODE -CLASS="CONSTANT" ->VIDIOC_DQBUF</CODE -> -is called with a pointer to this structure the driver fills the -remaining fields or returns an error code.</P -><P ->By default <CODE -CLASS="CONSTANT" ->VIDIOC_DQBUF</CODE -> blocks when no -buffer is in the outgoing queue. When the -<CODE -CLASS="CONSTANT" ->O_NONBLOCK</CODE -> flag was given to the <A -HREF="#FUNC-OPEN" -><CODE -CLASS="FUNCTION" ->open()</CODE -></A -> -function, <CODE -CLASS="CONSTANT" ->VIDIOC_DQBUF</CODE -> returns immediately -with an <SPAN -CLASS="ERRORCODE" ->EAGAIN</SPAN -> error code when no buffer is available.</P -><P ->The <CODE -CLASS="STRUCTNAME" ->v4l2_buffer</CODE -> structure is -specified in <A -HREF="#BUFFER" ->Section 3.5</A ->.</P -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN8456" -></A -><H2 ->Return Value</H2 -><P ->On success <SPAN -CLASS="RETURNVALUE" ->0</SPAN -> is returned, on -error <SPAN -CLASS="RETURNVALUE" ->-1</SPAN -> and <VAR -CLASS="VARNAME" ->errno</VAR -> is -set appropriately:</P -><P -></P -><DIV -CLASS="VARIABLELIST" -><DL -><DT -><SPAN -CLASS="ERRORCODE" ->EAGAIN</SPAN -></DT -><DD -><P ->Non-blocking I/O has been selected using -<CODE -CLASS="CONSTANT" ->O_NONBLOCK</CODE -> and no buffer was in the outgoing -queue.</P -></DD -><DT -><SPAN -CLASS="ERRORCODE" ->EINVAL</SPAN -></DT -><DD -><P ->The buffer <CODE -CLASS="STRUCTFIELD" ->type</CODE -> is not -supported, or the <CODE -CLASS="STRUCTFIELD" ->index</CODE -> is out of bounds, -or no buffers have been allocated yet, or the -<CODE -CLASS="STRUCTFIELD" ->userptr</CODE -> or -<CODE -CLASS="STRUCTFIELD" ->length</CODE -> are invalid.</P -></DD -><DT -><SPAN -CLASS="ERRORCODE" ->ENOMEM</SPAN -></DT -><DD -><P ->Insufficient memory to enqueue a user pointer buffer.</P -></DD -><DT -><SPAN -CLASS="ERRORCODE" ->EIO</SPAN -></DT -><DD -><P -><CODE -CLASS="CONSTANT" ->VIDIOC_DQBUF</CODE -> failed due to an -internal error. Can also indicate temporary problems like signal -loss. Note the driver might dequeue an (empty) buffer despite -returning an error, or even stop capturing.</P -></DD -></DL -></DIV -></DIV -><H1 -><A -NAME="VIDIOC-QUERYBUF" -></A ->ioctl VIDIOC_QUERYBUF</H1 -><DIV -CLASS="REFNAMEDIV" -><A -NAME="AEN8490" -></A -><H2 ->Name</H2 ->ioctl VIDIOC_QUERYBUF -- Query the status of a buffer</DIV -><DIV -CLASS="REFSYNOPSISDIV" -><A -NAME="AEN8493" -></A -><H2 ->Synopsis</H2 -><DIV -CLASS="FUNCSYNOPSIS" -><P -></P -><A -NAME="AEN8494" -></A -><P -><CODE -><CODE -CLASS="FUNCDEF" ->int ioctl</CODE ->(int fd, int request, struct v4l2_buffer *argp);</CODE -></P -><P -></P -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN8504" -></A -><H2 ->Arguments</H2 -><P -></P -><DIV -CLASS="VARIABLELIST" -><DL -><DT -><VAR -CLASS="PARAMETER" ->fd</VAR -></DT -><DD -><P ->File descriptor returned by <A -HREF="#FUNC-OPEN" -><CODE -CLASS="FUNCTION" ->open()</CODE -></A ->.</P -></DD -><DT -><VAR -CLASS="PARAMETER" ->request</VAR -></DT -><DD -><P ->VIDIOC_QUERYBUF</P -></DD -><DT -><VAR -CLASS="PARAMETER" ->argp</VAR -></DT -><DD -><P -></P -></DD -></DL -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN8524" -></A -><H2 ->Description</H2 -><P ->This ioctl is part of the <A -HREF="#MMAP" ->memory -mapping</A -> I/O method. It can be used to query the status of a -buffer at any time after buffers have been allocated with the -<A -HREF="#VIDIOC-REQBUFS" -><CODE -CLASS="CONSTANT" ->VIDIOC_REQBUFS</CODE -></A -> ioctl.</P -><P ->Applications set the <CODE -CLASS="STRUCTFIELD" ->type</CODE -> field - of a struct <A -HREF="#V4L2-BUFFER" ->v4l2_buffer</A -> to the same buffer type as previously -struct <A -HREF="#V4L2-FORMAT" ->v4l2_format</A -> <CODE -CLASS="STRUCTFIELD" ->type</CODE -> and struct <A -HREF="#V4L2-REQUESTBUFFERS" ->v4l2_requestbuffers</A -> -<CODE -CLASS="STRUCTFIELD" ->type</CODE ->, and the <CODE -CLASS="STRUCTFIELD" ->index</CODE -> - field. Valid index numbers range from zero -to the number of buffers allocated with <A -HREF="#VIDIOC-REQBUFS" -><CODE -CLASS="CONSTANT" ->VIDIOC_REQBUFS</CODE -></A -> - (struct <A -HREF="#V4L2-REQUESTBUFFERS" ->v4l2_requestbuffers</A -> <CODE -CLASS="STRUCTFIELD" ->count</CODE ->) minus one. -After calling <CODE -CLASS="CONSTANT" ->VIDIOC_QUERYBUF</CODE -> with a pointer to - this structure drivers return an error code or fill the rest of -the structure.</P -><P ->In the <CODE -CLASS="STRUCTFIELD" ->flags</CODE -> field the -<CODE -CLASS="CONSTANT" ->V4L2_BUF_FLAG_MAPPED</CODE ->, -<CODE -CLASS="CONSTANT" ->V4L2_BUF_FLAG_QUEUED</CODE -> and -<CODE -CLASS="CONSTANT" ->V4L2_BUF_FLAG_DONE</CODE -> flags will be valid. The -<CODE -CLASS="STRUCTFIELD" ->memory</CODE -> field will be set to -<CODE -CLASS="CONSTANT" ->V4L2_MEMORY_MMAP</CODE ->, the <CODE -CLASS="STRUCTFIELD" ->m.offset</CODE -> -contains the offset of the buffer from the start of the device memory, -the <CODE -CLASS="STRUCTFIELD" ->length</CODE -> field its size. The driver may -or may not set the remaining fields and flags, they are meaningless in -this context.</P -><P ->The <CODE -CLASS="STRUCTNAME" ->v4l2_buffer</CODE -> structure is - specified in <A -HREF="#BUFFER" ->Section 3.5</A ->.</P -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN8555" -></A -><H2 ->Return Value</H2 -><P ->On success <SPAN -CLASS="RETURNVALUE" ->0</SPAN -> is returned, on -error <SPAN -CLASS="RETURNVALUE" ->-1</SPAN -> and <VAR -CLASS="VARNAME" ->errno</VAR -> is -set appropriately:</P -><P -></P -><DIV -CLASS="VARIABLELIST" -><DL -><DT -><SPAN -CLASS="ERRORCODE" ->EINVAL</SPAN -></DT -><DD -><P ->The buffer <CODE -CLASS="STRUCTFIELD" ->type</CODE -> is not -supported, or the <CODE -CLASS="STRUCTFIELD" ->index</CODE -> is out of bounds.</P -></DD -></DL -></DIV -></DIV -><H1 -><A -NAME="VIDIOC-QUERYCAP" -></A ->ioctl VIDIOC_QUERYCAP</H1 -><DIV -CLASS="REFNAMEDIV" -><A -NAME="AEN8570" -></A -><H2 ->Name</H2 ->ioctl VIDIOC_QUERYCAP -- Query device capabilities</DIV -><DIV -CLASS="REFSYNOPSISDIV" -><A -NAME="AEN8573" -></A -><H2 ->Synopsis</H2 -><DIV -CLASS="FUNCSYNOPSIS" -><P -></P -><A -NAME="AEN8574" -></A -><P -><CODE -><CODE -CLASS="FUNCDEF" ->int ioctl</CODE ->(int fd, int request, struct v4l2_capability *argp);</CODE -></P -><P -></P -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN8584" -></A -><H2 ->Arguments</H2 -><P -></P -><DIV -CLASS="VARIABLELIST" -><DL -><DT -><VAR -CLASS="PARAMETER" ->fd</VAR -></DT -><DD -><P ->File descriptor returned by <A -HREF="#FUNC-OPEN" -><CODE -CLASS="FUNCTION" ->open()</CODE -></A ->.</P -></DD -><DT -><VAR -CLASS="PARAMETER" ->request</VAR -></DT -><DD -><P ->VIDIOC_QUERYCAP</P -></DD -><DT -><VAR -CLASS="PARAMETER" ->argp</VAR -></DT -><DD -><P -></P -></DD -></DL -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN8604" -></A -><H2 ->Description</H2 -><P ->All V4L2 devices support the -<CODE -CLASS="CONSTANT" ->VIDIOC_QUERYCAP</CODE -> ioctl. It is used to identify -kernel devices compatible with this specification and to obtain -information about individual hardware capabilities. The ioctl takes a -pointer to a struct <A -HREF="#V4L2-CAPABILITY" ->v4l2_capability</A -> which is filled by the driver. When the -driver is not compatible with this specification the ioctl returns the -<SPAN -CLASS="ERRORCODE" ->EINVAL</SPAN -> error code.</P -><DIV -CLASS="TABLE" -><A -NAME="V4L2-CAPABILITY" -></A -><P -><B ->Table 1. struct <CODE -CLASS="STRUCTNAME" ->v4l2_capability</CODE -></B -></P -><TABLE -BORDER="0" -FRAME="void" -WIDTH="100%" -CLASS="CALSTABLE" -><COL -WIDTH="25%" -TITLE="C1"><COL -WIDTH="25%" -TITLE="C2"><COL -WIDTH="50%" -TITLE="C3"><TBODY -><TR -><TD ->__u8</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->driver</CODE ->[16]</TD -><TD -><P ->Name of the driver, a unique NUL-terminated -ASCII string. For example: "bttv". Driver specific applications shall -use this information to verify the driver identity. It is also useful -to work around known bugs, or to print the driver name and version in -an error report to aid debugging. The driver version is stored in the -<CODE -CLASS="STRUCTFIELD" ->version</CODE -> field. [do we need a registry?]For -example: "bttv". Driver specific applications shall use this -information to verify the driver identity. It is also useful to work -around known bugs, or to print the driver name and version in an error -report to aid debugging. The driver version is stored in the -<CODE -CLASS="STRUCTFIELD" ->version</CODE -> field. [Do we need a -registry?]</P -><P ->Note storing strings in fixed sized arrays is -bad practice but unavoidable here. Drivers and applications should take -precautions to never read or write beyond the array end and to -properly terminate the strings.</P -></TD -></TR -><TR -><TD ->__u8</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->card</CODE ->[32]</TD -><TD ->Name of the device, a NUL-terminated ASCII -string. For example: "Yoyodyne TV/FM". Remember that one driver may -support different brands or models of video hardware. This information -can be used to build a menu of available devices for a device-select -user interface. Since drivers may support multiple installed devices -this name should be combined with the -<CODE -CLASS="STRUCTFIELD" ->bus_info</CODE -> string to avoid -ambiguities.</TD -></TR -><TR -><TD ->__u8</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->bus_info</CODE ->[32]</TD -><TD ->Location of the device in the system, a -NUL-terminated ASCII string. For example: "PCI Slot 4". This -information is intended for the user, to distinguish multiple -identical devices. If no such information is available the field may -simply count the devices controlled by the driver, or contain the -empty string (<CODE -CLASS="STRUCTFIELD" ->bus_info</CODE ->[0] = 0). [pci_dev->slot_name example].</TD -></TR -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->version</CODE -></TD -><TD -><P ->Version number of the driver. Together with -the <CODE -CLASS="STRUCTFIELD" ->driver</CODE -> field this identifies a -particular driver. The version number is formatted using the -<CODE -CLASS="CONSTANT" ->KERNEL_VERSION()</CODE -> macro:</P -></TD -></TR -><TR -><TD -COLSPAN="3" -><P -><PRE -CLASS="PROGRAMLISTING" ->#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c)) - -__u32 version = KERNEL_VERSION(0, 8, 1); - -printf ("Version: %u.%u.%u\n", - (version >> 16) & 0xFF, - (version >> 8) & 0xFF, - version & 0xFF);</PRE -></P -></TD -></TR -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->capabilities</CODE -></TD -><TD ->Device capabilities, see <A -HREF="#DEVICE-CAPABILITIES" ->Table 2</A ->.</TD -></TR -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->reserved</CODE ->[4]</TD -><TD ->Reserved for future extensions. Drivers must set -this array to zero.</TD -></TR -></TBODY -></TABLE -></DIV -><DIV -CLASS="TABLE" -><A -NAME="DEVICE-CAPABILITIES" -></A -><P -><B ->Table 2. Device Capabilities Flags</B -></P -><TABLE -BORDER="0" -FRAME="void" -WIDTH="100%" -CLASS="CALSTABLE" -><COL -WIDTH="38%" -TITLE="C1"><COL -WIDTH="12%" -TITLE="C2"><COL -WIDTH="50%" -TITLE="C3"><TBODY -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_CAP_VIDEO_CAPTURE</CODE -></TD -><TD ->0x00000001</TD -><TD ->The device supports the <A -HREF="#CAPTURE" ->video capture</A -> interface.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_CAP_VIDEO_OUTPUT</CODE -></TD -><TD ->0x00000002</TD -><TD ->The device supports the <A -HREF="#OUTPUT" ->video output</A -> interface.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_CAP_VIDEO_OVERLAY</CODE -></TD -><TD ->0x00000004</TD -><TD ->The device supports the <A -HREF="#OVERLAY" ->video overlay</A -> interface. Overlay typically -stores captured images directly in the video memory of a graphics -card, with support for clipping.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_CAP_VBI_CAPTURE</CODE -></TD -><TD ->0x00000010</TD -><TD ->The device supports the VBI capture interface, see -<A -HREF="#RAW-VBI" ->Section 4.6</A ->, <A -HREF="#SLICED" ->Section 4.7</A ->.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_CAP_VBI_OUTPUT</CODE -></TD -><TD ->0x00000020</TD -><TD ->The device supports the VBI output interface, -see <A -HREF="#RAW-VBI" ->Section 4.6</A ->, <A -HREF="#SLICED" ->Section 4.7</A ->.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_CAP_RDS_CAPTURE</CODE -></TD -><TD ->0x00000100</TD -><TD ->[to be defined]</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_CAP_TUNER</CODE -></TD -><TD ->0x00010000</TD -><TD ->The device has some sort of tuner or modulator to -receive or emit RF-modulated video signals. For more information see -<A -HREF="#TUNER" ->Section 1.6</A ->.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_CAP_AUDIO</CODE -></TD -><TD ->0x00020000</TD -><TD ->The device has audio inputs or outputs. For more -information see <A -HREF="#AUDIO" ->Section 1.5</A ->. It may or may not support PCM -sampling or output, this function must be implemented as ALSA or OSS -PCM interface.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_CAP_READWRITE</CODE -></TD -><TD ->0x01000000</TD -><TD ->The device supports the <A -HREF="#RW" ->read() -and/or write()</A -> I/O methods.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_CAP_ASYNCIO</CODE -></TD -><TD ->0x02000000</TD -><TD ->The device supports the <A -HREF="#ASYNC" ->asynchronous</A -> I/O methods.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_CAP_STREAMING</CODE -></TD -><TD ->0x04000000</TD -><TD ->The device supports the <A -HREF="#MMAP" ->streaming</A -> I/O method.</TD -></TR -></TBODY -></TABLE -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN8738" -></A -><H2 ->Return Value</H2 -><P ->On success <SPAN -CLASS="RETURNVALUE" ->0</SPAN -> is returned, on -error <SPAN -CLASS="RETURNVALUE" ->-1</SPAN -> and <VAR -CLASS="VARNAME" ->errno</VAR -> is -set appropriately:</P -><P -></P -><DIV -CLASS="VARIABLELIST" -><DL -><DT -><SPAN -CLASS="ERRORCODE" ->EINVAL</SPAN -></DT -><DD -><P ->The kernel device is not compatible with this -specification.</P -></DD -></DL -></DIV -></DIV -><H1 -><A -NAME="VIDIOC-QUERYCTRL" -></A ->ioctl VIDIOC_QUERYCTRL, VIDIOC_QUERYMENU</H1 -><DIV -CLASS="REFNAMEDIV" -><A -NAME="AEN8753" -></A -><H2 ->Name</H2 ->ioctl VIDIOC_QUERYCTRL, ioctl VIDIOC_QUERYMENU -- Enumerate controls and menu control items</DIV -><DIV -CLASS="REFSYNOPSISDIV" -><A -NAME="AEN8757" -></A -><H2 ->Synopsis</H2 -><DIV -CLASS="FUNCSYNOPSIS" -><P -></P -><A -NAME="AEN8758" -></A -><P -><CODE -><CODE -CLASS="FUNCDEF" ->int ioctl</CODE ->(int fd, int request, struct v4l2_queryctrl *argp);</CODE -></P -><P -></P -></DIV -><DIV -CLASS="FUNCSYNOPSIS" -><P -></P -><A -NAME="AEN8768" -></A -><P -><CODE -><CODE -CLASS="FUNCDEF" ->int ioctl</CODE ->(int fd, int request, struct v4l2_querymenu *argp);</CODE -></P -><P -></P -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN8778" -></A -><H2 ->Arguments</H2 -><P -></P -><DIV -CLASS="VARIABLELIST" -><DL -><DT -><VAR -CLASS="PARAMETER" ->fd</VAR -></DT -><DD -><P ->File descriptor returned by <A -HREF="#FUNC-OPEN" -><CODE -CLASS="FUNCTION" ->open()</CODE -></A ->.</P -></DD -><DT -><VAR -CLASS="PARAMETER" ->request</VAR -></DT -><DD -><P ->VIDIOC_QUERYCTRL, VIDIOC_QUERYMENU</P -></DD -><DT -><VAR -CLASS="PARAMETER" ->argp</VAR -></DT -><DD -><P -></P -></DD -></DL -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN8798" -></A -><H2 ->Description</H2 -><P ->To query the attributes of a control applications set the -<CODE -CLASS="STRUCTFIELD" ->id</CODE -> field of a struct <A -HREF="#V4L2-QUERYCTRL" ->v4l2_queryctrl</A -> and call the -<CODE -CLASS="CONSTANT" ->VIDIOC_QUERYCTRL</CODE -> ioctl with a pointer to this -structure. The driver fills the rest of the structure or returns an -<SPAN -CLASS="ERRORCODE" ->EINVAL</SPAN -> error code when the <CODE -CLASS="STRUCTFIELD" ->id</CODE -> is invalid.</P -><P ->It is possible to enumerate controls by calling -<CODE -CLASS="CONSTANT" ->VIDIOC_QUERYCTRL</CODE -> with successive -<CODE -CLASS="STRUCTFIELD" ->id</CODE -> values starting from -<CODE -CLASS="CONSTANT" ->V4L2_CID_BASE</CODE -> up to and exclusive -<CODE -CLASS="CONSTANT" ->V4L2_CID_BASE_LASTP1</CODE ->, or starting from -<CODE -CLASS="CONSTANT" ->V4L2_CID_PRIVATE_BASE</CODE -> until the driver returns -<SPAN -CLASS="ERRORCODE" ->EINVAL</SPAN ->. When the -<CODE -CLASS="CONSTANT" ->V4L2_CTRL_FLAG_DISABLED</CODE -> flag is set in the -<CODE -CLASS="STRUCTFIELD" ->flags</CODE -> field, this control is permanently -disabled and should be ignored by the application.<A -NAME="AEN8815" -HREF="#FTN.AEN8815" -><SPAN -CLASS="footnote" ->[25]</SPAN -></A -></P -><P ->Additional information is required for menu controls, the -name of menu items. To query them applications set the -<CODE -CLASS="STRUCTFIELD" ->id</CODE -> and <CODE -CLASS="STRUCTFIELD" ->index</CODE -> -fields of struct <A -HREF="#V4L2-QUERYMENU" ->v4l2_querymenu</A -> and call the -<CODE -CLASS="CONSTANT" ->VIDIOC_QUERYMENU</CODE -> ioctl with a pointer to this -structure. The driver fills the rest of the structure or returns an -<SPAN -CLASS="ERRORCODE" ->EINVAL</SPAN -> error code when the <CODE -CLASS="STRUCTFIELD" ->id</CODE -> or -<CODE -CLASS="STRUCTFIELD" ->index</CODE -> is invalid. Menu items are enumerated -by calling <CODE -CLASS="CONSTANT" ->VIDIOC_QUERYMENU</CODE -> with successive -<CODE -CLASS="STRUCTFIELD" ->index</CODE -> values from struct <A -HREF="#V4L2-QUERYCTRL" ->v4l2_queryctrl</A -> -<CODE -CLASS="STRUCTFIELD" ->minimum</CODE -> (0) to -<CODE -CLASS="STRUCTFIELD" ->maximum</CODE ->, inclusive.</P -><DIV -CLASS="TABLE" -><A -NAME="V4L2-QUERYCTRL" -></A -><P -><B ->Table 1. struct <CODE -CLASS="STRUCTNAME" ->v4l2_queryctrl</CODE -></B -></P -><TABLE -BORDER="0" -FRAME="void" -WIDTH="100%" -CLASS="CALSTABLE" -><COL -WIDTH="25%" -TITLE="C1"><COL -WIDTH="25%" -TITLE="C2"><COL -WIDTH="50%" -TITLE="C3"><TBODY -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->id</CODE -></TD -><TD ->Identifies the control, set by the application. -See <A -HREF="#CONTROL-ID" ->Table 1-1</A -> for predefined IDs.</TD -></TR -><TR -><TD ->enum <A -HREF="#V4L2-CTRL-TYPE" ->v4l2_ctrl_type</A -></TD -><TD -><CODE -CLASS="STRUCTFIELD" ->type</CODE -></TD -><TD ->Type of control, see <A -HREF="#V4L2-CTRL-TYPE" ->Table 3</A ->.</TD -></TR -><TR -><TD ->__u8</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->name</CODE ->[32]</TD -><TD ->Name of the control, a NUL-terminated ASCII -string. This information is intended for the user.</TD -></TR -><TR -><TD ->__s32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->minimum</CODE -></TD -><TD ->Minimum value, inclusive. This field is mostly -useful to define a lower bound for integer controls. Note the value is -signed.</TD -></TR -><TR -><TD ->__s32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->maximum</CODE -></TD -><TD ->Maximum value, inclusive. Note the value is -signed.</TD -></TR -><TR -><TD ->__s32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->step</CODE -></TD -><TD -><P ->Generally drivers should not scale hardware -control values. It may be necessary for example when the -<CODE -CLASS="STRUCTFIELD" ->name</CODE -> or <CODE -CLASS="STRUCTFIELD" ->id</CODE -> imply -a particular unit and the hardware actually accepts only multiples of -said unit. If so, drivers must take care values are properly rounded -when scaling, such that errors will not accumulate on repeated -read-write cycles.</P -><P ->This field reports the smallest change -of an integer control actually affecting hardware. Often the -information is needed when the user can change controls by keyboard or -GUI buttons, rather than a slider. When for example a hardware -register accepts values 0-511 and the driver reports 0-65535, step -should be 128.</P -><P ->Note although signed, the step value is -supposed to be always positive.</P -></TD -></TR -><TR -><TD ->__s32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->default_value</CODE -></TD -><TD ->The default value of the control. Drivers reset -controls only when the driver is loaded, not later, in particular not -when the <CODE -CLASS="FUNCTION" ->open()</CODE -> is called.</TD -></TR -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->flags</CODE -></TD -><TD ->Control flags, see <A -HREF="#CONTROL-FLAGS" ->Table 4</A ->.</TD -></TR -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->reserved</CODE ->[2]</TD -><TD ->Reserved for future extensions. Drivers must set -the array to zero.</TD -></TR -></TBODY -></TABLE -></DIV -><DIV -CLASS="TABLE" -><A -NAME="V4L2-QUERYMENU" -></A -><P -><B ->Table 2. struct <CODE -CLASS="STRUCTNAME" ->v4l2_querymenu</CODE -></B -></P -><TABLE -BORDER="0" -FRAME="void" -WIDTH="100%" -CLASS="CALSTABLE" -><COL -WIDTH="25%" -TITLE="C1"><COL -WIDTH="25%" -TITLE="C2"><COL -WIDTH="50%" -TITLE="C3"><TBODY -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->id</CODE -></TD -><TD ->Identifies the control, set by the application -from the respective struct <A -HREF="#V4L2-QUERYCTRL" ->v4l2_queryctrl</A -> -<CODE -CLASS="STRUCTFIELD" ->id</CODE ->.</TD -></TR -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->index</CODE -></TD -><TD ->Index of the menu item, starting at zero, set by - the application.</TD -></TR -><TR -><TD ->__u8</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->name</CODE ->[32]</TD -><TD ->Name of the menu item, a NUL-terminated ASCII -string. This information is intended for the user.</TD -></TR -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->reserved</CODE -></TD -><TD ->Reserved for future extensions. Drivers must set -the array to zero.</TD -></TR -></TBODY -></TABLE -></DIV -><DIV -CLASS="TABLE" -><A -NAME="V4L2-CTRL-TYPE" -></A -><P -><B ->Table 3. enum v4l2_ctrl_type</B -></P -><TABLE -BORDER="0" -FRAME="void" -WIDTH="100%" -CLASS="CALSTABLE" -><COL -WIDTH="30%"><COL -WIDTH="5%" -ALIGN="CENTER"><COL -WIDTH="5%" -ALIGN="CENTER"><COL -WIDTH="5%" -ALIGN="CENTER"><COL -WIDTH="55%"><THEAD -><TR -><TH ->Type</TH -><TH -><CODE -CLASS="STRUCTFIELD" ->minimum</CODE -></TH -><TH -><CODE -CLASS="STRUCTFIELD" ->step</CODE -></TH -><TH -><CODE -CLASS="STRUCTFIELD" ->maximum</CODE -></TH -><TH ->Description</TH -></TR -></THEAD -><TBODY -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_CTRL_TYPE_INTEGER</CODE -></TD -><TD ->low value</TD -><TD ->increment (positive) [__u32?]</TD -><TD ->high value</TD -><TD ->An integer-valued control ranging from minimum to -maximum inclusive. The step value indicates the increment between -values which are actually different on the hardware.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_CTRL_TYPE_BOOLEAN</CODE -></TD -><TD ->0</TD -><TD ->1</TD -><TD ->1</TD -><TD ->A boolean-valued control. Zero corresponds to -"disabled", and one means "enabled".</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_CTRL_TYPE_MENU</CODE -></TD -><TD ->0</TD -><TD ->1</TD -><TD ->N-1</TD -><TD ->The control has a menu of N choices. The names of -the menu items can be enumerated with the -<CODE -CLASS="CONSTANT" ->VIDIOC_QUERYMENU</CODE -> ioctl.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_CTRL_TYPE_BUTTON</CODE -></TD -><TD ->0</TD -><TD ->0</TD -><TD ->0</TD -><TD ->A control which performs an action when set. -Drivers must ignore the value passed with -<CODE -CLASS="CONSTANT" ->VIDIOC_S_CTRL</CODE -> and return an <SPAN -CLASS="ERRORCODE" ->EINVAL</SPAN -> error code on a -<CODE -CLASS="CONSTANT" ->VIDIOC_G_CTRL</CODE -> attempt.</TD -></TR -></TBODY -></TABLE -></DIV -><DIV -CLASS="TABLE" -><A -NAME="CONTROL-FLAGS" -></A -><P -><B ->Table 4. Control Flags</B -></P -><TABLE -BORDER="0" -FRAME="void" -WIDTH="100%" -CLASS="CALSTABLE" -><COL -WIDTH="38%" -TITLE="C1"><COL -WIDTH="12%" -TITLE="C2"><COL -WIDTH="50%" -TITLE="C3"><TBODY -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_CTRL_FLAG_DISABLED</CODE -></TD -><TD ->0x0001</TD -><TD ->This control is permanently disabled and should be ignored by the application. An attempt to change -this control results in an <SPAN -CLASS="ERRORCODE" ->EINVAL</SPAN -> error code.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_CTRL_FLAG_GRABBED</CODE -></TD -><TD ->0x0002</TD -><TD ->This control is temporarily unchangeable, for -example because another application took over control of the -respective resource. Such controls may be displayed specially in a -user interface. An attempt to change a "grabbed" control results in an -<SPAN -CLASS="ERRORCODE" ->EBUSY</SPAN -> error code.</TD -></TR -></TBODY -></TABLE -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN8997" -></A -><H2 ->Return Value</H2 -><P ->On success <SPAN -CLASS="RETURNVALUE" ->0</SPAN -> is returned, on -error <SPAN -CLASS="RETURNVALUE" ->-1</SPAN -> and <VAR -CLASS="VARNAME" ->errno</VAR -> is -set appropriately:</P -><P -></P -><DIV -CLASS="VARIABLELIST" -><DL -><DT -><SPAN -CLASS="ERRORCODE" ->EINVAL</SPAN -></DT -><DD -><P ->The struct <A -HREF="#V4L2-QUERYCTRL" ->v4l2_queryctrl</A -> <CODE -CLASS="STRUCTFIELD" ->id</CODE -> -is invalid. The struct <A -HREF="#V4L2-QUERYMENU" ->v4l2_querymenu</A -> <CODE -CLASS="STRUCTFIELD" ->id</CODE -> or -<CODE -CLASS="STRUCTFIELD" ->index</CODE -> is invalid.</P -></DD -></DL -></DIV -></DIV -><H1 -><A -NAME="VIDIOC-QUERYSTD" -></A ->ioctl VIDIOC_QUERYSTD</H1 -><DIV -CLASS="REFNAMEDIV" -><A -NAME="AEN9015" -></A -><H2 ->Name</H2 ->ioctl VIDIOC_QUERYSTD -- Sense the video standard received by the current input</DIV -><DIV -CLASS="REFSYNOPSISDIV" -><A -NAME="AEN9018" -></A -><H2 ->Synopsis</H2 -><DIV -CLASS="FUNCSYNOPSIS" -><P -></P -><A -NAME="AEN9019" -></A -><P -><CODE -><CODE -CLASS="FUNCDEF" ->int ioctl</CODE ->(int fd, int request, v4l2_std_id *argp);</CODE -></P -><P -></P -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN9029" -></A -><H2 ->Arguments</H2 -><P -></P -><DIV -CLASS="VARIABLELIST" -><DL -><DT -><VAR -CLASS="PARAMETER" ->fd</VAR -></DT -><DD -><P ->File descriptor returned by <A -HREF="#FUNC-OPEN" -><CODE -CLASS="FUNCTION" ->open()</CODE -></A ->.</P -></DD -><DT -><VAR -CLASS="PARAMETER" ->request</VAR -></DT -><DD -><P ->VIDIOC_QUERYSTD</P -></DD -><DT -><VAR -CLASS="PARAMETER" ->argp</VAR -></DT -><DD -><P -></P -></DD -></DL -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN9049" -></A -><H2 ->Description</H2 -><P ->The hardware may be able to detect the current video -standard automatically. To do so, applications call <CODE -CLASS="CONSTANT" ->VIDIOC_QUERYSTD</CODE -> with a pointer to a <A -HREF="#V4L2-STD-ID" ->v4l2_std_id</A -> type. The -driver stores here a set of candidates, this can be a single flag or a -set of supported standards if for example the hardware can only -distinguish between 50 and 60 Hz systems. When detection is not -possible or fails, the set must contain all standards supported by the -current video input or output.</P -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN9054" -></A -><H2 ->Return Value</H2 -><P ->On success <SPAN -CLASS="RETURNVALUE" ->0</SPAN -> is returned, on -error <SPAN -CLASS="RETURNVALUE" ->-1</SPAN -> and <VAR -CLASS="VARNAME" ->errno</VAR -> is -set appropriately:</P -><P -></P -><DIV -CLASS="VARIABLELIST" -><DL -><DT -><SPAN -CLASS="ERRORCODE" ->EINVAL</SPAN -></DT -><DD -><P ->This ioctl is not supported.</P -></DD -></DL -></DIV -></DIV -><H1 -><A -NAME="VIDIOC-REQBUFS" -></A ->ioctl VIDIOC_REQBUFS</H1 -><DIV -CLASS="REFNAMEDIV" -><A -NAME="AEN9067" -></A -><H2 ->Name</H2 ->ioctl VIDIOC_REQBUFS -- Initiate Memory Mapping or User Pointer I/O</DIV -><DIV -CLASS="REFSYNOPSISDIV" -><A -NAME="AEN9070" -></A -><H2 ->Synopsis</H2 -><DIV -CLASS="FUNCSYNOPSIS" -><P -></P -><A -NAME="AEN9071" -></A -><P -><CODE -><CODE -CLASS="FUNCDEF" ->int ioctl</CODE ->(int fd, int request, struct v4l2_requestbuffers *argp);</CODE -></P -><P -></P -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN9081" -></A -><H2 ->Arguments</H2 -><P -></P -><DIV -CLASS="VARIABLELIST" -><DL -><DT -><VAR -CLASS="PARAMETER" ->fd</VAR -></DT -><DD -><P ->File descriptor returned by <A -HREF="#FUNC-OPEN" -><CODE -CLASS="FUNCTION" ->open()</CODE -></A ->.</P -></DD -><DT -><VAR -CLASS="PARAMETER" ->request</VAR -></DT -><DD -><P ->VIDIOC_REQBUFS</P -></DD -><DT -><VAR -CLASS="PARAMETER" ->argp</VAR -></DT -><DD -><P -></P -></DD -></DL -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN9101" -></A -><H2 ->Description</H2 -><P ->This ioctl is used to initiate <A -HREF="#MMAP" ->memory -mapped</A -> or <A -HREF="#USERP" ->user pointer</A -> -I/O. Memory mapped buffers are located in device memory and must be -allocated with this ioctl before they can be mapped into the -application's address space. User buffers are allocated by -applications themselves, and this ioctl is merely used to switch the -driver into user pointer I/O mode.</P -><P ->To allocate device buffers applications initialize three -fields of a <CODE -CLASS="STRUCTNAME" ->v4l2_requestbuffers</CODE -> structure. -They set the <CODE -CLASS="STRUCTFIELD" ->type</CODE -> field to the respective -stream or buffer type, the <CODE -CLASS="STRUCTFIELD" ->count</CODE -> field to -the desired number of buffers, and <CODE -CLASS="STRUCTFIELD" ->memory</CODE -> -must be set to <CODE -CLASS="CONSTANT" ->V4L2_MEMORY_MMAP</CODE ->. When the ioctl -is called with a pointer to this structure the driver attempts to -allocate the requested number of buffers and stores the actual number -allocated in the <CODE -CLASS="STRUCTFIELD" ->count</CODE -> field. It can be -smaller than the number requested, even zero, when the driver runs out -of free memory. A larger number is possible when the driver requires -more buffers to function correctly.<A -NAME="AEN9113" -HREF="#FTN.AEN9113" -><SPAN -CLASS="footnote" ->[26]</SPAN -></A -> When memory mapping I/O is not supported the ioctl -returns an <SPAN -CLASS="ERRORCODE" ->EINVAL</SPAN -> error code.</P -><P ->Applications can call <CODE -CLASS="CONSTANT" ->VIDIOC_REQBUFS</CODE -> -again to change the number of buffers, however this cannot succeed -when any buffers are still mapped. A <CODE -CLASS="STRUCTFIELD" ->count</CODE -> -value of zero frees all buffers, after aborting or finishing any DMA -in progress, an implicit <A -HREF="#VIDIOC-STREAMON" -><CODE -CLASS="CONSTANT" ->VIDIOC_STREAMOFF</CODE -></A ->. </P -><P ->To negotiate user pointer I/O, applications initialize only -the <CODE -CLASS="STRUCTFIELD" ->type</CODE -> field and set -<CODE -CLASS="STRUCTFIELD" ->memory</CODE -> to -<CODE -CLASS="CONSTANT" ->V4L2_MEMORY_USERPTR</CODE ->. When the ioctl is called -with a pointer to this structure the driver prepares for user pointer -I/O, when this I/O method is not supported the ioctl returns an -<SPAN -CLASS="ERRORCODE" ->EINVAL</SPAN -> error code.</P -><DIV -CLASS="TABLE" -><A -NAME="V4L2-REQUESTBUFFERS" -></A -><P -><B ->Table 1. struct <CODE -CLASS="STRUCTNAME" ->v4l2_requestbuffers</CODE -></B -></P -><TABLE -BORDER="0" -FRAME="void" -WIDTH="100%" -CLASS="CALSTABLE" -><COL -WIDTH="25%" -TITLE="C1"><COL -WIDTH="25%" -TITLE="C2"><COL -WIDTH="50%" -TITLE="C3"><TBODY -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->count</CODE -></TD -><TD ->The number of buffers requested or granted. This -field is only used when <CODE -CLASS="STRUCTFIELD" ->memory</CODE -> is set to -<CODE -CLASS="CONSTANT" ->V4L2_MEMORY_MMAP</CODE ->.</TD -></TR -><TR -><TD ->enum <A -HREF="#V4L2-BUF-TYPE" ->v4l2_buf_type</A -></TD -><TD -><CODE -CLASS="STRUCTFIELD" ->type</CODE -></TD -><TD ->Type of the stream or buffers, this is the same -as the struct <A -HREF="#V4L2-FORMAT" ->v4l2_format</A -> <CODE -CLASS="STRUCTFIELD" ->type</CODE -> field. See <A -HREF="#V4L2-BUF-TYPE" ->Table 3-2</A -> for valid values.</TD -></TR -><TR -><TD ->enum <A -HREF="#V4L2-MEMORY" ->v4l2_memory</A -></TD -><TD -><CODE -CLASS="STRUCTFIELD" ->memory</CODE -></TD -><TD ->Applications set this field to -<CODE -CLASS="CONSTANT" ->V4L2_MEMORY_MMAP</CODE -> or -<CODE -CLASS="CONSTANT" ->V4L2_MEMORY_USERPTR</CODE ->.</TD -></TR -><TR -><TD ->__u32</TD -><TD -><CODE -CLASS="STRUCTFIELD" ->reserved</CODE ->[32]</TD -><TD ->A place holder for future extensions and custom -(driver defined) buffer types <CODE -CLASS="CONSTANT" ->V4L2_BUF_TYPE_PRIVATE</CODE -> and -higher.</TD -></TR -></TBODY -></TABLE -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN9165" -></A -><H2 ->Return Value</H2 -><P ->On success <SPAN -CLASS="RETURNVALUE" ->0</SPAN -> is returned, on -error <SPAN -CLASS="RETURNVALUE" ->-1</SPAN -> and <VAR -CLASS="VARNAME" ->errno</VAR -> is -set appropriately:</P -><P -></P -><DIV -CLASS="VARIABLELIST" -><DL -><DT -><SPAN -CLASS="ERRORCODE" ->EBUSY</SPAN -></DT -><DD -><P ->The driver supports multiple opens and I/O is already -in progress, or reallocation of buffers was attempted although one or -more are still mapped.</P -></DD -><DT -><SPAN -CLASS="ERRORCODE" ->EINVAL</SPAN -></DT -><DD -><P ->The buffer type (<CODE -CLASS="STRUCTFIELD" ->type</CODE -> field) or the -requested I/O method (<CODE -CLASS="STRUCTFIELD" ->memory</CODE ->) is not -supported.</P -></DD -></DL -></DIV -></DIV -><H1 -><A -NAME="VIDIOC-STREAMON" -></A ->ioctl VIDIOC_STREAMON, VIDIOC_STREAMOFF</H1 -><DIV -CLASS="REFNAMEDIV" -><A -NAME="AEN9187" -></A -><H2 ->Name</H2 ->ioctl VIDIOC_STREAMON, ioctl VIDIOC_STREAMOFF -- Start or stop streaming I/O.</DIV -><DIV -CLASS="REFSYNOPSISDIV" -><A -NAME="AEN9191" -></A -><H2 ->Synopsis</H2 -><DIV -CLASS="FUNCSYNOPSIS" -><P -></P -><A -NAME="AEN9192" -></A -><P -><CODE -><CODE -CLASS="FUNCDEF" ->int ioctl</CODE ->(int fd, int request, const int *argp);</CODE -></P -><P -></P -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN9202" -></A -><H2 ->Arguments</H2 -><P -></P -><DIV -CLASS="VARIABLELIST" -><DL -><DT -><VAR -CLASS="PARAMETER" ->fd</VAR -></DT -><DD -><P ->File descriptor returned by <A -HREF="#FUNC-OPEN" -><CODE -CLASS="FUNCTION" ->open()</CODE -></A ->.</P -></DD -><DT -><VAR -CLASS="PARAMETER" ->request</VAR -></DT -><DD -><P ->VIDIOC_STREAMON, VIDIOC_STREAMOFF</P -></DD -><DT -><VAR -CLASS="PARAMETER" ->argp</VAR -></DT -><DD -><P -></P -></DD -></DL -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN9222" -></A -><H2 ->Description</H2 -><P ->The <CODE -CLASS="CONSTANT" ->VIDIOC_STREAMON</CODE -> and -<CODE -CLASS="CONSTANT" ->VIDIOC_STREAMOFF</CODE -> ioctl start and stop the capture -or output process during streaming (<A -HREF="#MMAP" ->memory -mapping</A -> or <A -HREF="#USERP" ->user pointer</A ->) I/O.</P -><P ->Specifically the capture hardware is disabled and no input -buffers are filled (if there are any empty buffers in the incoming -queue) until <CODE -CLASS="CONSTANT" ->VIDIOC_STREAMON</CODE -> has been called. -Accordingly the output hardware is disabled, no video signal is -produced until <CODE -CLASS="CONSTANT" ->VIDIOC_STREAMON</CODE -> has been called. -The ioctl will succeed only when at least one output buffer is in the -incoming queue.</P -><P ->The <CODE -CLASS="CONSTANT" ->VIDIOC_STREAMOFF</CODE -> ioctl, apart of -aborting or finishing any DMA in progress, unlocks any user pointer -buffers locked in physical memory, and it removes all buffers from the -incoming and outgoing queues. That means all images captured but not -dequeued yet will be lost, likewise all images enqueued for output but -not transmitted yet. I/O returns to the same state as after calling -<A -HREF="#VIDIOC-REQBUFS" -><CODE -CLASS="CONSTANT" ->VIDIOC_REQBUFS</CODE -></A -> and can be restarted accordingly.</P -><P ->Both ioctls take a pointer to an integer, the desired buffer or -stream type. This is the same as struct <A -HREF="#V4L2-REQUESTBUFFERS" ->v4l2_requestbuffers</A -> -<CODE -CLASS="STRUCTFIELD" ->type</CODE ->.</P -><P ->Note applications can be preempted for unknown periods right -before or after the <CODE -CLASS="CONSTANT" ->VIDIOC_STREAMON</CODE -> or -<CODE -CLASS="CONSTANT" ->VIDIOC_STREAMOFF</CODE -> calls, there is no notion of -starting or stopping "now". Buffer timestamps can be used to -synchronize with other events.</P -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN9242" -></A -><H2 ->Return Value</H2 -><P ->On success <SPAN -CLASS="RETURNVALUE" ->0</SPAN -> is returned, on -error <SPAN -CLASS="RETURNVALUE" ->-1</SPAN -> and <VAR -CLASS="VARNAME" ->errno</VAR -> is -set appropriately:</P -><P -></P -><DIV -CLASS="VARIABLELIST" -><DL -><DT -><SPAN -CLASS="ERRORCODE" ->EINVAL</SPAN -></DT -><DD -><P ->Streaming I/O is not supported, the buffer -<CODE -CLASS="STRUCTFIELD" ->type</CODE -> is not supported, or no buffers have -been allocated (memory mapping) or enqueued (output) yet.</P -></DD -></DL -></DIV -></DIV -><H1 -><A -NAME="FUNC-MMAP" -></A ->mmap</H1 -><DIV -CLASS="REFNAMEDIV" -><A -NAME="AEN9256" -></A -><H2 ->Name</H2 ->mmap -- Map device memory into application address space</DIV -><DIV -CLASS="REFSYNOPSISDIV" -><A -NAME="AEN9259" -></A -><H2 ->Synopsis</H2 -><DIV -CLASS="FUNCSYNOPSIS" -><P -></P -><A -NAME="AEN9260" -></A -><PRE -CLASS="FUNCSYNOPSISINFO" ->#include <unistd.h> -#include <sys/mman.h></PRE -><P -><CODE -><CODE -CLASS="FUNCDEF" ->void *mmap</CODE ->(void *start, size_t length, int prot, int flags, int fd, off_t offset);</CODE -></P -><P -></P -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN9277" -></A -><H2 ->Arguments</H2 -><P -></P -><DIV -CLASS="VARIABLELIST" -><DL -><DT -><VAR -CLASS="PARAMETER" ->start</VAR -></DT -><DD -><P ->Map the buffer to this address in the -application's address space. When the <CODE -CLASS="CONSTANT" ->MAP_FIXED</CODE -> -flag is specified, <VAR -CLASS="PARAMETER" ->start</VAR -> must be a multiple of the -pagesize and mmap will fail when the specified address -cannot be used. Use of this option is discouraged; applications should -just specify a <CODE -CLASS="CONSTANT" ->NULL</CODE -> pointer here.</P -></DD -><DT -><VAR -CLASS="PARAMETER" ->length</VAR -></DT -><DD -><P ->Length of the memory area to map. This must be the -same value as returned by the driver in the struct <A -HREF="#V4L2-BUFFER" ->v4l2_buffer</A -> -<CODE -CLASS="STRUCTFIELD" ->length</CODE -> field.</P -></DD -><DT -><VAR -CLASS="PARAMETER" ->prot</VAR -></DT -><DD -><P ->The <VAR -CLASS="PARAMETER" ->prot</VAR -> argument describes the -desired memory protection. It must be set to -<CODE -CLASS="CONSTANT" ->PROT_READ</CODE -> | <CODE -CLASS="CONSTANT" ->PROT_WRITE</CODE ->, -indicating pages may be read and written. This is a technicality -independent of the -device type and direction of data exchange. Note device memory -accesses may incur a performance penalty. It can happen when writing -to capture buffers, when reading from output buffers, or always. When -the application intends to modify buffers, other I/O methods may be -more efficient.</P -></DD -><DT -><VAR -CLASS="PARAMETER" ->flags</VAR -></DT -><DD -><P ->The <VAR -CLASS="PARAMETER" ->flags</VAR -> parameter -specifies the type of the mapped object, mapping options and whether -modifications made to the mapped copy of the page are private to the -process or are to be shared with other references.</P -><P -><CODE -CLASS="CONSTANT" ->MAP_FIXED</CODE -> requests that the -driver selects no other address than the one specified. If the -specified address cannot be used, mmap will fail. If -<CODE -CLASS="CONSTANT" ->MAP_FIXED</CODE -> is specified, -<VAR -CLASS="PARAMETER" ->start</VAR -> must be a multiple of the pagesize. Use -of this option is discouraged.</P -><P ->One of the <CODE -CLASS="CONSTANT" ->MAP_SHARED</CODE -> or -<CODE -CLASS="CONSTANT" ->MAP_PRIVATE</CODE -> flags must be set. -<CODE -CLASS="CONSTANT" ->MAP_SHARED</CODE -> allows to share this mapping with all -other processes that map this object. <CODE -CLASS="CONSTANT" ->MAP_PRIVATE</CODE -> -requests copy-on-write semantics. We recommend to set -<CODE -CLASS="CONSTANT" ->MAP_SHARED</CODE ->. The <CODE -CLASS="CONSTANT" ->MAP_PRIVATE</CODE ->, -<CODE -CLASS="CONSTANT" ->MAP_DENYWRITE</CODE ->, -<CODE -CLASS="CONSTANT" ->MAP_EXECUTABLE</CODE -> and <CODE -CLASS="CONSTANT" ->MAP_ANON</CODE -> -flags should not be set.</P -></DD -><DT -><VAR -CLASS="PARAMETER" ->fd</VAR -></DT -><DD -><P ->File descriptor returned by <A -HREF="#FUNC-OPEN" -><CODE -CLASS="FUNCTION" ->open()</CODE -></A ->.</P -></DD -><DT -><VAR -CLASS="PARAMETER" ->offset</VAR -></DT -><DD -><P ->Offset of the buffer in device memory. This must be the -same value as returned by the driver in the struct <A -HREF="#V4L2-BUFFER" ->v4l2_buffer</A -> -<CODE -CLASS="STRUCTFIELD" ->m</CODE -> union <CODE -CLASS="STRUCTFIELD" ->offset</CODE -> field.</P -></DD -></DL -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN9338" -></A -><H2 ->Description</H2 -><P ->The <CODE -CLASS="FUNCTION" ->mmap()</CODE -> function asks to map -<VAR -CLASS="PARAMETER" ->length</VAR -> bytes starting at -<VAR -CLASS="PARAMETER" ->offset</VAR -> in the memory of the device specified by -<VAR -CLASS="PARAMETER" ->fd</VAR -> into the application address space, -preferably at address <VAR -CLASS="PARAMETER" ->start</VAR ->. This latter -address is a hint only, and is usually specified as 0.</P -><P ->Suitable length and offset parameters are queried with the -<A -HREF="#VIDIOC-QUERYBUF" -><CODE -CLASS="CONSTANT" ->VIDIOC_QUERYBUF</CODE -></A -> ioctl. Buffers must be allocated with the -<A -HREF="#VIDIOC-REQBUFS" -><CODE -CLASS="CONSTANT" ->VIDIOC_REQBUFS</CODE -></A -> ioctl before they can be queried.</P -><P ->To unmap buffers the <A -HREF="#FUNC-MUNMAP" -><CODE -CLASS="FUNCTION" ->munmap()</CODE -></A -> function is used.</P -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN9354" -></A -><H2 ->Return Value</H2 -><P ->On success, <CODE -CLASS="FUNCTION" ->mmap()</CODE -> returns a pointer to -the mapped buffer. On error, <CODE -CLASS="CONSTANT" ->MAP_FAILED</CODE -> (-1) is -returned, and <VAR -CLASS="VARNAME" ->errno</VAR -> is set appropriately. Possible -error codes:</P -><P -></P -><DIV -CLASS="VARIABLELIST" -><DL -><DT -><SPAN -CLASS="ERRORCODE" ->EBADF</SPAN -></DT -><DD -><P -><VAR -CLASS="PARAMETER" ->fd</VAR -> is not a valid file -descriptor.</P -></DD -><DT -><SPAN -CLASS="ERRORCODE" ->EACCESS</SPAN -></DT -><DD -><P -><VAR -CLASS="PARAMETER" ->fd</VAR -> is -not open for reading and writing.</P -></DD -><DT -><SPAN -CLASS="ERRORCODE" ->EINVAL</SPAN -></DT -><DD -><P ->The <VAR -CLASS="PARAMETER" ->start</VAR -> or -<VAR -CLASS="PARAMETER" ->length</VAR -> or <VAR -CLASS="PARAMETER" ->offset</VAR -> are not -suitable. (E.g., they are too large, or not aligned on a -<CODE -CLASS="CONSTANT" ->PAGESIZE</CODE -> boundary.) Or no buffers have been -allocated with the <A -HREF="#VIDIOC-REQBUFS" -><CODE -CLASS="CONSTANT" ->VIDIOC_REQBUFS</CODE -></A -> ioctl.</P -></DD -><DT -><SPAN -CLASS="ERRORCODE" ->ENOMEM</SPAN -></DT -><DD -><P ->No memory is available.</P -></DD -></DL -></DIV -></DIV -><H1 -><A -NAME="FUNC-MUNMAP" -></A ->munmap</H1 -><DIV -CLASS="REFNAMEDIV" -><A -NAME="AEN9390" -></A -><H2 ->Name</H2 ->munmap -- Unmap device memory</DIV -><DIV -CLASS="REFSYNOPSISDIV" -><A -NAME="AEN9393" -></A -><H2 ->Synopsis</H2 -><DIV -CLASS="FUNCSYNOPSIS" -><P -></P -><A -NAME="AEN9394" -></A -><PRE -CLASS="FUNCSYNOPSISINFO" ->#include <unistd.h> -#include <sys/mman.h></PRE -><P -><CODE -><CODE -CLASS="FUNCDEF" ->int munmap</CODE ->(void *start, size_t length);</CODE -></P -><P -></P -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN9403" -></A -><H2 ->Arguments</H2 -><P -></P -><DIV -CLASS="VARIABLELIST" -><DL -><DT -><VAR -CLASS="PARAMETER" ->start</VAR -></DT -><DD -><P ->Address of the mapped buffer as returned by the -<A -HREF="#FUNC-MMAP" -><CODE -CLASS="FUNCTION" ->mmap()</CODE -></A -> function.</P -></DD -><DT -><VAR -CLASS="PARAMETER" ->length</VAR -></DT -><DD -><P ->Length of the mapped buffer. This must be the same -value as given to <CODE -CLASS="FUNCTION" ->mmap()</CODE -> and returned by the -driver in the struct <A -HREF="#V4L2-BUFFER" ->v4l2_buffer</A -> <CODE -CLASS="STRUCTFIELD" ->length</CODE -> -field.</P -></DD -></DL -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN9421" -></A -><H2 ->Description</H2 -><P ->Unmaps a previously with the <A -HREF="#FUNC-MMAP" -><CODE -CLASS="FUNCTION" ->mmap()</CODE -></A -> function mapped -buffer and frees it, if possible. </P -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN9426" -></A -><H2 ->Return Value</H2 -><P ->On success <CODE -CLASS="FUNCTION" ->munmap()</CODE -> returns 0, on -failure -1, and errno is set.</P -><P -></P -><DIV -CLASS="VARIABLELIST" -><DL -><DT -><SPAN -CLASS="ERRORCODE" ->EINVAL</SPAN -></DT -><DD -><P ->The <VAR -CLASS="PARAMETER" ->start</VAR -> or -<VAR -CLASS="PARAMETER" ->length</VAR -> is incorrect, or no buffers have been -mapped yet.</P -></DD -></DL -></DIV -></DIV -><H1 -><A -NAME="FUNC-OPEN" -></A ->open</H1 -><DIV -CLASS="REFNAMEDIV" -><A -NAME="AEN9439" -></A -><H2 ->Name</H2 ->open -- Open a V4L2 device</DIV -><DIV -CLASS="REFSYNOPSISDIV" -><A -NAME="AEN9442" -></A -><H2 ->Synopsis</H2 -><DIV -CLASS="FUNCSYNOPSIS" -><P -></P -><A -NAME="AEN9443" -></A -><PRE -CLASS="FUNCSYNOPSISINFO" ->#include <fcntl.h></PRE -><P -><CODE -><CODE -CLASS="FUNCDEF" ->int open</CODE ->(const char *device_name, int flags);</CODE -></P -><P -></P -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN9452" -></A -><H2 ->Arguments</H2 -><P -></P -><DIV -CLASS="VARIABLELIST" -><DL -><DT -><VAR -CLASS="PARAMETER" ->device_name</VAR -></DT -><DD -><P ->Device to be opened.</P -></DD -><DT -><VAR -CLASS="PARAMETER" ->flags</VAR -></DT -><DD -><P ->Open flags. Access mode must be -<CODE -CLASS="CONSTANT" ->O_RDWR</CODE ->. This is just a technicality, input devices -still support only reading and output devices only writing.</P -><P ->When the <CODE -CLASS="CONSTANT" ->O_NONBLOCK</CODE -> flag is -given, the read() function and the <A -HREF="#VIDIOC-QBUF" -><CODE -CLASS="CONSTANT" ->VIDIOC_DQBUF</CODE -></A -> ioctl will return -the <SPAN -CLASS="ERRORCODE" ->EAGAIN</SPAN -> error code when no data is available or no buffer is in the driver -outgoing queue, otherwise these functions block until data becomes -available. All V4L2 drivers exchanging data with applications must -support the <CODE -CLASS="CONSTANT" ->O_NONBLOCK</CODE -> flag.</P -><P ->Other flags have no effect.</P -></DD -></DL -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN9473" -></A -><H2 ->Description</H2 -><P ->To open a V4L2 device applications call -<CODE -CLASS="FUNCTION" ->open()</CODE -> with the desired device name. This -function has no side effects; all data format parameters, current -input or output, control values or other properties remain unchanged. -At the first <CODE -CLASS="FUNCTION" ->open()</CODE -> call after loading the driver -they will be reset to default values, drivers are never in an -undefined state.</P -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN9478" -></A -><H2 ->Return Value</H2 -><P ->On success <CODE -CLASS="FUNCTION" ->open</CODE -> returns the new -file descriptor. On error -1 is returned, and <VAR -CLASS="VARNAME" ->errno</VAR -> -is set appropriately. Possible error codes:</P -><P -></P -><DIV -CLASS="VARIABLELIST" -><DL -><DT -><SPAN -CLASS="ERRORCODE" ->EACCES</SPAN -></DT -><DD -><P ->The caller has no permission to access the -device.</P -></DD -><DT -><SPAN -CLASS="ERRORCODE" ->EBUSY</SPAN -></DT -><DD -><P ->The driver does not support multiple opens and the -device is already in use.</P -></DD -><DT -><SPAN -CLASS="ERRORCODE" ->ENXIO</SPAN -></DT -><DD -><P ->No device corresponding to this device special file -exists.</P -></DD -><DT -><SPAN -CLASS="ERRORCODE" ->ENOMEM</SPAN -></DT -><DD -><P ->Insufficient kernel memory was available.</P -></DD -><DT -><SPAN -CLASS="ERRORCODE" ->EMFILE</SPAN -></DT -><DD -><P ->The process already has the maximum number of -files open.</P -></DD -><DT -><SPAN -CLASS="ERRORCODE" ->ENFILE</SPAN -></DT -><DD -><P ->The limit on the total number of files open on the -system has been reached.</P -></DD -></DL -></DIV -></DIV -><H1 -><A -NAME="FUNC-POLL" -></A ->poll</H1 -><DIV -CLASS="REFNAMEDIV" -><A -NAME="AEN9515" -></A -><H2 ->Name</H2 ->poll -- Wait for some event on a file descriptor</DIV -><DIV -CLASS="REFSYNOPSISDIV" -><A -NAME="AEN9518" -></A -><H2 ->Synopsis</H2 -><DIV -CLASS="FUNCSYNOPSIS" -><P -></P -><A -NAME="AEN9519" -></A -><PRE -CLASS="FUNCSYNOPSISINFO" ->#include <sys/poll.h></PRE -><P -><CODE -><CODE -CLASS="FUNCDEF" ->int poll</CODE ->(struct pollfd *ufds, unsigned int nfds, int timeout);</CODE -></P -><P -></P -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN9530" -></A -><H2 ->Description</H2 -><P ->All drivers implementing the <CODE -CLASS="FUNCTION" ->read()</CODE -> -or <CODE -CLASS="FUNCTION" ->write()</CODE -> function or streaming I/O must also support the -<CODE -CLASS="FUNCTION" ->poll()</CODE -> function. See the -<CODE -CLASS="FUNCTION" ->poll()</CODE -> manual page for details.</P -></DIV -><H1 -><A -NAME="FUNC-READ" -></A ->read</H1 -><DIV -CLASS="REFNAMEDIV" -><A -NAME="AEN9538" -></A -><H2 ->Name</H2 ->read -- Read from a V4L2 device</DIV -><DIV -CLASS="REFSYNOPSISDIV" -><A -NAME="AEN9541" -></A -><H2 ->Synopsis</H2 -><DIV -CLASS="FUNCSYNOPSIS" -><P -></P -><A -NAME="AEN9542" -></A -><PRE -CLASS="FUNCSYNOPSISINFO" ->#include <unistd.h></PRE -><P -><CODE -><CODE -CLASS="FUNCDEF" ->ssize_t read</CODE ->(int fd, void *buf, size_t count);</CODE -></P -><P -></P -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN9553" -></A -><H2 ->Arguments</H2 -><P -></P -><DIV -CLASS="VARIABLELIST" -><DL -><DT -><VAR -CLASS="PARAMETER" ->fd</VAR -></DT -><DD -><P ->File descriptor returned by <A -HREF="#FUNC-OPEN" -><CODE -CLASS="FUNCTION" ->open()</CODE -></A ->.</P -></DD -><DT -><VAR -CLASS="PARAMETER" ->buf</VAR -></DT -><DD -><P -></P -></DD -><DT -><VAR -CLASS="PARAMETER" ->count</VAR -></DT -><DD -><P -></P -></DD -></DL -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN9573" -></A -><H2 ->Description</H2 -><P -><CODE -CLASS="FUNCTION" ->read()</CODE -> attempts to read up to -<VAR -CLASS="PARAMETER" ->count</VAR -> bytes from file descriptor -<VAR -CLASS="PARAMETER" ->fd</VAR -> into the buffer starting at -<VAR -CLASS="PARAMETER" ->buf</VAR ->. The layout of the data in the buffer is -discussed in the respective device interface section, see ##. If <VAR -CLASS="PARAMETER" ->count</VAR -> is zero, -<CODE -CLASS="FUNCTION" ->read()</CODE -> returns zero and has no other results. If -<VAR -CLASS="PARAMETER" ->count</VAR -> is greater than -<CODE -CLASS="CONSTANT" ->SSIZE_MAX</CODE ->, the result is unspecified. Regardless -of the <VAR -CLASS="PARAMETER" ->count</VAR -> value each -<CODE -CLASS="FUNCTION" ->read()</CODE -> call will provide at most one frame (two -fields) worth of data.</P -><P ->By default <CODE -CLASS="FUNCTION" ->read()</CODE -> blocks until data -becomes available. When the <CODE -CLASS="CONSTANT" ->O_NONBLOCK</CODE -> flag was -given to the <A -HREF="#FUNC-OPEN" -><CODE -CLASS="FUNCTION" ->open()</CODE -></A -> function it -returns immediately with an <SPAN -CLASS="ERRORCODE" ->EAGAIN</SPAN -> error code when no data is available. The -<A -HREF="#FUNC-SELECT" -><CODE -CLASS="FUNCTION" ->select()</CODE -></A -> or <A -HREF="#FUNC-POLL" -><CODE -CLASS="FUNCTION" ->poll()</CODE -></A -> functions -can always be used to suspend execution until data becomes available. All -drivers supporting the <CODE -CLASS="FUNCTION" ->read()</CODE -> function must also -support <CODE -CLASS="FUNCTION" ->select()</CODE -> and -<CODE -CLASS="FUNCTION" ->poll()</CODE ->.</P -><P ->Drivers can implement read functionality in different -ways, using a single or multiple buffers and discarding the oldest or -newest frames once the internal buffers are filled.</P -><P -><CODE -CLASS="FUNCTION" ->read()</CODE -> never returns a "snapshot" of a -buffer being filled. Using a single buffer the driver will stop -capturing when the application starts reading the buffer until the -read is finished. Thus only the period of the vertical blanking -interval is available for reading, or the capture rate must fall below -the nominal frame rate of the video standard.</P -><P ->The behavior of -<CODE -CLASS="FUNCTION" ->read()</CODE -> when called during the active picture -period or the vertical blanking separating the top and bottom field -depends on the discarding policy. A driver discarding the oldest -frames keeps capturing into an internal buffer, continuously -overwriting the previously, not read frame, and returns the frame -being received at the time of the <CODE -CLASS="FUNCTION" ->read()</CODE -> call as -soon as it is complete.</P -><P ->A driver discarding the newest frames stops capturing until -the next <CODE -CLASS="FUNCTION" ->read()</CODE -> call. The frame being received at -<CODE -CLASS="FUNCTION" ->read()</CODE -> time is discarded, returning the following -frame instead. Again this implies a reduction of the capture rate to -one half or less of the nominal frame rate. An example of this model -is the video read mode of the "bttv" driver, initiating a DMA to user -memory when <CODE -CLASS="FUNCTION" ->read()</CODE -> is called and returning when -the DMA finished.</P -><P ->In the multiple buffer model drivers maintain a ring of -internal buffers, automatically advancing to the next free buffer. -This allows continuous capturing when the application can empty the -buffers fast enough. Again, the behavior when the driver runs out of -free buffers depends on the discarding policy.</P -><P ->Applications can get and set the number of buffers used -internally by the driver with the streaming parameter ioctls, see -##streaming-par. They -are optional, however. The discarding policy is not reported and -cannot be changed. For minimum requirements see the respective device -interface section in ##.</P -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN9611" -></A -><H2 ->Return Value</H2 -><P ->On success, the number of bytes read is returned. -It is not an error if this number is smaller than the number of bytes -requested, or the amount of data required for one frame. This may -happen for example because <CODE -CLASS="FUNCTION" ->read()</CODE -> was interrupted -by a signal. On error, -1 is returned, and <VAR -CLASS="VARNAME" ->errno</VAR -> -is set appropriately. In this case the next read will start at the -beginning of a new frame. Possible error codes:</P -><P -></P -><DIV -CLASS="VARIABLELIST" -><DL -><DT -><SPAN -CLASS="ERRORCODE" ->EAGAIN</SPAN -></DT -><DD -><P ->Non-blocking I/O has been selected using -O_NONBLOCK and no data was immediately available for reading.</P -></DD -><DT -><SPAN -CLASS="ERRORCODE" ->EBADF</SPAN -></DT -><DD -><P -><VAR -CLASS="PARAMETER" ->fd</VAR -> is not a valid file -descriptor or is not open for reading, or the process already has the -maximum number of files open.</P -></DD -><DT -><SPAN -CLASS="ERRORCODE" ->EBUSY</SPAN -></DT -><DD -><P ->The driver does not support multiple read streams and the -device is already in use.</P -></DD -><DT -><SPAN -CLASS="ERRORCODE" ->EFAULT</SPAN -></DT -><DD -><P -><VAR -CLASS="PARAMETER" ->buf</VAR -> is outside your -accessible address space.</P -></DD -><DT -><SPAN -CLASS="ERRORCODE" ->EINTR</SPAN -></DT -><DD -><P ->The call was interrupted by a signal before any -data was read.</P -></DD -><DT -><SPAN -CLASS="ERRORCODE" ->EIO</SPAN -></DT -><DD -><P ->I/O error. This indicates some hardware problem or a -failure to communicate with a remote device (USB camera etc.).</P -></DD -><DT -><SPAN -CLASS="ERRORCODE" ->EINVAL</SPAN -></DT -><DD -><P ->The <CODE -CLASS="FUNCTION" ->read()</CODE -> function is not -supported by this driver, not on this device, or generally not on this -type of device.</P -></DD -></DL -></DIV -></DIV -><H1 -><A -NAME="FUNC-SELECT" -></A ->select</H1 -><DIV -CLASS="REFNAMEDIV" -><A -NAME="AEN9656" -></A -><H2 ->Name</H2 ->select -- Synchronous I/O multiplexing</DIV -><DIV -CLASS="REFSYNOPSISDIV" -><A -NAME="AEN9659" -></A -><H2 ->Synopsis</H2 -><DIV -CLASS="FUNCSYNOPSIS" -><P -></P -><A -NAME="AEN9660" -></A -><PRE -CLASS="FUNCSYNOPSISINFO" ->#include <sys/time.h> -#include <sys/types.h> -#include <unistd.h></PRE -><P -><CODE -><CODE -CLASS="FUNCDEF" ->int select</CODE ->(int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);</CODE -></P -><P -></P -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN9675" -></A -><H2 ->Description</H2 -><P ->All drivers implementing the <CODE -CLASS="FUNCTION" ->read()</CODE -> -or <CODE -CLASS="FUNCTION" ->write()</CODE -> function or streaming I/O must also support the -<CODE -CLASS="FUNCTION" ->select()</CODE -> function. See the -<CODE -CLASS="FUNCTION" ->select()</CODE -> manual page for details.</P -></DIV -><H1 -><A -NAME="FUNC-WRITE" -></A ->write</H1 -><DIV -CLASS="REFNAMEDIV" -><A -NAME="AEN9683" -></A -><H2 ->Name</H2 ->write -- Write to a V4L2 device</DIV -><DIV -CLASS="REFSYNOPSISDIV" -><A -NAME="AEN9686" -></A -><H2 ->Synopsis</H2 -><DIV -CLASS="FUNCSYNOPSIS" -><P -></P -><A -NAME="AEN9687" -></A -><PRE -CLASS="FUNCSYNOPSISINFO" ->#include <unistd.h></PRE -><P -><CODE -><CODE -CLASS="FUNCDEF" ->ssize_t write</CODE ->(int fd, void *buf, size_t count);</CODE -></P -><P -></P -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN9698" -></A -><H2 ->Arguments</H2 -><P -></P -><DIV -CLASS="VARIABLELIST" -><DL -><DT -><VAR -CLASS="PARAMETER" ->fd</VAR -></DT -><DD -><P ->File descriptor returned by <A -HREF="#FUNC-OPEN" -><CODE -CLASS="FUNCTION" ->open()</CODE -></A ->.</P -></DD -><DT -><VAR -CLASS="PARAMETER" ->buf</VAR -></DT -><DD -><P -></P -></DD -><DT -><VAR -CLASS="PARAMETER" ->count</VAR -></DT -><DD -><P -></P -></DD -></DL -></DIV -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN9718" -></A -><H2 ->Description</H2 -><P -><CODE -CLASS="FUNCTION" ->write()</CODE -> -writes up to <VAR -CLASS="PARAMETER" ->count</VAR -> bytes to the device referenced by - the file descriptor <VAR -CLASS="PARAMETER" ->fd</VAR -> from the buffer -starting at <VAR -CLASS="PARAMETER" ->buf</VAR ->. -If <VAR -CLASS="PARAMETER" ->count</VAR -> is zero, 0 will be returned without -causing any other effect. [implementation tbd]</P -><P ->When the application does not provide more data in time, the -previous frame is displayed again.</P -></DIV -><DIV -CLASS="REFSECT1" -><A -NAME="AEN9727" -></A -><H2 ->Return Value</H2 -><P ->On success, the number of bytes written are returned. -Zero indicates nothing was written. [tbd] On error, -1 is -returned, and <VAR -CLASS="VARNAME" ->errno</VAR -> is set appropriately. In this -case the next write will start at the beginning of a new frame. -Possible error codes:</P -><P -></P -><DIV -CLASS="VARIABLELIST" -><DL -><DT -><SPAN -CLASS="ERRORCODE" ->EAGAIN</SPAN -></DT -><DD -><P ->Non-blocking I/O has been selected using -O_NONBLOCK and no buffer space was available to write the data -immediately. [tbd]</P -></DD -><DT -><SPAN -CLASS="ERRORCODE" ->EBADF</SPAN -></DT -><DD -><P -><VAR -CLASS="PARAMETER" ->fd</VAR -> is not a valid file -descriptor or is not open for writing.</P -></DD -><DT -><SPAN -CLASS="ERRORCODE" ->EBUSY</SPAN -></DT -><DD -><P ->The driver does not support multiple write streams and the -device is already in use.</P -></DD -><DT -><SPAN -CLASS="ERRORCODE" ->EFAULT</SPAN -></DT -><DD -><P -><VAR -CLASS="PARAMETER" ->buf</VAR -> is outside your -accessible address space.</P -></DD -><DT -><SPAN -CLASS="ERRORCODE" ->EINTR</SPAN -></DT -><DD -><P ->The call was interrupted by a signal before any -data was written.</P -></DD -><DT -><SPAN -CLASS="ERRORCODE" ->EIO</SPAN -></DT -><DD -><P ->I/O error. This indicates some hardware problem.</P -></DD -><DT -><SPAN -CLASS="ERRORCODE" ->EINVAL</SPAN -></DT -><DD -><P ->The <CODE -CLASS="FUNCTION" ->write()</CODE -> function is not -supported by this driver, not on this device, or generally not on this -type of device.</P -></DD -></DL -></DIV -></DIV -></DIV -><DIV -CLASS="CHAPTER" -><HR><H1 -><A -NAME="DRIVER" -></A ->Chapter 5. Driver Interface</H1 -><DIV -CLASS="SECTION" -><H2 -CLASS="SECTION" -><A -NAME="FOO" ->5.1. to do</A -></H2 -><DIV -CLASS="SECTION" -><H3 -CLASS="SECTION" -><A -NAME="AEN9774" ->5.1.1. to do</A -></H3 -><P ->to do</P -></DIV -></DIV -></DIV -><DIV -CLASS="CHAPTER" -><HR><H1 -><A -NAME="COMPAT" -></A ->Chapter 6. History</H1 -><P ->The following chapters document the evolution of the V4L2 API, -errata or extensions. They shall also aid application and driver -writers porting their software to later versions of V4L2.</P -><DIV -CLASS="SECTION" -><HR><H2 -CLASS="SECTION" -><A -NAME="DIFF-V4L" ->6.1. Differences between V4L and V4L2</A -></H2 -><P ->The Video For Linux API was first introduced in Linux 2.1 to -unify and replace various TV and radio device related interfaces, -developped independently by driver writers in prior years. Starting -with Linux 2.5 the much improved V4L2 API replaces the V4L API, -although existing drivers will continue to support V4L in the future, -either directly or through the V4L2 compatibility layer. For a -transition period not all drivers will support the V4L2 API.</P -><DIV -CLASS="SECTION" -><HR><H3 -CLASS="SECTION" -><A -NAME="AEN9783" ->6.1.1. Opening and Closing Devices</A -></H3 -><P ->For compatibility reasons the character device file names -recommended for V4L2 video capture, overlay, radio, teletext and raw -vbi capture devices did not change from those used by V4L. They are -listed in <A -HREF="#DEVICES" ->Chapter 4</A -> and below in <A -HREF="#V4L-DEV" ->Table 6-1</A ->.</P -><P ->The V4L "videodev" module automatically assigns minor -numbers to drivers in load order, depending on the registered device -type. We recommend V4L2 drivers by default register devices with the -same numbers, but in principle the system administrator can assign -arbitrary minor numbers using driver module options. The major device -number remains 81.</P -><DIV -CLASS="TABLE" -><A -NAME="V4L-DEV" -></A -><P -><B ->Table 6-1. V4L Device Types, Names and Numbers</B -></P -><TABLE -BORDER="1" -CLASS="CALSTABLE" -><COL><COL><COL><THEAD -><TR -><TH ->Device Type</TH -><TH ->File Name</TH -><TH ->Minor Numbers</TH -></TR -></THEAD -><TBODY -><TR -><TD ->Video capture and overlay</TD -><TD -><P -><TT -CLASS="FILENAME" ->/dev/video</TT -> and -<TT -CLASS="FILENAME" ->/dev/bttv0</TT -><SUP ->a</SUP ->, <TT -CLASS="FILENAME" ->/dev/video0</TT -> to -<TT -CLASS="FILENAME" ->/dev/video63</TT -></P -></TD -><TD ->0-63</TD -></TR -><TR -><TD ->Radio receiver</TD -><TD -><P -><TT -CLASS="FILENAME" ->/dev/radio</TT -><SUP ->b</SUP ->, <TT -CLASS="FILENAME" ->/dev/radio0</TT -> to -<TT -CLASS="FILENAME" ->/dev/radio63</TT -></P -></TD -><TD ->64-127</TD -></TR -><TR -><TD ->Teletext decoder</TD -><TD -><P -><TT -CLASS="FILENAME" ->/dev/vtx</TT ->, -<TT -CLASS="FILENAME" ->/dev/vtx0</TT -> to -<TT -CLASS="FILENAME" ->/dev/vtx31</TT -></P -></TD -><TD ->192-223</TD -></TR -><TR -><TD ->Raw VBI capture</TD -><TD -><P -><TT -CLASS="FILENAME" ->/dev/vbi</TT ->, -<TT -CLASS="FILENAME" ->/dev/vbi0</TT -> to -<TT -CLASS="FILENAME" ->/dev/vbi15</TT -></P -></TD -><TD -><P ->224-239<SUP ->c</SUP -></P -></TD -></TR -></TBODY -><TR -><TD -COLSPAN="3" ->Notes:<BR><A -NAME="FTN.AEN9804" ->a. </A ->According to Documentation/devices.txt these -should be symbolic links to <TT -CLASS="FILENAME" ->/dev/video0</TT ->. Note the original bttv interface is not compatible with V4L or V4L2.<BR><A -NAME="FTN.AEN9815" ->b. </A ->According to -<TT -CLASS="FILENAME" ->Documentation/devices.txt</TT -> a symbolic link to -<TT -CLASS="FILENAME" ->/dev/radio0</TT ->.<BR><A -NAME="FTN.AEN9839" ->c. </A ->The range used to be 224-255. More device -types may be added in the future, so you should expect more range -splitting in the future.<BR></TD -></TR -></TABLE -></DIV -><P ->V4L prohibits (or used to) multiple opens. V4L2 drivers -<SPAN -CLASS="emphasis" -><I -CLASS="EMPHASIS" ->may</I -></SPAN -> support multiple opens, see <A -HREF="#OPEN" ->Section 1.1</A -> for details and consequences.</P -><P ->V4L drivers respond to V4L2 ioctls with the <SPAN -CLASS="ERRORCODE" ->EINVAL</SPAN -> error code. The -V4L2 "videodev" module backward compatibility layer can translate V4L -ioctl requests to their V4L2 counterpart, however a V4L2 driver -usually needs more preparation to become fully V4L compatible. This is -covered in more detail in <A -HREF="#DRIVER" ->Chapter 5</A ->.</P -></DIV -><DIV -CLASS="SECTION" -><HR><H3 -CLASS="SECTION" -><A -NAME="AEN9847" ->6.1.2. Querying Capabilities</A -></H3 -><P ->The V4L <CODE -CLASS="CONSTANT" ->VIDIOCGCAP</CODE -> ioctl is - equivalent to V4L2's <A -HREF="#VIDIOC-QUERYCAP" -><CODE -CLASS="CONSTANT" ->VIDIOC_QUERYCAP</CODE -></A ->.</P -><P ->The <CODE -CLASS="STRUCTFIELD" ->name</CODE -> field in struct -<CODE -CLASS="STRUCTNAME" ->video_capability</CODE -> became -<CODE -CLASS="STRUCTFIELD" ->card</CODE -> in struct <A -HREF="#V4L2-CAPABILITY" ->v4l2_capability</A ->, -<CODE -CLASS="STRUCTFIELD" ->type</CODE -> was replaced by -<CODE -CLASS="STRUCTFIELD" ->capabilities</CODE ->. Note V4L2 does not -distinguish between device types like this, better think of -basic video input, video output and radio devices supporting a set -of related functions like video capturing, video overlay and VBI -capturing. See <A -HREF="#OPEN" ->Section 1.1</A -> for an introduction.<DIV -CLASS="INFORMALTABLE" -><P -></P -><A -NAME="AEN9861" -></A -><TABLE -BORDER="1" -CLASS="CALSTABLE" -><COL><COL><COL><THEAD -><TR -><TH ->struct <CODE -CLASS="STRUCTNAME" ->video_capability</CODE -> -<CODE -CLASS="STRUCTFIELD" ->type</CODE -></TH -><TH ->struct <A -HREF="#V4L2-CAPABILITY" ->v4l2_capability</A -> -<CODE -CLASS="STRUCTFIELD" ->capabilities</CODE -> flags</TH -><TH ->Purpose</TH -></TR -></THEAD -><TBODY -><TR -><TD -><CODE -CLASS="CONSTANT" ->VID_TYPE_CAPTURE</CODE -></TD -><TD -><CODE -CLASS="CONSTANT" ->V4L2_CAP_VIDEO_CAPTURE</CODE -></TD -><TD ->The <A -HREF="#CAPTURE" ->video -capture</A -> interface is supported.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->VID_TYPE_TUNER</CODE -></TD -><TD -><CODE -CLASS="CONSTANT" ->V4L2_CAP_TUNER</CODE -></TD -><TD ->The device has a <A -HREF="#TUNER" ->tuner or -modulator</A ->.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->VID_TYPE_TELETEXT</CODE -></TD -><TD -><CODE -CLASS="CONSTANT" ->V4L2_CAP_VBI_CAPTURE</CODE -></TD -><TD ->The <A -HREF="#RAW-VBI" ->raw VBI -capture</A -> interface is supported.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->VID_TYPE_OVERLAY</CODE -></TD -><TD -><CODE -CLASS="CONSTANT" ->V4L2_CAP_VIDEO_OVERLAY</CODE -></TD -><TD ->The <A -HREF="#OVERLAY" ->video overlay</A -> -interface is supported.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->VID_TYPE_CHROMAKEY</CODE -></TD -><TD -><CODE -CLASS="CONSTANT" ->V4L2_FBUF_CAP_CHROMAKEY</CODE -> in -field <CODE -CLASS="STRUCTFIELD" ->capability</CODE -> of -struct <A -HREF="#V4L2-FRAMEBUFFER" ->v4l2_framebuffer</A -></TD -><TD ->Whether chromakey overlay is supported. For -more information on overlay see -<A -HREF="#OVERLAY" ->Section 4.2</A ->.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->VID_TYPE_CLIPPING</CODE -></TD -><TD -><CODE -CLASS="CONSTANT" ->V4L2_FBUF_CAP_LIST_CLIPPING</CODE -> -and <CODE -CLASS="CONSTANT" ->V4L2_FBUF_CAP_BITMAP_CLIPPING</CODE -> in field -<CODE -CLASS="STRUCTFIELD" ->capability</CODE -> of struct <A -HREF="#V4L2-FRAMEBUFFER" ->v4l2_framebuffer</A -></TD -><TD ->Whether clipping the overlaid image is -supported, see <A -HREF="#OVERLAY" ->Section 4.2</A ->.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->VID_TYPE_FRAMERAM</CODE -></TD -><TD -><CODE -CLASS="CONSTANT" ->V4L2_FBUF_CAP_EXTERNOVERLAY</CODE -> -<SPAN -CLASS="emphasis" -><I -CLASS="EMPHASIS" ->not set</I -></SPAN -> in field -<CODE -CLASS="STRUCTFIELD" ->capability</CODE -> of struct <A -HREF="#V4L2-FRAMEBUFFER" ->v4l2_framebuffer</A -></TD -><TD ->Whether overlay overwrites frame buffer memory, -see <A -HREF="#OVERLAY" ->Section 4.2</A ->.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->VID_TYPE_SCALES</CODE -></TD -><TD -><CODE -CLASS="CONSTANT" ->-</CODE -></TD -><TD ->This flag indicates if the hardware can scale -images. The V4L2 API implies the scale factor by setting the cropping -dimensions and image size with the <A -HREF="#VIDIOC-G-CROP" -><CODE -CLASS="CONSTANT" ->VIDIOC_S_CROP</CODE -></A -> and <A -HREF="#VIDIOC-G-FMT" -><CODE -CLASS="CONSTANT" ->VIDIOC_S_FMT</CODE -></A -> -ioctl, respectively. The driver returns the closest sizes possible. -For more information on cropping and scaling see <A -HREF="#CROP" ->Section 1.10</A ->.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->VID_TYPE_MONOCHROME</CODE -></TD -><TD -><CODE -CLASS="CONSTANT" ->-</CODE -></TD -><TD ->Applications can enumerate the supported image -formats with the <A -HREF="#VIDIOC-ENUM-FMT" -><CODE -CLASS="CONSTANT" ->VIDIOC_ENUM_FMT</CODE -></A -> ioctl to determine if the device -supports grey scale capturing only. For more information on image -formats see <A -HREF="#PIXFMT" ->Chapter 2</A ->.</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->VID_TYPE_SUBCAPTURE</CODE -></TD -><TD -><CODE -CLASS="CONSTANT" ->-</CODE -></TD -><TD ->Applications can call the <A -HREF="#VIDIOC-G-CROP" -><CODE -CLASS="CONSTANT" ->VIDIOC_G_CROP</CODE -></A -> ioctl -to determine if the device supports capturing a subsection of the full -picture ("cropping" in V4L2). If not, the ioctl returns the <SPAN -CLASS="ERRORCODE" ->EINVAL</SPAN -> error code. -For more information on cropping and scaling see <A -HREF="#CROP" ->Section 1.10</A ->.</TD -></TR -></TBODY -></TABLE -><P -></P -></DIV -></P -><P ->The <CODE -CLASS="STRUCTFIELD" ->audios</CODE -> field was replaced -by <CODE -CLASS="STRUCTFIELD" ->capabilities</CODE -> flag -<CODE -CLASS="CONSTANT" ->V4L2_CAP_AUDIO</CODE ->, indicating -<SPAN -CLASS="emphasis" -><I -CLASS="EMPHASIS" ->if</I -></SPAN -> the device has any audio inputs or outputs. To -determine their number applications can enumerate audio inputs with -the <A -HREF="#VIDIOC-G-AUDIO" -><CODE -CLASS="CONSTANT" ->VIDIOC_G_AUDIO</CODE -></A -> ioctl. The audio ioctls are described in <A -HREF="#AUDIO" ->Section 1.5</A ->.</P -><P ->The <CODE -CLASS="STRUCTFIELD" ->maxwidth</CODE ->, -<CODE -CLASS="STRUCTFIELD" ->maxheight</CODE ->, -<CODE -CLASS="STRUCTFIELD" ->minwidth</CODE -> and -<CODE -CLASS="STRUCTFIELD" ->minheight</CODE -> fields were removed. Calling the -<A -HREF="#VIDIOC-G-FMT" -><CODE -CLASS="CONSTANT" ->VIDIOC_S_FMT</CODE -></A -> or <A -HREF="#VIDIOC-G-FMT" -><CODE -CLASS="CONSTANT" ->VIDIOC_TRY_FMT</CODE -></A -> ioctl with the desired dimensions -returns the closest size possible, taking into account the current -video standard, cropping and scaling.</P -></DIV -><DIV -CLASS="SECTION" -><HR><H3 -CLASS="SECTION" -><A -NAME="AEN9977" ->6.1.3. Video Sources</A -></H3 -><P ->V4L provides the <CODE -CLASS="CONSTANT" ->VIDIOCGCHAN</CODE -> and -<CODE -CLASS="CONSTANT" ->VIDIOCSCHAN</CODE -> ioctl using struct -<CODE -CLASS="STRUCTNAME" ->video_channel</CODE -> to enumerate -the video inputs of a V4L device. The equivalent V4L2 ioctls -are <A -HREF="#VIDIOC-ENUMINPUT" -><CODE -CLASS="CONSTANT" ->VIDIOC_ENUMINPUT</CODE -></A ->, <A -HREF="#VIDIOC-G-INPUT" -><CODE -CLASS="CONSTANT" ->VIDIOC_G_INPUT</CODE -></A -> and <A -HREF="#VIDIOC-G-INPUT" -><CODE -CLASS="CONSTANT" ->VIDIOC_S_INPUT</CODE -></A -> -using struct <A -HREF="#V4L2-INPUT" ->v4l2_input</A -> as discussed in <A -HREF="#VIDEO" ->Section 1.4</A ->.</P -><P ->The <CODE -CLASS="STRUCTFIELD" ->channel</CODE -> field counting -inputs was renamed to <CODE -CLASS="STRUCTFIELD" ->index</CODE ->, the video -input types were renamed: <DIV -CLASS="INFORMALTABLE" -><P -></P -><A -NAME="AEN9994" -></A -><TABLE -BORDER="1" -CLASS="CALSTABLE" -><COL><COL><THEAD -><TR -><TH ->struct <CODE -CLASS="STRUCTNAME" ->video_channel</CODE -> -<CODE -CLASS="STRUCTFIELD" ->type</CODE -></TH -><TH ->struct <A -HREF="#V4L2-INPUT" ->v4l2_input</A -> -<CODE -CLASS="STRUCTFIELD" ->type</CODE -></TH -></TR -></THEAD -><TBODY -><TR -><TD -><CODE -CLASS="CONSTANT" ->VIDEO_TYPE_TV</CODE -></TD -><TD -><CODE -CLASS="CONSTANT" ->V4L2_INPUT_TYPE_TUNER</CODE -></TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->VIDEO_TYPE_CAMERA</CODE -></TD -><TD -><CODE -CLASS="CONSTANT" ->V4L2_INPUT_TYPE_CAMERA</CODE -></TD -></TR -></TBODY -></TABLE -><P -></P -></DIV -></P -><P ->Unlike the <CODE -CLASS="STRUCTFIELD" ->tuners</CODE -> field -expressing the number of tuners of this input, V4L2 assumes each -video input is associated with at most one tuner. On the contrary a -tuner can have more than one input, i.e. RF connectors, and a device -can have multiple tuners. The index of the tuner associated with the -input, if any, is stored in field <CODE -CLASS="STRUCTFIELD" ->tuner</CODE -> of -struct <CODE -CLASS="STRUCTNAME" ->v4l2_input</CODE ->. Enumeration of tuners is -discussed in <A -HREF="#TUNER" ->Section 1.6</A ->.</P -><P ->The redundant <CODE -CLASS="CONSTANT" ->VIDEO_VC_TUNER</CODE -> flag was -dropped. Video inputs associated with a tuner are of type -<CODE -CLASS="CONSTANT" ->V4L2_INPUT_TYPE_TUNER</CODE ->. The -<CODE -CLASS="CONSTANT" ->VIDEO_VC_AUDIO</CODE -> flag was replaced by the -<CODE -CLASS="STRUCTFIELD" ->audioset</CODE -> field. V4L2 considers devices with -up to 32 audio inputs. Each set bit in the -<CODE -CLASS="STRUCTFIELD" ->audioset</CODE -> field represents one audio input -this video input combines with. For information about audio inputs and -how to switch see <A -HREF="#AUDIO" ->Section 1.5</A ->.</P -><P ->The <CODE -CLASS="STRUCTFIELD" ->norm</CODE -> field describing the -supported video standards was replaced by -<CODE -CLASS="STRUCTFIELD" ->std</CODE ->. The V4L specification mentions a flag -<CODE -CLASS="CONSTANT" ->VIDEO_VC_NORM</CODE -> indicating whether the standard can -be changed. This flag was a later addition together with the -<CODE -CLASS="STRUCTFIELD" ->norm</CODE -> field and has been removed in the -meantime. V4L2 has a similar, albeit more comprehensive approach -to video standards, see <A -HREF="#STANDARD" ->Section 1.7</A -> for more -information.</P -></DIV -><DIV -CLASS="SECTION" -><HR><H3 -CLASS="SECTION" -><A -NAME="AEN10033" ->6.1.4. Tuning</A -></H3 -><P ->The V4L <CODE -CLASS="CONSTANT" ->VIDIOCGTUNER</CODE -> and -<CODE -CLASS="CONSTANT" ->VIDIOCSTUNER</CODE -> ioctl and struct -<CODE -CLASS="STRUCTNAME" ->video_tuner</CODE -> can be used to enumerate the -tuners of a V4L TV or radio device. The equivalent V4L2 ioctls are -<A -HREF="#VIDIOC-G-TUNER" -><CODE -CLASS="CONSTANT" ->VIDIOC_G_TUNER</CODE -></A -> and <A -HREF="#VIDIOC-G-TUNER" -><CODE -CLASS="CONSTANT" ->VIDIOC_S_TUNER</CODE -></A -> using struct <A -HREF="#V4L2-TUNER" ->v4l2_tuner</A ->. Tuners are -covered in <A -HREF="#TUNER" ->Section 1.6</A ->.</P -><P ->The <CODE -CLASS="STRUCTFIELD" ->tuner</CODE -> field counting tuners -was renamed to <CODE -CLASS="STRUCTFIELD" ->index</CODE ->. The fields -<CODE -CLASS="STRUCTFIELD" ->name</CODE ->, <CODE -CLASS="STRUCTFIELD" ->rangelow</CODE -> -and <CODE -CLASS="STRUCTFIELD" ->rangehigh</CODE -> remained unchanged.</P -><P ->The <CODE -CLASS="CONSTANT" ->VIDEO_TUNER_PAL</CODE ->, -<CODE -CLASS="CONSTANT" ->VIDEO_TUNER_NTSC</CODE -> and -<CODE -CLASS="CONSTANT" ->VIDEO_TUNER_SECAM</CODE -> flags indicating the supported -video standards were dropped. This information is now contained in the -associated struct <A -HREF="#V4L2-INPUT" ->v4l2_input</A ->. No replacement exists for the -<CODE -CLASS="CONSTANT" ->VIDEO_TUNER_NORM</CODE -> flag indicating whether the -video standard can be switched. The <CODE -CLASS="STRUCTFIELD" ->mode</CODE -> -field to select a different video standard was replaced by a whole new -set of ioctls and structures described in <A -HREF="#STANDARD" ->Section 1.7</A ->. -Due to its ubiquity it should be mentioned the BTTV driver supports -several standards in addition to the regular -<CODE -CLASS="CONSTANT" ->VIDEO_MODE_PAL</CODE -> (0), -<CODE -CLASS="CONSTANT" ->VIDEO_MODE_NTSC</CODE ->, -<CODE -CLASS="CONSTANT" ->VIDEO_MODE_SECAM</CODE -> and -<CODE -CLASS="CONSTANT" ->VIDEO_MODE_AUTO</CODE -> (3). Namely N/PAL Argentina, -M/PAL, N/PAL, and NTSC Japan with numbers 3-6 (sic).</P -><P ->The <CODE -CLASS="CONSTANT" ->VIDEO_TUNER_STEREO_ON</CODE -> flag -indicating stereo reception became -<CODE -CLASS="CONSTANT" ->V4L2_TUNER_SUB_STEREO</CODE -> in field -<CODE -CLASS="STRUCTFIELD" ->rxsubchans</CODE ->. This field also permits the -detection of monaural and bilingual audio, see the definition of -struct <A -HREF="#V4L2-TUNER" ->v4l2_tuner</A -> for details. Presently no replacement exists for the -<CODE -CLASS="CONSTANT" ->VIDEO_TUNER_RDS_ON</CODE -> and -<CODE -CLASS="CONSTANT" ->VIDEO_TUNER_MBS_ON</CODE -> flags.</P -><P -> The <CODE -CLASS="CONSTANT" ->VIDEO_TUNER_LOW</CODE -> flag was renamed -to <CODE -CLASS="CONSTANT" ->V4L2_TUNER_CAP_LOW</CODE -> in the struct <A -HREF="#V4L2-TUNER" ->v4l2_tuner</A -> -<CODE -CLASS="STRUCTFIELD" ->capability</CODE -> field.</P -><P ->The <CODE -CLASS="CONSTANT" ->VIDIOCGFREQ</CODE -> and -<CODE -CLASS="CONSTANT" ->VIDIOCSFREQ</CODE -> ioctl to change the tuner frequency -where renamed to <A -HREF="#VIDIOC-G-FREQUENCY" -><CODE -CLASS="CONSTANT" ->VIDIOC_G_FREQUENCY</CODE -></A -> and <A -HREF="#VIDIOC-G-FREQUENCY" -><CODE -CLASS="CONSTANT" ->VIDIOC_S_FREQUENCY</CODE -></A ->. They -take a pointer to a struct <A -HREF="#V4L2-FREQUENCY" ->v4l2_frequency</A -> instead of an unsigned long -integer.</P -></DIV -><DIV -CLASS="SECTION" -><HR><H3 -CLASS="SECTION" -><A -NAME="V4L-IMAGE-PROPERTIES" ->6.1.5. Image Properties</A -></H3 -><P ->V4L2 has no equivalent of the -<CODE -CLASS="CONSTANT" ->VIDIOCGPICT</CODE -> and <CODE -CLASS="CONSTANT" ->VIDIOCSPICT</CODE -> -ioctl and struct <CODE -CLASS="STRUCTNAME" ->video_picture</CODE ->. The following -fields where replaced by V4L2 controls accessible with the -<A -HREF="#VIDIOC-QUERYCTRL" -><CODE -CLASS="CONSTANT" ->VIDIOC_QUERYCTRL</CODE -></A ->, <A -HREF="#VIDIOC-G-CTRL" -><CODE -CLASS="CONSTANT" ->VIDIOC_G_CTRL</CODE -></A -> and <A -HREF="#VIDIOC-G-CTRL" -><CODE -CLASS="CONSTANT" ->VIDIOC_S_CTRL</CODE -></A -> ioctls:<DIV -CLASS="INFORMALTABLE" -><P -></P -><A -NAME="AEN10095" -></A -><TABLE -BORDER="1" -CLASS="CALSTABLE" -><COL><COL><THEAD -><TR -><TH ->struct <CODE -CLASS="STRUCTNAME" ->video_picture</CODE -></TH -><TH ->V4L2 Control ID</TH -></TR -></THEAD -><TBODY -><TR -><TD -><CODE -CLASS="STRUCTFIELD" ->brightness</CODE -></TD -><TD -><CODE -CLASS="CONSTANT" ->V4L2_CID_BRIGHTNESS</CODE -></TD -></TR -><TR -><TD -><CODE -CLASS="STRUCTFIELD" ->hue</CODE -></TD -><TD -><CODE -CLASS="CONSTANT" ->V4L2_CID_HUE</CODE -></TD -></TR -><TR -><TD -><CODE -CLASS="STRUCTFIELD" ->colour</CODE -></TD -><TD -><CODE -CLASS="CONSTANT" ->V4L2_CID_SATURATION</CODE -></TD -></TR -><TR -><TD -><CODE -CLASS="STRUCTFIELD" ->contrast</CODE -></TD -><TD -><CODE -CLASS="CONSTANT" ->V4L2_CID_CONTRAST</CODE -></TD -></TR -><TR -><TD -><CODE -CLASS="STRUCTFIELD" ->whiteness</CODE -></TD -><TD -><CODE -CLASS="CONSTANT" ->V4L2_CID_WHITENESS</CODE -></TD -></TR -></TBODY -></TABLE -><P -></P -></DIV -></P -><P ->The V4L picture controls are assumed to range from 0 to -65535 with no particular reset value. The V4L2 API permits arbitrary -limits and defaults which can be queried with the <A -HREF="#VIDIOC-QUERYCTRL" -><CODE -CLASS="CONSTANT" ->VIDIOC_QUERYCTRL</CODE -></A -> -ioctl. For general information about controls see <A -HREF="#CONTROL" ->Section 1.8</A ->.</P -><P ->The <CODE -CLASS="STRUCTFIELD" ->depth</CODE -> (average number of -bits per pixel) of a video image is implied by the selected image -format. V4L2 does not explicitely provide such information assuming -applications recognizing the format are aware of the image depth and -others need not know. The <CODE -CLASS="STRUCTFIELD" ->palette</CODE -> field -moved into the struct <A -HREF="#V4L2-PIX-FORMAT" ->v4l2_pix_format</A ->:<DIV -CLASS="INFORMALTABLE" -><P -></P -><A -NAME="AEN10136" -></A -><TABLE -BORDER="1" -CLASS="CALSTABLE" -><COL><COL><THEAD -><TR -><TH ->struct <CODE -CLASS="STRUCTNAME" ->video_picture</CODE -> -<CODE -CLASS="STRUCTFIELD" ->palette</CODE -></TH -><TH ->struct <A -HREF="#V4L2-PIX-FORMAT" ->v4l2_pix_format</A -> -<CODE -CLASS="STRUCTFIELD" ->pixfmt</CODE -></TH -></TR -></THEAD -><TBODY -><TR -><TD -><CODE -CLASS="CONSTANT" ->VIDEO_PALETTE_GREY</CODE -></TD -><TD -><P -><A -HREF="#PIXFMT-GREY" -><CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_GREY</CODE -></A -></P -></TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->VIDEO_PALETTE_HI240</CODE -></TD -><TD -><P -><A -HREF="#PIXFMT-RESERVED" -><CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_HI240</CODE -></A -><SUP ->a</SUP -></P -></TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->VIDEO_PALETTE_RGB565</CODE -></TD -><TD -><P -><A -HREF="#PIXFMT-RGB" -><CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_RGB565</CODE -></A -></P -></TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->VIDEO_PALETTE_RGB555</CODE -></TD -><TD -><P -><A -HREF="#PIXFMT-RGB" -><CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_RGB555</CODE -></A -></P -></TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->VIDEO_PALETTE_RGB24</CODE -></TD -><TD -><P -><A -HREF="#PIXFMT-RGB" -><CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_BGR24</CODE -></A -></P -></TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->VIDEO_PALETTE_RGB32</CODE -></TD -><TD -><P -><A -HREF="#PIXFMT-RGB" -><CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_BGR32</CODE -></A -><SUP ->b</SUP -></P -></TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->VIDEO_PALETTE_YUV422</CODE -></TD -><TD -><P -><A -HREF="#PIXFMT-YUYV" -><CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_YUYV</CODE -></A -></P -></TD -></TR -><TR -><TD -><P -><CODE -CLASS="CONSTANT" ->VIDEO_PALETTE_YUYV</CODE -><SUP ->c</SUP -></P -></TD -><TD -><P -><A -HREF="#PIXFMT-YUYV" -><CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_YUYV</CODE -></A -></P -></TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->VIDEO_PALETTE_UYVY</CODE -></TD -><TD -><P -><A -HREF="#PIXFMT-UYVY" -><CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_UYVY</CODE -></A -></P -></TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->VIDEO_PALETTE_YUV420</CODE -></TD -><TD ->None</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->VIDEO_PALETTE_YUV411</CODE -></TD -><TD -><P -><A -HREF="#PIXFMT-Y41P" -><CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_Y41P</CODE -></A -><SUP ->d</SUP -></P -></TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->VIDEO_PALETTE_RAW</CODE -></TD -><TD -><P ->None<SUP ->e</SUP -></P -></TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->VIDEO_PALETTE_YUV422P</CODE -></TD -><TD -><P -><A -HREF="#PIXFMT-YUV422P" -><CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_YUV422P</CODE -></A -></P -></TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->VIDEO_PALETTE_YUV411P</CODE -></TD -><TD -><P -><A -HREF="#PIXFMT-YUV411P" -><CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_YUV411P</CODE -></A -><SUP ->f</SUP -></P -></TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->VIDEO_PALETTE_YUV420P</CODE -></TD -><TD -><P -><A -HREF="#PIXFMT-YVU420" -><CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_YVU420</CODE -></A -></P -></TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->VIDEO_PALETTE_YUV410P</CODE -></TD -><TD -><P -><A -HREF="#PIXFMT-YVU410" -><CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_YVU410</CODE -></A -></P -></TD -></TR -></TBODY -><TR -><TD -COLSPAN="2" ->Notes:<BR><A -NAME="FTN.AEN10161" ->a. </A ->This is a custom format used by the BTTV -driver, not one of the V4L2 standard formats.<BR><A -NAME="FTN.AEN10191" ->b. </A ->Presumably all V4L RGB formats are -little-endian, although some drivers might interpret them according to machine endianess. V4L2 defines little-endian, big-endian and red/blue -swapped variants. For details see <A -HREF="#PIXFMT-RGB" ->Section 2.3</A ->.<BR><A -NAME="FTN.AEN10205" ->c. </A -><CODE -CLASS="CONSTANT" ->VIDEO_PALETTE_YUV422</CODE -> -and <CODE -CLASS="CONSTANT" ->VIDEO_PALETTE_YUYV</CODE -> are the same formats. Some -V4L drivers respond to one, some to the other.<BR><A -NAME="FTN.AEN10231" ->d. </A ->Not to be confused with -<CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_YUV411P</CODE ->, which is a planar -format.<BR><A -NAME="FTN.AEN10239" ->e. </A ->V4L explains this -as: "RAW capture (BT848)"<BR><A -NAME="FTN.AEN10255" ->f. </A ->Not to be confused with -<CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_Y41P</CODE ->, which is a packed -format.<BR></TD -></TR -></TABLE -><P -></P -></DIV -></P -><P ->V4L2 image formats are defined in <A -HREF="#PIXFMT" ->Chapter 2</A ->. The image format can be selected with the -<A -HREF="#VIDIOC-G-FMT" -><CODE -CLASS="CONSTANT" ->VIDIOC_S_FMT</CODE -></A -> ioctl.</P -></DIV -><DIV -CLASS="SECTION" -><HR><H3 -CLASS="SECTION" -><A -NAME="AEN10276" ->6.1.6. Audio</A -></H3 -><P ->The <CODE -CLASS="CONSTANT" ->VIDIOCGAUDIO</CODE -> and -<CODE -CLASS="CONSTANT" ->VIDIOCSAUDIO</CODE -> ioctl and struct -<CODE -CLASS="STRUCTNAME" ->video_audio</CODE -> are used to enumerate the -audio inputs of a V4L device. The equivalent V4L2 ioctls are -<A -HREF="#VIDIOC-G-AUDIO" -><CODE -CLASS="CONSTANT" ->VIDIOC_G_AUDIO</CODE -></A -> and <A -HREF="#VIDIOC-G-AUDIO" -><CODE -CLASS="CONSTANT" ->VIDIOC_S_AUDIO</CODE -></A -> using struct <A -HREF="#V4L2-AUDIO" ->v4l2_audio</A -> as -discussed in <A -HREF="#AUDIO" ->Section 1.5</A ->.</P -><P ->The <CODE -CLASS="STRUCTFIELD" ->audio</CODE -> "channel number" -field counting audio inputs was renamed to -<CODE -CLASS="STRUCTFIELD" ->index</CODE ->.</P -><P ->On <CODE -CLASS="CONSTANT" ->VIDIOCSAUDIO</CODE -> the -<CODE -CLASS="STRUCTFIELD" ->mode</CODE -> field selects <SPAN -CLASS="emphasis" -><I -CLASS="EMPHASIS" ->one</I -></SPAN -> -of the <CODE -CLASS="CONSTANT" ->VIDEO_SOUND_MONO</CODE ->, -<CODE -CLASS="CONSTANT" ->VIDEO_SOUND_STEREO</CODE ->, -<CODE -CLASS="CONSTANT" ->VIDEO_SOUND_LANG1</CODE -> or -<CODE -CLASS="CONSTANT" ->VIDEO_SOUND_LANG2</CODE -> audio demodulation modes. When -the current audio standard is BTSC -<CODE -CLASS="CONSTANT" ->VIDEO_SOUND_LANG2</CODE -> refers to SAP and -<CODE -CLASS="CONSTANT" ->VIDEO_SOUND_LANG1</CODE -> is meaningless. Also -undocumented in the V4L specification, there is no way to query the -selected mode. On <CODE -CLASS="CONSTANT" ->VIDIOCGAUDIO</CODE -> the driver returns -the <SPAN -CLASS="emphasis" -><I -CLASS="EMPHASIS" ->actually received</I -></SPAN -> audio programmes in this -field. In the V4L2 API this information is stored in the struct <A -HREF="#V4L2-TUNER" ->v4l2_tuner</A -> -<CODE -CLASS="STRUCTFIELD" ->rxsubchans</CODE -> and -<CODE -CLASS="STRUCTFIELD" ->audmode</CODE -> fields, respectively. See <A -HREF="#TUNER" ->Section 1.6</A -> for more information on tuners. Related to audio -modes struct <A -HREF="#V4L2-AUDIO" ->v4l2_audio</A -> also reports if this is a mono or stereo -input, regardless if the source is a tuner.</P -><P ->The following fields where replaced by V4L2 controls -accessible with the <A -HREF="#VIDIOC-QUERYCTRL" -><CODE -CLASS="CONSTANT" ->VIDIOC_QUERYCTRL</CODE -></A ->, <A -HREF="#VIDIOC-G-CTRL" -><CODE -CLASS="CONSTANT" ->VIDIOC_G_CTRL</CODE -></A -> and -<A -HREF="#VIDIOC-G-CTRL" -><CODE -CLASS="CONSTANT" ->VIDIOC_S_CTRL</CODE -></A -> ioctls:<DIV -CLASS="INFORMALTABLE" -><P -></P -><A -NAME="AEN10315" -></A -><TABLE -BORDER="1" -CLASS="CALSTABLE" -><COL><COL><THEAD -><TR -><TH ->struct -<CODE -CLASS="STRUCTNAME" ->video_audio</CODE -></TH -><TH ->V4L2 Control ID</TH -></TR -></THEAD -><TBODY -><TR -><TD -><CODE -CLASS="STRUCTFIELD" ->volume</CODE -></TD -><TD -><CODE -CLASS="CONSTANT" ->V4L2_CID_AUDIO_VOLUME</CODE -></TD -></TR -><TR -><TD -><CODE -CLASS="STRUCTFIELD" ->bass</CODE -></TD -><TD -><CODE -CLASS="CONSTANT" ->V4L2_CID_AUDIO_BASS</CODE -></TD -></TR -><TR -><TD -><CODE -CLASS="STRUCTFIELD" ->treble</CODE -></TD -><TD -><CODE -CLASS="CONSTANT" ->V4L2_CID_AUDIO_TREBLE</CODE -></TD -></TR -><TR -><TD -><CODE -CLASS="STRUCTFIELD" ->balance</CODE -></TD -><TD -><CODE -CLASS="CONSTANT" ->V4L2_CID_AUDIO_BALANCE</CODE -></TD -></TR -></TBODY -></TABLE -><P -></P -></DIV -></P -><P ->To determine which of these controls are supported by a -driver V4L provides the <CODE -CLASS="STRUCTFIELD" ->flags</CODE -> -<CODE -CLASS="CONSTANT" ->VIDEO_AUDIO_VOLUME</CODE ->, -<CODE -CLASS="CONSTANT" ->VIDEO_AUDIO_BASS</CODE ->, -<CODE -CLASS="CONSTANT" ->VIDEO_AUDIO_TREBLE</CODE -> and -<CODE -CLASS="CONSTANT" ->VIDEO_AUDIO_BALANCE</CODE ->. In the V4L2 API the -<A -HREF="#VIDIOC-QUERYCTRL" -><CODE -CLASS="CONSTANT" ->VIDIOC_QUERYCTRL</CODE -></A -> ioctl reports if the respective control is -supported. Accordingly the <CODE -CLASS="CONSTANT" ->VIDEO_AUDIO_MUTABLE</CODE -> -and <CODE -CLASS="CONSTANT" ->VIDEO_AUDIO_MUTE</CODE -> flags where replaced by the -boolean <CODE -CLASS="CONSTANT" ->V4L2_CID_AUDIO_MUTE</CODE -> control.</P -><P ->All V4L2 controls have a <CODE -CLASS="STRUCTFIELD" ->step</CODE -> -attribute replacing the struct <CODE -CLASS="STRUCTNAME" ->video_audio</CODE -> -<CODE -CLASS="STRUCTFIELD" ->step</CODE -> field. The V4L audio controls are -assumed to range from 0 to 65535 with no particular reset value. The -V4L2 API permits arbitrary limits and defaults which can be queried -with the <A -HREF="#VIDIOC-QUERYCTRL" -><CODE -CLASS="CONSTANT" ->VIDIOC_QUERYCTRL</CODE -></A -> ioctl. For general information about -controls see <A -HREF="#CONTROL" ->Section 1.8</A ->.</P -></DIV -><DIV -CLASS="SECTION" -><HR><H3 -CLASS="SECTION" -><A -NAME="AEN10361" ->6.1.7. Frame Buffer Overlay</A -></H3 -><P ->The V4L2 ioctls equivalent to -<CODE -CLASS="CONSTANT" ->VIDIOCGFBUF</CODE -> and <CODE -CLASS="CONSTANT" ->VIDIOCSFBUF</CODE -> -are <A -HREF="#VIDIOC-G-FBUF" -><CODE -CLASS="CONSTANT" ->VIDIOC_G_FBUF</CODE -></A -> and <A -HREF="#VIDIOC-G-FBUF" -><CODE -CLASS="CONSTANT" ->VIDIOC_S_FBUF</CODE -></A ->. The -<CODE -CLASS="STRUCTFIELD" ->base</CODE -> field of struct -<CODE -CLASS="STRUCTNAME" ->video_buffer</CODE -> remained unchanged, except V4L2 -using a flag to indicate non-destructive overlay instead of a -<CODE -CLASS="CONSTANT" ->NULL</CODE -> pointer. All other fields moved into the -struct <A -HREF="#V4L2-PIX-FORMAT" ->v4l2_pix_format</A -> substructure <CODE -CLASS="STRUCTFIELD" ->fmt</CODE -> of -struct <A -HREF="#V4L2-FRAMEBUFFER" ->v4l2_framebuffer</A ->. The <CODE -CLASS="STRUCTFIELD" ->depth</CODE -> field was -replaced by <CODE -CLASS="STRUCTFIELD" ->pixelformat</CODE ->. A conversion table -is available in the <A -HREF="#PIXFMT-RGB" ->Section 2.3</A ->.</P -><P ->Instead of the special ioctls -<CODE -CLASS="CONSTANT" ->VIDIOCGWIN</CODE -> and <CODE -CLASS="CONSTANT" ->VIDIOCSWIN</CODE -> -V4L2 uses the general-purpose data format negotiation ioctls -<A -HREF="#VIDIOC-G-FMT" -><CODE -CLASS="CONSTANT" ->VIDIOC_G_FMT</CODE -></A -> and <A -HREF="#VIDIOC-G-FMT" -><CODE -CLASS="CONSTANT" ->VIDIOC_S_FMT</CODE -></A ->. They take a pointer to a -struct <A -HREF="#V4L2-FORMAT" ->v4l2_format</A -> as argument, here the struct <A -HREF="#V4L2-WINDOW" ->v4l2_window</A -> named -<CODE -CLASS="STRUCTFIELD" ->win</CODE -> of its <CODE -CLASS="STRUCTFIELD" ->fmt</CODE -> -union is used.</P -><P ->The <CODE -CLASS="STRUCTFIELD" ->x</CODE ->, -<CODE -CLASS="STRUCTFIELD" ->y</CODE ->, <CODE -CLASS="STRUCTFIELD" ->width</CODE -> and -<CODE -CLASS="STRUCTFIELD" ->height</CODE -> fields of struct -<CODE -CLASS="STRUCTNAME" ->video_window</CODE -> moved into struct <A -HREF="#V4L2-RECT" ->v4l2_rect</A -> -substructure <CODE -CLASS="STRUCTFIELD" ->w</CODE -> of struct -<CODE -CLASS="STRUCTNAME" ->v4l2_window</CODE ->. The -<CODE -CLASS="STRUCTFIELD" ->chromakey</CODE ->, -<CODE -CLASS="STRUCTFIELD" ->clips</CODE ->, and -<CODE -CLASS="STRUCTFIELD" ->clipcount</CODE -> fields remained unchanged. Struct -<CODE -CLASS="STRUCTNAME" ->video_clip</CODE -> was renamed to struct <A -HREF="#V4L2-CLIP" ->v4l2_clip</A ->, also -containing a struct <CODE -CLASS="STRUCTNAME" ->v4l2_rect</CODE ->, but the -semantics are still the same.</P -><P ->The <CODE -CLASS="CONSTANT" ->VIDEO_WINDOW_INTERLACE</CODE -> flag was -dropped, instead applications must set the -<CODE -CLASS="STRUCTFIELD" ->field</CODE -> field to -<CODE -CLASS="CONSTANT" ->V4L2_FIELD_ANY</CODE -> or -<CODE -CLASS="CONSTANT" ->V4L2_FIELD_INTERLACED</CODE ->. The -<CODE -CLASS="CONSTANT" ->VIDEO_WINDOW_CHROMAKEY</CODE -> flag moved into -struct <A -HREF="#V4L2-FRAMEBUFFER" ->v4l2_framebuffer</A ->, renamed to -<CODE -CLASS="CONSTANT" ->V4L2_FBUF_FLAG_CHROMAKEY</CODE ->.</P -><P ->In V4L, storing a bitmap pointer in -<CODE -CLASS="STRUCTFIELD" ->clips</CODE -> and setting -<CODE -CLASS="STRUCTFIELD" ->clipcount</CODE -> to -<CODE -CLASS="CONSTANT" ->VIDEO_CLIP_BITMAP</CODE -> (-1) requests bitmap -clipping, using a fixed size bitmap of 1024 × 625 bits. Struct -<CODE -CLASS="STRUCTNAME" ->v4l2_window</CODE -> has a separate -<CODE -CLASS="STRUCTFIELD" ->bitmap</CODE -> pointer field for this purpose and -the bitmap size is determined by <CODE -CLASS="STRUCTFIELD" ->w.width</CODE -> and -<CODE -CLASS="STRUCTFIELD" ->w.height</CODE ->.</P -><P ->The <CODE -CLASS="CONSTANT" ->VIDIOCCAPTURE</CODE -> ioctl to enable or -disable overlay was renamed to <A -HREF="#VIDIOC-OVERLAY" -><CODE -CLASS="CONSTANT" ->VIDIOC_OVERLAY</CODE -></A ->.</P -></DIV -><DIV -CLASS="SECTION" -><HR><H3 -CLASS="SECTION" -><A -NAME="AEN10425" ->6.1.8. Cropping</A -></H3 -><P ->To capture only a subsection of the full picture V4L -provides the <CODE -CLASS="CONSTANT" ->VIDIOCGCAPTURE</CODE -> and -<CODE -CLASS="CONSTANT" ->VIDIOCSCAPTURE</CODE -> ioctl using struct -<CODE -CLASS="STRUCTNAME" ->video_capture</CODE ->. The equivalent V4L2 ioctls are -<A -HREF="#VIDIOC-G-CROP" -><CODE -CLASS="CONSTANT" ->VIDIOC_G_CROP</CODE -></A -> and <A -HREF="#VIDIOC-G-CROP" -><CODE -CLASS="CONSTANT" ->VIDIOC_S_CROP</CODE -></A -> using struct <A -HREF="#V4L2-CROP" ->v4l2_crop</A ->, and the related -<A -HREF="#VIDIOC-CROPCAP" -><CODE -CLASS="CONSTANT" ->VIDIOC_CROPCAP</CODE -></A -> ioctl. This is a rather complex matter, see -<A -HREF="#CROP" ->Section 1.10</A -> for details.</P -><P ->The <CODE -CLASS="STRUCTFIELD" ->x</CODE ->, -<CODE -CLASS="STRUCTFIELD" ->y</CODE ->, <CODE -CLASS="STRUCTFIELD" ->width</CODE -> and -<CODE -CLASS="STRUCTFIELD" ->height</CODE -> fields moved into struct <A -HREF="#V4L2-RECT" ->v4l2_rect</A -> -substructure <CODE -CLASS="STRUCTFIELD" ->c</CODE -> of struct -<CODE -CLASS="STRUCTNAME" ->v4l2_crop</CODE ->. The -<CODE -CLASS="STRUCTFIELD" ->decimation</CODE -> field was dropped. The scaling factor is -implied by the size of the cropping rectangle and the size of the -captured or overlaid image.</P -><P ->The <CODE -CLASS="CONSTANT" ->VIDEO_CAPTURE_ODD</CODE -> -and <CODE -CLASS="CONSTANT" ->VIDEO_CAPTURE_EVEN</CODE -> flags to capture only the -odd or even field, respectively, were replaced by -<CODE -CLASS="CONSTANT" ->V4L2_FIELD_TOP</CODE -> and -<CODE -CLASS="CONSTANT" ->V4L2_FIELD_BOTTOM</CODE -> in the field named -<CODE -CLASS="STRUCTFIELD" ->field</CODE -> of struct <A -HREF="#V4L2-PIX-FORMAT" ->v4l2_pix_format</A -> and -struct <A -HREF="#V4L2-WINDOW" ->v4l2_window</A ->. These structures are used to determine the capture or -overlay format with the <A -HREF="#VIDIOC-G-FMT" -><CODE -CLASS="CONSTANT" ->VIDIOC_S_FMT</CODE -></A -> ioctl.</P -></DIV -><DIV -CLASS="SECTION" -><HR><H3 -CLASS="SECTION" -><A -NAME="AEN10458" ->6.1.9. Reading Images, Memory Mapping</A -></H3 -><DIV -CLASS="SECTION" -><H4 -CLASS="SECTION" -><A -NAME="AEN10460" ->6.1.9.1. Capturing using the read method</A -></H4 -><P ->There is no essential difference between reading images -from a V4L or V4L2 device using the <A -HREF="#FUNC-READ" -><CODE -CLASS="FUNCTION" ->read()</CODE -></A -> function. Supporting -this method is optional for V4L2 devices. Whether the function is -available can be determined with the <A -HREF="#VIDIOC-QUERYCAP" -><CODE -CLASS="CONSTANT" ->VIDIOC_QUERYCAP</CODE -></A -> ioctl. All V4L2 -devices exchanging data with applications must support the -<A -HREF="#FUNC-SELECT" -><CODE -CLASS="FUNCTION" ->select()</CODE -></A -> and <A -HREF="#FUNC-POLL" -><CODE -CLASS="FUNCTION" ->poll()</CODE -></A -> function.</P -><P ->To select an image format and size, V4L provides the -<CODE -CLASS="CONSTANT" ->VIDIOCSPICT</CODE -> and <CODE -CLASS="CONSTANT" ->VIDIOCSWIN</CODE -> -ioctls. V4L2 uses the general-purpose data format negotiation ioctls -<A -HREF="#VIDIOC-G-FMT" -><CODE -CLASS="CONSTANT" ->VIDIOC_G_FMT</CODE -></A -> and <A -HREF="#VIDIOC-G-FMT" -><CODE -CLASS="CONSTANT" ->VIDIOC_S_FMT</CODE -></A ->. They take a pointer to a -struct <A -HREF="#V4L2-FORMAT" ->v4l2_format</A -> as argument, here the struct <A -HREF="#V4L2-PIX-FORMAT" ->v4l2_pix_format</A -> named -<CODE -CLASS="STRUCTFIELD" ->pix</CODE -> of its <CODE -CLASS="STRUCTFIELD" ->fmt</CODE -> -union is used.</P -><P ->For more information about the V4L2 read interface see -<A -HREF="#RW" ->Section 3.1</A ->.</P -></DIV -><DIV -CLASS="SECTION" -><HR><H4 -CLASS="SECTION" -><A -NAME="AEN10484" ->6.1.9.2. Capturing using memory mapping</A -></H4 -><P ->Applications can read from V4L devices by mapping -buffers in device memory, or more often just buffers allocated in -DMA-able system memory, into their address space. This avoids the data -copy overhead of the read method. V4L2 supports memory mapping as -well, with a few differences.</P -><DIV -CLASS="INFORMALTABLE" -><P -></P -><A -NAME="AEN10487" -></A -><TABLE -BORDER="1" -CLASS="CALSTABLE" -><COL><COL><THEAD -><TR -><TH ->V4L</TH -><TH ->V4L2</TH -></TR -></THEAD -><TBODY -><TR -><TD -> </TD -><TD ->The image format must be selected before -buffers are allocated, with the <A -HREF="#VIDIOC-G-FMT" -><CODE -CLASS="CONSTANT" ->VIDIOC_S_FMT</CODE -></A -> ioctl. When no format -is selected the driver may use the last, possibly by another -application requested format.</TD -></TR -><TR -><TD -><P ->Applications cannot change the number of -buffers allocated. The number is built into the driver, unless it -has a module option to change the number when the driver module is -loaded.</P -></TD -><TD -><P ->The <A -HREF="#VIDIOC-REQBUFS" -><CODE -CLASS="CONSTANT" ->VIDIOC_REQBUFS</CODE -></A -> ioctl allocates the -desired number of buffers, this is a required step in the initialization -sequence.</P -></TD -></TR -><TR -><TD -><P ->Drivers map all buffers as one contiguous range - of memory. The <CODE -CLASS="CONSTANT" ->VIDIOCGMBUF</CODE -> ioctl is - available to query the number of buffers, the offset of - each buffer from the start of the virtual file, and the -overall amount of memory used, which can be used as arguments to the - <A -HREF="#FUNC-MMAP" -><CODE -CLASS="FUNCTION" ->mmap()</CODE -></A -> function.</P -></TD -><TD -><P ->Buffers are individually mapped. The offset and size of each buffer can be determined with the <A -HREF="#VIDIOC-QUERYBUF" -><CODE -CLASS="CONSTANT" ->VIDIOC_QUERYBUF</CODE -></A -> ioctl.</P -></TD -></TR -><TR -><TD -><P ->The <CODE -CLASS="CONSTANT" ->VIDIOCMCAPTURE</CODE -> -ioctl prepares a buffer for capturing. It also determines the image -format for this buffer. The ioctl returns immediately, eventually with -an <SPAN -CLASS="ERRORCODE" ->EAGAIN</SPAN -> error code if no video signal had been detected. When the driver -supports more than one buffer applications can call the ioctl multiple -times and thus have multiple outstanding capture -requests.</P -><P ->The <CODE -CLASS="CONSTANT" ->VIDIOCSYNC</CODE -> ioctl -suspends execution until a particular buffer has been -filled.</P -></TD -><TD -><P ->Drivers maintain an incoming and outgoing -queue. <A -HREF="#VIDIOC-QBUF" -><CODE -CLASS="CONSTANT" ->VIDIOC_QBUF</CODE -></A -> enqueues any empty buffer into the incoming -queue. Filled buffers are dequeued from the outgoing queue with the -<A -HREF="#VIDIOC-QBUF" -><CODE -CLASS="CONSTANT" ->VIDIOC_DQBUF</CODE -></A -> ioctl. To wait until filled buffers become available this -function, <A -HREF="#FUNC-SELECT" -><CODE -CLASS="FUNCTION" ->select()</CODE -></A -> or <A -HREF="#FUNC-POLL" -><CODE -CLASS="FUNCTION" ->poll()</CODE -></A -> can be used. The -<A -HREF="#VIDIOC-STREAMON" -><CODE -CLASS="CONSTANT" ->VIDIOC_STREAMON</CODE -></A -> ioctl must be called once after enqueuing one or -more buffers to start capturing. Its counterpart -<A -HREF="#VIDIOC-STREAMON" -><CODE -CLASS="CONSTANT" ->VIDIOC_STREAMOFF</CODE -></A -> stops capturing and dequeues all buffers from both -queues. Applications can query the signal status, if known, with the -<A -HREF="#VIDIOC-ENUMINPUT" -><CODE -CLASS="CONSTANT" ->VIDIOC_ENUMINPUT</CODE -></A -> ioctl.</P -></TD -></TR -></TBODY -></TABLE -><P -></P -></DIV -><P ->For a more in-depth discussion of memory mapping and -examples, see <A -HREF="#MMAP" ->Section 3.2</A ->.</P -></DIV -></DIV -><DIV -CLASS="SECTION" -><HR><H3 -CLASS="SECTION" -><A -NAME="AEN10541" ->6.1.10. Reading Raw VBI Data</A -></H3 -><P ->Originally the V4L API did not specify a raw VBI capture -interface, merely the device file <TT -CLASS="FILENAME" ->/dev/vbi</TT -> was -reserved for this purpose. The only driver supporting this interface -was the BTTV driver, de-facto defining the V4L VBI interface. Reading -from the device yields a raw VBI image with the following -parameters:<DIV -CLASS="INFORMALTABLE" -><P -></P -><A -NAME="AEN10545" -></A -><TABLE -BORDER="1" -CLASS="CALSTABLE" -><COL><COL><THEAD -><TR -><TH ->struct <A -HREF="#V4L2-VBI-FORMAT" ->v4l2_vbi_format</A -></TH -><TH ->V4L, BTTV driver</TH -></TR -></THEAD -><TBODY -><TR -><TD ->sampling_rate</TD -><TD ->28636363 Hz NTSC (precisely all 525-line -standards); 35468950 Hz PAL and SECAM (625-line)</TD -></TR -><TR -><TD ->offset</TD -><TD ->?</TD -></TR -><TR -><TD ->samples_per_line</TD -><TD ->2048</TD -></TR -><TR -><TD ->sample_format</TD -><TD ->V4L2_PIX_FMT_GREY. The last four bytes -(machine endianess integer) contain a frame counter.</TD -></TR -><TR -><TD ->start[]</TD -><TD ->10, 273 NTSC; 22, 335 PAL and SECAM</TD -></TR -><TR -><TD ->count[]</TD -><TD -><P ->16, 16<SUP ->a</SUP -></P -></TD -></TR -><TR -><TD ->flags</TD -><TD ->0</TD -></TR -></TBODY -><TR -><TD -COLSPAN="2" ->Notes:<BR><A -NAME="FTN.AEN10572" ->a. </A ->Old driver -versions used different values, eventually the custom -<CODE -CLASS="CONSTANT" ->BTTV_VBISIZE</CODE -> ioctl was added to query the -correct values.<BR></TD -></TR -></TABLE -><P -></P -></DIV -></P -><P ->Undocumented in the V4L specification, in Linux 2.3 the -<CODE -CLASS="CONSTANT" ->VIDIOCGVBIFMT</CODE -> and -<CODE -CLASS="CONSTANT" ->VIDIOCSVBIFMT</CODE -> ioctls using struct -<CODE -CLASS="STRUCTNAME" ->vbi_format</CODE -> were added to determine the VBI -image parameters. These ioctls are only partially compatible with the -V4L2 VBI interface specified in <A -HREF="#RAW-VBI" ->Section 4.6</A ->.</P -><P ->An <CODE -CLASS="STRUCTFIELD" ->offset</CODE -> field does not -exist, <CODE -CLASS="STRUCTFIELD" ->sample_format</CODE -> is supposed to be -<CODE -CLASS="CONSTANT" ->VIDEO_PALETTE_RAW</CODE ->, here equivalent to -<CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_GREY</CODE ->. The remaining fields are -probably equivalent to struct <A -HREF="#V4L2-VBI-FORMAT" ->v4l2_vbi_format</A ->.</P -><P ->Apparently only the Zoran (ZR 36120) driver implements -these ioctls. The semantics differ from those specified for V4L2 in two -ways. The parameters are reset on <A -HREF="#FUNC-OPEN" -><CODE -CLASS="FUNCTION" ->open()</CODE -></A -> and -<CODE -CLASS="CONSTANT" ->VIDIOCSVBIFMT</CODE -> always returns the <SPAN -CLASS="ERRORCODE" ->EINVAL</SPAN -> error code if the -parameters are invalid.</P -></DIV -><DIV -CLASS="SECTION" -><HR><H3 -CLASS="SECTION" -><A -NAME="AEN10594" ->6.1.11. Miscellaneous</A -></H3 -><P ->V4L2 has no equivalent of the -<CODE -CLASS="CONSTANT" ->VIDIOCGUNIT</CODE -> ioctl. Applications can find the VBI -device associated with a video capture device (or vice versa) by -reopening the device and requesting VBI data. For details see -<A -HREF="#OPEN" ->Section 1.1</A ->.</P -><P ->Presently no replacement exists for - <CODE -CLASS="CONSTANT" ->VIDIOCKEY</CODE ->, the V4L functions -regarding MPEG compression and decompression, and microcode -programming. Drivers may implement the respective V4L ioctls for -these purposes.</P -></DIV -></DIV -><DIV -CLASS="SECTION" -><HR><H2 -CLASS="SECTION" -><A -NAME="HIST-V4L2" ->6.2. History of the V4L2 API</A -></H2 -><P ->Soon after the V4L API was added to the kernel it was -criticised as too inflexible. In August 1998 Bill Dirks proposed a -number of improvements and began work on documentation, example -drivers and applications. With the help of other volunteers this -eventually became the V4L2 API, not just an extension but a -replacement for the V4L API. However it took another four years and -two stable kernel releases until the new API was finally accepted for -inclusion into the kernel in its present form.</P -><DIV -CLASS="SECTION" -><HR><H3 -CLASS="SECTION" -><A -NAME="AEN10604" ->6.2.1. Early Versions</A -></H3 -><P ->1998-08-20: First version.</P -><P ->1998-08-27: select() function was introduced.</P -><P ->1998-09-10: New video standard interface.</P -><P ->1998-09-18: The VIDIOC_NONCAP ioctl was replaced by the O_TRUNC open() -flag (with synonym O_NONCAP/O_NOIO) to indicate a non-capturing open. The -VIDEO_STD_XXX identifiers are now ordinals rather than bits, and -video_std_construct helper function takes id and transmission as -arguments.</P -><P ->1998-09-28: Revamped video standard. Made video controls individually -enumerable.</P -><P ->1998-10-02: Removed id from video_standard, renamed color subcarrier -fields. Renamed VIDIOC_QUERYSTD to VIDIOC_ENUMSTD and VIDIOC_G_INPUT -to VIDIOC_ENUMINPUT. Added preliminary /proc/videodev file. First -draft of CODEC driver API spec.</P -><P ->1998-11-08: Updating for many minor changes to the V4L2 spec. Most -symbols have been renamed. Some material changes to -v4l2_capability.</P -><P ->1998-11-12 bugfix: some of the VIDIOC_* symbols were not constructed -with the right macros, which could lead to errors on what should have -been valid ioctl() calls.</P -><P ->1998-11-14: V4L2_PIX_FMT_RGB24 changed to V4L2_PIX_FMT_BGR24. Same for -RGB32. Audio UI controls moved to VIDIOC_S_CTRL system and assigned -V4L2_CID_AUDIO_* symbols. Removed V4L2_MAJOR from videodev.h since it -is only used at one place in videodev. Added YUV422 and YUV411 planar -formats.</P -><P ->1998-11-28: Changed a few ioctl symbols. Added stuff for codec and -video output devices.</P -><P ->1999-01-14: Added raw VBI interface.</P -><P ->1999-01-19: Removed VIDIOC_NEXTBUF ioctl.</P -></DIV -><DIV -CLASS="SECTION" -><HR><H3 -CLASS="SECTION" -><A -NAME="AEN10618" ->6.2.2. V4L2 Version 0.16 1999-01-31</A -></H3 -><P ->1999-01-27: There is now one QBUF ioctl, VIDIOC_QWBUF and VIDIOC_QRBUF -are gone. VIDIOC_QBUF takes a v4l2_buffer as a parameter. Added -digital zoom (cropping) controls.</P -></DIV -><DIV -CLASS="SECTION" -><HR><H3 -CLASS="SECTION" -><A -NAME="AEN10621" ->6.2.3. V4L2 Version 0.18 1999-03-16</A -></H3 -><P ->Added a v4l to V4L2 ioctl compatibility layer to -videodev.c. Driver writers, this changes how you implement your ioctl -handler. See the Driver Writer's Guide. Added some more control id -codes.</P -></DIV -><DIV -CLASS="SECTION" -><HR><H3 -CLASS="SECTION" -><A -NAME="AEN10624" ->6.2.4. V4L2 Version 0.19 1999-06-05</A -></H3 -><P ->1999-03-18: Fill in the category and catname fields of -v4l2_queryctrl objects before passing them to the driver. Required a -minor change to the VIDIOC_QUERYCTRL handlers in the sample -drivers.</P -><P ->1999-03-31: Better compatibility for v4l memory capture -ioctls. Requires changes to drivers to fully support new compatibility -features, see Driver Writer's Guide and v4l2cap.c. Added new control -IDs: V4L2_CID_HFLIP, _VFLIP. Changed V4L2_PIX_FMT_YUV422P to _YUV422P, -and _YUV411P to _YUV411P.</P -><P ->1999-04-04: Added a few more control IDs.</P -><P ->1999-04-07: Added the button control type.</P -><P ->1999-05-02: Fixed a typo in videodev.h, and added the -V4L2_CTRL_FLAG_GRAYED (later V4L2_CTRL_FLAG_GRABBED) flag.</P -><P ->1999-05-20: Definition of VIDIOC_G_CTRL was wrong causing -a malfunction of this ioctl.</P -><P ->1999-06-05: Changed the value of -V4L2_CID_WHITENESS.</P -></DIV -><DIV -CLASS="SECTION" -><HR><H3 -CLASS="SECTION" -><A -NAME="AEN10633" ->6.2.5. V4L2 Version 0.20 1999-09-10</A -></H3 -><P ->Version 0.20 introduced a number of changes not backward -compatible with 0.19 and earlier. The purpose was to simplify the API, -while at the same time make it more extensible, and follow common -Linux driver API conventions.</P -><P -></P -><OL -TYPE="1" -><LI -><P ->Fixed typos in some V4L2_FMT_FLAG symbols. Changed -struct <A -HREF="#V4L2-CLIP" ->v4l2_clip</A -> to be compatible with v4l. (1999-08-30)</P -></LI -><LI -><P ->Added V4L2_TUNER_SUB_LANG1. (1999-09-05)</P -></LI -><LI -><P ->All ioctl() commands that took an integer argument -before, will now take a pointer to an integer. Where it makes sense, -the driver will return the actual value used in the integer pointed to -by the argument. This is a common convention, and also makes certain -things easier in libv4l2 and other system code when the parameter to -ioctl() is always a pointer. The ioctl commands affected are: -VIDIOC_PREVIEW, VIDIOC_STREAMON, VIDIOC_STREAMOFF, VIDIOC_S_FREQ, -VIDIOC_S_INPUT, VIDIOC_S_OUTPUT, VIDIOC_S_EFFECT. For example, where -before you might have had code like: <PRE -CLASS="PROGRAMLISTING" ->err = ioctl (fd, VIDIOC_XXX, V4L2_XXX);</PRE -> that becomes <PRE -CLASS="PROGRAMLISTING" ->int a = V4L2_XXX; err = ioctl(fd, VIDIOC_XXX, &a);</PRE -> - </P -></LI -><LI -><P ->All the different set-format ioctl() commands are -swept into a single set-format command whose parameter consists of an -integer value indicating the type of format, followed by the format -data. The same for the get-format commands, of course. This will -simplify the API by eliminating several ioctl codes and also make it -possible to add additional kinds of data streams, or driver-private -kinds of streams without having to add more set-format ioctls. The -parameter to VIDIOC_S_FMT is as follows. The first field is a -V4L2_BUF_TYPE_XXX value that indicates which stream the set-format is -for, and implicitly, what type of format data. After that is a union -of the different format structures. More can be added later without -breaking backward compatibility. Nonstandard driver-private formats -can be used by casting raw_data.</P -><P -><PRE -CLASS="PROGRAMLISTING" ->struct <A -HREF="#V4L2-FORMAT" ->v4l2_format</A -> { - __u32 type; - union { - struct <A -HREF="#V4L2-PIX-FORMAT" ->v4l2_pix_format</A -> pix; - struct <A -HREF="#V4L2-VBI-FORMAT" ->v4l2_vbi_format</A -> vbi; - ... and so on ... - __u8 raw_data[200]; - } fmt; -}; - </PRE -></P -><P ->For a get-format, the application fills in the type -field, and the driver fills in the rest. What was before the image -format structure, struct <A -HREF="#V4L2-FORMAT" ->v4l2_format</A ->, becomes struct <A -HREF="#V4L2-PIX-FORMAT" ->v4l2_pix_format</A ->. These -ioctls become obsolete: VIDIOC_S_INFMT, VIDIOC_G_INFMT, -VIDIOC_S_OUTFMT, VIDIOC_G_OUTFMT, VIDIOC_S_VBIFMT -VIDIOC_G_VBIFMT.</P -></LI -><LI -><P ->Similar to item 2, VIDIOC_G/S_PARM and -VIDIOC_G/S_OUTPARM are merged, along with the corresponding 'get' -functions. A type field will indicate which stream the parameters are -for, set to a V4L2_BUF_TYPE_* value.</P -><P -><PRE -CLASS="PROGRAMLISTING" ->struct <A -HREF="#V4L2-STREAMPARM" ->v4l2_streamparm</A -> { - __u32 type; - union { - struct <A -HREF="#V4L2-CAPTUREPARM" ->v4l2_captureparm</A -> capture; - struct <A -HREF="#V4L2-OUTPUTPARM" ->v4l2_outputparm</A -> output; - __u8 raw_data[200]; - } parm; -}; - </PRE -></P -><P ->These ioctls become obsolete: VIDIOC_G_OUTPARM, -VIDIOC_S_OUTPARM.</P -></LI -><LI -><P ->The way controls are enumerated is simplified. -Simultaneously, two new control flags are introduced and the existing -flag is dropped. Also, the catname field is dropped in favor of a -group name. To enumerate controls call VIDIOC_QUERYCTRL with -successive id's starting from V4L2_CID_BASE or V4L2_CID_PRIVATE_BASE -and stop when the driver returns the EINVAL error code. Controls that -are not supported on the hardware are marked with the -V4L2_CTRL_FLAG_DISABLED flag.</P -><P ->Additionally, controls that are temporarily -unavailable, or that can only be controlled from another file -descriptor are marked with the V4L2_CTRL_FLAG_GRABBED flag. Usually, a -control that is GRABBED, but not DISABLED can be read, but changed. -The group name indicates a possibly narrower classification than the -category. In other words, there may be multiple groups within a -category. Controls within a group would typically be drawn within a -group box. Controls in different categories might have a greater -separation, or even be in separate windows.</P -></LI -><LI -><P ->The v4l2_buffer timestamp field is changed to a 64-bit -integer, and holds the time of the frame based on the system time, in -1 nanosecond units. Additionally, timestamps will be in absolute -system time, not starting from zero at the beginning of a stream as it -is now. The data type name for timestamps is stamp_t, defined as a -signed 64-bit integer. Output devices should not send a buffer out -until the time in the timestamp field has arrived. I would like to -follow SGI's lead, and adopt a multimedia timestamping system like -their UST (Unadjusted System Time). See -http://reality.sgi.com/cpirazzi_engr/lg/time/intro.html. [This link is -no longer valid.] UST uses timestamps that are 64-bit signed integers -(not struct timeval's) and given in nanosecond units. The UST clock -starts at zero when the system is booted and runs continuously and -uniformly. It takes a little over 292 years for UST to overflow. There -is no way to set the UST clock. The regular Linux time-of-day clock -can be changed periodically, which would cause errors if it were being -used for timestamping a multimedia stream. A real UST style clock will -require some support in the kernel that is not there yet. But in -anticipation, I will change the timestamp field to a 64-bit integer, -and I will change the v4l2_masterclock_gettime() function (used only -by drivers) to return a 64-bit integer.</P -></LI -><LI -><P ->The sequence field is added to the struct <A -HREF="#V4L2-BUFFER" ->v4l2_buffer</A ->. The -sequence field indicates which frame this is in the sequence-- 0, 1, -2, 3, 4, etc. Set by capturing devices. Ignored by output devices. If -a capture driver drops a frame, the sequence number of that frame is -skipped. A break in the sequence will indicate to the application -which frame was dropped.</P -></LI -></OL -></DIV -><DIV -CLASS="SECTION" -><HR><H3 -CLASS="SECTION" -><A -NAME="AEN10672" ->6.2.6. V4L2 Version 0.20 incremental changes</A -></H3 -><P ->1999-12-23: In struct <A -HREF="#V4L2-VBI-FORMAT" ->v4l2_vbi_format</A -> field -<CODE -CLASS="STRUCTFIELD" ->reserved1</CODE -> became <CODE -CLASS="STRUCTFIELD" ->offset</CODE ->. -Previously <CODE -CLASS="STRUCTFIELD" ->reserved1</CODE -> was required to always read -zero.</P -><P ->2000-01-13: Added V4L2_FMT_FLAG_NOT_INTERLACED.</P -><P ->2000-07-31: Included linux/poll.h in videodev.h for compatibility with -the original videodev.h.</P -><P ->2000-11-20: Added V4L2_TYPE_VBI_OUTPUT. Added V4L2_PIX_FMT_Y41P.</P -><P ->2000-11-25: Added V4L2_TYPE_VBI_INPUT.</P -><P ->2000-12-04: Fixed a couple typos in symbol names.</P -><P ->2001-01-18: Fixed a namespace conflict (the fourcc macro changed to -v4l2_fourcc).</P -><P ->2001-01-25: Fixed a possible driver-level compatibility problem -between the original 2.4.0 videodev.h and the videodev.h that comes -with videodevX. If you were using an earlier version of videodevX on -2.4.0, then you should recompile your v4l and V4L2 drivers to be -safe.</P -><P ->2001-01-26: videodevX: Fixed a possible kernel-level incompatibility -between the videodevX videodev.h and the 2.2.x videodev.h that had the -devfs patches applied. videodev: Changed fourcc to v4l2_fourcc to -avoid namespace pollution. Some other cleanup.</P -><P ->2001-03-02: Certain v4l ioctls that really pass data both ways, but -whose types are read-only, did not work correctly through the backward -compatibility layer. [Solution?]</P -><P ->2001-04-13: Added big endian 16-bit RGB formats.</P -><P ->2001-09-17: Added new YUV formats. Added VIDIOC_G_FREQUENCY and -VIDIOC_S_FREQUENCY. (The VIDIOC_G/S_FREQ ioctls did not take multiple -tuners into account.)</P -><P ->2000-09-18: Added V4L2_BUF_TYPE_VBI. Raw VBI VIDIOC_G_FMT and -VIDIOC_S_FMT may fail if field <CODE -CLASS="STRUCTFIELD" ->type</CODE -> is not -V4L2_BUF_TYPE_VBI. Changed the ambiguous phrase "rising edge" to "leading -edge" in the definition of struct <A -HREF="#V4L2-VBI-FORMAT" ->v4l2_vbi_format</A -> field -<CODE -CLASS="STRUCTFIELD" ->offset</CODE ->.</P -></DIV -><DIV -CLASS="SECTION" -><HR><H3 -CLASS="SECTION" -><A -NAME="AEN10694" ->6.2.7. V4L2 Version 0.20 2000-11-23</A -></H3 -><P ->A number of changes were made to the raw VBI -interface.</P -><P -></P -><OL -TYPE="1" -><LI -><P ->Added figures clarifying the line numbering scheme. -The description of <CODE -CLASS="STRUCTFIELD" ->start</CODE ->[0] and -<CODE -CLASS="STRUCTFIELD" ->start</CODE ->[1] as base 0 offset has been dropped. -Rationale: a) The previous definition was unclear. b) The -<CODE -CLASS="STRUCTFIELD" ->start</CODE ->[] values are not an offset into anything, -as a means of identifying scanning lines it can only be -counterproductive to deviate from common numbering conventions. -Compatibility: Add one to the start values. Applications depending on -the previous semantics of start values may not function -correctly.</P -></LI -><LI -><P ->The restriction "count[0] > 0 and count[1] > 0" has -been relaxed to "(count[0] + count[1]) > 0". Rationale: Drivers -allocating resources at scanning line granularity and first field only -data services. The comment that both 'count' values will usually be -equal is misleading and pointless and has been removed. Compatibility: -Drivers may return EINVAL, applications depending on the previous -restriction may not function correctly.</P -></LI -><LI -><P ->Restored description of the driver option to return -negative start values. Existed in the initial revision of this -document, not traceable why it disappeared in later versions. -Compatibility: Applications depending on the returned start values -being positive may not function correctly. Clarification on the use of -EBUSY and EINVAL in VIDIOC_S_FMT ioctl. Added EBUSY paragraph to -section. Added description of reserved2, previously mentioned only in -videodev.h.</P -></LI -><LI -><P ->Added V4L2_TYPE_VBI_INPUT and V4L2_TYPE_VBI_OUTPUT -here and in videodev.h. The first is an alias for the older -V4L2_TYPE_VBI, the latter was missing in videodev.h.</P -></LI -></OL -></DIV -><DIV -CLASS="SECTION" -><HR><H3 -CLASS="SECTION" -><A -NAME="AEN10709" ->6.2.8. V4L2 Version 0.20 2002-07-25</A -></H3 -><P ->Added sliced VBI interface proposal.</P -></DIV -><DIV -CLASS="SECTION" -><HR><H3 -CLASS="SECTION" -><A -NAME="AEN10712" ->6.2.9. V4L2 in Linux 2.5.46, 2002-10</A -></H3 -><P ->Around October-November 2002, prior to an announced -feature freeze of Linux 2.5, the API was revised, drawing from -experience with V4L2 0.20. This unnamed version was finally merged -into Linux 2.5.46.</P -><P -></P -><OL -TYPE="1" -><LI -><P ->As specified in <A -HREF="#RELATED" ->Section 1.1.2</A -> drivers -must make related device functions available under all minor device -numbers.</P -></LI -><LI -><P ->The <A -HREF="#FUNC-OPEN" -><CODE -CLASS="FUNCTION" ->open()</CODE -></A -> function requires access mode -<CODE -CLASS="CONSTANT" ->O_RDWR</CODE -> regardless of device type. All V4L2 -drivers exchanging data with applications must support the -<CODE -CLASS="CONSTANT" ->O_NONBLOCK</CODE -> flag. The <CODE -CLASS="CONSTANT" ->O_NOIO</CODE -> -flag (alias of meaningless <CODE -CLASS="CONSTANT" ->O_TRUNC</CODE ->) to indicate -accesses without data exchange (panel applications) was -dropped. Drivers must assume panel mode until the application attempts -to initiate data exchange, see <A -HREF="#OPEN" ->Section 1.1</A ->.</P -></LI -><LI -><P ->The struct <A -HREF="#V4L2-CAPABILITY" ->v4l2_capability</A -> changed dramatically. Note that -also the size of the structure changed, which is encoded in the ioctl -request code, thus older V4L2 devices will respond with an <SPAN -CLASS="ERRORCODE" ->EINVAL</SPAN -> error code to -the new <A -HREF="#VIDIOC-QUERYCAP" -><CODE -CLASS="CONSTANT" ->VIDIOC_QUERYCAP</CODE -></A -> ioctl.</P -><P ->There are new fields to identify the driver, a new (as -of yet unspecified) device function -<CODE -CLASS="CONSTANT" ->V4L2_CAP_RDS_CAPTURE</CODE ->, the -<CODE -CLASS="CONSTANT" ->V4L2_CAP_AUDIO</CODE -> flag indicates if the device has -any audio connectors, another I/O capability -<CODE -CLASS="CONSTANT" ->V4L2_CAP_ASYNCIO</CODE -> can be flagged. Field -<CODE -CLASS="STRUCTFIELD" ->type</CODE -> became a set in response to the change -above and was merged with <CODE -CLASS="STRUCTFIELD" ->flags</CODE ->. -<CODE -CLASS="CONSTANT" ->V4L2_FLAG_TUNER</CODE -> was renamed to -<CODE -CLASS="CONSTANT" ->V4L2_CAP_TUNER</CODE ->, -<CODE -CLASS="CONSTANT" ->V4L2_CAP_VIDEO_OVERLAY</CODE -> replaced -<CODE -CLASS="CONSTANT" ->V4L2_FLAG_PREVIEW</CODE -> and -<CODE -CLASS="CONSTANT" ->V4L2_CAP_VBI_CAPTURE</CODE -> and -<CODE -CLASS="CONSTANT" ->V4L2_CAP_VBI_OUTPUT</CODE -> replaced -<CODE -CLASS="CONSTANT" ->V4L2_FLAG_DATA_SERVICE</CODE ->. -<CODE -CLASS="CONSTANT" ->V4L2_FLAG_READ</CODE -> and -<CODE -CLASS="CONSTANT" ->V4L2_FLAG_WRITE</CODE -> merged to -<CODE -CLASS="CONSTANT" ->V4L2_CAP_READWRITE</CODE ->.</P -><P ->Redundant fields -<CODE -CLASS="STRUCTFIELD" ->inputs</CODE ->, <CODE -CLASS="STRUCTFIELD" ->outputs</CODE ->, -<CODE -CLASS="STRUCTFIELD" ->audios</CODE -> were removed, these can be -determined as described in <A -HREF="#VIDEO" ->Section 1.4</A -> and <A -HREF="#AUDIO" ->Section 1.5</A ->.</P -><P ->The somewhat volatile and therefore -barely useful fields <CODE -CLASS="STRUCTFIELD" ->maxwidth</CODE ->, -<CODE -CLASS="STRUCTFIELD" ->maxheight</CODE ->, -<CODE -CLASS="STRUCTFIELD" ->minwidth</CODE ->, -<CODE -CLASS="STRUCTFIELD" ->minheight</CODE ->, -<CODE -CLASS="STRUCTFIELD" ->maxframerate</CODE -> were removed, this information -is available as described in <A -HREF="#FORMAT" ->Section 1.9</A -> and -<A -HREF="#STANDARD" ->Section 1.7</A ->.</P -><P -><CODE -CLASS="CONSTANT" ->V4L2_FLAG_SELECT</CODE -> -was removed, this function is considered important enough that all -V4L2 drivers exchanging data with applications must support -<CODE -CLASS="FUNCTION" ->select()</CODE ->. The redundant flag -<CODE -CLASS="CONSTANT" ->V4L2_FLAG_MONOCHROME</CODE -> was removed, this -information is available as described in <A -HREF="#FORMAT" ->Section 1.9</A ->.</P -></LI -><LI -><P ->In struct <A -HREF="#V4L2-INPUT" ->v4l2_input</A -> the - <CODE -CLASS="STRUCTFIELD" ->assoc_audio</CODE -> field and the -<CODE -CLASS="STRUCTFIELD" ->capability</CODE -> field and its only - flag <CODE -CLASS="CONSTANT" ->V4L2_INPUT_CAP_AUDIO</CODE -> was replaced - by the new <CODE -CLASS="STRUCTFIELD" ->audioset</CODE -> - field. Instead of linking one video input to one audio input - this field reports all audio inputs this video input - combines with.</P -><P ->New fields are <CODE -CLASS="STRUCTFIELD" ->tuner</CODE -> -(reversing the former link from tuners to video inputs), -<CODE -CLASS="STRUCTFIELD" ->std</CODE -> and -<CODE -CLASS="STRUCTFIELD" ->status</CODE ->.</P -><P ->Accordingly struct <A -HREF="#V4L2-OUTPUT" ->v4l2_output</A -> lost its - <CODE -CLASS="STRUCTFIELD" ->capability</CODE -> and - <CODE -CLASS="STRUCTFIELD" ->assoc_audio</CODE -> fields, - <CODE -CLASS="STRUCTFIELD" ->audioset</CODE ->, - <CODE -CLASS="STRUCTFIELD" ->modulator</CODE -> and - <CODE -CLASS="STRUCTFIELD" ->std</CODE -> where added.</P -></LI -><LI -><P ->The struct <A -HREF="#V4L2-AUDIO" ->v4l2_audio</A -> field -<CODE -CLASS="STRUCTFIELD" ->audio</CODE -> was renamed to -<CODE -CLASS="STRUCTFIELD" ->index</CODE ->, consistent with other structures. -Capability flag <CODE -CLASS="CONSTANT" ->V4L2_AUDCAP_STEREO</CODE -> was added to -indicated if this is a stereo input. -<CODE -CLASS="CONSTANT" ->V4L2_AUDCAP_EFFECTS</CODE -> and the corresponding -<CODE -CLASS="CONSTANT" ->V4L2_AUDMODE</CODE -> flags where removed, this can be -easily implemented using controls. (However the same applies to AVL -which is still there.)</P -><P ->The struct <A -HREF="#V4L2-AUDIOOUT" ->v4l2_audioout</A -> field -<CODE -CLASS="STRUCTFIELD" ->audio</CODE -> was renamed to -<CODE -CLASS="STRUCTFIELD" ->index</CODE ->.</P -></LI -><LI -><P ->The struct <A -HREF="#V4L2-TUNER" ->v4l2_tuner</A -> -<CODE -CLASS="STRUCTFIELD" ->input</CODE -> field was replaced by an -<CODE -CLASS="STRUCTFIELD" ->index</CODE -> field, permitting devices with -multiple tuners. The link between video inputs and tuners is now -reversed, inputs point to the tuner they are on. The -<CODE -CLASS="STRUCTFIELD" ->std</CODE -> substructure became a -simple set (more about this below) and moved into struct <A -HREF="#V4L2-INPUT" ->v4l2_input</A ->. A -<CODE -CLASS="STRUCTFIELD" ->type</CODE -> field was added.</P -><P ->Accordingly in struct <A -HREF="#V4L2-MODULATOR" ->v4l2_modulator</A -> the -<CODE -CLASS="STRUCTFIELD" ->output</CODE -> was replaced by an -<CODE -CLASS="STRUCTFIELD" ->index</CODE -> field.</P -><P ->In struct <A -HREF="#V4L2-FREQUENCY" ->v4l2_frequency</A -> the -<CODE -CLASS="STRUCTFIELD" ->port</CODE -> field was replaced by a -<CODE -CLASS="STRUCTFIELD" ->tuner</CODE -> field containing the respective tuner -or modulator index number. A tuner <CODE -CLASS="STRUCTFIELD" ->type</CODE -> -field was added and the <CODE -CLASS="STRUCTFIELD" ->reserved</CODE -> field -became larger for future extensions (satellite tuners in -particular).</P -></LI -><LI -><P ->The idea of completely transparent video standards was -dropped. Experience showed that applications must be able to work with -video standards beyond presenting the user a menu. To this end V4L2 -returned to defined standards as <A -HREF="#V4L2-STD-ID" ->v4l2_std_id</A ->, replacing references -to standards throughout the API. For details see <A -HREF="#STANDARD" ->Section 1.7</A ->. <A -HREF="#VIDIOC-G-STD" -><CODE -CLASS="CONSTANT" ->VIDIOC_G_STD</CODE -></A -> and <A -HREF="#VIDIOC-G-STD" -><CODE -CLASS="CONSTANT" ->VIDIOC_S_STD</CODE -></A -> -now take a pointer to this type as argument. <A -HREF="#VIDIOC-QUERYSTD" -><CODE -CLASS="CONSTANT" ->VIDIOC_QUERYSTD</CODE -></A -> was -added to autodetect the received standard. In struct <A -HREF="#V4L2-STANDARD" ->v4l2_standard</A -> an -<CODE -CLASS="STRUCTFIELD" ->index</CODE -> field was added for <A -HREF="#VIDIOC-ENUMSTD" -><CODE -CLASS="CONSTANT" ->VIDIOC_ENUMSTD</CODE -></A ->. -A <A -HREF="#V4L2-STD-ID" ->v4l2_std_id</A -> field named <CODE -CLASS="STRUCTFIELD" ->id</CODE -> was added as -machine readable identifier, also replacing the -<CODE -CLASS="STRUCTFIELD" ->transmission</CODE -> field. -<CODE -CLASS="STRUCTFIELD" ->framerate</CODE ->, which is misleading, was renamed -to <CODE -CLASS="STRUCTFIELD" ->frameperiod</CODE ->. The now obsolete -<CODE -CLASS="STRUCTFIELD" ->colorstandard</CODE -> information, originally -needed to distguish between variations of standards, were -removed.</P -><P ->Struct <CODE -CLASS="STRUCTNAME" ->v4l2_enumstd</CODE -> ceased to -be. <A -HREF="#VIDIOC-ENUMSTD" -><CODE -CLASS="CONSTANT" ->VIDIOC_ENUMSTD</CODE -></A -> now takes a pointer to a struct <A -HREF="#V4L2-STANDARD" ->v4l2_standard</A -> -directly. The information which standards are supported by a -particular video input or output moved into struct <A -HREF="#V4L2-INPUT" ->v4l2_input</A -> and -struct <A -HREF="#V4L2-OUTPUT" ->v4l2_output</A -> fields named <CODE -CLASS="STRUCTFIELD" ->std</CODE ->, -respectively.</P -></LI -><LI -><P ->The struct <A -HREF="#V4L2-QUERYCTRL" ->v4l2_queryctrl</A -> fields -<CODE -CLASS="STRUCTFIELD" ->category</CODE -> and -<CODE -CLASS="STRUCTFIELD" ->group</CODE -> did not catch on and/or were not -implemented as expected and therefore removed.</P -></LI -><LI -><P ->The <A -HREF="#VIDIOC-G-FMT" -><CODE -CLASS="CONSTANT" ->VIDIOC_TRY_FMT</CODE -></A -> ioctl was added to negotiate data -formats as with <A -HREF="#VIDIOC-G-FMT" -><CODE -CLASS="CONSTANT" ->VIDIOC_S_FMT</CODE -></A ->, but without the overhead of -programming the hardware and regardless of I/O in progress.</P -><P ->In struct <A -HREF="#V4L2-FORMAT" ->v4l2_format</A -> the <CODE -CLASS="STRUCTFIELD" ->fmt</CODE -> - union was extended to contain struct <A -HREF="#V4L2-WINDOW" ->v4l2_window</A ->. As a result - all data format negotiation is now possible with - <CODE -CLASS="CONSTANT" ->VIDIOC_G_FMT</CODE ->, - <CODE -CLASS="CONSTANT" ->VIDIOC_S_FMT</CODE -> and - <CODE -CLASS="CONSTANT" ->VIDIOC_TRY_FMT</CODE ->; the - <CODE -CLASS="CONSTANT" ->VIDIOC_G_WIN</CODE ->, - <CODE -CLASS="CONSTANT" ->VIDIOC_S_WIN</CODE -> and ioctl to prepare for - overlay were removed. The <CODE -CLASS="STRUCTFIELD" ->type</CODE -> - field changed to type enum <A -HREF="#V4L2-BUF-TYPE" ->v4l2_buf_type</A -> and the buffer type - names changed as follows.<DIV -CLASS="INFORMALTABLE" -><P -></P -><A -NAME="AEN10867" -></A -><TABLE -BORDER="1" -CLASS="CALSTABLE" -><COL><COL><THEAD -><TR -><TH ->Old defines</TH -><TH ->enum <A -HREF="#V4L2-BUF-TYPE" ->v4l2_buf_type</A -></TH -></TR -></THEAD -><TBODY -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_BUF_TYPE_CAPTURE</CODE -></TD -><TD -><CODE -CLASS="CONSTANT" ->V4L2_BUF_TYPE_VIDEO_CAPTURE</CODE -></TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_BUF_TYPE_CODECIN</CODE -></TD -><TD -><CODE -CLASS="CONSTANT" ->Preliminary omitted</CODE -></TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_BUF_TYPE_CODECOUT</CODE -></TD -><TD -><CODE -CLASS="CONSTANT" ->Preliminary omitted</CODE -></TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_BUF_TYPE_EFFECTSIN</CODE -></TD -><TD -><CODE -CLASS="CONSTANT" ->Preliminary omitted</CODE -></TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_BUF_TYPE_EFFECTSIN2</CODE -></TD -><TD -><CODE -CLASS="CONSTANT" ->Preliminary omitted</CODE -></TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_BUF_TYPE_EFFECTSOUT</CODE -></TD -><TD -><CODE -CLASS="CONSTANT" ->Preliminary omitted</CODE -></TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_BUF_TYPE_VIDEOOUT</CODE -></TD -><TD -><CODE -CLASS="CONSTANT" ->V4L2_BUF_TYPE_VIDEO_OUTPUT</CODE -></TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->-</CODE -></TD -><TD -><CODE -CLASS="CONSTANT" ->V4L2_BUF_TYPE_VIDEO_OVERLAY</CODE -></TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->-</CODE -></TD -><TD -><CODE -CLASS="CONSTANT" ->V4L2_BUF_TYPE_VBI_CAPTURE</CODE -></TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->-</CODE -></TD -><TD -><CODE -CLASS="CONSTANT" ->V4L2_BUF_TYPE_VBI_OUTPUT</CODE -></TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_BUF_TYPE_PRIVATE_BASE</CODE -></TD -><TD -><CODE -CLASS="CONSTANT" ->V4L2_BUF_TYPE_PRIVATE</CODE -></TD -></TR -></TBODY -></TABLE -><P -></P -></DIV -></P -></LI -><LI -><P ->In struct <A -HREF="#V4L2-FMTDESC" ->v4l2_fmtdesc</A -> a enum <A -HREF="#V4L2-BUF-TYPE" ->v4l2_buf_type</A -> field named -<CODE -CLASS="STRUCTFIELD" ->type</CODE -> was added as in struct <A -HREF="#V4L2-FORMAT" ->v4l2_format</A ->. As a -result the <CODE -CLASS="CONSTANT" ->VIDIOC_ENUM_FBUFFMT</CODE -> ioctl is no longer -needed and was removed. These calls can be replaced by -<A -HREF="#VIDIOC-ENUM-FMT" -><CODE -CLASS="CONSTANT" ->VIDIOC_ENUM_FMT</CODE -></A -> with type -<CODE -CLASS="CONSTANT" ->V4L2_BUF_TYPE_VIDEO_OVERLAY</CODE ->.</P -></LI -><LI -><P ->In struct <A -HREF="#V4L2-PIX-FORMAT" ->v4l2_pix_format</A -> the -<CODE -CLASS="STRUCTFIELD" ->depth</CODE -> was removed, assuming applications -recognizing the format are aware of the image depth and others need -not know. The same rationale lead to the removal of the -<CODE -CLASS="CONSTANT" ->V4L2_FMT_FLAG_COMPRESSED</CODE -> flag. The -<CODE -CLASS="CONSTANT" ->V4L2_FMT_FLAG_SWCONVECOMPRESSED</CODE -> flag was removed -because drivers are not supposed to convert image formats in kernel -space. The <CODE -CLASS="CONSTANT" ->V4L2_FMT_FLAG_BYTESPERLINE</CODE -> flag was -redundant, applications can set the -<CODE -CLASS="STRUCTFIELD" ->bytesperline</CODE -> field to zero to get a -reasonable default. Since also the remaining flags were replaced, the -<CODE -CLASS="STRUCTFIELD" ->flags</CODE -> field itself was removed.</P -><P ->The interlace flags were replaced by a enum <A -HREF="#V4L2-FIELD" ->v4l2_field</A -> -value in a newly added <CODE -CLASS="STRUCTFIELD" ->field</CODE -> field.<DIV -CLASS="INFORMALTABLE" -><P -></P -><A -NAME="AEN10952" -></A -><TABLE -BORDER="1" -CLASS="CALSTABLE" -><COL><COL><THEAD -><TR -><TH ->Old flag</TH -><TH ->enum <A -HREF="#V4L2-FIELD" ->v4l2_field</A -></TH -></TR -></THEAD -><TBODY -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_FMT_FLAG_NOT_INTERLACED</CODE -></TD -><TD -><CODE -CLASS="CONSTANT" ->?</CODE -></TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_FMT_FLAG_INTERLACED</CODE -> -= <CODE -CLASS="CONSTANT" ->V4L2_FMT_FLAG_COMBINED</CODE -></TD -><TD -><CODE -CLASS="CONSTANT" ->V4L2_FIELD_INTERLACED</CODE -></TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_FMT_FLAG_TOPFIELD</CODE -> -= <CODE -CLASS="CONSTANT" ->V4L2_FMT_FLAG_ODDFIELD</CODE -></TD -><TD -><CODE -CLASS="CONSTANT" ->V4L2_FIELD_TOP</CODE -></TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_FMT_FLAG_BOTFIELD</CODE -> -= <CODE -CLASS="CONSTANT" ->V4L2_FMT_FLAG_EVENFIELD</CODE -></TD -><TD -><CODE -CLASS="CONSTANT" ->V4L2_FIELD_BOTTOM</CODE -></TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->-</CODE -></TD -><TD -><CODE -CLASS="CONSTANT" ->V4L2_FIELD_SEQ_TB</CODE -></TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->-</CODE -></TD -><TD -><CODE -CLASS="CONSTANT" ->V4L2_FIELD_SEQ_BT</CODE -></TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->-</CODE -></TD -><TD -><CODE -CLASS="CONSTANT" ->V4L2_FIELD_ALTERNATE</CODE -></TD -></TR -></TBODY -></TABLE -><P -></P -></DIV -></P -><P ->The color space flags were replaced by a -enum <A -HREF="#V4L2-COLORSPACE" ->v4l2_colorspace</A -> value in a newly added -<CODE -CLASS="STRUCTFIELD" ->colorspace</CODE -> field, where one of -<CODE -CLASS="CONSTANT" ->V4L2_COLORSPACE_SMPTE170M</CODE ->, -<CODE -CLASS="CONSTANT" ->V4L2_COLORSPACE_BT878</CODE ->, -<CODE -CLASS="CONSTANT" ->V4L2_COLORSPACE_470_SYSTEM_M</CODE -> or -<CODE -CLASS="CONSTANT" ->V4L2_COLORSPACE_470_SYSTEM_BG</CODE -> replaces -<CODE -CLASS="CONSTANT" ->V4L2_FMT_CS_601YUV</CODE ->.</P -></LI -><LI -><P ->In struct <A -HREF="#V4L2-REQUESTBUFFERS" ->v4l2_requestbuffers</A -> the -<CODE -CLASS="STRUCTFIELD" ->type</CODE -> field was properly typed as -enum <A -HREF="#V4L2-BUF-TYPE" ->v4l2_buf_type</A ->. Buffer types changed as mentioned above. A new -<CODE -CLASS="STRUCTFIELD" ->memory</CODE -> field of type enum <A -HREF="#V4L2-MEMORY" ->v4l2_memory</A -> was -added to distinguish between mapping methods using buffers allocated -by the driver or the application. See <A -HREF="#IO" ->Chapter 3</A -> for -details.</P -></LI -><LI -><P ->In struct <A -HREF="#V4L2-BUFFER" ->v4l2_buffer</A -> the <CODE -CLASS="STRUCTFIELD" ->type</CODE -> -field was properly typed as enum <A -HREF="#V4L2-BUF-TYPE" ->v4l2_buf_type</A ->. Buffer types changed as -mentioned above. A <CODE -CLASS="STRUCTFIELD" ->field</CODE -> field of type -enum <A -HREF="#V4L2-FIELD" ->v4l2_field</A -> was added to indicate if a buffer contains a top or -bottom field, the field flags were removed. Realizing the efforts to -introduce an unadjusted system time clock failed, the -<CODE -CLASS="STRUCTFIELD" ->timestamp</CODE -> field changed back from type -stamp_t, an unsigned 64 bit integer expressing time in nanoseconds, to -struct <CODE -CLASS="STRUCTNAME" ->timeval</CODE ->. With the addition of a second -memory mapping method the <CODE -CLASS="STRUCTFIELD" ->offset</CODE -> field -moved into union <CODE -CLASS="STRUCTFIELD" ->m</CODE ->, and a new -<CODE -CLASS="STRUCTFIELD" ->memory</CODE -> field of type enum <A -HREF="#V4L2-MEMORY" ->v4l2_memory</A -> was -added to distinguish between mapping methods. See <A -HREF="#IO" ->Chapter 3</A -> -for details.</P -><P ->The <CODE -CLASS="CONSTANT" ->V4L2_BUF_REQ_CONTIG</CODE -> -flag was used by the V4L compatibility layer, after changes to this -code it was no longer needed. The -<CODE -CLASS="CONSTANT" ->V4L2_BUF_ATTR_DEVICEMEM</CODE -> flag would indicate if -the buffer was indeed allocated in device memory rather than DMA-able -system memory. It was barely useful and so has been removed.</P -></LI -><LI -><P ->In struct <A -HREF="#V4L2-FRAMEBUFFER" ->v4l2_framebuffer</A -> the -<CODE -CLASS="STRUCTFIELD" ->base[3]</CODE -> array anticipating double- and -triple-buffering in off-screen video memory, however without defining - a synchronization mechanism, was replaced by a single - pointer. The <CODE -CLASS="CONSTANT" ->V4L2_FBUF_CAP_SCALEUP</CODE -> and - <CODE -CLASS="CONSTANT" ->V4L2_FBUF_CAP_SCALEDOWN</CODE -> flags were - removed. Applications can determine this capability more - accurately using the new cropping and scaling interface. The - <CODE -CLASS="CONSTANT" ->V4L2_FBUF_CAP_CLIPPING</CODE -> flag was - replaced by <CODE -CLASS="CONSTANT" ->V4L2_FBUF_CAP_LIST_CLIPPING</CODE -> - and <CODE -CLASS="CONSTANT" ->V4L2_FBUF_CAP_BITMAP_CLIPPING</CODE ->.</P -></LI -><LI -><P ->In struct <A -HREF="#V4L2-CLIP" ->v4l2_clip</A -> the <CODE -CLASS="STRUCTFIELD" ->x</CODE ->, -<CODE -CLASS="STRUCTFIELD" ->y</CODE ->, <CODE -CLASS="STRUCTFIELD" ->width</CODE -> and -<CODE -CLASS="STRUCTFIELD" ->height</CODE -> field moved into a -<CODE -CLASS="STRUCTFIELD" ->c</CODE -> substructure of type struct <A -HREF="#V4L2-RECT" ->v4l2_rect</A ->. The -<CODE -CLASS="STRUCTFIELD" ->x</CODE -> and <CODE -CLASS="STRUCTFIELD" ->y</CODE -> field -were renamed to <CODE -CLASS="STRUCTFIELD" ->left</CODE -> and -<CODE -CLASS="STRUCTFIELD" ->top</CODE ->, i. e. offsets to a context dependent -origin.</P -></LI -><LI -><P ->In struct <A -HREF="#V4L2-WINDOW" ->v4l2_window</A -> the <CODE -CLASS="STRUCTFIELD" ->x</CODE ->, -<CODE -CLASS="STRUCTFIELD" ->y</CODE ->, <CODE -CLASS="STRUCTFIELD" ->width</CODE -> and -<CODE -CLASS="STRUCTFIELD" ->height</CODE -> field moved into a -<CODE -CLASS="STRUCTFIELD" ->w</CODE -> substructure as above. A -<CODE -CLASS="STRUCTFIELD" ->field</CODE -> field of type %v4l2-field; was added -to distinguish between field and frame (interlaced) overlay.</P -></LI -><LI -><P ->The digital zoom interface, including struct -<CODE -CLASS="STRUCTNAME" ->v4l2_zoomcap</CODE ->, struct -<CODE -CLASS="STRUCTNAME" ->v4l2_zoom</CODE ->, -<CODE -CLASS="CONSTANT" ->V4L2_ZOOM_NONCAP</CODE -> and -<CODE -CLASS="CONSTANT" ->V4L2_ZOOM_WHILESTREAMING</CODE -> was replaced by a new -cropping and scaling interface. The previously unused struct -<CODE -CLASS="STRUCTNAME" ->v4l2_cropcap</CODE -> and -<CODE -CLASS="STRUCTNAME" ->v4l2_crop</CODE -> where redefined for this purpose. -See <A -HREF="#CROP" ->Section 1.10</A -> for details.</P -></LI -><LI -><P ->In struct <A -HREF="#V4L2-VBI-FORMAT" ->v4l2_vbi_format</A -> the -<CODE -CLASS="STRUCTFIELD" ->SAMPLE_FORMAT</CODE -> field now contains a -four-character-code as used to identify video image formats. -<CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_GREY</CODE -> replaces the -<CODE -CLASS="CONSTANT" ->V4L2_VBI_SF_UBYTE</CODE -> define. The -<CODE -CLASS="STRUCTFIELD" ->reserved</CODE -> field was extended.</P -></LI -><LI -><P ->In struct <A -HREF="#V4L2-CAPTUREPARM" ->v4l2_captureparm</A -> the type of the -<CODE -CLASS="STRUCTFIELD" ->timeperframe</CODE -> field changed from unsigned -long to struct <A -HREF="#V4L2-FRACT" ->v4l2_fract</A ->. A new field -<CODE -CLASS="STRUCTFIELD" ->readbuffers</CODE -> was added to control the driver -behaviour in read I/O mode.</P -><P ->According changes were made to -struct <A -HREF="#V4L2-OUTPUTPARM" ->v4l2_outputparm</A ->.</P -></LI -><LI -><P ->The struct <CODE -CLASS="STRUCTNAME" ->v4l2_performance</CODE -> -and <CODE -CLASS="CONSTANT" ->VIDIOC_G_PERF</CODE -> ioctl were dropped. Except when -using the <A -HREF="#RW" ->read/write I/O method</A ->, which is -limited anyway, this information is already available to the -application.</P -></LI -><LI -><P ->The example transformation from RGB to YCbCr color -space in the old V4L2 documentation was inaccurate, this has been -corrected in <A -HREF="#PIXFMT" ->Chapter 2</A ->.</P -></LI -></OL -></DIV -><DIV -CLASS="SECTION" -><HR><H3 -CLASS="SECTION" -><A -NAME="AEN11094" ->6.2.10. V4L2 2003-06-19</A -></H3 -><P -></P -><OL -TYPE="1" -><LI -><P ->A new capability flag -<CODE -CLASS="CONSTANT" ->V4L2_CAP_RADIO</CODE -> was added for radio devices. Prior -to this change radio devices would identify soley by having exactly one -tuner whose type field reads <CODE -CLASS="CONSTANT" ->V4L2_TUNER_RADIO</CODE ->.</P -></LI -><LI -><P ->An optional priority mechanism was added, see <A -HREF="#APP-PRI" ->Section 1.3</A -> for details.</P -></LI -><LI -><P ->The audio input and output interface was found to be -incomplete.</P -><P ->Previously the <CODE -CLASS="CONSTANT" ->VIDIOC_G_AUDIO</CODE -> -ioctl would enumerate the available audio inputs. An ioctl to -determine the current audio input, if more than one combines with the -current video input, did not exist. So -<CODE -CLASS="CONSTANT" ->VIDIOC_G_AUDIO</CODE -> was renamed to -<CODE -CLASS="CONSTANT" ->VIDIOC_G_AUDIO_OLD</CODE ->, this ioctl will be removed in -the future. The <A -HREF="#VIDIOC-ENUMAUDIO" -><CODE -CLASS="CONSTANT" ->VIDIOC_ENUMAUDIO</CODE -></A -> ioctl was added to enumerate -audio inputs, while <A -HREF="#VIDIOC-G-AUDIO" -><CODE -CLASS="CONSTANT" ->VIDIOC_G_AUDIO</CODE -></A -> now reports the current audio -input.</P -><P ->The same changes were made to <A -HREF="#VIDIOC-G-AUDIOOUT" -><CODE -CLASS="CONSTANT" ->VIDIOC_G_AUDOUT</CODE -></A -> and -<A -HREF="#VIDIOC-ENUMAUDIOOUT" -><CODE -CLASS="CONSTANT" ->VIDIOC_ENUMAUDOUT</CODE -></A ->.</P -><P ->Until further the "videodev" module will automatically -translate to the new versions, drivers and applications must be updated -when they are recompiled.</P -></LI -><LI -><P ->The <A -HREF="#VIDIOC-OVERLAY" -><CODE -CLASS="CONSTANT" ->VIDIOC_OVERLAY</CODE -></A -> ioctl was incorrectly defined with -read-write parameter. It was changed to write-only, while the read-write -version was renamed to <CODE -CLASS="CONSTANT" ->VIDIOC_OVERLAY_OLD</CODE ->. This -function will be removed in the future. Until further the "videodev" -module will automatically translate to the new version, so drivers -must be recompiled, but not applications.</P -></LI -><LI -><P -><A -HREF="#OVERLAY" ->Section 4.2</A -> incorrectly stated that -clipping rectangles define regions where the video can be seen. -Correct is that clipping rectangles define regions where -<SPAN -CLASS="emphasis" -><I -CLASS="EMPHASIS" ->no</I -></SPAN -> video shall be displayed and so the graphics -surface can be seen.</P -></LI -><LI -><P ->The <A -HREF="#VIDIOC-G-PARM" -><CODE -CLASS="CONSTANT" ->VIDIOC_S_PARM</CODE -></A -> and <A -HREF="#VIDIOC-G-CTRL" -><CODE -CLASS="CONSTANT" ->VIDIOC_S_CTRL</CODE -></A -> were defined -with write-only parameter, inconsistent with other ioctls modifying -their argument. They were changed to read-write, while a -<CODE -CLASS="CONSTANT" ->_OLD</CODE -> suffix was added to the write-only version. -These functions will be removed in the future. Drivers, and -applications assuming a constant parameter, need an update.</P -></LI -></OL -></DIV -><DIV -CLASS="SECTION" -><HR><H3 -CLASS="SECTION" -><A -NAME="AEN11136" ->6.2.11. V4L2 2003-11-05</A -></H3 -><P -></P -><OL -TYPE="1" -><LI -><P ->In <A -HREF="#PIXFMT-RGB" ->Section 2.3</A -> the following pixel -formats were incorrectly transferred from Bill Dirks' V4L2 -specification. Descriptions refer to bytes in memory, in ascending -address order.<DIV -CLASS="INFORMALTABLE" -><P -></P -><A -NAME="AEN11142" -></A -><TABLE -BORDER="1" -CLASS="CALSTABLE" -><COL><COL><COL><THEAD -><TR -><TH ->Symbol</TH -><TH ->In this document prior to revision 0.5</TH -><TH ->Correct</TH -></TR -></THEAD -><TBODY -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_RGB24</CODE -></TD -><TD ->B, G, R</TD -><TD ->R, G, B</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_BGR24</CODE -></TD -><TD ->R, G, B</TD -><TD ->B, G, R</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_RGB32</CODE -></TD -><TD ->B, G, R, X</TD -><TD ->R, G, B, X</TD -></TR -><TR -><TD -><CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_BGR32</CODE -></TD -><TD ->R, G, B, X</TD -><TD ->B, G, R, X</TD -></TR -></TBODY -></TABLE -><P -></P -></DIV -> The -<CODE -CLASS="CONSTANT" ->V4L2_PIX_FMT_BGR24</CODE -> example was always -correct.</P -><P ->In <A -HREF="#V4L-IMAGE-PROPERTIES" ->Section 6.1.5</A -> the mapping of -<CODE -CLASS="CONSTANT" ->VIDEO_PALETTE_RGB24</CODE -> and -<CODE -CLASS="CONSTANT" ->VIDEO_PALETTE_RGB32</CODE -> to V4L2 pixel formats was accordingly corrected.</P -></LI -><LI -><P ->Unrelated to the fixes above, drivers may still interpret some V4L2 RGB pixel formats differently. These issues have yet to be addressed, for details see <A -HREF="#PIXFMT-RGB" ->Section 2.3</A ->.</P -></LI -></OL -></DIV -><DIV -CLASS="SECTION" -><HR><H3 -CLASS="SECTION" -><A -NAME="AEN11178" ->6.2.12. V4L2 in Linux 2.6.6, 2004-05-09</A -></H3 -><P -></P -><OL -TYPE="1" -><LI -><P ->The <A -HREF="#VIDIOC-CROPCAP" -><CODE -CLASS="CONSTANT" ->VIDIOC_CROPCAP</CODE -></A -> ioctl was incorrectly defined with -read-only parameter. It was changed to read-write, while the read-only -version was renamed to <CODE -CLASS="CONSTANT" ->VIDIOC_CROPCAP_OLD</CODE ->. This -function will be removed in the future.</P -></LI -></OL -></DIV -><DIV -CLASS="SECTION" -><HR><H3 -CLASS="SECTION" -><A -NAME="AEN11186" ->6.2.13. V4L2 in Linux 2.6.8</A -></H3 -><P -></P -><OL -TYPE="1" -><LI -><P ->A new field <CODE -CLASS="STRUCTFIELD" ->input</CODE -> (former -<CODE -CLASS="STRUCTFIELD" ->reserved[0]</CODE ->) was added to the -struct <A -HREF="#V4L2-BUFFER" ->v4l2_buffer</A -> structure. It must be enabled with the new -<CODE -CLASS="CONSTANT" ->V4L2_BUF_FLAG_INPUT</CODE -> flag. The -<CODE -CLASS="STRUCTFIELD" ->flags</CODE -> field is no longer read-only.</P -></LI -></OL -></DIV -><DIV -CLASS="SECTION" -><HR><H3 -CLASS="SECTION" -><A -NAME="AEN11196" ->6.2.14. V4L2 spec erratum 2004-08-01</A -></H3 -><P -></P -><OL -TYPE="1" -><LI -><P ->The return value of the -<A -HREF="#FUNC-OPEN" ->open</A -> function was incorrect.</P -></LI -><LI -><P ->Audio output ioctls end in -AUDOUT, not -AUDIOOUT.</P -></LI -><LI -><P ->In the current audio input example the -<CODE -CLASS="CONSTANT" ->VIDIOC_G_AUDIO</CODE -> ioctl took the wrong -argument.</P -></LI -><LI -><P ->The <A -HREF="#VIDIOC-QBUF" -><CODE -CLASS="CONSTANT" ->VIDIOC_QBUF</CODE -></A -> and <A -HREF="#VIDIOC-QBUF" -><CODE -CLASS="CONSTANT" ->VIDIOC_DQBUF</CODE -></A -> ioctl did not -mention the struct <A -HREF="#V4L2-BUFFER" ->v4l2_buffer</A -> <CODE -CLASS="STRUCTFIELD" ->memory</CODE -> field, it -was also missing from examples. Added description of the -<CODE -CLASS="CONSTANT" ->VIDIOC_DQBUF</CODE -> <CODE -CLASS="CONSTANT" ->EIO</CODE -> error.</P -></LI -></OL -></DIV -></DIV -><DIV -CLASS="SECTION" -><HR><H2 -CLASS="SECTION" -><A -NAME="OTHER" ->6.3. Relation of V4L2 to other Linux multimedia APIs</A -></H2 -><DIV -CLASS="SECTION" -><H3 -CLASS="SECTION" -><A -NAME="XVIDEO" ->6.3.1. X Video Extension</A -></H3 -><P ->The X Video Extension (abbreviated XVideo or just Xv) is -an extension of the X Window system, implemented for example by the -XFree86 project. Its scope is similar to V4L2, an API to video capture -and output devices for X clients. Xv allows applications to display -live video in a window, send window contents to a TV output, and -capture or output still images in XPixmaps<A -NAME="AEN11222" -HREF="#FTN.AEN11222" -><SPAN -CLASS="footnote" ->[27]</SPAN -></A ->. With their implementation XFree86 makes the -extension available across many operating systems and -architectures.</P -><P ->Because the driver is embedded into the X server Xv has a -number of advantages over the V4L2 <A -HREF="#OVERLAY" ->video -overlay interface</A ->. The driver can easily determine the overlay -target, i. e. visible graphics memory or off-screen buffers for -non-destructive overlay. It can program the RAMDAC for overlay, -scaling or color-keying, or the clipping functions of the video -capture hardware, always in sync with drawing operations or windows -moving or changing their stacking order.</P -><P ->To combine the advantages of Xv and V4L a special Xv -driver exists in XFree86, just programming any overlay capable -Video4Linux device it finds. To enable it -<TT -CLASS="FILENAME" ->/etc/X11/XF86Config</TT -> must contain these lines:</P -><P -><PRE -CLASS="SCREEN" ->Section "Module" - Load "v4l" -EndSection</PRE -></P -><P ->As of XFree86 4.2 this driver still supports only V4L -ioctls, however it should work just fine with all V4L2 devices through -the V4L2 backward-compatibility layer. Since V4L2 permits multiple -opens it is possible (if supported by the V4L2 driver) to capture -video while an X client requested video overlay. Restrictions of -simultaneous capturing and overlay mentioned in <A -HREF="#OVERLAY" ->Section 4.2</A -> apply.</P -><P ->Only marginally related to V4L2, XFree86 extended Xv to -support hardware YUV to RGB conversion and scaling for faster video -playback, and added an interface to MPEG-2 decoding hardware. This -can be used to improve displaying captured images.</P -></DIV -><DIV -CLASS="SECTION" -><HR><H3 -CLASS="SECTION" -><A -NAME="AEN11233" ->6.3.2. Digital Video</A -></H3 -><P ->V4L2 does not, at this time and possibly never, support -digital terrestrial, cable or satellite broadcast. A separate project -aiming at digital receivers exists. You can find its homepage at -<A -HREF="http://linuxtv.org" -TARGET="_top" ->http://linuxtv.org</A ->. This group -found the requirements sufficiently different from analog television -to choose independent development of their interfaces.</P -></DIV -><DIV -CLASS="SECTION" -><HR><H3 -CLASS="SECTION" -><A -NAME="AEN11237" ->6.3.3. Audio Interfaces</A -></H3 -><P ->[to do - OSS/ALSA]</P -></DIV -></DIV -></DIV -><DIV -CLASS="APPENDIX" -><HR><H1 -><A -NAME="VIDEODEV" -></A ->Appendix A. Video For Linux Two Header File</H1 -><PRE -CLASS="PROGRAMLISTING" ->#ifndef __LINUX_VIDEODEV2_H -#define __LINUX_VIDEODEV2_H -/* - * Video for Linux Two - * - * Header file for v4l or V4L2 drivers and applications, for - * Linux kernels 2.2.x or 2.4.x. - * - * See http://bytesex.org/v4l/ for API specs and other - * v4l2 documentation. - * - * Author: Bill Dirks <bdirks@pacbell.net> - * Justin Schoeman - * et al. - */ -#ifdef __KERNEL__ -#include <linux/time.h> /* need struct timeval */ -#endif - -/* - * M I S C E L L A N E O U S - */ - -/* Four-character-code (FOURCC) */ -#define v4l2_fourcc(a,b,c,d)\ - (((__u32)(a)<<0)|((__u32)(b)<<8)|((__u32)(c)<<16)|((__u32)(d)<<24)) - -/* - * E N U M S - */ -enum <A -HREF="#V4L2-FIELD" ->v4l2_field</A -> { - V4L2_FIELD_ANY = 0, /* driver can choose from none, - top, bottom, interlaced - depending on whatever it thinks - is approximate ... */ - V4L2_FIELD_NONE = 1, /* this device has no fields ... */ - V4L2_FIELD_TOP = 2, /* top field only */ - V4L2_FIELD_BOTTOM = 3, /* bottom field only */ - V4L2_FIELD_INTERLACED = 4, /* both fields interlaced */ - V4L2_FIELD_SEQ_TB = 5, /* both fields sequential into one - buffer, top-bottom order */ - V4L2_FIELD_SEQ_BT = 6, /* same as above + bottom-top order */ - V4L2_FIELD_ALTERNATE = 7, /* both fields alternating into - separate buffers */ -}; -#define V4L2_FIELD_HAS_TOP(field) \ - ((field) == V4L2_FIELD_TOP ||\ - (field) == V4L2_FIELD_INTERLACED ||\ - (field) == V4L2_FIELD_SEQ_TB ||\ - (field) == V4L2_FIELD_SEQ_BT) -#define V4L2_FIELD_HAS_BOTTOM(field) \ - ((field) == V4L2_FIELD_BOTTOM ||\ - (field) == V4L2_FIELD_INTERLACED ||\ - (field) == V4L2_FIELD_SEQ_TB ||\ - (field) == V4L2_FIELD_SEQ_BT) -#define V4L2_FIELD_HAS_BOTH(field) \ - ((field) == V4L2_FIELD_INTERLACED ||\ - (field) == V4L2_FIELD_SEQ_TB ||\ - (field) == V4L2_FIELD_SEQ_BT) - -enum <A -HREF="#V4L2-BUF-TYPE" ->v4l2_buf_type</A -> { - V4L2_BUF_TYPE_VIDEO_CAPTURE = 1, - V4L2_BUF_TYPE_VIDEO_OUTPUT = 2, - V4L2_BUF_TYPE_VIDEO_OVERLAY = 3, - V4L2_BUF_TYPE_VBI_CAPTURE = 4, - V4L2_BUF_TYPE_VBI_OUTPUT = 5, - V4L2_BUF_TYPE_PRIVATE = 0x80, -}; - -enum <A -HREF="#V4L2-CTRL-TYPE" ->v4l2_ctrl_type</A -> { - V4L2_CTRL_TYPE_INTEGER = 1, - V4L2_CTRL_TYPE_BOOLEAN = 2, - V4L2_CTRL_TYPE_MENU = 3, - V4L2_CTRL_TYPE_BUTTON = 4, -}; - -enum <A -HREF="#V4L2-TUNER-TYPE" ->v4l2_tuner_type</A -> { - V4L2_TUNER_RADIO = 1, - V4L2_TUNER_ANALOG_TV = 2, -}; - -enum <A -HREF="#V4L2-MEMORY" ->v4l2_memory</A -> { - V4L2_MEMORY_MMAP = 1, - V4L2_MEMORY_USERPTR = 2, - V4L2_MEMORY_OVERLAY = 3, -}; - -/* see also http://vektor.theorem.ca/graphics/ycbcr/ */ -enum <A -HREF="#V4L2-COLORSPACE" ->v4l2_colorspace</A -> { - /* ITU-R 601 -- broadcast NTSC/PAL */ - V4L2_COLORSPACE_SMPTE170M = 1, - - /* 1125-Line (US) HDTV */ - V4L2_COLORSPACE_SMPTE240M = 2, - - /* HD and modern captures. */ - V4L2_COLORSPACE_REC709 = 3, - - /* broken BT878 extents (601, luma range 16-253 instead of 16-235) */ - V4L2_COLORSPACE_BT878 = 4, - - /* These should be useful. Assume 601 extents. */ - V4L2_COLORSPACE_470_SYSTEM_M = 5, - V4L2_COLORSPACE_470_SYSTEM_BG = 6, - - /* I know there will be cameras that send this. So, this is - * unspecified chromaticities and full 0-255 on each of the - * Y'CbCr components - */ - V4L2_COLORSPACE_JPEG = 7, - - /* For RGB colourspaces, this is probably a good start. */ - V4L2_COLORSPACE_SRGB = 8, -}; - -enum <A -HREF="#V4L2-PRIORITY" ->v4l2_priority</A -> { - V4L2_PRIORITY_UNSET = 0, /* not initialized */ - V4L2_PRIORITY_BACKGROUND = 1, - V4L2_PRIORITY_INTERACTIVE = 2, - V4L2_PRIORITY_RECORD = 3, - V4L2_PRIORITY_DEFAULT = V4L2_PRIORITY_INTERACTIVE, -}; - -struct <A -HREF="#V4L2-RECT" ->v4l2_rect</A -> { - __s32 left; - __s32 top; - __s32 width; - __s32 height; -}; - -struct <A -HREF="#V4L2-FRACT" ->v4l2_fract</A -> { - __u32 numerator; - __u32 denominator; -}; - -/* - * D R I V E R C A P A B I L I T I E S - */ -struct <A -HREF="#V4L2-CAPABILITY" ->v4l2_capability</A -> -{ - __u8 driver[16]; /* i.e. "bttv" */ - __u8 card[32]; /* i.e. "Hauppauge WinTV" */ - __u8 bus_info[32]; /* "PCI:" + pci_name(pci_dev) */ - __u32 version; /* should use KERNEL_VERSION() */ - __u32 capabilities; /* Device capabilities */ - __u32 reserved[4]; -}; - -/* Values for 'capabilities' field */ -#define V4L2_CAP_VIDEO_CAPTURE 0x00000001 /* Is a video capture device */ -#define V4L2_CAP_VIDEO_OUTPUT 0x00000002 /* Is a video output device */ -#define V4L2_CAP_VIDEO_OVERLAY 0x00000004 /* Can do video overlay */ -#define V4L2_CAP_VBI_CAPTURE 0x00000010 /* Is a VBI capture device */ -#define V4L2_CAP_VBI_OUTPUT 0x00000020 /* Is a VBI output device */ -#define V4L2_CAP_RDS_CAPTURE 0x00000100 /* RDS data capture */ - -#define V4L2_CAP_TUNER 0x00010000 /* has a tuner */ -#define V4L2_CAP_AUDIO 0x00020000 /* has audio support */ -#define V4L2_CAP_RADIO 0x00040000 /* is a radio device */ - -#define V4L2_CAP_READWRITE 0x01000000 /* read/write systemcalls */ -#define V4L2_CAP_ASYNCIO 0x02000000 /* async I/O */ -#define V4L2_CAP_STREAMING 0x04000000 /* streaming I/O ioctls */ - -/* - * V I D E O I M A G E F O R M A T - */ - -struct <A -HREF="#V4L2-PIX-FORMAT" ->v4l2_pix_format</A -> -{ - __u32 width; - __u32 height; - __u32 pixelformat; - enum <A -HREF="#V4L2-FIELD" ->v4l2_field</A -> field; - __u32 bytesperline; /* for padding, zero if unused */ - __u32 sizeimage; - enum <A -HREF="#V4L2-COLORSPACE" ->v4l2_colorspace</A -> colorspace; - __u32 priv; /* private data, depends on pixelformat */ -}; - -/* Pixel format FOURCC depth Description */ -#define V4L2_PIX_FMT_RGB332 v4l2_fourcc('R','G','B','1') /* 8 RGB-3-3-2 */ -#define V4L2_PIX_FMT_RGB555 v4l2_fourcc('R','G','B','O') /* 16 RGB-5-5-5 */ -#define V4L2_PIX_FMT_RGB565 v4l2_fourcc('R','G','B','P') /* 16 RGB-5-6-5 */ -#define V4L2_PIX_FMT_RGB555X v4l2_fourcc('R','G','B','Q') /* 16 RGB-5-5-5 BE */ -#define V4L2_PIX_FMT_RGB565X v4l2_fourcc('R','G','B','R') /* 16 RGB-5-6-5 BE */ -#define V4L2_PIX_FMT_BGR24 v4l2_fourcc('B','G','R','3') /* 24 BGR-8-8-8 */ -#define V4L2_PIX_FMT_RGB24 v4l2_fourcc('R','G','B','3') /* 24 RGB-8-8-8 */ -#define V4L2_PIX_FMT_BGR32 v4l2_fourcc('B','G','R','4') /* 32 BGR-8-8-8-8 */ -#define V4L2_PIX_FMT_RGB32 v4l2_fourcc('R','G','B','4') /* 32 RGB-8-8-8-8 */ -#define V4L2_PIX_FMT_GREY v4l2_fourcc('G','R','E','Y') /* 8 Greyscale */ -#define V4L2_PIX_FMT_YVU410 v4l2_fourcc('Y','V','U','9') /* 9 YVU 4:1:0 */ -#define V4L2_PIX_FMT_YVU420 v4l2_fourcc('Y','V','1','2') /* 12 YVU 4:2:0 */ -#define V4L2_PIX_FMT_YUYV v4l2_fourcc('Y','U','Y','V') /* 16 YUV 4:2:2 */ -#define V4L2_PIX_FMT_UYVY v4l2_fourcc('U','Y','V','Y') /* 16 YUV 4:2:2 */ -#define V4L2_PIX_FMT_YUV422P v4l2_fourcc('4','2','2','P') /* 16 YVU422 planar */ -#define V4L2_PIX_FMT_YUV411P v4l2_fourcc('4','1','1','P') /* 16 YVU411 planar */ -#define V4L2_PIX_FMT_Y41P v4l2_fourcc('Y','4','1','P') /* 12 YUV 4:1:1 */ - -/* two planes -- one Y, one Cr + Cb interleaved */ -#define V4L2_PIX_FMT_NV12 v4l2_fourcc('N','V','1','2') /* 12 Y/CbCr 4:2:0 */ -#define V4L2_PIX_FMT_NV21 v4l2_fourcc('N','V','2','1') /* 12 Y/CrCb 4:2:0 */ - -/* The following formats are not defined in the V4L2 specification */ -#define V4L2_PIX_FMT_YUV410 v4l2_fourcc('Y','U','V','9') /* 9 YUV 4:1:0 */ -#define V4L2_PIX_FMT_YUV420 v4l2_fourcc('Y','U','1','2') /* 12 YUV 4:2:0 */ -#define V4L2_PIX_FMT_YYUV v4l2_fourcc('Y','Y','U','V') /* 16 YUV 4:2:2 */ -#define V4L2_PIX_FMT_HI240 v4l2_fourcc('H','I','2','4') /* 8 8-bit color */ - -/* compressed formats */ -#define V4L2_PIX_FMT_MJPEG v4l2_fourcc('M','J','P','G') /* Motion-JPEG */ -#define V4L2_PIX_FMT_JPEG v4l2_fourcc('J','P','E','G') /* JFIF JPEG */ -#define V4L2_PIX_FMT_DV v4l2_fourcc('d','v','s','d') /* 1394 */ -#define V4L2_PIX_FMT_MPEG v4l2_fourcc('M','P','E','G') /* MPEG */ - -/* Vendor-specific formats */ -#define V4L2_PIX_FMT_WNVA v4l2_fourcc('W','N','V','A') /* Winnov hw compress */ - -/* - * F O R M A T E N U M E R A T I O N - */ -struct <A -HREF="#V4L2-FMTDESC" ->v4l2_fmtdesc</A -> -{ - __u32 index; /* Format number */ - enum <A -HREF="#V4L2-BUF-TYPE" ->v4l2_buf_type</A -> type; /* buffer type */ - __u32 flags; - __u8 description[32]; /* Description string */ - __u32 pixelformat; /* Format fourcc */ - __u32 reserved[4]; -}; - -#define V4L2_FMT_FLAG_COMPRESSED 0x0001 - - -/* - * T I M E C O D E - */ -struct <A -HREF="#V4L2-TIMECODE" ->v4l2_timecode</A -> -{ - __u32 type; - __u32 flags; - __u8 frames; - __u8 seconds; - __u8 minutes; - __u8 hours; - __u8 userbits[4]; -}; - -/* Type */ -#define V4L2_TC_TYPE_24FPS 1 -#define V4L2_TC_TYPE_25FPS 2 -#define V4L2_TC_TYPE_30FPS 3 -#define V4L2_TC_TYPE_50FPS 4 -#define V4L2_TC_TYPE_60FPS 5 - -/* Flags */ -#define V4L2_TC_FLAG_DROPFRAME 0x0001 /* "drop-frame" mode */ -#define V4L2_TC_FLAG_COLORFRAME 0x0002 -#define V4L2_TC_USERBITS_field 0x000C -#define V4L2_TC_USERBITS_USERDEFINED 0x0000 -#define V4L2_TC_USERBITS_8BITCHARS 0x0008 -/* The above is based on SMPTE timecodes */ - - -/* - * C O M P R E S S I O N P A R A M E T E R S - */ -#if 0 -/* ### generic compression settings don't work, there is too much - * ### codec-specific stuff. Maybe reuse that for MPEG codec settings - * ### later ... */ -struct <A -HREF="#V4L2-COMPRESSION" ->v4l2_compression</A -> -{ - __u32 quality; - __u32 keyframerate; - __u32 pframerate; - __u32 reserved[5]; - -/* what we'll need for MPEG, extracted from some postings on - the v4l list (Gert Vervoort, PlasmaJohn). - -system stream: - - type: elementary stream(ES), packatised elementary stream(s) (PES) - program stream(PS), transport stream(TS) - - system bitrate - - PS packet size (DVD: 2048 bytes, VCD: 2324 bytes) - - TS video PID - - TS audio PID - - TS PCR PID - - TS system information tables (PAT, PMT, CAT, NIT and SIT) - - (MPEG-1 systems stream vs. MPEG-2 program stream (TS not supported - by MPEG-1 systems) - -audio: - - type: MPEG (+Layer I,II,III), AC-3, LPCM - - bitrate - - sampling frequency (DVD: 48 Khz, VCD: 44.1 KHz, 32 kHz) - - Trick Modes? (ff, rew) - - Copyright - - Inverse Telecine - -video: - - picturesize (SIF, 1/2 D1, 2/3 D1, D1) and PAL/NTSC norm can be set - through excisting V4L2 controls - - noise reduction, parameters encoder specific? - - MPEG video version: MPEG-1, MPEG-2 - - GOP (Group Of Pictures) definition: - - N: number of frames per GOP - - M: distance between reference (I,P) frames - - open/closed GOP - - quantiser matrix: inter Q matrix (64 bytes) and intra Q matrix (64 bytes) - - quantiser scale: linear or logarithmic - - scanning: alternate or zigzag - - bitrate mode: CBR (constant bitrate) or VBR (variable bitrate). - - target video bitrate for CBR - - target video bitrate for VBR - - maximum video bitrate for VBR - min. quantiser value for VBR - - max. quantiser value for VBR - - adaptive quantisation value - - return the number of bytes per GOP or bitrate for bitrate monitoring - -*/ -}; -#endif - -struct <A -HREF="#V4L2-JPEGCOMPRESSION" ->v4l2_jpegcompression</A -> -{ - int quality; - - int APPn; /* Number of APP segment to be written, - * must be 0..15 */ - int APP_len; /* Length of data in JPEG APPn segment */ - char APP_data[60]; /* Data in the JPEG APPn segment. */ - - int COM_len; /* Length of data in JPEG COM segment */ - char COM_data[60]; /* Data in JPEG COM segment */ - - __u32 jpeg_markers; /* Which markers should go into the JPEG - * output. Unless you exactly know what - * you do, leave them untouched. - * Inluding less markers will make the - * resulting code smaller, but there will - * be fewer aplications which can read it. - * The presence of the APP and COM marker - * is influenced by APP_len and COM_len - * ONLY, not by this property! */ - -#define V4L2_JPEG_MARKER_DHT (1<<3) /* Define Huffman Tables */ -#define V4L2_JPEG_MARKER_DQT (1<<4) /* Define Quantization Tables */ -#define V4L2_JPEG_MARKER_DRI (1<<5) /* Define Restart Interval */ -#define V4L2_JPEG_MARKER_COM (1<<6) /* Comment segment */ -#define V4L2_JPEG_MARKER_APP (1<<7) /* App segment, driver will - * allways use APP0 */ -}; - - -/* - * M E M O R Y - M A P P I N G B U F F E R S - */ -struct <A -HREF="#V4L2-REQUESTBUFFERS" ->v4l2_requestbuffers</A -> -{ - __u32 count; - enum <A -HREF="#V4L2-BUF-TYPE" ->v4l2_buf_type</A -> type; - enum <A -HREF="#V4L2-MEMORY" ->v4l2_memory</A -> memory; - __u32 reserved[2]; -}; - -struct <A -HREF="#V4L2-BUFFER" ->v4l2_buffer</A -> -{ - __u32 index; - enum <A -HREF="#V4L2-BUF-TYPE" ->v4l2_buf_type</A -> type; - __u32 bytesused; - __u32 flags; - enum <A -HREF="#V4L2-FIELD" ->v4l2_field</A -> field; - struct timeval timestamp; - struct <A -HREF="#V4L2-TIMECODE" ->v4l2_timecode</A -> timecode; - __u32 sequence; - - /* memory location */ - enum <A -HREF="#V4L2-MEMORY" ->v4l2_memory</A -> memory; - union { - __u32 offset; - unsigned long userptr; - } m; - __u32 length; - __u32 input; - __u32 reserved; -}; - -/* Flags for 'flags' field */ -#define V4L2_BUF_FLAG_MAPPED 0x0001 /* Buffer is mapped (flag) */ -#define V4L2_BUF_FLAG_QUEUED 0x0002 /* Buffer is queued for processing */ -#define V4L2_BUF_FLAG_DONE 0x0004 /* Buffer is ready */ -#define V4L2_BUF_FLAG_KEYFRAME 0x0008 /* Image is a keyframe (I-frame) */ -#define V4L2_BUF_FLAG_PFRAME 0x0010 /* Image is a P-frame */ -#define V4L2_BUF_FLAG_BFRAME 0x0020 /* Image is a B-frame */ -#define V4L2_BUF_FLAG_TIMECODE 0x0100 /* timecode field is valid */ -#define V4L2_BUF_FLAG_INPUT 0x0200 /* input field is valid */ - -/* - * O V E R L A Y P R E V I E W - */ -struct <A -HREF="#V4L2-FRAMEBUFFER" ->v4l2_framebuffer</A -> -{ - __u32 capability; - __u32 flags; -/* FIXME: in theory we should pass something like PCI device + memory - * region + offset instead of some physical address */ - void* base; - struct <A -HREF="#V4L2-PIX-FORMAT" ->v4l2_pix_format</A -> fmt; -}; -/* Flags for the 'capability' field. Read only */ -#define V4L2_FBUF_CAP_EXTERNOVERLAY 0x0001 -#define V4L2_FBUF_CAP_CHROMAKEY 0x0002 -#define V4L2_FBUF_CAP_LIST_CLIPPING 0x0004 -#define V4L2_FBUF_CAP_BITMAP_CLIPPING 0x0008 -/* Flags for the 'flags' field. */ -#define V4L2_FBUF_FLAG_PRIMARY 0x0001 -#define V4L2_FBUF_FLAG_OVERLAY 0x0002 -#define V4L2_FBUF_FLAG_CHROMAKEY 0x0004 - -struct <A -HREF="#V4L2-CLIP" ->v4l2_clip</A -> -{ - struct <A -HREF="#V4L2-RECT" ->v4l2_rect</A -> c; - struct <A -HREF="#V4L2-CLIP" ->v4l2_clip</A -> *next; -}; - -struct <A -HREF="#V4L2-WINDOW" ->v4l2_window</A -> -{ - struct <A -HREF="#V4L2-RECT" ->v4l2_rect</A -> w; - enum <A -HREF="#V4L2-FIELD" ->v4l2_field</A -> field; - __u32 chromakey; - struct <A -HREF="#V4L2-CLIP" ->v4l2_clip</A -> *clips; - __u32 clipcount; - void *bitmap; -}; - - -/* - * C A P T U R E P A R A M E T E R S - */ -struct <A -HREF="#V4L2-CAPTUREPARM" ->v4l2_captureparm</A -> -{ - __u32 capability; /* Supported modes */ - __u32 capturemode; /* Current mode */ - struct <A -HREF="#V4L2-FRACT" ->v4l2_fract</A -> timeperframe; /* Time per frame in .1us units */ - __u32 extendedmode; /* Driver-specific extensions */ - __u32 readbuffers; /* # of buffers for read */ - __u32 reserved[4]; -}; -/* Flags for 'capability' and 'capturemode' fields */ -#define V4L2_MODE_HIGHQUALITY 0x0001 /* High quality imaging mode */ -#define V4L2_CAP_TIMEPERFRAME 0x1000 /* timeperframe field is supported */ - -struct <A -HREF="#V4L2-OUTPUTPARM" ->v4l2_outputparm</A -> -{ - __u32 capability; /* Supported modes */ - __u32 outputmode; /* Current mode */ - struct <A -HREF="#V4L2-FRACT" ->v4l2_fract</A -> timeperframe; /* Time per frame in seconds */ - __u32 extendedmode; /* Driver-specific extensions */ - __u32 writebuffers; /* # of buffers for write */ - __u32 reserved[4]; -}; - -/* - * I N P U T I M A G E C R O P P I N G - */ - -struct <A -HREF="#V4L2-CROPCAP" ->v4l2_cropcap</A -> { - enum <A -HREF="#V4L2-BUF-TYPE" ->v4l2_buf_type</A -> type; - struct <A -HREF="#V4L2-RECT" ->v4l2_rect</A -> bounds; - struct <A -HREF="#V4L2-RECT" ->v4l2_rect</A -> defrect; - struct <A -HREF="#V4L2-FRACT" ->v4l2_fract</A -> pixelaspect; -}; - -struct <A -HREF="#V4L2-CROP" ->v4l2_crop</A -> { - enum <A -HREF="#V4L2-BUF-TYPE" ->v4l2_buf_type</A -> type; - struct <A -HREF="#V4L2-RECT" ->v4l2_rect</A -> c; -}; - -/* - * A N A L O G V I D E O S T A N D A R D - */ - -typedef __u64 v4l2_std_id; - -/* one bit for each */ -#define V4L2_STD_PAL_B ((v4l2_std_id)0x00000001) -#define V4L2_STD_PAL_B1 ((v4l2_std_id)0x00000002) -#define V4L2_STD_PAL_G ((v4l2_std_id)0x00000004) -#define V4L2_STD_PAL_H ((v4l2_std_id)0x00000008) -#define V4L2_STD_PAL_I ((v4l2_std_id)0x00000010) -#define V4L2_STD_PAL_D ((v4l2_std_id)0x00000020) -#define V4L2_STD_PAL_D1 ((v4l2_std_id)0x00000040) -#define V4L2_STD_PAL_K ((v4l2_std_id)0x00000080) - -#define V4L2_STD_PAL_M ((v4l2_std_id)0x00000100) -#define V4L2_STD_PAL_N ((v4l2_std_id)0x00000200) -#define V4L2_STD_PAL_Nc ((v4l2_std_id)0x00000400) -#define V4L2_STD_PAL_60 ((v4l2_std_id)0x00000800) - -#define V4L2_STD_NTSC_M ((v4l2_std_id)0x00001000) -#define V4L2_STD_NTSC_M_JP ((v4l2_std_id)0x00002000) - -#define V4L2_STD_SECAM_B ((v4l2_std_id)0x00010000) -#define V4L2_STD_SECAM_D ((v4l2_std_id)0x00020000) -#define V4L2_STD_SECAM_G ((v4l2_std_id)0x00040000) -#define V4L2_STD_SECAM_H ((v4l2_std_id)0x00080000) -#define V4L2_STD_SECAM_K ((v4l2_std_id)0x00100000) -#define V4L2_STD_SECAM_K1 ((v4l2_std_id)0x00200000) -#define V4L2_STD_SECAM_L ((v4l2_std_id)0x00400000) - -/* ATSC/HDTV */ -#define V4L2_STD_ATSC_8_VSB ((v4l2_std_id)0x01000000) -#define V4L2_STD_ATSC_16_VSB ((v4l2_std_id)0x02000000) - -/* some common needed stuff */ -#define V4L2_STD_PAL_BG (V4L2_STD_PAL_B |\ - V4L2_STD_PAL_B1 |\ - V4L2_STD_PAL_G) -#define V4L2_STD_PAL_DK (V4L2_STD_PAL_D |\ - V4L2_STD_PAL_D1 |\ - V4L2_STD_PAL_K) -#define V4L2_STD_PAL (V4L2_STD_PAL_BG |\ - V4L2_STD_PAL_DK |\ - V4L2_STD_PAL_H |\ - V4L2_STD_PAL_I) -#define V4L2_STD_NTSC (V4L2_STD_NTSC_M |\ - V4L2_STD_NTSC_M_JP) -#define V4L2_STD_SECAM (V4L2_STD_SECAM_B |\ - V4L2_STD_SECAM_D |\ - V4L2_STD_SECAM_G |\ - V4L2_STD_SECAM_H |\ - V4L2_STD_SECAM_K |\ - V4L2_STD_SECAM_K1 |\ - V4L2_STD_SECAM_L) - -#define V4L2_STD_525_60 (V4L2_STD_PAL_M |\ - V4L2_STD_PAL_60 |\ - V4L2_STD_NTSC) -#define V4L2_STD_625_50 (V4L2_STD_PAL |\ - V4L2_STD_PAL_N |\ - V4L2_STD_PAL_Nc |\ - V4L2_STD_SECAM) - -#define V4L2_STD_UNKNOWN 0 -#define V4L2_STD_ALL (V4L2_STD_525_60 |\ - V4L2_STD_625_50) - -struct <A -HREF="#V4L2-STANDARD" ->v4l2_standard</A -> -{ - __u32 index; - v4l2_std_id id; - __u8 name[24]; - struct <A -HREF="#V4L2-FRACT" ->v4l2_fract</A -> frameperiod; /* Frames, not fields */ - __u32 framelines; - __u32 reserved[4]; -}; - - -/* - * V I D E O I N P U T S - */ -struct <A -HREF="#V4L2-INPUT" ->v4l2_input</A -> -{ - __u32 index; /* Which input */ - __u8 name[32]; /* Label */ - __u32 type; /* Type of input */ - __u32 audioset; /* Associated audios (bitfield) */ - __u32 tuner; /* Associated tuner */ - v4l2_std_id std; - __u32 status; - __u32 reserved[4]; -}; -/* Values for the 'type' field */ -#define V4L2_INPUT_TYPE_TUNER 1 -#define V4L2_INPUT_TYPE_CAMERA 2 - -/* field 'status' - general */ -#define V4L2_IN_ST_NO_POWER 0x00000001 /* Attached device is off */ -#define V4L2_IN_ST_NO_SIGNAL 0x00000002 -#define V4L2_IN_ST_NO_COLOR 0x00000004 - -/* field 'status' - analog */ -#define V4L2_IN_ST_NO_H_LOCK 0x00000100 /* No horizontal sync lock */ -#define V4L2_IN_ST_COLOR_KILL 0x00000200 /* Color killer is active */ - -/* field 'status' - digital */ -#define V4L2_IN_ST_NO_SYNC 0x00010000 /* No synchronization lock */ -#define V4L2_IN_ST_NO_EQU 0x00020000 /* No equalizer lock */ -#define V4L2_IN_ST_NO_CARRIER 0x00040000 /* Carrier recovery failed */ - -/* field 'status' - VCR and set-top box */ -#define V4L2_IN_ST_MACROVISION 0x01000000 /* Macrovision detected */ -#define V4L2_IN_ST_NO_ACCESS 0x02000000 /* Conditional access denied */ -#define V4L2_IN_ST_VTR 0x04000000 /* VTR time constant */ - -/* - * V I D E O O U T P U T S - */ -struct <A -HREF="#V4L2-OUTPUT" ->v4l2_output</A -> -{ - __u32 index; /* Which output */ - __u8 name[32]; /* Label */ - __u32 type; /* Type of output */ - __u32 audioset; /* Associated audios (bitfield) */ - __u32 modulator; /* Associated modulator */ - v4l2_std_id std; - __u32 reserved[4]; -}; -/* Values for the 'type' field */ -#define V4L2_OUTPUT_TYPE_MODULATOR 1 -#define V4L2_OUTPUT_TYPE_ANALOG 2 -#define V4L2_OUTPUT_TYPE_ANALOGVGAOVERLAY 3 - -/* - * C O N T R O L S - */ -struct <A -HREF="#V4L2-CONTROL" ->v4l2_control</A -> -{ - __u32 id; - __s32 value; -}; - -/* Used in the VIDIOC_QUERYCTRL ioctl for querying controls */ -struct <A -HREF="#V4L2-QUERYCTRL" ->v4l2_queryctrl</A -> -{ - __u32 id; - enum <A -HREF="#V4L2-CTRL-TYPE" ->v4l2_ctrl_type</A -> type; - __u8 name[32]; /* Whatever */ - __s32 minimum; /* Note signedness */ - __s32 maximum; - __s32 step; - __s32 default_value; - __u32 flags; - __u32 reserved[2]; -}; - -/* Used in the VIDIOC_QUERYMENU ioctl for querying menu items */ -struct <A -HREF="#V4L2-QUERYMENU" ->v4l2_querymenu</A -> -{ - __u32 id; - __u32 index; - __u8 name[32]; /* Whatever */ - __u32 reserved; -}; - -/* Control flags */ -#define V4L2_CTRL_FLAG_DISABLED 0x0001 -#define V4L2_CTRL_FLAG_GRABBED 0x0002 - -/* Control IDs defined by V4L2 */ -#define V4L2_CID_BASE 0x00980900 -/* IDs reserved for driver specific controls */ -#define V4L2_CID_PRIVATE_BASE 0x08000000 - -#define V4L2_CID_BRIGHTNESS (V4L2_CID_BASE+0) -#define V4L2_CID_CONTRAST (V4L2_CID_BASE+1) -#define V4L2_CID_SATURATION (V4L2_CID_BASE+2) -#define V4L2_CID_HUE (V4L2_CID_BASE+3) -#define V4L2_CID_AUDIO_VOLUME (V4L2_CID_BASE+5) -#define V4L2_CID_AUDIO_BALANCE (V4L2_CID_BASE+6) -#define V4L2_CID_AUDIO_BASS (V4L2_CID_BASE+7) -#define V4L2_CID_AUDIO_TREBLE (V4L2_CID_BASE+8) -#define V4L2_CID_AUDIO_MUTE (V4L2_CID_BASE+9) -#define V4L2_CID_AUDIO_LOUDNESS (V4L2_CID_BASE+10) -#define V4L2_CID_BLACK_LEVEL (V4L2_CID_BASE+11) -#define V4L2_CID_AUTO_WHITE_BALANCE (V4L2_CID_BASE+12) -#define V4L2_CID_DO_WHITE_BALANCE (V4L2_CID_BASE+13) -#define V4L2_CID_RED_BALANCE (V4L2_CID_BASE+14) -#define V4L2_CID_BLUE_BALANCE (V4L2_CID_BASE+15) -#define V4L2_CID_GAMMA (V4L2_CID_BASE+16) -#define V4L2_CID_WHITENESS (V4L2_CID_GAMMA) /* ? Not sure */ -#define V4L2_CID_EXPOSURE (V4L2_CID_BASE+17) -#define V4L2_CID_AUTOGAIN (V4L2_CID_BASE+18) -#define V4L2_CID_GAIN (V4L2_CID_BASE+19) -#define V4L2_CID_HFLIP (V4L2_CID_BASE+20) -#define V4L2_CID_VFLIP (V4L2_CID_BASE+21) -#define V4L2_CID_HCENTER (V4L2_CID_BASE+22) -#define V4L2_CID_VCENTER (V4L2_CID_BASE+23) -#define V4L2_CID_LASTP1 (V4L2_CID_BASE+24) /* last CID + 1 */ - -/* - * T U N I N G - */ -struct <A -HREF="#V4L2-TUNER" ->v4l2_tuner</A -> -{ - __u32 index; - __u8 name[32]; - enum <A -HREF="#V4L2-TUNER-TYPE" ->v4l2_tuner_type</A -> type; - __u32 capability; - __u32 rangelow; - __u32 rangehigh; - __u32 rxsubchans; - __u32 audmode; - __s32 signal; - __s32 afc; - __u32 reserved[4]; -}; - -struct <A -HREF="#V4L2-MODULATOR" ->v4l2_modulator</A -> -{ - __u32 index; - __u8 name[32]; - __u32 capability; - __u32 rangelow; - __u32 rangehigh; - __u32 txsubchans; - __u32 reserved[4]; -}; - -/* Flags for the 'capability' field */ -#define V4L2_TUNER_CAP_LOW 0x0001 -#define V4L2_TUNER_CAP_NORM 0x0002 -#define V4L2_TUNER_CAP_STEREO 0x0010 -#define V4L2_TUNER_CAP_LANG2 0x0020 -#define V4L2_TUNER_CAP_SAP 0x0020 -#define V4L2_TUNER_CAP_LANG1 0x0040 - -/* Flags for the 'rxsubchans' field */ -#define V4L2_TUNER_SUB_MONO 0x0001 -#define V4L2_TUNER_SUB_STEREO 0x0002 -#define V4L2_TUNER_SUB_LANG2 0x0004 -#define V4L2_TUNER_SUB_SAP 0x0004 -#define V4L2_TUNER_SUB_LANG1 0x0008 - -/* Values for the 'audmode' field */ -#define V4L2_TUNER_MODE_MONO 0x0000 -#define V4L2_TUNER_MODE_STEREO 0x0001 -#define V4L2_TUNER_MODE_LANG2 0x0002 -#define V4L2_TUNER_MODE_SAP 0x0002 -#define V4L2_TUNER_MODE_LANG1 0x0003 - -struct <A -HREF="#V4L2-FREQUENCY" ->v4l2_frequency</A -> -{ - __u32 tuner; - enum <A -HREF="#V4L2-TUNER-TYPE" ->v4l2_tuner_type</A -> type; - __u32 frequency; - __u32 reserved[8]; -}; - -/* - * A U D I O - */ -struct <A -HREF="#V4L2-AUDIO" ->v4l2_audio</A -> -{ - __u32 index; - __u8 name[32]; - __u32 capability; - __u32 mode; - __u32 reserved[2]; -}; -/* Flags for the 'capability' field */ -#define V4L2_AUDCAP_STEREO 0x00001 -#define V4L2_AUDCAP_AVL 0x00002 - -/* Flags for the 'mode' field */ -#define V4L2_AUDMODE_AVL 0x00001 - -struct <A -HREF="#V4L2-AUDIOOUT" ->v4l2_audioout</A -> -{ - __u32 index; - __u8 name[32]; - __u32 capability; - __u32 mode; - __u32 reserved[2]; -}; - -/* - * D A T A S E R V I C E S ( V B I ) - * - * Data services API by Michael Schimek - */ - -struct <A -HREF="#V4L2-VBI-FORMAT" ->v4l2_vbi_format</A -> -{ - __u32 sampling_rate; /* in 1 Hz */ - __u32 offset; - __u32 samples_per_line; - __u32 sample_format; /* V4L2_PIX_FMT_* */ - __s32 start[2]; - __u32 count[2]; - __u32 flags; /* V4L2_VBI_* */ - __u32 reserved[2]; /* must be zero */ -}; - -/* VBI flags */ -#define V4L2_VBI_UNSYNC (1<< 0) -#define V4L2_VBI_INTERLACED (1<< 1) - - -/* - * A G G R E G A T E S T R U C T U R E S - */ - -/* Stream data format - */ -struct <A -HREF="#V4L2-FORMAT" ->v4l2_format</A -> -{ - enum <A -HREF="#V4L2-BUF-TYPE" ->v4l2_buf_type</A -> type; - union - { - struct <A -HREF="#V4L2-PIX-FORMAT" ->v4l2_pix_format</A -> pix; // V4L2_BUF_TYPE_VIDEO_CAPTURE - struct <A -HREF="#V4L2-WINDOW" ->v4l2_window</A -> win; // V4L2_BUF_TYPE_VIDEO_OVERLAY - struct <A -HREF="#V4L2-VBI-FORMAT" ->v4l2_vbi_format</A -> vbi; // V4L2_BUF_TYPE_VBI_CAPTURE - __u8 raw_data[200]; // user-defined - } fmt; -}; - - -/* Stream type-dependent parameters - */ -struct <A -HREF="#V4L2-STREAMPARM" ->v4l2_streamparm</A -> -{ - enum <A -HREF="#V4L2-BUF-TYPE" ->v4l2_buf_type</A -> type; - union - { - struct <A -HREF="#V4L2-CAPTUREPARM" ->v4l2_captureparm</A -> capture; - struct <A -HREF="#V4L2-OUTPUTPARM" ->v4l2_outputparm</A -> output; - __u8 raw_data[200]; /* user-defined */ - } parm; -}; - - - -/* - * I O C T L C O D E S F O R V I D E O D E V I C E S - * - */ -#define VIDIOC_QUERYCAP _IOR ('V', 0, struct <A -HREF="#V4L2-CAPABILITY" ->v4l2_capability</A ->) -#define VIDIOC_RESERVED _IO ('V', 1) -#define VIDIOC_ENUM_FMT _IOWR ('V', 2, struct <A -HREF="#V4L2-FMTDESC" ->v4l2_fmtdesc</A ->) -#define VIDIOC_G_FMT _IOWR ('V', 4, struct <A -HREF="#V4L2-FORMAT" ->v4l2_format</A ->) -#define VIDIOC_S_FMT _IOWR ('V', 5, struct <A -HREF="#V4L2-FORMAT" ->v4l2_format</A ->) -#if 0 -#define VIDIOC_G_COMP _IOR ('V', 6, struct <A -HREF="#V4L2-COMPRESSION" ->v4l2_compression</A ->) -#define VIDIOC_S_COMP _IOW ('V', 7, struct <A -HREF="#V4L2-COMPRESSION" ->v4l2_compression</A ->) -#endif -#define VIDIOC_REQBUFS _IOWR ('V', 8, struct <A -HREF="#V4L2-REQUESTBUFFERS" ->v4l2_requestbuffers</A ->) -#define VIDIOC_QUERYBUF _IOWR ('V', 9, struct <A -HREF="#V4L2-BUFFER" ->v4l2_buffer</A ->) -#define VIDIOC_G_FBUF _IOR ('V', 10, struct <A -HREF="#V4L2-FRAMEBUFFER" ->v4l2_framebuffer</A ->) -#define VIDIOC_S_FBUF _IOW ('V', 11, struct <A -HREF="#V4L2-FRAMEBUFFER" ->v4l2_framebuffer</A ->) -#define VIDIOC_OVERLAY _IOW ('V', 14, int) -#define VIDIOC_QBUF _IOWR ('V', 15, struct <A -HREF="#V4L2-BUFFER" ->v4l2_buffer</A ->) -#define VIDIOC_DQBUF _IOWR ('V', 17, struct <A -HREF="#V4L2-BUFFER" ->v4l2_buffer</A ->) -#define VIDIOC_STREAMON _IOW ('V', 18, int) -#define VIDIOC_STREAMOFF _IOW ('V', 19, int) -#define VIDIOC_G_PARM _IOWR ('V', 21, struct <A -HREF="#V4L2-STREAMPARM" ->v4l2_streamparm</A ->) -#define VIDIOC_S_PARM _IOWR ('V', 22, struct <A -HREF="#V4L2-STREAMPARM" ->v4l2_streamparm</A ->) -#define VIDIOC_G_STD _IOR ('V', 23, v4l2_std_id) -#define VIDIOC_S_STD _IOW ('V', 24, v4l2_std_id) -#define VIDIOC_ENUMSTD _IOWR ('V', 25, struct <A -HREF="#V4L2-STANDARD" ->v4l2_standard</A ->) -#define VIDIOC_ENUMINPUT _IOWR ('V', 26, struct <A -HREF="#V4L2-INPUT" ->v4l2_input</A ->) -#define VIDIOC_G_CTRL _IOWR ('V', 27, struct <A -HREF="#V4L2-CONTROL" ->v4l2_control</A ->) -#define VIDIOC_S_CTRL _IOWR ('V', 28, struct <A -HREF="#V4L2-CONTROL" ->v4l2_control</A ->) -#define VIDIOC_G_TUNER _IOWR ('V', 29, struct <A -HREF="#V4L2-TUNER" ->v4l2_tuner</A ->) -#define VIDIOC_S_TUNER _IOW ('V', 30, struct <A -HREF="#V4L2-TUNER" ->v4l2_tuner</A ->) -#define VIDIOC_G_AUDIO _IOR ('V', 33, struct <A -HREF="#V4L2-AUDIO" ->v4l2_audio</A ->) -#define VIDIOC_S_AUDIO _IOW ('V', 34, struct <A -HREF="#V4L2-AUDIO" ->v4l2_audio</A ->) -#define VIDIOC_QUERYCTRL _IOWR ('V', 36, struct <A -HREF="#V4L2-QUERYCTRL" ->v4l2_queryctrl</A ->) -#define VIDIOC_QUERYMENU _IOWR ('V', 37, struct <A -HREF="#V4L2-QUERYMENU" ->v4l2_querymenu</A ->) -#define VIDIOC_G_INPUT _IOR ('V', 38, int) -#define VIDIOC_S_INPUT _IOWR ('V', 39, int) -#define VIDIOC_G_OUTPUT _IOR ('V', 46, int) -#define VIDIOC_S_OUTPUT _IOWR ('V', 47, int) -#define VIDIOC_ENUMOUTPUT _IOWR ('V', 48, struct <A -HREF="#V4L2-OUTPUT" ->v4l2_output</A ->) -#define VIDIOC_G_AUDOUT _IOR ('V', 49, struct <A -HREF="#V4L2-AUDIOOUT" ->v4l2_audioout</A ->) -#define VIDIOC_S_AUDOUT _IOW ('V', 50, struct <A -HREF="#V4L2-AUDIOOUT" ->v4l2_audioout</A ->) -#define VIDIOC_G_MODULATOR _IOWR ('V', 54, struct <A -HREF="#V4L2-MODULATOR" ->v4l2_modulator</A ->) -#define VIDIOC_S_MODULATOR _IOW ('V', 55, struct <A -HREF="#V4L2-MODULATOR" ->v4l2_modulator</A ->) -#define VIDIOC_G_FREQUENCY _IOWR ('V', 56, struct <A -HREF="#V4L2-FREQUENCY" ->v4l2_frequency</A ->) -#define VIDIOC_S_FREQUENCY _IOW ('V', 57, struct <A -HREF="#V4L2-FREQUENCY" ->v4l2_frequency</A ->) -#define VIDIOC_CROPCAP _IOWR ('V', 58, struct <A -HREF="#V4L2-CROPCAP" ->v4l2_cropcap</A ->) -#define VIDIOC_G_CROP _IOWR ('V', 59, struct <A -HREF="#V4L2-CROP" ->v4l2_crop</A ->) -#define VIDIOC_S_CROP _IOW ('V', 60, struct <A -HREF="#V4L2-CROP" ->v4l2_crop</A ->) -#define VIDIOC_G_JPEGCOMP _IOR ('V', 61, struct <A -HREF="#V4L2-JPEGCOMPRESSION" ->v4l2_jpegcompression</A ->) -#define VIDIOC_S_JPEGCOMP _IOW ('V', 62, struct <A -HREF="#V4L2-JPEGCOMPRESSION" ->v4l2_jpegcompression</A ->) -#define VIDIOC_QUERYSTD _IOR ('V', 63, v4l2_std_id) -#define VIDIOC_TRY_FMT _IOWR ('V', 64, struct <A -HREF="#V4L2-FORMAT" ->v4l2_format</A ->) -#define VIDIOC_ENUMAUDIO _IOWR ('V', 65, struct <A -HREF="#V4L2-AUDIO" ->v4l2_audio</A ->) -#define VIDIOC_ENUMAUDOUT _IOWR ('V', 66, struct <A -HREF="#V4L2-AUDIOOUT" ->v4l2_audioout</A ->) -#define VIDIOC_G_PRIORITY _IOR ('V', 67, enum <A -HREF="#V4L2-PRIORITY" ->v4l2_priority</A ->) -#define VIDIOC_S_PRIORITY _IOW ('V', 68, enum <A -HREF="#V4L2-PRIORITY" ->v4l2_priority</A ->) - -/* for compatibility, will go away some day */ -#define VIDIOC_OVERLAY_OLD _IOWR ('V', 14, int) -#define VIDIOC_S_PARM_OLD _IOW ('V', 22, struct <A -HREF="#V4L2-STREAMPARM" ->v4l2_streamparm</A ->) -#define VIDIOC_S_CTRL_OLD _IOW ('V', 28, struct <A -HREF="#V4L2-CONTROL" ->v4l2_control</A ->) -#define VIDIOC_G_AUDIO_OLD _IOWR ('V', 33, struct <A -HREF="#V4L2-AUDIO" ->v4l2_audio</A ->) -#define VIDIOC_G_AUDOUT_OLD _IOWR ('V', 49, struct <A -HREF="#V4L2-AUDIOOUT" ->v4l2_audioout</A ->) -#define VIDIOC_CROPCAP_OLD _IOR ('V', 58, struct <A -HREF="#V4L2-CROPCAP" ->v4l2_cropcap</A ->) - -#define BASE_VIDIOC_PRIVATE 192 /* 192-255 are private */ - - -#ifdef __KERNEL__ -/* - * - * V 4 L 2 D R I V E R H E L P E R A P I - * - * Some commonly needed functions for drivers (v4l2-common.o module) - */ -#include <linux/fs.h> - -/* Video standard functions */ -extern unsigned int v4l2_video_std_fps(struct <A -HREF="#V4L2-STANDARD" ->v4l2_standard</A -> *vs); -extern int v4l2_video_std_construct(struct <A -HREF="#V4L2-STANDARD" ->v4l2_standard</A -> *vs, - int id, char *name); - -/* prority handling */ -struct v4l2_prio_state { - atomic_t prios[4]; -}; -int v4l2_prio_init(struct v4l2_prio_state *global); -int v4l2_prio_change(struct v4l2_prio_state *global, enum <A -HREF="#V4L2-PRIORITY" ->v4l2_priority</A -> *local, - enum <A -HREF="#V4L2-PRIORITY" ->v4l2_priority</A -> new); -int v4l2_prio_open(struct v4l2_prio_state *global, enum <A -HREF="#V4L2-PRIORITY" ->v4l2_priority</A -> *local); -int v4l2_prio_close(struct v4l2_prio_state *global, enum <A -HREF="#V4L2-PRIORITY" ->v4l2_priority</A -> *local); -enum <A -HREF="#V4L2-PRIORITY" ->v4l2_priority</A -> v4l2_prio_max(struct v4l2_prio_state *global); -int v4l2_prio_check(struct v4l2_prio_state *global, enum <A -HREF="#V4L2-PRIORITY" ->v4l2_priority</A -> *local); - -/* names for fancy debug output */ -extern char *v4l2_field_names[]; -extern char *v4l2_type_names[]; -extern char *v4l2_ioctl_names[]; - -/* Compatibility layer interface -- v4l1-compat module */ -typedef int (*v4l2_kioctl)(struct inode *inode, struct file *file, - unsigned int cmd, void *arg); -int v4l_compat_translate_ioctl(struct inode *inode, struct file *file, - int cmd, void *arg, v4l2_kioctl driver_ioctl); - -#endif /* __KERNEL__ */ -#endif /* __LINUX_VIDEODEV2_H */ - -/* - * Local variables: - * c-basic-offset: 8 - * End: - */</PRE -></DIV -><DIV -CLASS="APPENDIX" -><HR><H1 -><A -NAME="CAPTURE-EXAMPLE" -></A ->Appendix B. Video Capture Example</H1 -><PRE -CLASS="PROGRAMLISTING" ->/* - * V4L2 video capture example - */ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <assert.h> - -#include <getopt.h> /* getopt_long() */ - -#include <fcntl.h> /* low-level i/o */ -#include <unistd.h> -#include <errno.h> -#include <sys/stat.h> -#include <sys/types.h> -#include <sys/time.h> -#include <sys/mman.h> -#include <sys/ioctl.h> - -#include <asm/types.h> /* for videodev2.h */ - -#include <linux/videodev2.h> - -#define CLEAR(x) memset (&(x), 0, sizeof (x)) - -typedef enum { - IO_METHOD_READ, - IO_METHOD_MMAP, - IO_METHOD_USERPTR, -} io_method; - -struct buffer { - void * start; - size_t length; -}; - -static char * dev_name = NULL; -static io_method io = IO_METHOD_MMAP; -static int fd = -1; -struct buffer * buffers = NULL; -static unsigned int n_buffers = 0; - -static void -errno_exit (const char * s) -{ - fprintf (stderr, "%s error %d, %s\n", - s, errno, strerror (errno)); - - exit (EXIT_FAILURE); -} - -static int -xioctl (int fd, - int request, - void * arg) -{ - int r; - - do r = ioctl (fd, request, arg); - while (-1 == r && EINTR == errno); - - return r; -} - -static void -process_image (const void * p) -{ - fputc ('.', stdout); - fflush (stdout); -} - -static int -read_frame (void) -{ - struct <A -HREF="#V4L2-BUFFER" ->v4l2_buffer</A -> buf; - unsigned int i; - - switch (io) { - case IO_METHOD_READ: - if (-1 == read (fd, buffers[0].start, buffers[0].length)) { - switch (errno) { - case EAGAIN: - return 0; - - case EIO: - /* Could ignore EIO, see spec. */ - - /* fall through */ - - default: - errno_exit ("read"); - } - } - - process_image (buffers[0].start); - - break; - - case IO_METHOD_MMAP: - CLEAR (buf); - - buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - buf.memory = V4L2_MEMORY_MMAP; - - if (-1 == xioctl (fd, VIDIOC_DQBUF, &buf)) { - switch (errno) { - case EAGAIN: - return 0; - - case EIO: - /* Could ignore EIO, see spec. */ - - /* fall through */ - - default: - errno_exit ("VIDIOC_DQBUF"); - } - } - - assert (buf.index < n_buffers); - - process_image (buffers[buf.index].start); - - if (-1 == xioctl (fd, VIDIOC_QBUF, &buf)) - errno_exit ("VIDIOC_QBUF"); - - break; - - case IO_METHOD_USERPTR: - CLEAR (buf); - - buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - buf.memory = V4L2_MEMORY_USERPTR; - - if (-1 == xioctl (fd, VIDIOC_DQBUF, &buf)) { - switch (errno) { - case EAGAIN: - return 0; - - case EIO: - /* Could ignore EIO, see spec. */ - - /* fall through */ - - default: - errno_exit ("VIDIOC_DQBUF"); - } - } - - for (i = 0; i < n_buffers; ++i) - if (buf.m.userptr == (unsigned long) buffers[i].start - && buf.length == buffers[i].length) - break; - - assert (i < n_buffers); - - process_image ((void *) buf.m.userptr); - - if (-1 == xioctl (fd, VIDIOC_QBUF, &buf)) - errno_exit ("VIDIOC_QBUF"); - - break; - } - - return 1; -} - -static void -mainloop (void) -{ - unsigned int count; - - count = 100; - - while (count-- > 0) { - for (;;) { - fd_set fds; - struct timeval tv; - int r; - - FD_ZERO (&fds); - FD_SET (fd, &fds); - - /* Timeout. */ - tv.tv_sec = 2; - tv.tv_usec = 0; - - r = select (fd + 1, &fds, NULL, NULL, &tv); - - if (-1 == r) { - if (EINTR == errno) - continue; - - errno_exit ("select"); - } - - if (0 == r) { - fprintf (stderr, "select timeout\n"); - exit (EXIT_FAILURE); - } - - if (read_frame ()) - break; - - /* EAGAIN - continue select loop. */ - } - } -} - -static void -stop_capturing (void) -{ - enum <A -HREF="#V4L2-BUF-TYPE" ->v4l2_buf_type</A -> type; - - switch (io) { - case IO_METHOD_READ: - /* Nothing to do. */ - break; - - case IO_METHOD_MMAP: - case IO_METHOD_USERPTR: - type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - - if (-1 == xioctl (fd, VIDIOC_STREAMOFF, &type)) - errno_exit ("VIDIOC_STREAMOFF"); - - break; - } -} - -static void -start_capturing (void) -{ - unsigned int i; - enum <A -HREF="#V4L2-BUF-TYPE" ->v4l2_buf_type</A -> type; - - switch (io) { - case IO_METHOD_READ: - /* Nothing to do. */ - break; - - case IO_METHOD_MMAP: - for (i = 0; i < n_buffers; ++i) { - struct <A -HREF="#V4L2-BUFFER" ->v4l2_buffer</A -> buf; - - CLEAR (buf); - - buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - buf.memory = V4L2_MEMORY_MMAP; - buf.index = i; - - if (-1 == xioctl (fd, VIDIOC_QBUF, &buf)) - errno_exit ("VIDIOC_QBUF"); - } - - type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - - if (-1 == xioctl (fd, VIDIOC_STREAMON, &type)) - errno_exit ("VIDIOC_STREAMON"); - - break; - - case IO_METHOD_USERPTR: - for (i = 0; i < n_buffers; ++i) { - struct <A -HREF="#V4L2-BUFFER" ->v4l2_buffer</A -> buf; - - CLEAR (buf); - - buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - buf.memory = V4L2_MEMORY_USERPTR; - buf.m.userptr = (unsigned long) buffers[i].start; - buf.length = buffers[i].length; - - if (-1 == xioctl (fd, VIDIOC_QBUF, &buf)) - errno_exit ("VIDIOC_QBUF"); - } - - - type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - - if (-1 == xioctl (fd, VIDIOC_STREAMON, &type)) - errno_exit ("VIDIOC_STREAMON"); - - break; - } -} - -static void -uninit_device (void) -{ - unsigned int i; - - switch (io) { - case IO_METHOD_READ: - free (buffers[0].start); - break; - - case IO_METHOD_MMAP: - for (i = 0; i < n_buffers; ++i) - if (-1 == munmap (buffers[i].start, buffers[i].length)) - errno_exit ("munmap"); - break; - - case IO_METHOD_USERPTR: - for (i = 0; i < n_buffers; ++i) - free (buffers[i].start); - break; - } - - free (buffers); -} - -static void -init_read (unsigned int buffer_size) -{ - buffers = calloc (1, sizeof (*buffers)); - - if (!buffers) { - fprintf (stderr, "Out of memory\n"); - exit (EXIT_FAILURE); - } - - buffers[0].length = buffer_size; - buffers[0].start = malloc (buffer_size); - - if (!buffers[0].start) { - fprintf (stderr, "Out of memory\n"); - exit (EXIT_FAILURE); - } -} - -static void -init_mmap (void) -{ - struct <A -HREF="#V4L2-REQUESTBUFFERS" ->v4l2_requestbuffers</A -> req; - - CLEAR (req); - - req.count = 4; - req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - req.memory = V4L2_MEMORY_MMAP; - - if (-1 == xioctl (fd, VIDIOC_REQBUFS, &req)) { - if (EINVAL == errno) { - fprintf (stderr, "%s does not support " - "memory mapping\n", dev_name); - exit (EXIT_FAILURE); - } else { - errno_exit ("VIDIOC_REQBUFS"); - } - } - - if (req.count < 2) { - fprintf (stderr, "Insufficient buffer memory on %s\n", - dev_name); - exit (EXIT_FAILURE); - } - - buffers = calloc (req.count, sizeof (*buffers)); - - if (!buffers) { - fprintf (stderr, "Out of memory\n"); - exit (EXIT_FAILURE); - } - - for (n_buffers = 0; n_buffers < req.count; ++n_buffers) { - struct <A -HREF="#V4L2-BUFFER" ->v4l2_buffer</A -> buf; - - CLEAR (buf); - - buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - buf.memory = V4L2_MEMORY_MMAP; - buf.index = n_buffers; - - if (-1 == xioctl (fd, VIDIOC_QUERYBUF, &buf)) - errno_exit ("VIDIOC_QUERYBUF"); - - buffers[n_buffers].length = buf.length; - buffers[n_buffers].start = - mmap (NULL /* start anywhere */, - buf.length, - PROT_READ | PROT_WRITE /* required */, - MAP_SHARED /* recommended */, - fd, buf.m.offset); - - if (MAP_FAILED == buffers[n_buffers].start) - errno_exit ("mmap"); - } -} - -static void -init_userp (unsigned int buffer_size) -{ - struct <A -HREF="#V4L2-REQUESTBUFFERS" ->v4l2_requestbuffers</A -> req; - - CLEAR (req); - - req.count = 4; - req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - req.memory = V4L2_MEMORY_USERPTR; - - if (-1 == xioctl (fd, VIDIOC_REQBUFS, &req)) { - if (EINVAL == errno) { - fprintf (stderr, "%s does not support " - "user pointer i/o\n", dev_name); - exit (EXIT_FAILURE); - } else { - errno_exit ("VIDIOC_REQBUFS"); - } - } - - buffers = calloc (4, sizeof (*buffers)); - - if (!buffers) { - fprintf (stderr, "Out of memory\n"); - exit (EXIT_FAILURE); - } - - for (n_buffers = 0; n_buffers < 4; ++n_buffers) { - buffers[n_buffers].length = buffer_size; - buffers[n_buffers].start = malloc (buffer_size); - - if (!buffers[n_buffers].start) { - fprintf (stderr, "Out of memory\n"); - exit (EXIT_FAILURE); - } - } -} - -static void -init_device (void) -{ - struct <A -HREF="#V4L2-CAPABILITY" ->v4l2_capability</A -> cap; - struct <A -HREF="#V4L2-CROPCAP" ->v4l2_cropcap</A -> cropcap; - struct <A -HREF="#V4L2-CROP" ->v4l2_crop</A -> crop; - struct <A -HREF="#V4L2-FORMAT" ->v4l2_format</A -> fmt; - unsigned int min; - - if (-1 == xioctl (fd, VIDIOC_QUERYCAP, &cap)) { - if (EINVAL == errno) { - fprintf (stderr, "%s is no V4L2 device\n", - dev_name); - exit (EXIT_FAILURE); - } else { - errno_exit ("VIDIOC_QUERYCAP"); - } - } - - if (!(cap.capabilities & V4L2_CAP_VIDEO_CAPTURE)) { - fprintf (stderr, "%s is no video capture device\n", - dev_name); - exit (EXIT_FAILURE); - } - - switch (io) { - case IO_METHOD_READ: - if (!(cap.capabilities & V4L2_CAP_READWRITE)) { - fprintf (stderr, "%s does not support read i/o\n", - dev_name); - exit (EXIT_FAILURE); - } - - break; - - case IO_METHOD_MMAP: - case IO_METHOD_USERPTR: - if (!(cap.capabilities & V4L2_CAP_STREAMING)) { - fprintf (stderr, "%s does not support streaming i/o\n", - dev_name); - exit (EXIT_FAILURE); - } - - break; - } - - /* Select video input, video standard and tune here. */ - - cropcap.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - - if (-1 == xioctl (fd, VIDIOC_CROPCAP, &cropcap)) { - /* Errors ignored. */ - } - - crop.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - crop.c = cropcap.defrect; /* reset to default */ - - if (-1 == xioctl (fd, VIDIOC_S_CROP, &crop)) { - switch (errno) { - case EINVAL: - /* Cropping not supported. */ - break; - default: - /* Errors ignored. */ - break; - } - } - - CLEAR (fmt); - - fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - fmt.fmt.pix.width = 640; - fmt.fmt.pix.height = 480; - fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV; - fmt.fmt.pix.field = V4L2_FIELD_INTERLACED; - - if (-1 == xioctl (fd, VIDIOC_S_FMT, &fmt)) - errno_exit ("VIDIOC_S_FMT"); - - /* Note VIDIOC_S_FMT may change width and height. */ - - /* Buggy driver paranoia. */ - min = fmt.fmt.pix.width * 2; - if (fmt.fmt.pix.bytesperline < min) - fmt.fmt.pix.bytesperline = min; - min = fmt.fmt.pix.bytesperline * fmt.fmt.pix.height; - if (fmt.fmt.pix.sizeimage < min) - fmt.fmt.pix.sizeimage = min; - - switch (io) { - case IO_METHOD_READ: - init_read (fmt.fmt.pix.sizeimage); - break; - - case IO_METHOD_MMAP: - init_mmap (); - break; - - case IO_METHOD_USERPTR: - init_userp (fmt.fmt.pix.sizeimage); - break; - } -} - -static void -close_device (void) -{ - if (-1 == close (fd)) - errno_exit ("close"); - - fd = -1; -} - -static void -open_device (void) -{ - struct stat st; - - if (-1 == stat (dev_name, &st)) { - fprintf (stderr, "Cannot identify '%s': %d, %s\n", - dev_name, errno, strerror (errno)); - exit (EXIT_FAILURE); - } - - if (!S_ISCHR (st.st_mode)) { - fprintf (stderr, "%s is no device\n", dev_name); - exit (EXIT_FAILURE); - } - - fd = open (dev_name, O_RDWR /* required */ | O_NONBLOCK, 0); - - if (-1 == fd) { - fprintf (stderr, "Cannot open '%s': %d, %s\n", - dev_name, errno, strerror (errno)); - exit (EXIT_FAILURE); - } -} - -static void -usage (FILE * fp, - int argc, - char ** argv) -{ - fprintf (fp, - "Usage: %s [options]\n\n" - "Options:\n" - "-d | --device name Video device name [/dev/video]\n" - "-h | --help Print this message\n" - "-m | --mmap Use memory mapped buffers\n" - "-r | --read Use read() calls\n" - "-u | --userp Use application allocated buffers\n" - "", - argv[0]); -} - -static const char short_options [] = "d:hmru"; - -static const struct option -long_options [] = { - { "device", required_argument, NULL, 'd' }, - { "help", no_argument, NULL, 'h' }, - { "mmap", no_argument, NULL, 'm' }, - { "read", no_argument, NULL, 'r' }, - { "userp", no_argument, NULL, 'u' }, - { 0, 0, 0, 0 } -}; - -int -main (int argc, - char ** argv) -{ - dev_name = "/dev/video"; - - for (;;) { - int index; - int c; - - c = getopt_long (argc, argv, - short_options, long_options, - &index); - - if (-1 == c) - break; - - switch (c) { - case 0: /* getopt_long() flag */ - break; - - case 'd': - dev_name = optarg; - break; - - case 'h': - usage (stdout, argc, argv); - exit (EXIT_SUCCESS); - - case 'm': - io = IO_METHOD_MMAP; - break; - - case 'r': - io = IO_METHOD_READ; - break; - - case 'u': - io = IO_METHOD_USERPTR; - break; - - default: - usage (stderr, argc, argv); - exit (EXIT_FAILURE); - } - } - - open_device (); - - init_device (); - - start_capturing (); - - mainloop (); - - stop_capturing (); - - uninit_device (); - - close_device (); - - exit (EXIT_SUCCESS); - - return 0; -}</PRE -></DIV -><DIV -CLASS="APPENDIX" -><HR><H1 -><A -NAME="FDL" -></A ->Appendix C. GNU Free Documentation License</H1 -><DIV -CLASS="SECT1" -><H2 -CLASS="SECT1" -><A -NAME="FDL-PREAMBLE" ->C.1. 0. PREAMBLE</A -></H2 -><P -> The purpose of this License is to make a manual, textbook, or - other written document <SPAN -CLASS="QUOTE" ->"free"</SPAN -> in the sense of - freedom: to assure everyone the effective freedom to copy and - redistribute it, with or without modifying it, either - commercially or noncommercially. Secondarily, this License - preserves for the author and publisher a way to get credit for - their work, while not being considered responsible for - modifications made by others. - </P -><P -> This License is a kind of <SPAN -CLASS="QUOTE" ->"copyleft"</SPAN ->, which means - that derivative works of the document must themselves be free in - the same sense. It complements the GNU General Public License, - which is a copyleft license designed for free software. - </P -><P -> We have designed this License in order to use it for manuals for - free software, because free software needs free documentation: a - free program should come with manuals providing the same - freedoms that the software does. But this License is not limited - to software manuals; it can be used for any textual work, - regardless of subject matter or whether it is published as a - printed book. We recommend this License principally for works - whose purpose is instruction or reference. - </P -></DIV -><DIV -CLASS="SECT1" -><HR><H2 -CLASS="SECT1" -><A -NAME="FDL-SECTION1" ->C.2. 1. APPLICABILITY AND DEFINITIONS</A -></H2 -><P -> This License applies to any manual or other work that contains a - notice placed by the copyright holder saying it can be - distributed under the terms of this License. The - <SPAN -CLASS="QUOTE" ->"Document"</SPAN ->, below, refers to any such manual or - work. Any member of the public is a licensee, and is addressed - as <SPAN -CLASS="QUOTE" ->"you"</SPAN ->. - </P -><P -> A <SPAN -CLASS="QUOTE" ->"Modified Version"</SPAN -> of the Document means any work - containing the Document or a portion of it, either copied - verbatim, or with modifications and/or translated into another - language. - </P -><P -> A <SPAN -CLASS="QUOTE" ->"Secondary Section"</SPAN -> is a named appendix or a - front-matter section of the <A -HREF="#FDL-DOCUMENT" ->Document</A -> that deals exclusively - with the relationship of the publishers or authors of the - Document to the Document's overall subject (or to related - matters) and contains nothing that could fall directly within - that overall subject. (For example, if the Document is in part a - textbook of mathematics, a Secondary Section may not explain any - mathematics.) The relationship could be a matter of historical - connection with the subject or with related matters, or of - legal, commercial, philosophical, ethical or political position - regarding them. - </P -><P -> The <SPAN -CLASS="QUOTE" ->"Invariant Sections"</SPAN -> are certain <A -HREF="#FDL-SECONDARY" -> Secondary Sections</A -> whose titles - are designated, as being those of Invariant Sections, in the - notice that says that the <A -HREF="#FDL-DOCUMENT" ->Document</A -> is released under this - License. - </P -><P -> The <SPAN -CLASS="QUOTE" ->"Cover Texts"</SPAN -> are certain short passages of - text that are listed, as Front-Cover Texts or Back-Cover Texts, - in the notice that says that the <A -HREF="#FDL-DOCUMENT" ->Document</A -> is released under this - License. - </P -><P -> A <SPAN -CLASS="QUOTE" ->"Transparent"</SPAN -> copy of the <A -HREF="#FDL-DOCUMENT" -> Document</A -> means a machine-readable - copy, represented in a format whose specification is available - to the general public, whose contents can be viewed and edited - directly and straightforwardly with generic text editors or (for - images composed of pixels) generic paint programs or (for - drawings) some widely available drawing editor, and that is - suitable for input to text formatters or for automatic - translation to a variety of formats suitable for input to text - formatters. A copy made in an otherwise Transparent file format - whose markup has been designed to thwart or discourage - subsequent modification by readers is not Transparent. A copy - that is not <SPAN -CLASS="QUOTE" ->"Transparent"</SPAN -> is called - <SPAN -CLASS="QUOTE" ->"Opaque"</SPAN ->. - </P -><P -> Examples of suitable formats for Transparent copies include - plain ASCII without markup, Texinfo input format, LaTeX input - format, SGML or XML using a publicly available DTD, and - standard-conforming simple HTML designed for human - modification. Opaque formats include PostScript, PDF, - proprietary formats that can be read and edited only by - proprietary word processors, SGML or XML for which the DTD - and/or processing tools are not generally available, and the - machine-generated HTML produced by some word processors for - output purposes only. - </P -><P -> The <SPAN -CLASS="QUOTE" ->"Title Page"</SPAN -> means, for a printed book, the - title page itself, plus such following pages as are needed to - hold, legibly, the material this License requires to appear in - the title page. For works in formats which do not have any title - page as such, <SPAN -CLASS="QUOTE" ->"Title Page"</SPAN -> means the text near the - most prominent appearance of the work's title, preceding the - beginning of the body of the text. - </P -></DIV -><DIV -CLASS="SECT1" -><HR><H2 -CLASS="SECT1" -><A -NAME="FDL-SECTION2" ->C.3. 2. VERBATIM COPYING</A -></H2 -><P -> You may copy and distribute the <A -HREF="#FDL-DOCUMENT" ->Document</A -> in any medium, either - commercially or noncommercially, provided that this License, the - copyright notices, and the license notice saying this License - applies to the Document are reproduced in all copies, and that - you add no other conditions whatsoever to those of this - License. You may not use technical measures to obstruct or - control the reading or further copying of the copies you make or - distribute. However, you may accept compensation in exchange for - copies. If you distribute a large enough number of copies you - must also follow the conditions in <A -HREF="#FDL-SECTION3" ->section 3</A ->. - </P -><P -> You may also lend copies, under the same conditions stated - above, and you may publicly display copies. - </P -></DIV -><DIV -CLASS="SECT1" -><HR><H2 -CLASS="SECT1" -><A -NAME="FDL-SECTION3" ->C.4. 3. COPYING IN QUANTITY</A -></H2 -><P -> If you publish printed copies of the <A -HREF="#FDL-DOCUMENT" ->Document</A -> numbering more than 100, - and the Document's license notice requires <A -HREF="#FDL-COVER-TEXTS" ->Cover Texts</A ->, you must enclose - the copies in covers that carry, clearly and legibly, all these - Cover Texts: Front-Cover Texts on the front cover, and - Back-Cover Texts on the back cover. Both covers must also - clearly and legibly identify you as the publisher of these - copies. The front cover must present the full title with all - words of the title equally prominent and visible. You may add - other material on the covers in addition. Copying with changes - limited to the covers, as long as they preserve the title of the - <A -HREF="#FDL-DOCUMENT" ->Document</A -> and satisfy these - conditions, can be treated as verbatim copying in other - respects. - </P -><P -> If the required texts for either cover are too voluminous to fit - legibly, you should put the first ones listed (as many as fit - reasonably) on the actual cover, and continue the rest onto - adjacent pages. - </P -><P -> If you publish or distribute <A -HREF="#FDL-TRANSPARENT" ->Opaque</A -> copies of the <A -HREF="#FDL-DOCUMENT" ->Document</A -> numbering more than 100, - you must either include a machine-readable <A -HREF="#FDL-TRANSPARENT" ->Transparent</A -> copy along with - each Opaque copy, or state in or with each Opaque copy a - publicly-accessible computer-network location containing a - complete Transparent copy of the Document, free of added - material, which the general network-using public has access to - download anonymously at no charge using public-standard network - protocols. If you use the latter option, you must take - reasonably prudent steps, when you begin distribution of Opaque - copies in quantity, to ensure that this Transparent copy will - remain thus accessible at the stated location until at least one - year after the last time you distribute an Opaque copy (directly - or through your agents or retailers) of that edition to the - public. - </P -><P -> It is requested, but not required, that you contact the authors - of the <A -HREF="#FDL-DOCUMENT" ->Document</A -> well before - redistributing any large number of copies, to give them a chance - to provide you with an updated version of the Document. - </P -></DIV -><DIV -CLASS="SECT1" -><HR><H2 -CLASS="SECT1" -><A -NAME="FDL-SECTION4" ->C.5. 4. MODIFICATIONS</A -></H2 -><P -> You may copy and distribute a <A -HREF="#FDL-MODIFIED" ->Modified Version</A -> of the <A -HREF="#FDL-DOCUMENT" ->Document</A -> under the conditions of - sections <A -HREF="#FDL-SECTION2" ->2</A -> and <A -HREF="#FDL-SECTION3" ->3</A -> above, provided that you release - the Modified Version under precisely this License, with the - Modified Version filling the role of the Document, thus - licensing distribution and modification of the Modified Version - to whoever possesses a copy of it. In addition, you must do - these things in the Modified Version: - </P -><P -></P -><UL -><LI -STYLE="list-style-type: opencircle" -><DIV -CLASS="FORMALPARA" -><P -><B ->A. </B -> Use in the <A -HREF="#FDL-TITLE-PAGE" ->Title - Page</A -> (and on the covers, if any) a title distinct - from that of the <A -HREF="#FDL-DOCUMENT" ->Document</A ->, and from those of - previous versions (which should, if there were any, be - listed in the History section of the Document). You may - use the same title as a previous version if the original - publisher of that version gives permission. - </P -></DIV -></LI -><LI -STYLE="list-style-type: opencircle" -><DIV -CLASS="FORMALPARA" -><P -><B ->B. </B -> List on the <A -HREF="#FDL-TITLE-PAGE" ->Title - Page</A ->, as authors, one or more persons or entities - responsible for authorship of the modifications in the - <A -HREF="#FDL-MODIFIED" ->Modified Version</A ->, - together with at least five of the principal authors of - the <A -HREF="#FDL-DOCUMENT" ->Document</A -> (all of - its principal authors, if it has less than five). - </P -></DIV -></LI -><LI -STYLE="list-style-type: opencircle" -><DIV -CLASS="FORMALPARA" -><P -><B ->C. </B -> State on the <A -HREF="#FDL-TITLE-PAGE" ->Title - Page</A -> the name of the publisher of the <A -HREF="#FDL-MODIFIED" ->Modified Version</A ->, as the - publisher. - </P -></DIV -></LI -><LI -STYLE="list-style-type: opencircle" -><DIV -CLASS="FORMALPARA" -><P -><B ->D. </B -> Preserve all the copyright notices of the <A -HREF="#FDL-DOCUMENT" ->Document</A ->. - </P -></DIV -></LI -><LI -STYLE="list-style-type: opencircle" -><DIV -CLASS="FORMALPARA" -><P -><B ->E. </B -> Add an appropriate copyright notice for your modifications - adjacent to the other copyright notices. - </P -></DIV -></LI -><LI -STYLE="list-style-type: opencircle" -><DIV -CLASS="FORMALPARA" -><P -><B ->F. </B -> Include, immediately after the copyright notices, a - license notice giving the public permission to use the - <A -HREF="#FDL-MODIFIED" ->Modified Version</A -> under - the terms of this License, in the form shown in the - Addendum below. - </P -></DIV -></LI -><LI -STYLE="list-style-type: opencircle" -><DIV -CLASS="FORMALPARA" -><P -><B ->G. </B -> Preserve in that license notice the full lists of <A -HREF="#FDL-INVARIANT" -> Invariant Sections</A -> and - required <A -HREF="#FDL-COVER-TEXTS" ->Cover - Texts</A -> given in the <A -HREF="#FDL-DOCUMENT" ->Document's</A -> license notice. - </P -></DIV -></LI -><LI -STYLE="list-style-type: opencircle" -><DIV -CLASS="FORMALPARA" -><P -><B ->H. </B -> Include an unaltered copy of this License. - </P -></DIV -></LI -><LI -STYLE="list-style-type: opencircle" -><DIV -CLASS="FORMALPARA" -><P -><B ->I. </B -> Preserve the section entitled <SPAN -CLASS="QUOTE" ->"History"</SPAN ->, and - its title, and add to it an item stating at least the - title, year, new authors, and publisher of the <A -HREF="#FDL-MODIFIED" ->Modified Version </A ->as given on - the <A -HREF="#FDL-TITLE-PAGE" ->Title Page</A ->. If - there is no section entitled <SPAN -CLASS="QUOTE" ->"History"</SPAN -> in the - <A -HREF="#FDL-DOCUMENT" ->Document</A ->, create one - stating the title, year, authors, and publisher of the - Document as given on its Title Page, then add an item - describing the Modified Version as stated in the previous - sentence. - </P -></DIV -></LI -><LI -STYLE="list-style-type: opencircle" -><DIV -CLASS="FORMALPARA" -><P -><B ->J. </B -> Preserve the network location, if any, given in the <A -HREF="#FDL-DOCUMENT" ->Document</A -> for public access - to a <A -HREF="#FDL-TRANSPARENT" ->Transparent</A -> - copy of the Document, and likewise the network locations - given in the Document for previous versions it was based - on. These may be placed in the <SPAN -CLASS="QUOTE" ->"History"</SPAN -> - section. You may omit a network location for a work that - was published at least four years before the Document - itself, or if the original publisher of the version it - refers to gives permission. - </P -></DIV -></LI -><LI -STYLE="list-style-type: opencircle" -><DIV -CLASS="FORMALPARA" -><P -><B ->K. </B -> In any section entitled <SPAN -CLASS="QUOTE" ->"Acknowledgements"</SPAN -> or - <SPAN -CLASS="QUOTE" ->"Dedications"</SPAN ->, preserve the section's title, - and preserve in the section all the substance and tone of - each of the contributor acknowledgements and/or - dedications given therein. - </P -></DIV -></LI -><LI -STYLE="list-style-type: opencircle" -><DIV -CLASS="FORMALPARA" -><P -><B ->L. </B -> Preserve all the <A -HREF="#FDL-INVARIANT" ->Invariant - Sections</A -> of the <A -HREF="#FDL-DOCUMENT" ->Document</A ->, unaltered in their - text and in their titles. Section numbers or the - equivalent are not considered part of the section titles. - </P -></DIV -></LI -><LI -STYLE="list-style-type: opencircle" -><DIV -CLASS="FORMALPARA" -><P -><B ->M. </B -> Delete any section entitled - <SPAN -CLASS="QUOTE" ->"Endorsements"</SPAN ->. Such a section may not be - included in the <A -HREF="#FDL-MODIFIED" ->Modified - Version</A ->. - </P -></DIV -></LI -><LI -STYLE="list-style-type: opencircle" -><DIV -CLASS="FORMALPARA" -><P -><B ->N. </B -> Do not retitle any existing section as - <SPAN -CLASS="QUOTE" ->"Endorsements"</SPAN -> or to conflict in title with - any <A -HREF="#FDL-INVARIANT" ->Invariant - Section</A ->. - </P -></DIV -></LI -></UL -><P -> If the <A -HREF="#FDL-MODIFIED" ->Modified Version</A -> - includes new front-matter sections or appendices that qualify as - <A -HREF="#FDL-SECONDARY" ->Secondary Sections</A -> and - contain no material copied from the Document, you may at your - option designate some or all of these sections as invariant. To - do this, add their titles to the list of <A -HREF="#FDL-INVARIANT" ->Invariant Sections</A -> in the - Modified Version's license notice. These titles must be - distinct from any other section titles. - </P -><P -> You may add a section entitled <SPAN -CLASS="QUOTE" ->"Endorsements"</SPAN ->, - provided it contains nothing but endorsements of your <A -HREF="#FDL-MODIFIED" ->Modified Version</A -> by various - parties--for example, statements of peer review or that the text - has been approved by an organization as the authoritative - definition of a standard. - </P -><P -> You may add a passage of up to five words as a <A -HREF="#FDL-COVER-TEXTS" ->Front-Cover Text</A ->, and a passage - of up to 25 words as a <A -HREF="#FDL-COVER-TEXTS" ->Back-Cover Text</A ->, to the end of - the list of <A -HREF="#FDL-COVER-TEXTS" ->Cover Texts</A -> - in the <A -HREF="#FDL-MODIFIED" ->Modified Version</A ->. - Only one passage of Front-Cover Text and one of Back-Cover Text - may be added by (or through arrangements made by) any one - entity. If the <A -HREF="#FDL-DOCUMENT" ->Document</A -> - already includes a cover text for the same cover, previously - added by you or by arrangement made by the same entity you are - acting on behalf of, you may not add another; but you may - replace the old one, on explicit permission from the previous - publisher that added the old one. - </P -><P -> The author(s) and publisher(s) of the <A -HREF="#FDL-DOCUMENT" ->Document</A -> do not by this License - give permission to use their names for publicity for or to - assert or imply endorsement of any <A -HREF="#FDL-MODIFIED" ->Modified Version </A ->. - </P -></DIV -><DIV -CLASS="SECT1" -><HR><H2 -CLASS="SECT1" -><A -NAME="FDL-SECTION5" ->C.6. 5. COMBINING DOCUMENTS</A -></H2 -><P -> You may combine the <A -HREF="#FDL-DOCUMENT" ->Document</A -> - with other documents released under this License, under the - terms defined in <A -HREF="#FDL-SECTION4" ->section 4</A -> - above for modified versions, provided that you include in the - combination all of the <A -HREF="#FDL-INVARIANT" ->Invariant - Sections</A -> of all of the original documents, unmodified, - and list them all as Invariant Sections of your combined work in - its license notice. - </P -><P -> The combined work need only contain one copy of this License, - and multiple identical <A -HREF="#FDL-INVARIANT" ->Invariant - Sections</A -> may be replaced with a single copy. If there are - multiple Invariant Sections with the same name but different - contents, make the title of each such section unique by adding - at the end of it, in parentheses, the name of the original - author or publisher of that section if known, or else a unique - number. Make the same adjustment to the section titles in the - list of Invariant Sections in the license notice of the combined - work. - </P -><P -> In the combination, you must combine any sections entitled - <SPAN -CLASS="QUOTE" ->"History"</SPAN -> in the various original documents, - forming one section entitled <SPAN -CLASS="QUOTE" ->"History"</SPAN ->; likewise - combine any sections entitled <SPAN -CLASS="QUOTE" ->"Acknowledgements"</SPAN ->, - and any sections entitled <SPAN -CLASS="QUOTE" ->"Dedications"</SPAN ->. You must - delete all sections entitled <SPAN -CLASS="QUOTE" ->"Endorsements."</SPAN -> - </P -></DIV -><DIV -CLASS="SECT1" -><HR><H2 -CLASS="SECT1" -><A -NAME="FDL-SECTION6" ->C.7. 6. COLLECTIONS OF DOCUMENTS</A -></H2 -><P -> You may make a collection consisting of the <A -HREF="#FDL-DOCUMENT" ->Document</A -> and other documents - released under this License, and replace the individual copies - of this License in the various documents with a single copy that - is included in the collection, provided that you follow the - rules of this License for verbatim copying of each of the - documents in all other respects. - </P -><P -> You may extract a single document from such a collection, and - dispbibute it individually under this License, provided you - insert a copy of this License into the extracted document, and - follow this License in all other respects regarding verbatim - copying of that document. - </P -></DIV -><DIV -CLASS="SECT1" -><HR><H2 -CLASS="SECT1" -><A -NAME="FDL-SECTION7" ->C.8. 7. AGGREGATION WITH INDEPENDENT WORKS</A -></H2 -><P -> A compilation of the <A -HREF="#FDL-DOCUMENT" ->Document</A -> or its derivatives with - other separate and independent documents or works, in or on a - volume of a storage or distribution medium, does not as a whole - count as a <A -HREF="#FDL-MODIFIED" ->Modified Version</A -> - of the Document, provided no compilation copyright is claimed - for the compilation. Such a compilation is called an - <SPAN -CLASS="QUOTE" ->"aggregate"</SPAN ->, and this License does not apply to the - other self-contained works thus compiled with the Document , on - account of their being thus compiled, if they are not themselves - derivative works of the Document. If the <A -HREF="#FDL-COVER-TEXTS" ->Cover Text</A -> requirement of <A -HREF="#FDL-SECTION3" ->section 3</A -> is applicable to these - copies of the Document, then if the Document is less than one - quarter of the entire aggregate, the Document's Cover Texts may - be placed on covers that surround only the Document within the - aggregate. Otherwise they must appear on covers around the whole - aggregate. - </P -></DIV -><DIV -CLASS="SECT1" -><HR><H2 -CLASS="SECT1" -><A -NAME="FDL-SECTION8" ->C.9. 8. TRANSLATION</A -></H2 -><P -> Translation is considered a kind of modification, so you may - distribute translations of the <A -HREF="#FDL-DOCUMENT" ->Document</A -> under the terms of <A -HREF="#FDL-SECTION4" ->section 4</A ->. Replacing <A -HREF="#FDL-INVARIANT" -> Invariant Sections</A -> with - translations requires special permission from their copyright - holders, but you may include translations of some or all - Invariant Sections in addition to the original versions of these - Invariant Sections. You may include a translation of this - License provided that you also include the original English - version of this License. In case of a disagreement between the - translation and the original English version of this License, - the original English version will prevail. - </P -></DIV -><DIV -CLASS="SECT1" -><HR><H2 -CLASS="SECT1" -><A -NAME="FDL-SECTION9" ->C.10. 9. TERMINATION</A -></H2 -><P -> You may not copy, modify, sublicense, or distribute the <A -HREF="#FDL-DOCUMENT" ->Document</A -> except as expressly - provided for under this License. Any other attempt to copy, - modify, sublicense or distribute the Document is void, and will - automatically terminate your rights under this License. However, - parties who have received copies, or rights, from you under this - License will not have their licenses terminated so long as such - parties remain in full compliance. - </P -></DIV -><DIV -CLASS="SECT1" -><HR><H2 -CLASS="SECT1" -><A -NAME="FDL-SECTION10" ->C.11. 10. FUTURE REVISIONS OF THIS LICENSE</A -></H2 -><P -> The <A -HREF="http://www.gnu.org/fsf/fsf.html" -TARGET="_top" ->Free Software - Foundation</A -> may publish new, revised versions of the GNU - Free Documentation License from time to time. Such new versions - will be similar in spirit to the present version, but may differ - in detail to address new problems or concerns. See <A -HREF="http://www.gnu.org/copyleft" -TARGET="_top" ->http://www.gnu.org/copyleft/</A ->. - </P -><P -> Each version of the License is given a distinguishing version - number. If the <A -HREF="#FDL-DOCUMENT" ->Document</A -> - specifies that a particular numbered version of this License - <SPAN -CLASS="QUOTE" ->"or any later version"</SPAN -> applies to it, you have the - option of following the terms and conditions either of that - specified version or of any later version that has been - published (not as a draft) by the Free Software Foundation. If - the Document does not specify a version number of this License, - you may choose any version ever published (not as a draft) by - the Free Software Foundation. - </P -></DIV -><DIV -CLASS="SECT1" -><HR><H2 -CLASS="SECT1" -><A -NAME="FDL-USING" ->C.12. Addendum</A -></H2 -><P -> To use this License in a document you have written, include a copy of - the License in the document and put the following copyright and - license notices just after the title page: - </P -><A -NAME="AEN11607" -></A -><BLOCKQUOTE -CLASS="BLOCKQUOTE" -><P -> Copyright © YEAR YOUR NAME. - </P -><P -> Permission is granted to copy, distribute and/or modify this - document under the terms of the GNU Free Documentation - License, Version 1.1 or any later version published by the - Free Software Foundation; with the <A -HREF="#FDL-INVARIANT" ->Invariant Sections</A -> being LIST - THEIR TITLES, with the <A -HREF="#FDL-COVER-TEXTS" ->Front-Cover Texts</A -> being LIST, - and with the <A -HREF="#FDL-COVER-TEXTS" ->Back-Cover - Texts</A -> being LIST. A copy of the license is included in - the section entitled <SPAN -CLASS="QUOTE" ->"GNU Free Documentation - License"</SPAN ->. - </P -></BLOCKQUOTE -><P -> If you have no <A -HREF="#FDL-INVARIANT" ->Invariant - Sections</A ->, write <SPAN -CLASS="QUOTE" ->"with no Invariant Sections"</SPAN -> - instead of saying which ones are invariant. If you have no - <A -HREF="#FDL-COVER-TEXTS" ->Front-Cover Texts</A ->, write - <SPAN -CLASS="QUOTE" ->"no Front-Cover Texts"</SPAN -> instead of - <SPAN -CLASS="QUOTE" ->"Front-Cover Texts being LIST"</SPAN ->; likewise for <A -HREF="#FDL-COVER-TEXTS" ->Back-Cover Texts</A ->. - </P -><P -> If your document contains nontrivial examples of program code, - we recommend releasing these examples in parallel under your - choice of free software license, such as the <A -HREF="http://www.gnu.org/copyleft/gpl.html" -TARGET="_top" -> GNU General Public - License</A ->, to permit their use in free software. - </P -></DIV -></DIV -><A -NAME="AEN11623" -></A -><HR><H1 -><A -NAME="AEN11623" -></A ->Bibliography</H1 -><DIV -CLASS="BIBLIOENTRY" -><A -NAME="EIA608" -></A -><P ->[EIA608] Electronic Industries Alliance (<A -HREF="http://www.eia.org" -TARGET="_top" ->http://www.eia.org</A ->), <I ->EIA 608 "Recommended Practice for Line 21 Data -Service"</I ->.</P -><DIV -CLASS="BIBLIOENTRYBLOCK" -STYLE="margin-left: 0.5in" -></DIV -></DIV -><DIV -CLASS="BIBLIOENTRY" -><A -NAME="ITU470" -></A -><P ->[ITU470] International Telecommunication Union (<A -HREF="http://www.itu.ch" -TARGET="_top" ->http://www.itu.ch</A ->), <I ->ITU-R Recommendation BT.470-6 "Conventional Television -Systems"</I ->.</P -><DIV -CLASS="BIBLIOENTRYBLOCK" -STYLE="margin-left: 0.5in" -></DIV -></DIV -><DIV -CLASS="BIBLIOENTRY" -><A -NAME="ITU601" -></A -><P ->[ITU601] International Telecommunication Union (<A -HREF="http://www.itu.ch" -TARGET="_top" ->http://www.itu.ch</A ->), <I ->ITU-R Recommendation BT.601-5 "Studio Encoding Parameters -of Digital Television for Standard 4:3 and Wide-Screen 16:9 Aspect -Ratios"</I ->.</P -><DIV -CLASS="BIBLIOENTRYBLOCK" -STYLE="margin-left: 0.5in" -></DIV -></DIV -><DIV -CLASS="BIBLIOENTRY" -><A -NAME="ITU709" -></A -><P ->[ITU709] International Telecommunication Union (<A -HREF="http://www.itu.ch" -TARGET="_top" ->http://www.itu.ch</A ->), <I ->ITU-R Recommendation BT.709-5 "Parameter values for the -HDTV standards for production and international programme -exchange"</I ->.</P -><DIV -CLASS="BIBLIOENTRYBLOCK" -STYLE="margin-left: 0.5in" -></DIV -></DIV -><DIV -CLASS="BIBLIOENTRY" -><A -NAME="JFIF" -></A -><P ->[JFIF] Independent JPEG Group (<A -HREF="http://www.ijg.org" -TARGET="_top" ->http://www.ijg.org</A ->), <I ->JPEG File Interchange Format</I -><I ->: </I -><I ->Version 1.02</I ->.</P -><DIV -CLASS="BIBLIOENTRYBLOCK" -STYLE="margin-left: 0.5in" -></DIV -></DIV -><DIV -CLASS="BIBLIOENTRY" -><A -NAME="SMPTE12M" -></A -><P ->[SMPTE12M] Society of Motion Picture and Television Engineers -(<A -HREF="http://www.smpte.org" -TARGET="_top" ->http://www.smpte.org</A ->), <I ->SMPTE 12M-1999 "Television, Audio and Film - Time and -Control Code"</I ->.</P -><DIV -CLASS="BIBLIOENTRYBLOCK" -STYLE="margin-left: 0.5in" -></DIV -></DIV -><DIV -CLASS="BIBLIOENTRY" -><A -NAME="SMPTE170M" -></A -><P ->[SMPTE170M] Society of Motion Picture and Television Engineers -(<A -HREF="http://www.smpte.org" -TARGET="_top" ->http://www.smpte.org</A ->), <I ->SMPTE 170M-1999 "Television - Composite Analog Video -Signal - NTSC for Studio Applications"</I ->.</P -><DIV -CLASS="BIBLIOENTRYBLOCK" -STYLE="margin-left: 0.5in" -></DIV -></DIV -><DIV -CLASS="BIBLIOENTRY" -><A -NAME="SMPTE240M" -></A -><P ->[SMPTE240M] Society of Motion Picture and Television Engineers -(<A -HREF="http://www.smpte.org" -TARGET="_top" ->http://www.smpte.org</A ->), <I ->SMPTE 240M-1999 "Television - Signal Parameters - -1125-Line High-Definition Production"</I ->.</P -><DIV -CLASS="BIBLIOENTRYBLOCK" -STYLE="margin-left: 0.5in" -></DIV -></DIV -><DIV -CLASS="BIBLIOENTRY" -><A -NAME="TELETEXT" -></A -><P ->[TELETEXT] European Telecommunication Standards Institute -(<A -HREF="http://www.etsi.org" -TARGET="_top" ->http://www.etsi.org</A ->), <I ->ETS 300 706 "Enhanced Teletext specification"</I ->.</P -><DIV -CLASS="BIBLIOENTRYBLOCK" -STYLE="margin-left: 0.5in" -></DIV -></DIV -><DIV -CLASS="BIBLIOENTRY" -><A -NAME="V4L" -></A -><P ->[V4L] <SPAN -CLASS="AUTHOR" ->Alan Cox</SPAN ->, <I ->Video4Linux API Specification</I ->.</P -><DIV -CLASS="BIBLIOENTRYBLOCK" -STYLE="margin-left: 0.5in" -><DIV -CLASS="ABSTRACT" -><P ->This file is part of the Linux kernel sources under -<TT -CLASS="FILENAME" ->Documentation/video4linux</TT ->.</P -></DIV -></DIV -></DIV -><DIV -CLASS="BIBLIOENTRY" -><A -NAME="V4LPROG" -></A -><P ->[V4LPROG] <SPAN -CLASS="AUTHOR" ->Alan Cox</SPAN ->, <I ->Video4Linux Programming (a.k.a. The Video4Linux -Book)</I ->, 2000.</P -><DIV -CLASS="BIBLIOENTRYBLOCK" -STYLE="margin-left: 0.5in" -><DIV -CLASS="ABSTRACT" -><P ->About V4L <SPAN -CLASS="emphasis" -><I -CLASS="EMPHASIS" ->driver</I -></SPAN -> programming. This -book is part of the Linux kernel DocBook documentation, for example at -<A -HREF="http://kernelnewbies.org/documents/" -TARGET="_top" ->http://kernelnewbies.org/documents/</A ->. SGML sources are included -in the kernel sources.</P -></DIV -></DIV -></DIV -><DIV -CLASS="BIBLIOENTRY" -><A -NAME="VPS" -></A -><P ->[VPS] European Telecommunication Standards Institute -(<A -HREF="http://www.etsi.org" -TARGET="_top" ->http://www.etsi.org</A ->), <I ->ETS 300 231 "Specification of the domestic video -Programme Delivery Control system (PDC)"</I ->.</P -><DIV -CLASS="BIBLIOENTRYBLOCK" -STYLE="margin-left: 0.5in" -></DIV -></DIV -><DIV -CLASS="BIBLIOENTRY" -><A -NAME="WSS" -></A -><P ->[WSS] International Telecommunication Union (<A -HREF="http://www.itu.ch" -TARGET="_top" ->http://www.itu.ch</A ->), European -Telecommunication Standards Institute (<A -HREF="http://www.etsi.org" -TARGET="_top" ->http://www.etsi.org</A ->), <I ->ITU-R Recommendation BT.1119, EN 300 294 "625-line -television Wide Screen Signalling (WSS)"</I ->.</P -><DIV -CLASS="BIBLIOENTRYBLOCK" -STYLE="margin-left: 0.5in" -></DIV -></DIV -></DIV -><H3 -CLASS="FOOTNOTES" ->Notes</H3 -><TABLE -BORDER="0" -CLASS="FOOTNOTES" -WIDTH="100%" -><TR -><TD -ALIGN="LEFT" -VALIGN="TOP" -WIDTH="5%" -><A -NAME="FTN.AEN104" -HREF="#AEN104" -><SPAN -CLASS="footnote" ->[1]</SPAN -></A -></TD -><TD -ALIGN="LEFT" -VALIGN="TOP" -WIDTH="95%" -><P ->Access permissions are associated with character -device special files, we must ensure device numbers cannot change with -load order. To this end minor numbers are no longer automatically assigned -by the "videodev" module as in V4L but requested by the driver. The defaults -will suffice for most people, unless two drivers are used which compete for -the same minor numbers.</P -></TD -></TR -><TR -><TD -ALIGN="LEFT" -VALIGN="TOP" -WIDTH="5%" -><A -NAME="FTN.AEN107" -HREF="#AEN107" -><SPAN -CLASS="footnote" ->[2]</SPAN -></A -></TD -><TD -ALIGN="LEFT" -VALIGN="TOP" -WIDTH="95%" -><P ->In earlier versions of the V4L2 API the module options -where named after the device special file with a "unit_" prefix, expressing -the minor number itself, not an offset. Rationale for this change is unknown. -Lastly the naming and semantics are just a convention among driver writers, -the point to note is that minor numbers are not supposed to be hardcoded -into drivers.</P -></TD -></TR -><TR -><TD -ALIGN="LEFT" -VALIGN="TOP" -WIDTH="5%" -><A -NAME="FTN.AEN135" -HREF="#AEN135" -><SPAN -CLASS="footnote" ->[3]</SPAN -></A -></TD -><TD -ALIGN="LEFT" -VALIGN="TOP" -WIDTH="95%" -><P ->Given a device file name one cannot reliable find -related devices. For once names are arbitrary, they can be chosen -freely by the system administrator. Also when there are multiple -devices and only some support VBI capturing, say, -<TT -CLASS="FILENAME" ->/dev/video2</TT -> is not necessarily related to -<TT -CLASS="FILENAME" ->/dev/vbi2</TT ->. We already noted finding devices by -name or minor number is unreliable, accordingly useful is the ioctl -offered by V4L to query the minor numbers of related devices.</P -></TD -></TR -><TR -><TD -ALIGN="LEFT" -VALIGN="TOP" -WIDTH="5%" -><A -NAME="FTN.AEN166" -HREF="#AEN166" -><SPAN -CLASS="footnote" ->[4]</SPAN -></A -></TD -><TD -ALIGN="LEFT" -VALIGN="TOP" -WIDTH="95%" -><P ->Drivers could recognize the -<CODE -CLASS="CONSTANT" ->O_EXCL</CODE -> open flag. Presently this is not required, -so application cannot know if it really works.</P -></TD -></TR -><TR -><TD -ALIGN="LEFT" -VALIGN="TOP" -WIDTH="5%" -><A -NAME="FTN.AEN245" -HREF="#AEN245" -><SPAN -CLASS="footnote" ->[5]</SPAN -></A -></TD -><TD -ALIGN="LEFT" -VALIGN="TOP" -WIDTH="95%" -><P ->Actually struct <A -HREF="#V4L2-AUDIO" ->v4l2_audio</A -> ought to have a -<CODE -CLASS="STRUCTFIELD" ->tuner</CODE -> field like struct <A -HREF="#V4L2-INPUT" ->v4l2_input</A ->, not only -making the API more consistent but also permitting radio devices with -multiple tuners.</P -></TD -></TR -><TR -><TD -ALIGN="LEFT" -VALIGN="TOP" -WIDTH="5%" -><A -NAME="FTN.AEN363" -HREF="#AEN363" -><SPAN -CLASS="footnote" ->[6]</SPAN -></A -></TD -><TD -ALIGN="LEFT" -VALIGN="TOP" -WIDTH="95%" -><P ->Some users are already confused by technical terms PAL, -NTSC and SECAM. There is no point asking them to distinguish between -B, G, D, or K when the software or hardware can do that -automatically.</P -></TD -></TR -><TR -><TD -ALIGN="LEFT" -VALIGN="TOP" -WIDTH="5%" -><A -NAME="FTN.AEN375" -HREF="#AEN375" -><SPAN -CLASS="footnote" ->[7]</SPAN -></A -></TD -><TD -ALIGN="LEFT" -VALIGN="TOP" -WIDTH="95%" -><P ->An alternative to the current scheme is to use pointers -to indices as arguments of <CODE -CLASS="CONSTANT" ->VIDIOC_G_STD</CODE -> and -<CODE -CLASS="CONSTANT" ->VIDIOC_S_STD</CODE ->, the struct <A -HREF="#V4L2-INPUT" ->v4l2_input</A -> and -struct <A -HREF="#V4L2-OUTPUT" ->v4l2_output</A -> <CODE -CLASS="STRUCTFIELD" ->std</CODE -> field would be a set of -indices like <CODE -CLASS="STRUCTFIELD" ->audioset</CODE ->.</P -><P ->Indices are consistent with the rest of the API -and identify the standard unambiguously. In the present scheme of -things an enumerated standard is looked up by <A -HREF="#V4L2-STD-ID" ->v4l2_std_id</A ->. Now the -standards supported by the inputs of a device can overlap. Just -assume the tuner and composite input in the example above both -exist on a device. An enumeration of "PAL-B/G", "PAL-H/I" suggests -a choice which does not exist. We cannot merge or omit sets, because -applications would be unable to find the standards reported by -<CODE -CLASS="CONSTANT" ->VIDIOC_G_STD</CODE ->. That leaves separate enumerations -for each input. Also selecting a standard by <A -HREF="#V4L2-STD-ID" ->v4l2_std_id</A -> can be -ambiguous. Advantage of this method is that applications need not -identify the standard indirectly, after enumerating.</P -><P ->So in -summary, the lookup itself is unavoidable. The difference is only -whether the lookup is necessary to find an enumerated standard or to -switch to a standard by <A -HREF="#V4L2-STD-ID" ->v4l2_std_id</A ->.</P -></TD -></TR -><TR -><TD -ALIGN="LEFT" -VALIGN="TOP" -WIDTH="5%" -><A -NAME="FTN.AEN407" -HREF="#AEN407" -><SPAN -CLASS="footnote" ->[8]</SPAN -></A -></TD -><TD -ALIGN="LEFT" -VALIGN="TOP" -WIDTH="95%" -><P ->See <A -HREF="#BUFFER" ->Section 3.5</A -> for a rationale. Probably -even USB cameras follow some well known video standard. It might have -been better to explicitly indicate elsewhere if a device cannot live -up to normal expectations, instead of this exception.</P -></TD -></TR -><TR -><TD -ALIGN="LEFT" -VALIGN="TOP" -WIDTH="5%" -><A -NAME="FTN.AEN451" -HREF="#AEN451" -><SPAN -CLASS="footnote" ->[9]</SPAN -></A -></TD -><TD -ALIGN="LEFT" -VALIGN="TOP" -WIDTH="95%" -><P ->It will be more convenient for applications if drivers -make use of the <CODE -CLASS="CONSTANT" ->V4L2_CTRL_FLAG_DISABLED</CODE -> flag, but -that was never required.</P -></TD -></TR -><TR -><TD -ALIGN="LEFT" -VALIGN="TOP" -WIDTH="5%" -><A -NAME="FTN.AEN454" -HREF="#AEN454" -><SPAN -CLASS="footnote" ->[10]</SPAN -></A -></TD -><TD -ALIGN="LEFT" -VALIGN="TOP" -WIDTH="95%" -><P ->Applications could call an ioctl to request events. -After another process called <A -HREF="#VIDIOC-G-CTRL" -><CODE -CLASS="CONSTANT" ->VIDIOC_S_CTRL</CODE -></A -> or another ioctl changing -shared properties the <CODE -CLASS="FUNCTION" ->select()</CODE -> function would -indicate readability until any ioctl (querying the properties) is -called.</P -></TD -></TR -><TR -><TD -ALIGN="LEFT" -VALIGN="TOP" -WIDTH="5%" -><A -NAME="FTN.AEN692" -HREF="#AEN692" -><SPAN -CLASS="footnote" ->[11]</SPAN -></A -></TD -><TD -ALIGN="LEFT" -VALIGN="TOP" -WIDTH="95%" -><P ->Enumerating formats an application has no a-priori -knowledge of (otherwise it could explicitely ask for them and need not -enumerate) seems useless, but there are applications serving as proxy -between drivers and the actual video applications for which this is -useful.</P -></TD -></TR -><TR -><TD -ALIGN="LEFT" -VALIGN="TOP" -WIDTH="5%" -><A -NAME="FTN.AEN714" -HREF="#AEN714" -><SPAN -CLASS="footnote" ->[12]</SPAN -></A -></TD -><TD -ALIGN="LEFT" -VALIGN="TOP" -WIDTH="95%" -><P ->It may be desirable to refer to the cropping area in -terms of sampling frequency and scanning system lines, but in order to -support a wide range of hardware we better make as few assumptions as -possible.</P -></TD -></TR -><TR -><TD -ALIGN="LEFT" -VALIGN="TOP" -WIDTH="5%" -><A -NAME="FTN.AEN3273" -HREF="#AEN3273" -><SPAN -CLASS="footnote" ->[13]</SPAN -></A -></TD -><TD -ALIGN="LEFT" -VALIGN="TOP" -WIDTH="95%" -><P ->It would be desirable if applications could depend on -drivers supporting all I/O interfaces, but as much as the complex -memory mapping I/O can be inadequate for some devices we have no -reason to require this interface, which is most useful for simple -applications capturing still images.</P -></TD -></TR -><TR -><TD -ALIGN="LEFT" -VALIGN="TOP" -WIDTH="5%" -><A -NAME="FTN.AEN3279" -HREF="#AEN3279" -><SPAN -CLASS="footnote" ->[14]</SPAN -></A -></TD -><TD -ALIGN="LEFT" -VALIGN="TOP" -WIDTH="95%" -><P ->At the driver level <CODE -CLASS="FUNCTION" ->select()</CODE -> and -<CODE -CLASS="FUNCTION" ->poll()</CODE -> are the same, and -<CODE -CLASS="FUNCTION" ->select()</CODE -> is too important to be optional.</P -></TD -></TR -><TR -><TD -ALIGN="LEFT" -VALIGN="TOP" -WIDTH="5%" -><A -NAME="FTN.AEN3296" -HREF="#AEN3296" -><SPAN -CLASS="footnote" ->[15]</SPAN -></A -></TD -><TD -ALIGN="LEFT" -VALIGN="TOP" -WIDTH="95%" -><P ->One could use one file descriptor and set the buffer -type field accordingly when calling <A -HREF="#VIDIOC-QBUF" -><CODE -CLASS="CONSTANT" ->VIDIOC_QBUF</CODE -></A -> etc., but it makes -the <CODE -CLASS="FUNCTION" ->select()</CODE -> function ambiguous. We also like the -clean approach of one file descriptor per logical stream. Video -overlay for example is also a logical stream, although the CPU is not -needed for continuous operation.</P -></TD -></TR -><TR -><TD -ALIGN="LEFT" -VALIGN="TOP" -WIDTH="5%" -><A -NAME="FTN.AEN3329" -HREF="#AEN3329" -><SPAN -CLASS="footnote" ->[16]</SPAN -></A -></TD -><TD -ALIGN="LEFT" -VALIGN="TOP" -WIDTH="95%" -><P ->Random enqueue order permits applications processing -images out of order (such as video codecs) to return buffers earlier, -reducing the probability of data loss. Random fill order allows -drivers to reuse buffers on a LIFO-basis, taking advantage of caches -holding scatter-gather lists and the like.</P -></TD -></TR -><TR -><TD -ALIGN="LEFT" -VALIGN="TOP" -WIDTH="5%" -><A -NAME="FTN.AEN3371" -HREF="#AEN3371" -><SPAN -CLASS="footnote" ->[17]</SPAN -></A -></TD -><TD -ALIGN="LEFT" -VALIGN="TOP" -WIDTH="95%" -><P ->At the driver level <CODE -CLASS="FUNCTION" ->select()</CODE -> and -<CODE -CLASS="FUNCTION" ->poll()</CODE -> are the same, and -<CODE -CLASS="FUNCTION" ->select()</CODE -> is too important to be optional. The -rest should be evident.</P -></TD -></TR -><TR -><TD -ALIGN="LEFT" -VALIGN="TOP" -WIDTH="5%" -><A -NAME="FTN.AEN3402" -HREF="#AEN3402" -><SPAN -CLASS="footnote" ->[18]</SPAN -></A -></TD -><TD -ALIGN="LEFT" -VALIGN="TOP" -WIDTH="95%" -><P ->We expect that frequently used buffers are typically not -swapped out. Anyway, the process of swapping, locking or generating -scatter-gather lists may be time consuming. The delay can be masked by -the depth of the incoming buffer queue, and perhaps by maintaining -caches assuming a buffer will be soon enqueued again. On the other -hand, to optimize memory usage drivers can limit the number of buffers -locked in advance and recycle the most recently used buffers first. Of -course, the pages of empty buffers in the incoming queue need not be -saved to disk. Output buffers must be saved on the incoming and -outgoing queue because an application may share them with other -processes.</P -></TD -></TR -><TR -><TD -ALIGN="LEFT" -VALIGN="TOP" -WIDTH="5%" -><A -NAME="FTN.AEN3438" -HREF="#AEN3438" -><SPAN -CLASS="footnote" ->[19]</SPAN -></A -></TD -><TD -ALIGN="LEFT" -VALIGN="TOP" -WIDTH="95%" -><P ->At the driver level <CODE -CLASS="FUNCTION" ->select()</CODE -> and -<CODE -CLASS="FUNCTION" ->poll()</CODE -> are the same, and -<CODE -CLASS="FUNCTION" ->select()</CODE -> is too important to be optional. The -rest should be evident.</P -></TD -></TR -><TR -><TD -ALIGN="LEFT" -VALIGN="TOP" -WIDTH="5%" -><A -NAME="FTN.AEN3460" -HREF="#AEN3460" -><SPAN -CLASS="footnote" ->[20]</SPAN -></A -></TD -><TD -ALIGN="LEFT" -VALIGN="TOP" -WIDTH="95%" -><P ->Since no other Linux multimedia -API supports unadjusted time it would be foolish to introduce here. We -must use a universally supported clock to synchronize different media, -hence time of day.</P -></TD -></TR -><TR -><TD -ALIGN="LEFT" -VALIGN="TOP" -WIDTH="5%" -><A -NAME="FTN.AEN4042" -HREF="#AEN4042" -><SPAN -CLASS="footnote" ->[21]</SPAN -></A -></TD -><TD -ALIGN="LEFT" -VALIGN="TOP" -WIDTH="95%" -><P ->A common application of two file descriptors is the -XFree86 <A -HREF="#XVIDEO" ->Xv/V4L</A -> interface driver and -a V4L2 application. While the X server controls video overlay, the -application can take advantage of memory mapping and DMA.</P -><P ->In the opinion of the designers of this API, no driver -writer taking the efforts to support simultaneous capturing and -overlay will restrict this ability by requiring a single file -descriptor, as in V4L and earlier versions of V4L2. Making this -optional means applications depending on two file descriptors need -backup routines to be compatible with all drivers, which is -considerable more work than using two fds in applications which do -not. Also two fd's fit the general concept of one file descriptor for -each logical stream. Hence as a complexity trade-off drivers -<SPAN -CLASS="emphasis" -><I -CLASS="EMPHASIS" ->must</I -></SPAN -> support two file descriptors and -<SPAN -CLASS="emphasis" -><I -CLASS="EMPHASIS" ->may</I -></SPAN -> support single fd operation.</P -></TD -></TR -><TR -><TD -ALIGN="LEFT" -VALIGN="TOP" -WIDTH="5%" -><A -NAME="FTN.AEN4216" -HREF="#AEN4216" -><SPAN -CLASS="footnote" ->[22]</SPAN -></A -></TD -><TD -ALIGN="LEFT" -VALIGN="TOP" -WIDTH="95%" -><P ->The X Window system defines "regions" which are -vectors of struct BoxRec { short x1, y1, x2, y2; } with width = x2 - -x1 and height = y2 - y1, so one cannot pass X11 clip lists -directly.</P -></TD -></TR -><TR -><TD -ALIGN="LEFT" -VALIGN="TOP" -WIDTH="5%" -><A -NAME="FTN.AEN4369" -HREF="#AEN4369" -><SPAN -CLASS="footnote" ->[23]</SPAN -></A -></TD -><TD -ALIGN="LEFT" -VALIGN="TOP" -WIDTH="95%" -><P ->ASK: Amplitude-Shift Keying. A high signal -level represents a '1' bit, a low level a '0' bit.</P -></TD -></TR -><TR -><TD -ALIGN="LEFT" -VALIGN="TOP" -WIDTH="5%" -><A -NAME="FTN.AEN5736" -HREF="#AEN5736" -><SPAN -CLASS="footnote" ->[24]</SPAN -></A -></TD -><TD -ALIGN="LEFT" -VALIGN="TOP" -WIDTH="95%" -><P ->The supported standards may overlap and we need an -unambiguous set to find the current standard returned by -<CODE -CLASS="CONSTANT" ->VIDIOC_G_STD</CODE ->.</P -></TD -></TR -><TR -><TD -ALIGN="LEFT" -VALIGN="TOP" -WIDTH="5%" -><A -NAME="FTN.AEN8815" -HREF="#AEN8815" -><SPAN -CLASS="footnote" ->[25]</SPAN -></A -></TD -><TD -ALIGN="LEFT" -VALIGN="TOP" -WIDTH="95%" -><P -><CODE -CLASS="CONSTANT" ->V4L2_CTRL_FLAG_DISABLED</CODE -> was intended -for two purposes: Drivers can skip predefined controls not supported -by the hardware (although returning EINVAL would do as well), or -disable predefined and custom controls after hardware detection -without the trouble of reordering control arrays and indices.</P -></TD -></TR -><TR -><TD -ALIGN="LEFT" -VALIGN="TOP" -WIDTH="5%" -><A -NAME="FTN.AEN9113" -HREF="#AEN9113" -><SPAN -CLASS="footnote" ->[26]</SPAN -></A -></TD -><TD -ALIGN="LEFT" -VALIGN="TOP" -WIDTH="95%" -><P ->For example video output requires at least two buffers, -one displayed and one filled by the application.</P -></TD -></TR -><TR -><TD -ALIGN="LEFT" -VALIGN="TOP" -WIDTH="5%" -><A -NAME="FTN.AEN11222" -HREF="#AEN11222" -><SPAN -CLASS="footnote" ->[27]</SPAN -></A -></TD -><TD -ALIGN="LEFT" -VALIGN="TOP" -WIDTH="95%" -><P ->This is not implemented in XFree86.</P -></TD -></TR -></TABLE -></BODY -></HTML ->
\ No newline at end of file diff --git a/v4l/scripts/make_kconfig.pl b/v4l/scripts/make_kconfig.pl index 57c663c00..cfe53a636 100755 --- a/v4l/scripts/make_kconfig.pl +++ b/v4l/scripts/make_kconfig.pl @@ -277,11 +277,13 @@ sub open_kconfig($$) { my $in_help = 0; my $default_seen = 0; my $if; + my $line; print "Opening $file\n" if $debug; open $in, '<', $file or die "File not found: $file"; push @kconfigfiles, $file; while (<$in>) { + $line = $_; # In our Kconfig files, the first non-help line after the # help text always has no indention. Technically, the # help text is ended by just by the indention decreasing, @@ -303,7 +305,7 @@ sub open_kconfig($$) { print OUT "\tdefault n\n"; } print OUT "\tdepends on VIDEO_KERNEL_VERSION\n"; - $_ = sprintf($disabled_msg, $minver{$key}); + $line = sprintf($disabled_msg, $minver{$key}); } next; } @@ -319,10 +321,13 @@ sub open_kconfig($$) { } next if (/^\s*#/ || /^\s*$/); # skip comments and blank lines + # Erase any comments on this line + s/(?<!\\)#(.*)$//; + if (m|^\s*source\s+"([^"]+)"\s*$| || m|^\s*source\s+(\S+)\s*$|) { open_kconfig($dir, "$dir/$1"); - $_ = ''; # don't print the source line itself + $line = ''; # don't print the source line itself next; } @@ -453,13 +458,13 @@ sub open_kconfig($$) { if ($disabled) { $default_seen = 1; - $_ = "\tdefault n\n"; + $line = "\tdefault n\n"; } } else { print "Skipping $file:$. $_" if $debug; } } continue { - print OUT $_; + print OUT $line; } close $in; } @@ -571,8 +576,8 @@ config VIDEO_KERNEL_VERSION requiring a newer kernel is that no one has tested them with an older one yet. - If the driver works, please post a report at V4L mailing list: - video4linux-list\@redhat.com. + If the driver works, please post a report to the V4L mailing list: + linux-media\@vger.kernel.org. Unless you know what you are doing, you should answer N. diff --git a/v4l/versions.txt b/v4l/versions.txt index b4869a157..eb206b520 100644 --- a/v4l/versions.txt +++ b/v4l/versions.txt @@ -45,6 +45,8 @@ USB_GSPCA_FINEPIX USB_SI470X # due to INIT_WORK changes USB_GSPCA_SQ905 +USB_GSPCA_SQ905C +VIDEO_HDPVR [2.6.19] #This driver were developed at kernel 2.6.19, requiring vmalloc_user/remap_vmalloc_range diff --git a/v4l2-apps/libv4l/ChangeLog b/v4l2-apps/libv4l/ChangeLog index dd53eced9..11f6ca2fd 100644 --- a/v4l2-apps/libv4l/ChangeLog +++ b/v4l2-apps/libv4l/ChangeLog @@ -1,3 +1,90 @@ +libv4l-0.5.9 +------------ +* Add support for MR97310A decompression by Kyle Guinn <elyk03@gmail.com> +* Add support for sq905c decompression by Theodore Kilgore + <kilgota@auburn.edu> +* Add hm12 support for the cx2341x MPEG encoder devices by Hans Verkuil + <hverkuil@xs4all.nl> + +libv4l-0.5.8 +------------ +* Add support for UYVY (for USB Apple iSight) patch by Julien BLACHE + <jb@jblache.org> +* Remove v4lconvert_yvyu_to_yuv420 function as its functionality is + duplicate with v4lconvert_yuyv_to_yuv420 +* Use Requires.private where appropiate in .pc files (patch by Gregor Jasny) +* Switch to using USB-id's instead of USB product string, as not all devices + set a unique product string. This fixes the upside down issues with + genius e-messenger 112 cams +* Add support for sn9c20x-i420 format patch by Vasily Khoruzhick + <anarsoul@gmail.com> + +libv4l-0.5.7 +------------ +* Fix a nasty (and stupid) bug in the special try_fmt handling for UVC cams +* Add some more verbose logging of various calls when asking libv4l to log + calls to a file, to assist in (future) debugging + +libv4l-0.5.6 +------------ +* Always do a s_fmt on uvc cams even if this changes nothing, as not doing + the s_fmt triggers a bug in the uvcvideo driver in kernel <= 2.6.28 + (with certain cams) + +libv4l-0.5.5 +------------ +* Avoid the use of try_fmt as much as possible on UVC cams, instead use the + results of the enum_framesizes ioctl. This is because: + 1) try_fmt actually causes IO with UVC cams making apps which do lot of + querrying of device capabilities slow (cheese) + 2) some buggy cams don't like getting lots of UVC video probes and crash + when they do + +libv4l-0.5.4 +------------ +* Don't report DQBUF errors when errno is EAGAIN, this fixes flooding the + screen with errors when applications use non blocking mode +* Add support for downscaling to make apps which want low resolutions + (skype, spcaview) happy when used with cams which can only do high + resolutions (by Lukáš Karas <lukas.karas@centrum.cz>). +* Add support for converting to YV12 planar (next to the already supported + YU12 / I420) +* Implement RGB/BGR24 -> YU/YV12 conversion + +libv4l-0.5.3 +------------ +* When conversion requires multiple passes don't alloc the needed temporary + buffer on the stack, as some apps (ekiga) use so much stack themselves + this causes us to run out of stack space + +libv4l-0.5.2 +------------ +* Add Philips SPC210NC to list of cams with upside down sensor, reported by + Rieker Flaik +* Work around some drivers (pwc) not properly reflecting what one gets after a + s_fmt in their try_fmt answer +* Check that s_fmt atleast gives us the width, height and pixelformat try_fmt + promised us, and if not disable conversion +* Only check width, height and pixelformat when checking if we are doing + conversion, instead of doing a memcmp, as that are the only things which + the convert code checks +* Take into account that the buffers only contain half of the lines when + field is V4L2_FIELD_ALTERNATE + +libv4l-0.5.1 +------------ +* Add support for software cropping from 352x288 -> 320x240 / 176x144 -> + 160x120, so that apps which will only work with vga resolutions like + 320x240 (Skype!) will work with cams/drivers which do not support cropping + CIF resolutions to VGA resolutions in hardware. This makes all 2.6.27 gspca + supported cams, except for the pac7302 which only does 640x480 (and skype + wants 320x240), work with skype +* The v4lconvert_convert function was becoming a bit of a mess, so split the + functionailiy into separate v4lconvert_convert_pixfmt, v4lconvert_rotate and + v4lconvert_crop functions, and make v4lconvert_convert a frontend to + these +* Do not link the wrapper libs against libpthread (patch from Gregor Jasny) + libv4l-0.5.0 ------------ * Add support for enumerating framesizes and frameintervals of emulated diff --git a/v4l2-apps/libv4l/Makefile b/v4l2-apps/libv4l/Makefile index 4c99c3167..703f3298f 100644 --- a/v4l2-apps/libv4l/Makefile +++ b/v4l2-apps/libv4l/Makefile @@ -1,16 +1,17 @@ LIB_RELEASE=0 -V4L2_LIB_VERSION=$(LIB_RELEASE).5.0 +V4L2_LIB_VERSION=$(LIB_RELEASE).5.9 -all clean install: +all install: + $(MAKE) -C libv4lconvert V4L2_LIB_VERSION=$(V4L2_LIB_VERSION) $@ + $(MAKE) -C libv4l2 V4L2_LIB_VERSION=$(V4L2_LIB_VERSION) $@ + $(MAKE) -C libv4l1 V4L2_LIB_VERSION=$(V4L2_LIB_VERSION) $@ + +clean: + rm -f *~ include/*~ $(MAKE) -C libv4lconvert V4L2_LIB_VERSION=$(V4L2_LIB_VERSION) $@ $(MAKE) -C libv4l2 V4L2_LIB_VERSION=$(V4L2_LIB_VERSION) $@ $(MAKE) -C libv4l1 V4L2_LIB_VERSION=$(V4L2_LIB_VERSION) $@ export: clean - mkdir /tmp/libv4l-$(V4L2_LIB_VERSION) - cp -a . /tmp/libv4l-$(V4L2_LIB_VERSION)/ - cd /tmp/ && \ - tar cvf /tmp/libv4l-$(V4L2_LIB_VERSION).tar\ - libv4l-$(V4L2_LIB_VERSION) - gzip /tmp/libv4l-$(V4L2_LIB_VERSION).tar - rm -rf /tmp/libv4l-$(V4L2_LIB_VERSION) + tar --transform s/^\./libv4l-$(V4L2_LIB_VERSION)/g -zcvf \ + /tmp/libv4l-$(V4L2_LIB_VERSION).tar.gz . diff --git a/v4l2-apps/libv4l/TODO b/v4l2-apps/libv4l/TODO index f3f9ff527..debb9c78c 100644 --- a/v4l2-apps/libv4l/TODO +++ b/v4l2-apps/libv4l/TODO @@ -7,6 +7,4 @@ impossible for overlays) can be done, so that it will no longer be necessary to implement CGMBUF in the kernel for each driver. --check v4l2_field during conversion - --add conversion from bgr24 to yuv420 +-take the possibility of pitch != width into account everywhere diff --git a/v4l2-apps/libv4l/libv4l1/Makefile b/v4l2-apps/libv4l/libv4l1/Makefile index 27848477e..9f30cbb0f 100644 --- a/v4l2-apps/libv4l/libv4l1/Makefile +++ b/v4l2-apps/libv4l/libv4l1/Makefile @@ -3,7 +3,7 @@ override CPPFLAGS += -I../include -I../../../include -fvisibility=hidden CFLAGS := -g -O1 CFLAGS += -Wall -Wno-unused -Wpointer-arith -Wstrict-prototypes -Wmissing-prototypes -LIBS = -lpthread +LIBS_libv4l1 = -lpthread V4L1_OBJS = libv4l1.o log.o V4L1COMPAT = v4l1compat.so @@ -46,7 +46,7 @@ libv4l1.pc: @echo 'Name: libv4l1' >> libv4l1.pc @echo 'Description: v4l1 compatibility library' >> libv4l1.pc @echo 'Version: '$(V4L2_LIB_VERSION) >> libv4l1.pc - @echo 'Requires: libv4l2' >> libv4l1.pc + @echo 'Requires.private: libv4l2' >> libv4l1.pc @echo 'Libs: -L$${libdir} -lv4l1' >> libv4l1.pc @echo 'Libs.private: -lpthread' >> libv4l1.pc @echo 'Cflags: -I$${prefix}/include' >> libv4l1.pc @@ -69,13 +69,13 @@ endif install -m 644 libv4l1.pc $(DESTDIR)$(LIBDIR)/pkgconfig clean:: - rm -f *.a *.so* *.o *.d libv4l1.pc log *~ + rm -f *.a *.so* *.o *.d libv4l1.pc log *~ *.orig *.rej %.o: %.c $(CC) -c -MMD $(CPPFLAGS) $(CFLAGS) -o $@ $< %.so: - $(CC) -shared $(LDFLAGS) -Wl,-soname,$@.$(LIB_RELEASE) -o $@.$(LIB_RELEASE) $^ $(LIBS) + $(CC) -shared $(LDFLAGS) -Wl,-soname,$@.$(LIB_RELEASE) -o $@.$(LIB_RELEASE) $^ $(LIBS_$*) ln -f -s $@.$(LIB_RELEASE) $@ %.a: diff --git a/v4l2-apps/libv4l/libv4l2/Makefile b/v4l2-apps/libv4l/libv4l2/Makefile index 648d27c0c..614b36cf8 100644 --- a/v4l2-apps/libv4l/libv4l2/Makefile +++ b/v4l2-apps/libv4l/libv4l2/Makefile @@ -3,7 +3,7 @@ override CPPFLAGS += -I../include -I../../../include -fvisibility=hidden CFLAGS := -g -O1 CFLAGS += -Wall -Wno-unused -Wpointer-arith -Wstrict-prototypes -Wmissing-prototypes -LIBS = -lpthread +LIBS_libv4l2 = -lpthread V4L2_OBJS = libv4l2.o log.o V4L2CONVERT = v4l2convert.so @@ -45,7 +45,7 @@ libv4l2.pc: @echo 'Name: libv4l2' >> libv4l2.pc @echo 'Description: v4l2 device access library' >> libv4l2.pc @echo 'Version: '$(V4L2_LIB_VERSION) >> libv4l2.pc - @echo 'Requires: libv4lconvert' >> libv4l2.pc + @echo 'Requires.private: libv4lconvert' >> libv4l2.pc @echo 'Libs: -L$${libdir} -lv4l2' >> libv4l2.pc @echo 'Libs.private: -lpthread' >> libv4l2.pc @echo 'Cflags: -I$${prefix}/include' >> libv4l2.pc @@ -68,13 +68,13 @@ endif install -m 644 libv4l2.pc $(DESTDIR)$(LIBDIR)/pkgconfig clean:: - rm -f *.a *.so* *.o *.d libv4l2.pc log *~ + rm -f *.a *.so* *.o *.d libv4l2.pc log *~ *.orig *.rej %.o: %.c $(CC) -c -MMD $(CPPFLAGS) $(CFLAGS) -o $@ $< %.so: - $(CC) -shared $(LDFLAGS) -Wl,-soname,$@.$(LIB_RELEASE) -o $@.$(LIB_RELEASE) $^ $(LIBS) + $(CC) -shared $(LDFLAGS) -Wl,-soname,$@.$(LIB_RELEASE) -o $@.$(LIB_RELEASE) $^ $(LIBS_$*) ln -f -s $@.$(LIB_RELEASE) $@ %.a: diff --git a/v4l2-apps/libv4l/libv4l2/libv4l2.c b/v4l2-apps/libv4l/libv4l2/libv4l2.c index b4a10afac..b6ddef6e8 100644 --- a/v4l2-apps/libv4l/libv4l2/libv4l2.c +++ b/v4l2-apps/libv4l/libv4l2/libv4l2.c @@ -76,6 +76,7 @@ #define V4L2_BUFFERS_REQUESTED_BY_READ 0x0200 #define V4L2_STREAM_CONTROLLED_BY_READ 0x0400 #define V4L2_SUPPORTS_READ 0x0800 +#define V4L2_IS_UVC 0x1000 #define V4L2_MMAP_OFFSET_MAGIC 0xABCDEF00u @@ -264,9 +265,11 @@ static int v4l2_dequeue_and_convert(int index, struct v4l2_buffer *buf, do { if ((result = syscall(SYS_ioctl, devices[index].fd, VIDIOC_DQBUF, buf))) { - int saved_err = errno; - V4L2_LOG_ERR("dequeuing buf: %s\n", strerror(errno)); - errno = saved_err; + if (errno != EAGAIN) { + int saved_err = errno; + V4L2_LOG_ERR("dequeuing buf: %s\n", strerror(errno)); + errno = saved_err; + } return result; } @@ -490,6 +493,8 @@ int v4l2_fd_open(int fd, int v4l2_flags) devices[index].flags = v4l2_flags; if (cap.capabilities & V4L2_CAP_READWRITE) devices[index].flags |= V4L2_SUPPORTS_READ; + if (!strcmp((char *)cap.driver, "uvcvideo")) + devices[index].flags |= V4L2_IS_UVC; devices[index].open_count = 1; devices[index].src_fmt = fmt; devices[index].dest_fmt = fmt; @@ -620,6 +625,36 @@ static int v4l2_check_buffer_change_ok(int index) return 0; } +static int v4l2_pix_fmt_identical(struct v4l2_format *a, struct v4l2_format *b) +{ + if (a->fmt.pix.width == b->fmt.pix.width && + a->fmt.pix.height == b->fmt.pix.height && + a->fmt.pix.pixelformat == b->fmt.pix.pixelformat && + a->fmt.pix.field == b->fmt.pix.field) + return 1; + + return 0; +} + +static void v4l2_set_src_and_dest_format(int index, + struct v4l2_format *src_fmt, struct v4l2_format *dest_fmt) +{ + /* Sigh some drivers (pwc) do not properly reflect what one really gets + after a s_fmt in their try_fmt answer. So update dest format (which we + report as result from s_fmt / g_fmt to the app) with all info from the src + format not changed by conversion */ + dest_fmt->fmt.pix.field = src_fmt->fmt.pix.field; + dest_fmt->fmt.pix.colorspace = src_fmt->fmt.pix.colorspace; + /* When we're not converting use bytesperline and imagesize from src_fmt */ + if (v4l2_pix_fmt_identical(src_fmt, dest_fmt)) { + dest_fmt->fmt.pix.bytesperline = src_fmt->fmt.pix.bytesperline; + dest_fmt->fmt.pix.sizeimage = src_fmt->fmt.pix.sizeimage; + } + + devices[index].src_fmt = *src_fmt; + devices[index].dest_fmt = *dest_fmt; +} + int v4l2_ioctl (int fd, unsigned long int request, ...) { void *arg; @@ -725,6 +760,9 @@ int v4l2_ioctl (int fd, unsigned long int request, ...) case VIDIOC_ENUM_FRAMEINTERVALS: result = v4lconvert_enum_frameintervals(devices[index].convert, arg); + if (result) + V4L2_LOG("ENUM_FRAMEINTERVALS Error: %s", + v4lconvert_get_error_message(devices[index].convert)); break; case VIDIOC_TRY_FMT: @@ -734,12 +772,27 @@ int v4l2_ioctl (int fd, unsigned long int request, ...) case VIDIOC_S_FMT: { struct v4l2_format src_fmt, *dest_fmt = arg; + struct v4l2_pix_format req_pix_fmt; - if (!memcmp(&devices[index].dest_fmt, dest_fmt, sizeof(*dest_fmt))) { + /* Don't be lazy on uvc cams, as this triggers a bug in the uvcvideo + driver in kernel <= 2.6.28 (with certain cams) */ + if (!(devices[index].flags & V4L2_IS_UVC) && + v4l2_pix_fmt_identical(&devices[index].dest_fmt, dest_fmt)) { + *dest_fmt = devices[index].dest_fmt; result = 0; break; } + if (v4l2_log_file) { + int pixfmt = dest_fmt->fmt.pix.pixelformat; + + fprintf(v4l2_log_file, "VIDIOC_S_FMT app requesting: %c%c%c%c\n", + pixfmt & 0xff, + (pixfmt >> 8) & 0xff, + (pixfmt >> 16) & 0xff, + pixfmt >> 24); + } + if (devices[index].flags & V4L2_DISABLE_CONVERSION) { result = syscall(SYS_ioctl, devices[index].fd, VIDIOC_TRY_FMT, dest_fmt); @@ -749,8 +802,12 @@ int v4l2_ioctl (int fd, unsigned long int request, ...) &src_fmt); } - if (result) + if (result) { + saved_err = errno; + V4L2_LOG("S_FMT error trying format: %s\n", strerror(errno)); + errno = saved_err; break; + } if (src_fmt.fmt.pix.pixelformat != dest_fmt->fmt.pix.pixelformat && v4l2_log_file) { @@ -765,8 +822,10 @@ int v4l2_ioctl (int fd, unsigned long int request, ...) /* Maybe after try format has adjusted width/height etc, to whats available nothing has changed (on the cam side) ? */ - if (!memcmp(&devices[index].src_fmt, &src_fmt, sizeof(src_fmt))) { - devices[index].dest_fmt = *dest_fmt; + if (!(devices[index].flags & V4L2_IS_UVC) && + v4l2_pix_fmt_identical(&devices[index].src_fmt, &src_fmt)) { + v4l2_set_src_and_dest_format(index, &devices[index].src_fmt, + dest_fmt); result = 0; break; } @@ -774,6 +833,7 @@ int v4l2_ioctl (int fd, unsigned long int request, ...) if ((result = v4l2_check_buffer_change_ok(index))) break; + req_pix_fmt = src_fmt.fmt.pix; result = syscall(SYS_ioctl, devices[index].fd, VIDIOC_S_FMT, &src_fmt); if (result) { saved_err = errno; @@ -783,9 +843,17 @@ int v4l2_ioctl (int fd, unsigned long int request, ...) errno = saved_err; break; } + /* See if we've gotten what try_fmt promised us + (this check should never fail) */ + if (src_fmt.fmt.pix.width != req_pix_fmt.width || + src_fmt.fmt.pix.height != req_pix_fmt.height || + src_fmt.fmt.pix.pixelformat != req_pix_fmt.pixelformat) { + V4L2_LOG_ERR("set_fmt gave us a different result then try_fmt!\n"); + /* Not what we expected / wanted, disable conversion */ + *dest_fmt = src_fmt; + } - devices[index].src_fmt = src_fmt; - devices[index].dest_fmt = *dest_fmt; + v4l2_set_src_and_dest_format(index, &src_fmt, dest_fmt); } break; @@ -884,7 +952,7 @@ int v4l2_ioctl (int fd, unsigned long int request, ...) but we need the buffer _now_ to write our converted data to it! */ if (devices[index].convert_mmap_buf == MAP_FAILED) { - devices[index].convert_mmap_buf = (void *)syscall(SYS_mmap2, + devices[index].convert_mmap_buf = (void *)syscall(SYS_mmap2, NULL, (size_t)( devices[index].no_frames * V4L2_FRAME_BUF_SIZE), diff --git a/v4l2-apps/libv4l/libv4l2/log.c b/v4l2-apps/libv4l/libv4l2/log.c index 6237d55ec..c29086ff4 100644 --- a/v4l2-apps/libv4l/libv4l2/log.c +++ b/v4l2-apps/libv4l/libv4l2/log.c @@ -18,6 +18,8 @@ #include <stdio.h> #include <stdlib.h> +#include <string.h> +#include <errno.h> #include <linux/ioctl.h> /* These headers are not needed by us, but by linux/videodev2.h, which is broken on some systems and doesn't include them itself :( */ @@ -89,12 +91,17 @@ static const char *v4l2_ioctls[] = { [_IOC_NR(VIDIOC_G_EXT_CTRLS)] = "VIDIOC_G_EXT_CTRLS", [_IOC_NR(VIDIOC_S_EXT_CTRLS)] = "VIDIOC_S_EXT_CTRLS", [_IOC_NR(VIDIOC_TRY_EXT_CTRLS)] = "VIDIOC_TRY_EXT_CTRLS", +#ifdef VIDIOC_ENUM_FRAMESIZES + [_IOC_NR(VIDIOC_ENUM_FRAMESIZES)] = "VIDIOC_ENUM_FRAMESIZES", + [_IOC_NR(VIDIOC_ENUM_FRAMEINTERVALS)] = "VIDIOC_ENUM_FRAMEINTERVALS", +#endif }; void v4l2_log_ioctl(unsigned long int request, void *arg, int result) { const char *ioctl_str; char buf[40]; + int saved_errno = errno; if (!v4l2_log_file) return; @@ -102,7 +109,7 @@ void v4l2_log_ioctl(unsigned long int request, void *arg, int result) if (_IOC_TYPE(request) == 'V' && _IOC_NR(request) < ARRAY_SIZE(v4l2_ioctls)) ioctl_str = v4l2_ioctls[_IOC_NR(request)]; else { - snprintf(buf, sizeof(buf), "unknown request: %c %d\n", + snprintf(buf, sizeof(buf), "unknown request: %c %d", (int)_IOC_TYPE(request), (int)_IOC_NR(request)); ioctl_str = buf; } @@ -110,11 +117,18 @@ void v4l2_log_ioctl(unsigned long int request, void *arg, int result) fprintf(v4l2_log_file, "request == %s\n", ioctl_str); switch (request) { + case VIDIOC_ENUM_FMT: + { + struct v4l2_fmtdesc *fmt = arg; + fprintf(v4l2_log_file, " index: %u, description: %s\n", + fmt->index, (result < 0) ? "" : (const char *)fmt->description); + } + break; case VIDIOC_G_FMT: case VIDIOC_S_FMT: case VIDIOC_TRY_FMT: { - struct v4l2_format* fmt = arg; + struct v4l2_format *fmt = arg; int pixfmt = fmt->fmt.pix.pixelformat; if (fmt->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) { @@ -141,8 +155,68 @@ void v4l2_log_ioctl(unsigned long int request, void *arg, int result) req->count, (int)req->type, (int)req->memory); } break; +#ifdef VIDIOC_ENUM_FRAMESIZES + case VIDIOC_ENUM_FRAMESIZES: + { + struct v4l2_frmsizeenum *frmsize = arg; + int pixfmt = frmsize->pixel_format; + + fprintf(v4l2_log_file, " index: %u pixelformat: %c%c%c%c", + frmsize->index, + pixfmt & 0xff, + (pixfmt >> 8) & 0xff, + (pixfmt >> 16) & 0xff, + pixfmt >> 24); + switch (frmsize->type) { + case V4L2_FRMSIZE_TYPE_DISCRETE: + fprintf(v4l2_log_file, " %ux%u\n", frmsize->discrete.width, + frmsize->discrete.height); + break; + case V4L2_FRMSIZE_TYPE_CONTINUOUS: + case V4L2_FRMSIZE_TYPE_STEPWISE: + fprintf(v4l2_log_file, " %ux%u -> %ux%u\n", + frmsize->stepwise.min_width, frmsize->stepwise.min_height, + frmsize->stepwise.max_width, frmsize->stepwise.max_height); + break; + } + } + break; + case VIDIOC_ENUM_FRAMEINTERVALS: + { + struct v4l2_frmivalenum *frmival = arg; + int pixfmt = frmival->pixel_format; + + fprintf(v4l2_log_file, " index: %u pixelformat: %c%c%c%c %ux%u: ", + frmival->index, + pixfmt & 0xff, + (pixfmt >> 8) & 0xff, + (pixfmt >> 16) & 0xff, + pixfmt >> 24, + frmival->width, + frmival->height); + switch (frmival->type) { + case V4L2_FRMIVAL_TYPE_DISCRETE: + fprintf(v4l2_log_file, "%u/%u\n", frmival->discrete.numerator, + frmival->discrete.denominator); + break; + case V4L2_FRMIVAL_TYPE_CONTINUOUS: + case V4L2_FRMIVAL_TYPE_STEPWISE: + fprintf(v4l2_log_file, "%u/%u -> %u/%u\n", + frmival->stepwise.min.numerator, + frmival->stepwise.min.denominator, + frmival->stepwise.max.numerator, + frmival->stepwise.max.denominator); + break; + } + } + break; +#endif } - fprintf(v4l2_log_file, "result == %d\n", result); + if (result < 0) + fprintf(v4l2_log_file, "result == %d (%s)\n", result, strerror(saved_errno)); + else + fprintf(v4l2_log_file, "result == %d\n", result); + fflush(v4l2_log_file); } diff --git a/v4l2-apps/libv4l/libv4lconvert/Makefile b/v4l2-apps/libv4l/libv4lconvert/Makefile index 641d19d6e..f779011b4 100644 --- a/v4l2-apps/libv4l/libv4lconvert/Makefile +++ b/v4l2-apps/libv4l/libv4lconvert/Makefile @@ -10,8 +10,9 @@ CONVERT_LIB = libv4lconvert.so override CPPFLAGS += -fPIC endif -CONVERT_OBJS = libv4lconvert.o tinyjpeg.o sn9c10x.o pac207.o flip.o \ - jidctflt.o spca561-decompress.o rgbyuv.o spca501.o bayer.o +CONVERT_OBJS = libv4lconvert.o tinyjpeg.o sn9c10x.o sn9c20x.o pac207.o \ + mr97310a.o flip.o crop.o jidctflt.o spca561-decompress.o \ + rgbyuv.o spca501.o sq905c.o bayer.o hm12.o TARGETS = $(CONVERT_LIB) libv4lconvert.pc INCLUDES = ../include/libv4lconvert.h @@ -57,7 +58,7 @@ endif install -m 644 libv4lconvert.pc $(DESTDIR)$(LIBDIR)/pkgconfig clean:: - rm -f *.a *.so* *.o *.d libv4lconvert.pc log *~ + rm -f *.a *.so* *.o *.d libv4lconvert.pc log *~ *.orig *.rej %.o: %.c $(CC) -c -MMD $(CPPFLAGS) $(CFLAGS) -o $@ $< diff --git a/v4l2-apps/libv4l/libv4lconvert/bayer.c b/v4l2-apps/libv4l/libv4lconvert/bayer.c index ca7bb486f..033ee2724 100644 --- a/v4l2-apps/libv4l/libv4lconvert/bayer.c +++ b/v4l2-apps/libv4l/libv4lconvert/bayer.c @@ -433,16 +433,23 @@ static void v4lconvert_border_bayer_line_to_y( } } -void v4lconvert_bayer_to_yuv420(const unsigned char *bayer, - unsigned char *yuv, int width, int height, unsigned int pixfmt) +void v4lconvert_bayer_to_yuv420(const unsigned char *bayer, unsigned char *yuv, + int width, int height, unsigned int src_pixfmt, int yvu) { int blue_line = 0, start_with_green = 0, x, y; unsigned char *ydst = yuv; - unsigned char *udst = yuv + width * height; - unsigned char *vdst = udst + width * height / 4; + unsigned char *udst, *vdst; + + if (yvu) { + vdst = yuv + width * height; + udst = vdst + width * height / 4; + } else { + udst = yuv + width * height; + vdst = udst + width * height / 4; + } /* First calculate the u and v planes 2x2 pixels at a time */ - switch (pixfmt) { + switch (src_pixfmt) { case V4L2_PIX_FMT_SBGGR8: for (y = 0; y < height; y += 2) { for (x = 0; x < width; x += 2) { diff --git a/v4l2-apps/libv4l/libv4lconvert/crop.c b/v4l2-apps/libv4l/libv4lconvert/crop.c new file mode 100644 index 000000000..4294fbeaf --- /dev/null +++ b/v4l2-apps/libv4l/libv4lconvert/crop.c @@ -0,0 +1,168 @@ +/* + +# RGB and YUV crop routines + +# (C) 2008 Hans de Goede <j.w.r.degoede@hhs.nl> + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation; either version 2.1 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +*/ + +#include <string.h> +#include "libv4lconvert-priv.h" + + +static void v4lconvert_reduceandcrop_rgbbgr24( + unsigned char *src, unsigned char *dest, + const struct v4l2_format *src_fmt, const struct v4l2_format *dest_fmt) +{ + int x, y; + int startx = src_fmt->fmt.pix.width / 2 - dest_fmt->fmt.pix.width; + int starty = src_fmt->fmt.pix.height / 2 - dest_fmt->fmt.pix.height; + + src += starty * src_fmt->fmt.pix.bytesperline + 3 * startx; + + for (y = 0; y < dest_fmt->fmt.pix.height; y++) { + unsigned char *mysrc = src; + for (x = 0; x < dest_fmt->fmt.pix.width; x++) { + *(dest++) = *(mysrc++); + *(dest++) = *(mysrc++); + *(dest++) = *(mysrc++); + mysrc += 3; /* skip one pixel */ + } + src += 2 * src_fmt->fmt.pix.bytesperline; /* skip one line */ + } +} + +static void v4lconvert_crop_rgbbgr24(unsigned char *src, unsigned char *dest, + const struct v4l2_format *src_fmt, const struct v4l2_format *dest_fmt) +{ + int x; + int startx = (src_fmt->fmt.pix.width - dest_fmt->fmt.pix.width) / 2; + int starty = (src_fmt->fmt.pix.height - dest_fmt->fmt.pix.height) / 2; + + src += starty * src_fmt->fmt.pix.bytesperline + 3 * startx; + + for (x = 0; x < dest_fmt->fmt.pix.height; x++) { + memcpy(dest, src, dest_fmt->fmt.pix.width * 3); + src += src_fmt->fmt.pix.bytesperline; + dest += dest_fmt->fmt.pix.bytesperline; + } +} + +static void v4lconvert_reduceandcrop_yuv420( + unsigned char *src, unsigned char *dest, + const struct v4l2_format *src_fmt, const struct v4l2_format *dest_fmt) +{ + int x,y; + int dest_height_half = dest_fmt->fmt.pix.height / 2; + int dest_width_half = dest_fmt->fmt.pix.width / 2; + int startx = src_fmt->fmt.pix.width / 2 - dest_fmt->fmt.pix.width; + int starty = src_fmt->fmt.pix.height / 2 - dest_fmt->fmt.pix.height; + unsigned char *mysrc, *mysrc2; + + /* Y */ + mysrc = src + starty * src_fmt->fmt.pix.bytesperline + startx; + for (y = 0; y < dest_fmt->fmt.pix.height; y++){ + mysrc2 = mysrc; + for (x = 0; x < dest_fmt->fmt.pix.width; x++){ + *(dest++) = *mysrc2; + mysrc2 += 2; /* skip one pixel */ + } + mysrc += 2 * src_fmt->fmt.pix.bytesperline; /* skip one line */ + } + + /* U */ + mysrc = src + src_fmt->fmt.pix.height * src_fmt->fmt.pix.bytesperline + + (starty / 2) * src_fmt->fmt.pix.bytesperline / 2 + startx / 2; + for (y = 0; y < dest_height_half; y++){ + mysrc2 = mysrc; + for (x = 0; x < dest_width_half; x++){ + *(dest++) = *mysrc2; + mysrc2 += 2; /* skip one pixel */ + } + mysrc += src_fmt->fmt.pix.bytesperline ; /* skip one line */ + } + + /* V */ + mysrc = src + src_fmt->fmt.pix.height * src_fmt->fmt.pix.bytesperline * 5 / 4 + + (starty / 2) * src_fmt->fmt.pix.bytesperline / 2 + startx / 2; + for (y = 0; y < dest_height_half; y++){ + mysrc2 = mysrc; + for (x = 0; x < dest_width_half; x++){ + *(dest++) = *mysrc2; + mysrc2 += 2; /* skip one pixel */ + } + mysrc += src_fmt->fmt.pix.bytesperline ; /* skip one line */ + } +} + +static void v4lconvert_crop_yuv420(unsigned char *src, unsigned char *dest, + const struct v4l2_format *src_fmt, const struct v4l2_format *dest_fmt) +{ + int x; + int startx = (src_fmt->fmt.pix.width - dest_fmt->fmt.pix.width) / 2; + int starty = (src_fmt->fmt.pix.height - dest_fmt->fmt.pix.height) / 2; + unsigned char *mysrc = src + starty * src_fmt->fmt.pix.bytesperline + startx; + + /* Y */ + for (x = 0; x < dest_fmt->fmt.pix.height; x++) { + memcpy(dest, mysrc, dest_fmt->fmt.pix.width); + mysrc += src_fmt->fmt.pix.bytesperline; + dest += dest_fmt->fmt.pix.bytesperline; + } + + /* U */ + mysrc = src + src_fmt->fmt.pix.height * src_fmt->fmt.pix.bytesperline + + (starty / 2) * src_fmt->fmt.pix.bytesperline / 2 + startx / 2; + for (x = 0; x < dest_fmt->fmt.pix.height / 2; x++) { + memcpy(dest, mysrc, dest_fmt->fmt.pix.width / 2); + mysrc += src_fmt->fmt.pix.bytesperline / 2; + dest += dest_fmt->fmt.pix.bytesperline / 2; + } + + /* V */ + mysrc = src + src_fmt->fmt.pix.height * src_fmt->fmt.pix.bytesperline * 5 / 4 + + (starty / 2) * src_fmt->fmt.pix.bytesperline / 2 + startx / 2; + for (x = 0; x < dest_fmt->fmt.pix.height / 2; x++) { + memcpy(dest, mysrc, dest_fmt->fmt.pix.width / 2); + mysrc += src_fmt->fmt.pix.bytesperline / 2; + dest += dest_fmt->fmt.pix.bytesperline / 2; + } +} + +void v4lconvert_crop(unsigned char *src, unsigned char *dest, + const struct v4l2_format *src_fmt, const struct v4l2_format *dest_fmt) +{ + switch (dest_fmt->fmt.pix.pixelformat) { + case V4L2_PIX_FMT_RGB24: + case V4L2_PIX_FMT_BGR24: + if (src_fmt->fmt.pix.width >= 2 * dest_fmt->fmt.pix.width && + src_fmt->fmt.pix.height >= 2 * dest_fmt->fmt.pix.height) + v4lconvert_reduceandcrop_rgbbgr24(src, dest, src_fmt, dest_fmt); + else + v4lconvert_crop_rgbbgr24(src, dest, src_fmt, dest_fmt); + break; + case V4L2_PIX_FMT_YUV420: + case V4L2_PIX_FMT_YVU420: + if (src_fmt->fmt.pix.width >= 2 * dest_fmt->fmt.pix.width && + src_fmt->fmt.pix.height >= 2 * dest_fmt->fmt.pix.height) + v4lconvert_reduceandcrop_yuv420(src, dest, src_fmt, dest_fmt); + else + v4lconvert_crop_yuv420(src, dest, src_fmt, dest_fmt); + + break; + } +} diff --git a/v4l2-apps/libv4l/libv4lconvert/flip.c b/v4l2-apps/libv4l/libv4lconvert/flip.c index cd3468a89..f47afde72 100644 --- a/v4l2-apps/libv4l/libv4lconvert/flip.c +++ b/v4l2-apps/libv4l/libv4lconvert/flip.c @@ -22,8 +22,8 @@ #include "libv4lconvert-priv.h" -void v4lconvert_rotate180_rgbbgr24(const unsigned char *src, unsigned char *dst, - int width, int height) +static void v4lconvert_rotate180_rgbbgr24(const unsigned char *src, + unsigned char *dst, int width, int height) { int i; @@ -38,8 +38,8 @@ void v4lconvert_rotate180_rgbbgr24(const unsigned char *src, unsigned char *dst, } } -void v4lconvert_rotate180_yuv420(const unsigned char *src, unsigned char *dst, - int width, int height) +static void v4lconvert_rotate180_yuv420(const unsigned char *src, + unsigned char *dst, int width, int height) { int i; @@ -59,8 +59,8 @@ void v4lconvert_rotate180_yuv420(const unsigned char *src, unsigned char *dst, *dst++ = *src--; } -void v4lconvert_rotate90_rgbbgr24(const unsigned char *src, unsigned char *dst, - int destwidth, int destheight) +static void v4lconvert_rotate90_rgbbgr24(const unsigned char *src, + unsigned char *dst, int destwidth, int destheight) { int x, y; #define srcwidth destheight @@ -75,8 +75,8 @@ void v4lconvert_rotate90_rgbbgr24(const unsigned char *src, unsigned char *dst, } } -void v4lconvert_rotate90_yuv420(const unsigned char *src, unsigned char *dst, - int destwidth, int destheight) +static void v4lconvert_rotate90_yuv420(const unsigned char *src, + unsigned char *dst, int destwidth, int destheight) { int x, y; @@ -105,3 +105,38 @@ void v4lconvert_rotate90_yuv420(const unsigned char *src, unsigned char *dst, *dst++ = src[offset]; } } + +void v4lconvert_rotate(unsigned char *src, unsigned char *dest, + int width, int height, unsigned int pix_fmt, int rotate) +{ + switch (rotate) { + case 0: + break; + case 90: + switch (pix_fmt) { + case V4L2_PIX_FMT_RGB24: + case V4L2_PIX_FMT_BGR24: + v4lconvert_rotate90_rgbbgr24(src, dest, width, height); + break; + case V4L2_PIX_FMT_YUV420: + case V4L2_PIX_FMT_YVU420: + v4lconvert_rotate90_yuv420(src, dest, width, height); + break; + } + break; + case 180: + switch (pix_fmt) { + case V4L2_PIX_FMT_RGB24: + case V4L2_PIX_FMT_BGR24: + v4lconvert_rotate180_rgbbgr24(src, dest, width, height); + break; + case V4L2_PIX_FMT_YUV420: + case V4L2_PIX_FMT_YVU420: + v4lconvert_rotate180_yuv420(src, dest, width, height); + break; + } + break; + default: + printf("FIXME add %d degrees rotation\n", rotate); + } +} diff --git a/v4l2-apps/libv4l/libv4lconvert/hm12.c b/v4l2-apps/libv4l/libv4lconvert/hm12.c new file mode 100644 index 000000000..f711627b4 --- /dev/null +++ b/v4l2-apps/libv4l/libv4lconvert/hm12.c @@ -0,0 +1,159 @@ +/* + +cx2341x HM12 conversion routines + +(C) 2009 Hans Verkuil <hverkuil@xs4all.nl> + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation; either version 2.1 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + */ + +#include "libv4lconvert-priv.h" +#include <string.h> + +/* The HM12 format is used in the Conexant cx23415/6/8 MPEG encoder devices. + It is a macroblock format with separate Y and UV planes, each plane + consisting of 16x16 values. All lines are always 720 bytes long. If the + width of the image is less than 720, then the remainder is padding. + + The height has to be a multiple of 32 in order to get correct chroma + values. + + It is basically a by-product of the MPEG encoding inside the device, + which is available for raw video as a 'bonus feature'. + */ + +#define CLIP(color) \ + (unsigned char)(((color) > 0xff) ? 0xff : (((color) < 0) ? 0 : (color))) + +static const int stride = 720; + +static void v4lconvert_hm12_to_rgb(const unsigned char *src, unsigned char *dest, + int width, int height, int rgb) +{ + unsigned int y, x, i, j; + const unsigned char *y_base = src; + const unsigned char *uv_base = src + stride * height; + const unsigned char *src_y; + const unsigned char *src_uv; + int mb_size = 256; + int r = rgb ? 0 : 2; + int b = 2 - r; + + for (y = 0; y < height; y += 16) { + int mb_y = (y / 16) * (stride / 16); + int mb_uv = (y / 32) * (stride / 16); + int maxy = (height - y < 16 ? height - y : 16); + + for (x = 0; x < width; x += 16, mb_y++, mb_uv++) { + int maxx = (width - x < 16 ? width - x : 16); + + src_y = y_base + mb_y * mb_size; + src_uv = uv_base + mb_uv * mb_size; + + if (y & 0x10) + src_uv += mb_size / 2; + + for (i = 0; i < maxy; i++) { + int idx = (x + (y + i) * width) * 3; + + for (j = 0; j < maxx; j++) { + int y = src_y[j]; + int u = src_uv[j & ~1]; + int v = src_uv[j | 1]; + int u1 = (((u - 128) << 7) + (u - 128)) >> 6; + int rg = (((u - 128) << 1) + (u - 128) + + ((v - 128) << 2) + ((v - 128) << 1)) >> 3; + int v1 = (((v - 128) << 1) + (v - 128)) >> 1; + + dest[idx+r] = CLIP(y + v1); + dest[idx+1] = CLIP(y - rg); + dest[idx+b] = CLIP(y + u1); + idx += 3; + } + src_y += 16; + if (i & 1) + src_uv += 16; + } + } + } +} + +void v4lconvert_hm12_to_rgb24(const unsigned char *src, unsigned char *dest, + int width, int height) +{ + v4lconvert_hm12_to_rgb(src, dest, width, height, 1); +} + +void v4lconvert_hm12_to_bgr24(const unsigned char *src, unsigned char *dest, + int width, int height) +{ + v4lconvert_hm12_to_rgb(src, dest, width, height, 0); +} + +static void de_macro_uv(unsigned char *dstu, unsigned char *dstv, + const unsigned char *src, int w, int h) +{ + unsigned int y, x, i, j; + + for (y = 0; y < h; y += 16) { + for (x = 0; x < w; x += 8) { + const unsigned char *src_uv = src + y * stride + x * 32; + int maxy = (h - y < 16 ? h - y : 16); + int maxx = (w - x < 8 ? w - x : 8); + + for (i = 0; i < maxy; i++) { + int idx = x + (y + i) * w; + + for (j = 0; j < maxx; j++) { + dstu[idx+j] = src_uv[2 * j]; + dstv[idx+j] = src_uv[2 * j + 1]; + } + src_uv += 16; + } + } + } +} + +static void de_macro_y(unsigned char *dst, const unsigned char *src, + int w, int h) +{ + unsigned int y, x, i; + + for (y = 0; y < h; y += 16) { + for (x = 0; x < w; x += 16) { + const unsigned char *src_y = src + y * stride + x * 16; + int maxy = (h - y < 16 ? h - y : 16); + int maxx = (w - x < 16 ? w - x : 16); + + for (i = 0; i < maxy; i++) { + memcpy(dst + x + (y + i) * w, src_y, maxx); + src_y += 16; + } + } + } +} + +void v4lconvert_hm12_to_yuv420(const unsigned char *src, unsigned char *dest, + int width, int height, int yvu) +{ + de_macro_y(dest, src, width, height); + dest += width * height; + src += stride * height; + if (yvu) + de_macro_uv(dest + width * height / 4, dest, src, width / 2, height / 2); + else + de_macro_uv(dest, dest + width * height / 4, src, width / 2, height / 2); +} diff --git a/v4l2-apps/libv4l/libv4lconvert/libv4lconvert-priv.h b/v4l2-apps/libv4l/libv4lconvert/libv4lconvert-priv.h index 0c4eff6ce..5ce7bde3b 100644 --- a/v4l2-apps/libv4l/libv4lconvert/libv4lconvert-priv.h +++ b/v4l2-apps/libv4l/libv4lconvert/libv4lconvert-priv.h @@ -43,6 +43,14 @@ #define V4L2_PIX_FMT_PAC207 v4l2_fourcc('P','2','0','7') #endif +#ifndef V4L2_PIX_FMT_MR97310A +#define V4L2_PIX_FMT_MR97310A v4l2_fourcc('M','3','1','0') +#endif + +#ifndef V4L2_PIX_FMT_SQ905C +#define V4L2_PIX_FMT_SQ905C v4l2_fourcc('9', '0', '5', 'C') +#endif + #ifndef V4L2_PIX_FMT_PJPG #define V4L2_PIX_FMT_PJPG v4l2_fourcc('P', 'J', 'P', 'G') #endif @@ -63,6 +71,14 @@ #define V4L2_PIX_FMT_YVYU v4l2_fourcc('Y', 'V', 'Y', 'U') #endif +#ifndef V4L2_PIX_FMT_HM12 +#define V4L2_PIX_FMT_HM12 v4l2_fourcc('H', 'M', '1', '2') +#endif + +#ifndef V4L2_PIX_FMT_SN9C20X_I420 +#define V4L2_PIX_FMT_SN9C20X_I420 v4l2_fourcc('S', '9', '2', '0') +#endif + #define V4LCONVERT_ERROR_MSG_SIZE 256 #define V4LCONVERT_MAX_FRAMESIZES 16 @@ -71,7 +87,9 @@ "v4l-convert: error " __VA_ARGS__) /* Card flags */ -#define V4LCONVERT_UPSIDE_DOWN 0x01 +#define V4LCONVERT_ROTATE_90 0x01 +#define V4LCONVERT_ROTATE_180 0x02 +#define V4LCONVERT_IS_UVC 0x04 /* Pixformat flags */ #define V4LCONVERT_COMPRESSED 0x01 @@ -85,10 +103,20 @@ struct v4lconvert_data { struct jdec_private *jdec; struct v4l2_frmsizeenum framesizes[V4LCONVERT_MAX_FRAMESIZES]; unsigned int no_framesizes; + int convert_buf_size; + int rotate_buf_size; + int convert_pixfmt_buf_size; + unsigned char *convert_buf; + unsigned char *rotate_buf; + unsigned char *convert_pixfmt_buf; }; struct v4lconvert_flags_info { - const char *card; + unsigned short vendor_id; + unsigned short product_id; +/* We could also use the USB manufacturer and product strings some devices have + const char *manufacturer; + const char *product; */ int flags; }; @@ -97,11 +125,14 @@ struct v4lconvert_pixfmt { int flags; }; +void v4lconvert_rgb24_to_yuv420(const unsigned char *src, unsigned char *dest, + const struct v4l2_format *src_fmt, int bgr, int yvu); + void v4lconvert_yuv420_to_rgb24(const unsigned char *src, unsigned char *dst, - int width, int height); + int width, int height, int yvu); void v4lconvert_yuv420_to_bgr24(const unsigned char *src, unsigned char *dst, - int width, int height); + int width, int height, int yvu); void v4lconvert_yuyv_to_rgb24(const unsigned char *src, unsigned char *dst, int width, int height); @@ -110,7 +141,7 @@ void v4lconvert_yuyv_to_bgr24(const unsigned char *src, unsigned char *dst, int width, int height); void v4lconvert_yuyv_to_yuv420(const unsigned char *src, unsigned char *dst, - int width, int height); + int width, int height, int yvu); void v4lconvert_yvyu_to_rgb24(const unsigned char *src, unsigned char *dst, int width, int height); @@ -118,20 +149,32 @@ void v4lconvert_yvyu_to_rgb24(const unsigned char *src, unsigned char *dst, void v4lconvert_yvyu_to_bgr24(const unsigned char *src, unsigned char *dst, int width, int height); -void v4lconvert_yvyu_to_yuv420(const unsigned char *src, unsigned char *dst, +void v4lconvert_uyvy_to_rgb24(const unsigned char *src, unsigned char *dst, + int width, int height); + +void v4lconvert_uyvy_to_bgr24(const unsigned char *src, unsigned char *dst, int width, int height); +void v4lconvert_uyvy_to_yuv420(const unsigned char *src, unsigned char *dst, + int width, int height, int yvu); + void v4lconvert_swap_rgb(const unsigned char *src, unsigned char *dst, int width, int height); +void v4lconvert_swap_uv(const unsigned char *src, unsigned char *dst, + const struct v4l2_format *src_fmt); + void v4lconvert_spca501_to_yuv420(const unsigned char *src, unsigned char *dst, - int width, int height); + int width, int height, int yvu); void v4lconvert_spca505_to_yuv420(const unsigned char *src, unsigned char *dst, - int width, int height); + int width, int height, int yvu); void v4lconvert_spca508_to_yuv420(const unsigned char *src, unsigned char *dst, - int width, int height); + int width, int height, int yvu); + +void v4lconvert_sn9c20x_to_yuv420(const unsigned char *src, unsigned char *dst, + int width, int height, int yvu); void v4lconvert_decode_spca561(const unsigned char *src, unsigned char *dst, int width, int height); @@ -142,25 +185,34 @@ void v4lconvert_decode_sn9c10x(const unsigned char *src, unsigned char *dst, void v4lconvert_decode_pac207(const unsigned char *src, unsigned char *dst, int width, int height); +void v4lconvert_decode_mr97310a(const unsigned char *src, unsigned char *dst, + int width, int height); + +void v4lconvert_decode_sq905c(const unsigned char *src, unsigned char *dst, + int width, int height); + void v4lconvert_bayer_to_rgb24(const unsigned char *bayer, unsigned char *rgb, int width, int height, unsigned int pixfmt); void v4lconvert_bayer_to_bgr24(const unsigned char *bayer, unsigned char *rgb, int width, int height, unsigned int pixfmt); -void v4lconvert_bayer_to_yuv420(const unsigned char *bayer, - unsigned char *yuv, int width, int height, unsigned int pixfmt); +void v4lconvert_bayer_to_yuv420(const unsigned char *bayer, unsigned char *yuv, + int width, int height, unsigned int src_pixfmt, int yvu); -void v4lconvert_rotate90_rgbbgr24(const unsigned char *src, unsigned char *dst, - int destwidth, int destheight); +void v4lconvert_hm12_to_rgb24(const unsigned char *src, + unsigned char *dst, int width, int height); -void v4lconvert_rotate90_yuv420(const unsigned char *src, unsigned char *dst, - int destwidth, int destheight); +void v4lconvert_hm12_to_bgr24(const unsigned char *src, + unsigned char *dst, int width, int height); -void v4lconvert_rotate180_rgbbgr24(const unsigned char *src, unsigned char *dst, - int width, int height); +void v4lconvert_hm12_to_yuv420(const unsigned char *src, + unsigned char *dst, int width, int height, int yvu); -void v4lconvert_rotate180_yuv420(const unsigned char *src, unsigned char *dst, - int width, int height); +void v4lconvert_rotate(unsigned char *src, unsigned char *dest, + int width, int height, unsigned int pix_fmt, int rotate); + +void v4lconvert_crop(unsigned char *src, unsigned char *dest, + const struct v4l2_format *src_fmt, const struct v4l2_format *dest_fmt); #endif diff --git a/v4l2-apps/libv4l/libv4lconvert/libv4lconvert.c b/v4l2-apps/libv4l/libv4lconvert/libv4lconvert.c index 93bc67c7e..1204e8ef2 100644 --- a/v4l2-apps/libv4l/libv4lconvert/libv4lconvert.c +++ b/v4l2-apps/libv4l/libv4lconvert/libv4lconvert.c @@ -21,6 +21,8 @@ #include <stdlib.h> #include <syscall.h> #include <unistd.h> +#include <sys/stat.h> +#include <sys/types.h> #include "libv4lconvert.h" #include "libv4lconvert-priv.h" @@ -32,30 +34,36 @@ #define SUPPORTED_DST_PIXFMTS \ { V4L2_PIX_FMT_RGB24, 0 }, \ { V4L2_PIX_FMT_BGR24, 0 }, \ - { V4L2_PIX_FMT_YUV420, 0 } + { V4L2_PIX_FMT_YUV420, 0 }, \ + { V4L2_PIX_FMT_YVU420, 0 } static void v4lconvert_get_framesizes(struct v4lconvert_data *data, - unsigned int pixelformat); + unsigned int pixelformat, int index); /* Note uncompressed formats must go first so that they are prefered by v4lconvert_try_format for low resolutions */ static const struct v4lconvert_pixfmt supported_src_pixfmts[] = { SUPPORTED_DST_PIXFMTS, - { V4L2_PIX_FMT_YUYV, 0 }, - { V4L2_PIX_FMT_YVYU, 0 }, - { V4L2_PIX_FMT_SBGGR8, 0 }, - { V4L2_PIX_FMT_SGBRG8, 0 }, - { V4L2_PIX_FMT_SGRBG8, 0 }, - { V4L2_PIX_FMT_SRGGB8, 0 }, - { V4L2_PIX_FMT_SPCA501, 0 }, - { V4L2_PIX_FMT_SPCA505, 0 }, - { V4L2_PIX_FMT_SPCA508, 0 }, - { V4L2_PIX_FMT_MJPEG, V4LCONVERT_COMPRESSED }, - { V4L2_PIX_FMT_JPEG, V4LCONVERT_COMPRESSED }, - { V4L2_PIX_FMT_SPCA561, V4LCONVERT_COMPRESSED }, - { V4L2_PIX_FMT_SN9C10X, V4LCONVERT_COMPRESSED }, - { V4L2_PIX_FMT_PAC207, V4LCONVERT_COMPRESSED }, - { V4L2_PIX_FMT_PJPG, V4LCONVERT_COMPRESSED }, + { V4L2_PIX_FMT_YUYV, 0 }, + { V4L2_PIX_FMT_YVYU, 0 }, + { V4L2_PIX_FMT_UYVY, 0 }, + { V4L2_PIX_FMT_SN9C20X_I420, 0 }, + { V4L2_PIX_FMT_SBGGR8, 0 }, + { V4L2_PIX_FMT_SGBRG8, 0 }, + { V4L2_PIX_FMT_SGRBG8, 0 }, + { V4L2_PIX_FMT_SRGGB8, 0 }, + { V4L2_PIX_FMT_SPCA501, 0 }, + { V4L2_PIX_FMT_SPCA505, 0 }, + { V4L2_PIX_FMT_SPCA508, 0 }, + { V4L2_PIX_FMT_HM12, 0 }, + { V4L2_PIX_FMT_MJPEG, V4LCONVERT_COMPRESSED }, + { V4L2_PIX_FMT_JPEG, V4LCONVERT_COMPRESSED }, + { V4L2_PIX_FMT_SPCA561, V4LCONVERT_COMPRESSED }, + { V4L2_PIX_FMT_SN9C10X, V4LCONVERT_COMPRESSED }, + { V4L2_PIX_FMT_PAC207, V4LCONVERT_COMPRESSED }, + { V4L2_PIX_FMT_MR97310A, V4LCONVERT_COMPRESSED }, + { V4L2_PIX_FMT_SQ905C, V4LCONVERT_COMPRESSED }, + { V4L2_PIX_FMT_PJPG, V4LCONVERT_COMPRESSED }, }; static const struct v4lconvert_pixfmt supported_dst_pixfmts[] = { @@ -64,13 +72,65 @@ static const struct v4lconvert_pixfmt supported_dst_pixfmts[] = { /* List of cams which need special flags */ static const struct v4lconvert_flags_info v4lconvert_flags[] = { - { "SPC 200NC ", V4LCONVERT_UPSIDE_DOWN }, - { "SPC 300NC ", V4LCONVERT_UPSIDE_DOWN }, - { "USB Camera (0471:0325)", V4LCONVERT_UPSIDE_DOWN }, /* SPC200NC */ - { "USB Camera (0471:0326)", V4LCONVERT_UPSIDE_DOWN }, /* SPC300NC */ - { "USB Camera (093a:2476)", V4LCONVERT_UPSIDE_DOWN }, /* Genius E-M 112 */ + { 0x0471, 0x0325, V4LCONVERT_ROTATE_180 }, /* Philips SPC200NC */ + { 0x0471, 0x0326, V4LCONVERT_ROTATE_180 }, /* Philips SPC300NC */ + { 0x0471, 0x032d, V4LCONVERT_ROTATE_180 }, /* Philips SPC210NC */ + { 0x093a, 0x2476, V4LCONVERT_ROTATE_180 }, /* Genius E-M 112 */ }; +/* List of well known resolutions which we can get by cropping somewhat larger + resolutions */ +static const int v4lconvert_crop_res[][2] = { + /* low res VGA resolutions, can be made by software cropping SIF resolutions + for cam/drivers which do not support this in hardware */ + { 320, 240 }, + { 160, 120 }, + /* Some CIF cams (with vv6410 sensor) have slightly larger then usual CIF + resolutions, make regular CIF resolutions available on these by sw crop */ + { 352, 288 }, + { 176, 144 }, +}; + +static int v4lconvert_get_flags(int fd) +{ + struct stat st; + FILE *f; + char sysfs_name[512]; + unsigned short vendor_id = 0; + unsigned short product_id = 0; + int i; + + if (fstat(fd, &st) || !S_ISCHR(st.st_mode)) + return 0; /* Should never happen */ + + /* Get product ID */ + snprintf(sysfs_name, sizeof(sysfs_name), + "/sys/class/video4linux/video%d/device/idVendor", + minor(st.st_rdev)); + f = fopen(sysfs_name, "r"); + if (!f) + return 0; /* Not an USB device (or no sysfs) */ + i = fscanf(f, "%hx", &vendor_id); + fclose(f); + + /* Get product ID */ + snprintf(sysfs_name, sizeof(sysfs_name), + "/sys/class/video4linux/video%d/device/idProduct", + minor(st.st_rdev)); + f = fopen(sysfs_name, "r"); + if (!f) + return 0; /* Should never happen */ + i = fscanf(f, "%hx", &product_id); + fclose(f); + + for (i = 0; i < ARRAY_SIZE(v4lconvert_flags); i++) + if (v4lconvert_flags[i].vendor_id == vendor_id && + v4lconvert_flags[i].product_id == product_id) + return v4lconvert_flags[i].flags; + + return 0; +} + struct v4lconvert_data *v4lconvert_create(int fd) { int i, j; @@ -81,7 +141,6 @@ struct v4lconvert_data *v4lconvert_create(int fd) return NULL; data->fd = fd; - data->jdec = NULL; /* Check supported formats */ for (i = 0; ; i++) { @@ -95,21 +154,18 @@ struct v4lconvert_data *v4lconvert_create(int fd) for (j = 0; j < ARRAY_SIZE(supported_src_pixfmts); j++) if (fmt.pixelformat == supported_src_pixfmts[j].fmt) { data->supported_src_formats |= 1 << j; + v4lconvert_get_framesizes(data, fmt.pixelformat, j); break; } - - v4lconvert_get_framesizes(data, fmt.pixelformat); } data->no_formats = i; /* Check if this cam has any special flags */ + data->flags = v4lconvert_get_flags(data->fd); if (syscall(SYS_ioctl, fd, VIDIOC_QUERYCAP, &cap) == 0) { - for (i = 0; i < ARRAY_SIZE(v4lconvert_flags); i++) - if (!strcmp((const char *)v4lconvert_flags[i].card, (char *)cap.card)) { - data->flags = v4lconvert_flags[i].flags; - break; - } + if (!strcmp((char *)cap.driver, "uvcvideo")) + data->flags |= V4LCONVERT_IS_UVC; } return data; @@ -122,6 +178,9 @@ void v4lconvert_destroy(struct v4lconvert_data *data) tinyjpeg_set_components(data->jdec, comps, 3); tinyjpeg_free(data->jdec); } + free(data->convert_buf); + free(data->rotate_buf); + free(data->convert_pixfmt_buf); free(data); } @@ -171,8 +230,65 @@ int v4lconvert_enum_fmt(struct v4lconvert_data *data, struct v4l2_fmtdesc *fmt) return 0; } -/* See libv4lconvert.h for description of in / out parameters */ -int v4lconvert_try_format(struct v4lconvert_data *data, +/* Find out what format to use based on the (cached) results of enum + framesizes instead of doing a zillion try_fmt calls. This function + currently is intended for use with UVC cams only. This is esp. + important for UVC based cams as doing try_fmt there actually causes I/O */ +static int v4lconvert_do_try_format_uvc(struct v4lconvert_data *data, + struct v4l2_format *dest_fmt, struct v4l2_format *src_fmt) +{ + int i; + unsigned int closest_fmt_size_diff = -1; + int best_framesize = 0;/* Just use the first format if no small enough one */ + int best_format = 0; + + for (i = 0; i < data->no_framesizes; i++) { + if (data->framesizes[i].discrete.width <= dest_fmt->fmt.pix.width && + data->framesizes[i].discrete.height <= dest_fmt->fmt.pix.height) { + int size_x_diff = dest_fmt->fmt.pix.width - + data->framesizes[i].discrete.width; + int size_y_diff = dest_fmt->fmt.pix.height - + data->framesizes[i].discrete.height; + unsigned int size_diff = size_x_diff * size_x_diff + + size_y_diff * size_y_diff; + + if (size_diff < closest_fmt_size_diff) { + closest_fmt_size_diff = size_diff; + best_framesize = i; + } + } + } + + for (i = 0; i < ARRAY_SIZE(supported_src_pixfmts); i++) { + /* is this format supported? */ + if (!(data->framesizes[best_framesize].pixel_format & (1 << i))) + continue; + + if (!best_format || + supported_src_pixfmts[i].fmt == dest_fmt->fmt.pix.pixelformat || + ((data->framesizes[best_framesize].discrete.width > 180 || + data->framesizes[best_framesize].discrete.height > 148) && + (supported_src_pixfmts[i].flags & V4LCONVERT_COMPRESSED))) + best_format = supported_src_pixfmts[i].fmt; + } + + dest_fmt->fmt.pix.width = data->framesizes[best_framesize].discrete.width; + dest_fmt->fmt.pix.height = data->framesizes[best_framesize].discrete.height; + dest_fmt->fmt.pix.field = V4L2_FIELD_NONE; /* UVC has no fields */ + /* Not pretty, the pwc driver doesn't fill these in try_fmt either though, + so we should be able to get away with this. */ + dest_fmt->fmt.pix.bytesperline = 0; + dest_fmt->fmt.pix.sizeimage = 0; + dest_fmt->fmt.pix.colorspace = 0; + dest_fmt->fmt.pix.priv = 0; + + *src_fmt = *dest_fmt; + src_fmt->fmt.pix.pixelformat = best_format; + + return 0; +} + +static int v4lconvert_do_try_format(struct v4lconvert_data *data, struct v4l2_format *dest_fmt, struct v4l2_format *src_fmt) { int i; @@ -180,14 +296,8 @@ int v4lconvert_try_format(struct v4lconvert_data *data, unsigned int desired_pixfmt = dest_fmt->fmt.pix.pixelformat; struct v4l2_format try_fmt, closest_fmt = { .type = 0 }; - /* Can we do conversion to the requested format & type? */ - if (!v4lconvert_supported_dst_format(desired_pixfmt) || - dest_fmt->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) { - int ret = syscall(SYS_ioctl, data->fd, VIDIOC_TRY_FMT, dest_fmt); - if (src_fmt) - *src_fmt = *dest_fmt; - return ret; - } + if (data->flags & V4LCONVERT_IS_UVC) + return v4lconvert_do_try_format_uvc(data, dest_fmt, src_fmt); for (i = 0; i < ARRAY_SIZE(supported_src_pixfmts); i++) { /* is this format supported? */ @@ -209,7 +319,7 @@ int v4lconvert_try_format(struct v4lconvert_data *data, if (size_diff < closest_fmt_size_diff || (size_diff == closest_fmt_size_diff && (supported_src_pixfmts[i].fmt == desired_pixfmt || - ((try_fmt.fmt.pix.width > 176 || try_fmt.fmt.pix.height > 144) && + ((try_fmt.fmt.pix.width > 180 || try_fmt.fmt.pix.height > 148) && (supported_src_pixfmts[i].flags & V4LCONVERT_COMPRESSED))))) { closest_fmt_size_diff = size_diff; closest_fmt = try_fmt; @@ -218,35 +328,96 @@ int v4lconvert_try_format(struct v4lconvert_data *data, } } - if (closest_fmt.type == 0) { - int ret = syscall(SYS_ioctl, data->fd, VIDIOC_TRY_FMT, dest_fmt); + if (closest_fmt.type == 0) + return -1; + + *dest_fmt = closest_fmt; + if (closest_fmt.fmt.pix.pixelformat != desired_pixfmt) + dest_fmt->fmt.pix.pixelformat = desired_pixfmt; + *src_fmt = closest_fmt; + + return 0; +} + +static void v4lconvert_fixup_fmt(struct v4l2_format *fmt) +{ + switch (fmt->fmt.pix.pixelformat) { + case V4L2_PIX_FMT_RGB24: + case V4L2_PIX_FMT_BGR24: + fmt->fmt.pix.bytesperline = fmt->fmt.pix.width * 3; + fmt->fmt.pix.sizeimage = fmt->fmt.pix.width * fmt->fmt.pix.height * 3; + break; + case V4L2_PIX_FMT_YUV420: + case V4L2_PIX_FMT_YVU420: + fmt->fmt.pix.bytesperline = fmt->fmt.pix.width; + fmt->fmt.pix.sizeimage = fmt->fmt.pix.width * fmt->fmt.pix.height * 3 / 2; + break; + } +} + +/* See libv4lconvert.h for description of in / out parameters */ +int v4lconvert_try_format(struct v4lconvert_data *data, + struct v4l2_format *dest_fmt, struct v4l2_format *src_fmt) +{ + int i, result; + unsigned int desired_width = dest_fmt->fmt.pix.width; + unsigned int desired_height = dest_fmt->fmt.pix.height; + struct v4l2_format try_src, try_dest = *dest_fmt; + + /* Can we do conversion to the requested format & type? */ + if (!v4lconvert_supported_dst_format(dest_fmt->fmt.pix.pixelformat) || + dest_fmt->type != V4L2_BUF_TYPE_VIDEO_CAPTURE || + v4lconvert_do_try_format(data, &try_dest, &try_src)) { + result = syscall(SYS_ioctl, data->fd, VIDIOC_TRY_FMT, dest_fmt); if (src_fmt) *src_fmt = *dest_fmt; - return ret; + return result; } - *dest_fmt = closest_fmt; - - /* Are we converting? */ - if (closest_fmt.fmt.pix.pixelformat != desired_pixfmt) { - dest_fmt->fmt.pix.pixelformat = desired_pixfmt; - switch (dest_fmt->fmt.pix.pixelformat) { - case V4L2_PIX_FMT_RGB24: - case V4L2_PIX_FMT_BGR24: - dest_fmt->fmt.pix.bytesperline = dest_fmt->fmt.pix.width * 3; - dest_fmt->fmt.pix.sizeimage = dest_fmt->fmt.pix.width * - dest_fmt->fmt.pix.height * 3; - break; - case V4L2_PIX_FMT_YUV420: - dest_fmt->fmt.pix.bytesperline = dest_fmt->fmt.pix.width; - dest_fmt->fmt.pix.sizeimage = (dest_fmt->fmt.pix.width * - dest_fmt->fmt.pix.height * 3) / 2; + /* In case of a non exact resolution match, see if this is a well known + resolution some apps are hardcoded too and try to give the app what it + asked for by cropping a slightly larger resolution */ + if (try_dest.fmt.pix.width != desired_width || + try_dest.fmt.pix.height != desired_height) { + for (i = 0; i < ARRAY_SIZE(v4lconvert_crop_res); i++) { + if (v4lconvert_crop_res[i][0] == desired_width && + v4lconvert_crop_res[i][1] == desired_height) { + struct v4l2_format try2_src, try2_dest = *dest_fmt; + + /* Note these are chosen so that cropping to vga res just works for + vv6410 sensor cams, which have 356x292 and 180x148 */ + try2_dest.fmt.pix.width = desired_width * 113 / 100; + try2_dest.fmt.pix.height = desired_height * 124 / 100; + result = v4lconvert_do_try_format(data, &try2_dest, &try2_src); + if (result == 0 && + ((try2_dest.fmt.pix.width >= desired_width && + try2_dest.fmt.pix.width <= desired_width * 5 / 4 && + try2_dest.fmt.pix.height >= desired_height && + try2_dest.fmt.pix.height <= desired_height * 5 / 4) || + (try2_dest.fmt.pix.width >= desired_width * 2 && + try2_dest.fmt.pix.width <= desired_width * 5 / 2 && + try2_dest.fmt.pix.height >= desired_height && + try2_dest.fmt.pix.height <= desired_height * 5 / 2))) { + /* Success! */ + try2_dest.fmt.pix.width = desired_width; + try2_dest.fmt.pix.height = desired_height; + try_dest = try2_dest; + try_src = try2_src; + } break; + } } } + /* Are we converting? */ + if(try_src.fmt.pix.width != try_dest.fmt.pix.width || + try_src.fmt.pix.height != try_dest.fmt.pix.height || + try_src.fmt.pix.pixelformat != try_dest.fmt.pix.pixelformat) + v4lconvert_fixup_fmt(&try_dest); + + *dest_fmt = try_dest; if (src_fmt) - *src_fmt = closest_fmt; + *src_fmt = try_src; return 0; } @@ -256,10 +427,12 @@ int v4lconvert_needs_conversion(struct v4lconvert_data *data, const struct v4l2_format *src_fmt, /* in */ const struct v4l2_format *dest_fmt) /* in */ { - if(memcmp(src_fmt, dest_fmt, sizeof(*src_fmt))) + if(src_fmt->fmt.pix.width != dest_fmt->fmt.pix.width || + src_fmt->fmt.pix.height != dest_fmt->fmt.pix.height || + src_fmt->fmt.pix.pixelformat != dest_fmt->fmt.pix.pixelformat) return 1; /* Formats differ */ - if (!(data->flags & V4LCONVERT_UPSIDE_DOWN)) + if (!(data->flags & (V4LCONVERT_ROTATE_90|V4LCONVERT_ROTATE_180))) return 0; /* Formats identical and we don't need flip */ /* Formats are identical, but we need flip, do we support the dest_fmt? */ @@ -269,50 +442,35 @@ int v4lconvert_needs_conversion(struct v4lconvert_data *data, return 1; /* Needs flip and thus conversion */ } -int v4lconvert_convert(struct v4lconvert_data *data, - const struct v4l2_format *src_fmt, /* in */ - const struct v4l2_format *dest_fmt, /* in */ - unsigned char *src, int src_size, unsigned char *_dest, int dest_size) +static unsigned char *v4lconvert_alloc_buffer(struct v4lconvert_data *data, + int needed, unsigned char **buf, int *buf_size) { - unsigned int header_width, header_height; - int result, needed, rotate = 0, jpeg_flags = TINYJPEG_FLAGS_MJPEG_TABLE; - unsigned char *components[3]; - unsigned char *dest = _dest; - - /* Special case when no conversion is needed */ - if (!v4lconvert_needs_conversion(data, src_fmt, dest_fmt)) { - int to_copy = MIN(dest_size, src_size); - memcpy(dest, src, to_copy); - return to_copy; - } - - /* sanity check, is the dest buffer large enough? */ - switch (dest_fmt->fmt.pix.pixelformat) { - case V4L2_PIX_FMT_RGB24: - case V4L2_PIX_FMT_BGR24: - needed = dest_fmt->fmt.pix.width * dest_fmt->fmt.pix.height * 3; - break; - case V4L2_PIX_FMT_YUV420: - needed = (dest_fmt->fmt.pix.width * dest_fmt->fmt.pix.height * 3) / 2; - break; - default: - V4LCONVERT_ERR("Unknown dest format in conversion\n"); - errno = EINVAL; - return -1; - } - - if (dest_size < needed) { - V4LCONVERT_ERR("destination buffer too small\n"); - errno = EFAULT; - return -1; + if (*buf_size < needed) { + free(*buf); + *buf = malloc(needed); + if (*buf == NULL) { + *buf_size = 0; + V4LCONVERT_ERR("could not allocate memory\n"); + errno = ENOMEM; + return NULL; + } + *buf_size = needed; } + return *buf; +} - if (data->flags & V4LCONVERT_UPSIDE_DOWN) { - rotate = 180; - dest = alloca(needed); - } +static int v4lconvert_convert_pixfmt(struct v4lconvert_data *data, + unsigned char *src, int src_size, unsigned char *dest, + const struct v4l2_format *src_fmt, unsigned int dest_pix_fmt) +{ + unsigned int header_width, header_height; + int result = 0, jpeg_flags = TINYJPEG_FLAGS_MJPEG_TABLE; + unsigned char *components[3]; + unsigned int src_pix_fmt = src_fmt->fmt.pix.pixelformat; + unsigned int width = src_fmt->fmt.pix.width; + unsigned int height = src_fmt->fmt.pix.height; - switch (src_fmt->fmt.pix.pixelformat) { + switch (src_pix_fmt) { case V4L2_PIX_FMT_PJPG: jpeg_flags |= TINYJPEG_FLAGS_PIXART_JPEG; /* Fall through */ @@ -335,31 +493,27 @@ int v4lconvert_convert(struct v4lconvert_data *data, } tinyjpeg_get_size(data->jdec, &header_width, &header_height); - if (header_width != dest_fmt->fmt.pix.width || - header_height != dest_fmt->fmt.pix.height) { + if (header_width != width || header_height != height) { /* Check for (pixart) rotated JPEG */ - if (header_width == dest_fmt->fmt.pix.height || - header_height == dest_fmt->fmt.pix.width) { - if (!rotate) - dest = alloca(needed); - rotate += 90; + if (header_width == height && header_height == width) { + if (!(data->flags & V4LCONVERT_ROTATE_90)) { + V4LCONVERT_ERR("JPEG needs 90 degree rotation\n"); + data->flags |= V4LCONVERT_ROTATE_90; + errno = EAGAIN; + return -1; + } } else { V4LCONVERT_ERR("unexpected width / height in JPEG header" - "expected: %ux%u, header: %ux%u\n", - dest_fmt->fmt.pix.width, dest_fmt->fmt.pix.height, - header_width, header_height); + "expected: %ux%u, header: %ux%u\n", width, height, + header_width, header_height); errno = EIO; return -1; } } components[0] = dest; - components[1] = components[0] + dest_fmt->fmt.pix.width * - dest_fmt->fmt.pix.height; - components[2] = components[1] + (dest_fmt->fmt.pix.width * - dest_fmt->fmt.pix.height) / 4; - switch (dest_fmt->fmt.pix.pixelformat) { + switch (dest_pix_fmt) { case V4L2_PIX_FMT_RGB24: tinyjpeg_set_components(data->jdec, components, 1); result = tinyjpeg_decode(data->jdec, TINYJPEG_FMT_RGB24); @@ -368,7 +522,15 @@ int v4lconvert_convert(struct v4lconvert_data *data, tinyjpeg_set_components(data->jdec, components, 1); result = tinyjpeg_decode(data->jdec, TINYJPEG_FMT_BGR24); break; - default: + case V4L2_PIX_FMT_YUV420: + components[1] = components[0] + width * height; + components[2] = components[1] + width * height / 4; + tinyjpeg_set_components(data->jdec, components, 3); + result = tinyjpeg_decode(data->jdec, TINYJPEG_FMT_YUV420P); + break; + case V4L2_PIX_FMT_YVU420: + components[2] = components[0] + width * height; + components[1] = components[2] + width * height / 4; tinyjpeg_set_components(data->jdec, components, 3); result = tinyjpeg_decode(data->jdec, TINYJPEG_FMT_YUV420P); break; @@ -379,8 +541,8 @@ int v4lconvert_convert(struct v4lconvert_data *data, are best thrown away to avoid flashes in the video stream. Tell the upper layer this is an intermediate fault and it should try again with a new buffer by setting errno to EAGAIN */ - if (src_fmt->fmt.pix.pixelformat == V4L2_PIX_FMT_PJPG) { - V4LCONVERT_ERR("Error decompressing JPEG: %s", + if (src_pix_fmt == V4L2_PIX_FMT_PJPG) { + V4LCONVERT_ERR("decompressing JPEG: %s", tinyjpeg_get_errorstring(data->jdec)); errno = EAGAIN; return -1; @@ -394,223 +556,357 @@ int v4lconvert_convert(struct v4lconvert_data *data, } break; - case V4L2_PIX_FMT_SBGGR8: - case V4L2_PIX_FMT_SGBRG8: - case V4L2_PIX_FMT_SGRBG8: - case V4L2_PIX_FMT_SRGGB8: - switch (dest_fmt->fmt.pix.pixelformat) { - case V4L2_PIX_FMT_RGB24: - v4lconvert_bayer_to_rgb24(src, dest, dest_fmt->fmt.pix.width, - dest_fmt->fmt.pix.height, src_fmt->fmt.pix.pixelformat); - break; - case V4L2_PIX_FMT_BGR24: - v4lconvert_bayer_to_bgr24(src, dest, dest_fmt->fmt.pix.width, - dest_fmt->fmt.pix.height, src_fmt->fmt.pix.pixelformat); - break; - default: - v4lconvert_bayer_to_yuv420(src, dest, dest_fmt->fmt.pix.width, - dest_fmt->fmt.pix.height, src_fmt->fmt.pix.pixelformat); - break; - } - break; - - /* YUYV line by line formats */ + /* Custom cam specific YUV formats */ case V4L2_PIX_FMT_SPCA501: case V4L2_PIX_FMT_SPCA505: case V4L2_PIX_FMT_SPCA508: + case V4L2_PIX_FMT_SN9C20X_I420: { - unsigned char tmpbuf[dest_fmt->fmt.pix.width * dest_fmt->fmt.pix.height * - 3 / 2]; - unsigned char *my_dst = (dest_fmt->fmt.pix.pixelformat != - V4L2_PIX_FMT_YUV420) ? tmpbuf : dest; + unsigned char *d; + int yvu = 0; + + if (dest_pix_fmt != V4L2_PIX_FMT_YUV420 && + dest_pix_fmt != V4L2_PIX_FMT_YVU420) { + d = v4lconvert_alloc_buffer(data, width * height * 3 / 2, + &data->convert_pixfmt_buf, &data->convert_pixfmt_buf_size); + if (!d) + return -1; + } else + d = dest; - switch (src_fmt->fmt.pix.pixelformat) { + if (dest_pix_fmt == V4L2_PIX_FMT_YVU420) + yvu = 1; + + switch (src_pix_fmt) { case V4L2_PIX_FMT_SPCA501: - v4lconvert_spca501_to_yuv420(src, my_dst, dest_fmt->fmt.pix.width, - dest_fmt->fmt.pix.height); + v4lconvert_spca501_to_yuv420(src, d, width, height, yvu); break; case V4L2_PIX_FMT_SPCA505: - v4lconvert_spca505_to_yuv420(src, my_dst, dest_fmt->fmt.pix.width, - dest_fmt->fmt.pix.height); + v4lconvert_spca505_to_yuv420(src, d, width, height, yvu); break; case V4L2_PIX_FMT_SPCA508: - v4lconvert_spca508_to_yuv420(src, my_dst, dest_fmt->fmt.pix.width, - dest_fmt->fmt.pix.height); + v4lconvert_spca508_to_yuv420(src, d, width, height, yvu); + break; + case V4L2_PIX_FMT_SN9C20X_I420: + v4lconvert_sn9c20x_to_yuv420(src, d, width, height, yvu); break; } - switch (dest_fmt->fmt.pix.pixelformat) { + switch (dest_pix_fmt) { case V4L2_PIX_FMT_RGB24: - v4lconvert_yuv420_to_rgb24(tmpbuf, dest, dest_fmt->fmt.pix.width, - dest_fmt->fmt.pix.height); + v4lconvert_yuv420_to_rgb24(data->convert_pixfmt_buf, dest, width, + height, yvu); break; case V4L2_PIX_FMT_BGR24: - v4lconvert_yuv420_to_bgr24(tmpbuf, dest, dest_fmt->fmt.pix.width, - dest_fmt->fmt.pix.height); + v4lconvert_yuv420_to_bgr24(data->convert_pixfmt_buf, dest, width, + height, yvu); break; } break; } + /* Conexant cx2341x raw video macroblock format */ + case V4L2_PIX_FMT_HM12: + switch (dest_pix_fmt) { + case V4L2_PIX_FMT_RGB24: + v4lconvert_hm12_to_rgb24(src, dest, width, height); + break; + case V4L2_PIX_FMT_BGR24: + v4lconvert_hm12_to_bgr24(src, dest, width, height); + break; + case V4L2_PIX_FMT_YUV420: + v4lconvert_hm12_to_yuv420(src, dest, width, height, 0); + break; + case V4L2_PIX_FMT_YVU420: + v4lconvert_hm12_to_yuv420(src, dest, width, height, 1); + break; + } + break; + /* compressed bayer formats */ case V4L2_PIX_FMT_SPCA561: case V4L2_PIX_FMT_SN9C10X: case V4L2_PIX_FMT_PAC207: + case V4L2_PIX_FMT_MR97310A: + case V4L2_PIX_FMT_SQ905C: { - unsigned char tmpbuf[dest_fmt->fmt.pix.width*dest_fmt->fmt.pix.height]; - unsigned int bayer_fmt = 0; + unsigned char *tmpbuf; + + tmpbuf = v4lconvert_alloc_buffer(data, width * height, + &data->convert_pixfmt_buf, &data->convert_pixfmt_buf_size); + if (!tmpbuf) + return -1; - switch (src_fmt->fmt.pix.pixelformat) { + switch (src_pix_fmt) { case V4L2_PIX_FMT_SPCA561: - v4lconvert_decode_spca561(src, tmpbuf, dest_fmt->fmt.pix.width, - dest_fmt->fmt.pix.height); - bayer_fmt = V4L2_PIX_FMT_SGBRG8; + v4lconvert_decode_spca561(src, tmpbuf, width, height); + src_pix_fmt = V4L2_PIX_FMT_SGBRG8; break; case V4L2_PIX_FMT_SN9C10X: - v4lconvert_decode_sn9c10x(src, tmpbuf, dest_fmt->fmt.pix.width, - dest_fmt->fmt.pix.height); - bayer_fmt = V4L2_PIX_FMT_SBGGR8; + v4lconvert_decode_sn9c10x(src, tmpbuf, width, height); + src_pix_fmt = V4L2_PIX_FMT_SBGGR8; break; case V4L2_PIX_FMT_PAC207: - v4lconvert_decode_pac207(src, tmpbuf, dest_fmt->fmt.pix.width, - dest_fmt->fmt.pix.height); - bayer_fmt = V4L2_PIX_FMT_SBGGR8; + v4lconvert_decode_pac207(src, tmpbuf, width, height); + src_pix_fmt = V4L2_PIX_FMT_SBGGR8; + break; + case V4L2_PIX_FMT_MR97310A: + v4lconvert_decode_mr97310a(src, tmpbuf, width, height); + src_pix_fmt = V4L2_PIX_FMT_SBGGR8; + break; + case V4L2_PIX_FMT_SQ905C: + v4lconvert_decode_sq905c(src, tmpbuf, width, height); + src_pix_fmt = V4L2_PIX_FMT_SRGGB8; break; } + src = tmpbuf; + /* Deliberate fall through to raw bayer fmt code! */ + } - switch (dest_fmt->fmt.pix.pixelformat) { + /* Raw bayer formats */ + case V4L2_PIX_FMT_SBGGR8: + case V4L2_PIX_FMT_SGBRG8: + case V4L2_PIX_FMT_SGRBG8: + case V4L2_PIX_FMT_SRGGB8: + switch (dest_pix_fmt) { case V4L2_PIX_FMT_RGB24: - v4lconvert_bayer_to_rgb24(tmpbuf, dest, dest_fmt->fmt.pix.width, - dest_fmt->fmt.pix.height, bayer_fmt); + v4lconvert_bayer_to_rgb24(src, dest, width, height, src_pix_fmt); break; case V4L2_PIX_FMT_BGR24: - v4lconvert_bayer_to_bgr24(tmpbuf, dest, dest_fmt->fmt.pix.width, - dest_fmt->fmt.pix.height, bayer_fmt); + v4lconvert_bayer_to_bgr24(src, dest, width, height, src_pix_fmt); break; - default: - v4lconvert_bayer_to_yuv420(tmpbuf, dest, dest_fmt->fmt.pix.width, - dest_fmt->fmt.pix.height, bayer_fmt); + case V4L2_PIX_FMT_YUV420: + v4lconvert_bayer_to_yuv420(src, dest, width, height, src_pix_fmt, 0); + break; + case V4L2_PIX_FMT_YVU420: + v4lconvert_bayer_to_yuv420(src, dest, width, height, src_pix_fmt, 1); break; } break; - } case V4L2_PIX_FMT_RGB24: - switch (dest_fmt->fmt.pix.pixelformat) { + switch (dest_pix_fmt) { case V4L2_PIX_FMT_BGR24: - v4lconvert_swap_rgb(src, dest, dest_fmt->fmt.pix.width, - dest_fmt->fmt.pix.height); + v4lconvert_swap_rgb(src, dest, width, height); break; case V4L2_PIX_FMT_YUV420: - printf("FIXME add rgb24 -> yuv420 conversion\n"); + v4lconvert_rgb24_to_yuv420(src, dest, src_fmt, 0, 0); + break; + case V4L2_PIX_FMT_YVU420: + v4lconvert_rgb24_to_yuv420(src, dest, src_fmt, 0, 1); break; } break; + case V4L2_PIX_FMT_BGR24: - switch (dest_fmt->fmt.pix.pixelformat) { + switch (dest_pix_fmt) { case V4L2_PIX_FMT_RGB24: - v4lconvert_swap_rgb(src, dest, dest_fmt->fmt.pix.width, - dest_fmt->fmt.pix.height); + v4lconvert_swap_rgb(src, dest, width, height); break; case V4L2_PIX_FMT_YUV420: - printf("FIXME add bgr24 -> yuv420 conversion\n"); + v4lconvert_rgb24_to_yuv420(src, dest, src_fmt, 1, 0); + break; + case V4L2_PIX_FMT_YVU420: + v4lconvert_rgb24_to_yuv420(src, dest, src_fmt, 1, 1); break; } break; case V4L2_PIX_FMT_YUV420: - switch (dest_fmt->fmt.pix.pixelformat) { + switch (dest_pix_fmt) { case V4L2_PIX_FMT_RGB24: - v4lconvert_yuv420_to_rgb24(src, dest, dest_fmt->fmt.pix.width, - dest_fmt->fmt.pix.height); + v4lconvert_yuv420_to_rgb24(src, dest, width, + height, 0); break; case V4L2_PIX_FMT_BGR24: - v4lconvert_yuv420_to_bgr24(src, dest, dest_fmt->fmt.pix.width, - dest_fmt->fmt.pix.height); + v4lconvert_yuv420_to_bgr24(src, dest, width, + height, 0); + break; + case V4L2_PIX_FMT_YVU420: + v4lconvert_swap_uv(src, dest, src_fmt); break; } break; - case V4L2_PIX_FMT_YUYV: - switch (dest_fmt->fmt.pix.pixelformat) { + case V4L2_PIX_FMT_YVU420: + switch (dest_pix_fmt) { case V4L2_PIX_FMT_RGB24: - v4lconvert_yuyv_to_rgb24(src, dest, dest_fmt->fmt.pix.width, - dest_fmt->fmt.pix.height); + v4lconvert_yuv420_to_rgb24(src, dest, width, + height, 1); break; case V4L2_PIX_FMT_BGR24: - v4lconvert_yuyv_to_bgr24(src, dest, dest_fmt->fmt.pix.width, - dest_fmt->fmt.pix.height); + v4lconvert_yuv420_to_bgr24(src, dest, width, + height, 1); break; - default: - v4lconvert_yuyv_to_yuv420(src, dest, dest_fmt->fmt.pix.width, - dest_fmt->fmt.pix.height); + case V4L2_PIX_FMT_YUV420: + v4lconvert_swap_uv(src, dest, src_fmt); break; } break; - case V4L2_PIX_FMT_YVYU: - switch (dest_fmt->fmt.pix.pixelformat) { + case V4L2_PIX_FMT_YUYV: + switch (dest_pix_fmt) { case V4L2_PIX_FMT_RGB24: - v4lconvert_yvyu_to_rgb24(src, dest, dest_fmt->fmt.pix.width, - dest_fmt->fmt.pix.height); + v4lconvert_yuyv_to_rgb24(src, dest, width, height); break; case V4L2_PIX_FMT_BGR24: - v4lconvert_yvyu_to_bgr24(src, dest, dest_fmt->fmt.pix.width, - dest_fmt->fmt.pix.height); + v4lconvert_yuyv_to_bgr24(src, dest, width, height); break; - default: - v4lconvert_yvyu_to_yuv420(src, dest, dest_fmt->fmt.pix.width, - dest_fmt->fmt.pix.height); + case V4L2_PIX_FMT_YUV420: + v4lconvert_yuyv_to_yuv420(src, dest, width, height, 0); + break; + case V4L2_PIX_FMT_YVU420: + v4lconvert_yuyv_to_yuv420(src, dest, width, height, 1); break; } break; - default: - V4LCONVERT_ERR("Unknown src format in conversion\n"); - errno = EINVAL; - return -1; - } - - /* Note when rotating dest is our temporary buffer to which our conversion - was done and _dest is the real dest! If the formats are identical no - conversion has been done! */ - if (rotate && dest_fmt->fmt.pix.pixelformat == src_fmt->fmt.pix.pixelformat) - dest = src; - - switch (rotate) { - case 0: - break; - case 90: - switch (dest_fmt->fmt.pix.pixelformat) { + case V4L2_PIX_FMT_YVYU: + switch (dest_pix_fmt) { case V4L2_PIX_FMT_RGB24: + v4lconvert_yvyu_to_rgb24(src, dest, width, height); + break; case V4L2_PIX_FMT_BGR24: - v4lconvert_rotate90_rgbbgr24(dest, _dest, dest_fmt->fmt.pix.width, - dest_fmt->fmt.pix.height); + v4lconvert_yvyu_to_bgr24(src, dest, width, height); break; case V4L2_PIX_FMT_YUV420: - v4lconvert_rotate90_yuv420(dest, _dest, dest_fmt->fmt.pix.width, - dest_fmt->fmt.pix.height); + /* Note we use yuyv_to_yuv420 not v4lconvert_yvyu_to_yuv420, + with the last argument reversed to make it have as we want */ + v4lconvert_yuyv_to_yuv420(src, dest, width, height, 1); break; - } - break; - case 180: - switch (dest_fmt->fmt.pix.pixelformat) { + case V4L2_PIX_FMT_YVU420: + v4lconvert_yuyv_to_yuv420(src, dest, width, height, 0); + break; + } + break; + + case V4L2_PIX_FMT_UYVY: + switch (dest_pix_fmt) { case V4L2_PIX_FMT_RGB24: + v4lconvert_uyvy_to_rgb24(src, dest, width, height); + break; case V4L2_PIX_FMT_BGR24: - v4lconvert_rotate180_rgbbgr24(dest, _dest, dest_fmt->fmt.pix.width, - dest_fmt->fmt.pix.height); + v4lconvert_uyvy_to_bgr24(src, dest, width, height); break; case V4L2_PIX_FMT_YUV420: - v4lconvert_rotate180_yuv420(dest, _dest, dest_fmt->fmt.pix.width, - dest_fmt->fmt.pix.height); + v4lconvert_uyvy_to_yuv420(src, dest, width, height, 0); break; - } - break; - default: - printf("FIXME add %d degrees rotation\n", rotate); + case V4L2_PIX_FMT_YVU420: + v4lconvert_uyvy_to_yuv420(src, dest, width, height, 1); + break; + } + break; + + default: + V4LCONVERT_ERR("Unknown src format in conversion\n"); + errno = EINVAL; + return -1; + } + return 0; +} + +int v4lconvert_convert(struct v4lconvert_data *data, + const struct v4l2_format *src_fmt, /* in */ + const struct v4l2_format *dest_fmt, /* in */ + unsigned char *src, int src_size, unsigned char *dest, int dest_size) +{ + int res, dest_needed, temp_needed, convert = 0, rotate = 0, crop = 0; + unsigned char *convert_dest = dest, *rotate_src = src, *rotate_dest = dest; + unsigned char *crop_src = src; + struct v4l2_format my_src_fmt = *src_fmt; + struct v4l2_format my_dest_fmt = *dest_fmt; + + /* Special case when no conversion is needed */ + if (!v4lconvert_needs_conversion(data, src_fmt, dest_fmt)) { + int to_copy = MIN(dest_size, src_size); + memcpy(dest, src, to_copy); + return to_copy; + } + + /* When field is V4L2_FIELD_ALTERNATE, each buffer only contains half the + lines */ + if (my_src_fmt.fmt.pix.field == V4L2_FIELD_ALTERNATE) { + my_src_fmt.fmt.pix.height /= 2; + my_dest_fmt.fmt.pix.height /= 2; + } + + /* sanity check, is the dest buffer large enough? */ + switch (my_dest_fmt.fmt.pix.pixelformat) { + case V4L2_PIX_FMT_RGB24: + case V4L2_PIX_FMT_BGR24: + dest_needed = my_dest_fmt.fmt.pix.width * my_dest_fmt.fmt.pix.height * 3; + temp_needed = my_src_fmt.fmt.pix.width * my_src_fmt.fmt.pix.height * 3; + break; + case V4L2_PIX_FMT_YUV420: + case V4L2_PIX_FMT_YVU420: + dest_needed = + my_dest_fmt.fmt.pix.width * my_dest_fmt.fmt.pix.height * 3 / 2; + temp_needed = + my_src_fmt.fmt.pix.width * my_src_fmt.fmt.pix.height * 3 / 2; + break; + default: + V4LCONVERT_ERR("Unknown dest format in conversion\n"); + errno = EINVAL; + return -1; + } + + if (dest_size < dest_needed) { + V4LCONVERT_ERR("destination buffer too small\n"); + errno = EFAULT; + return -1; + } + + if (my_dest_fmt.fmt.pix.pixelformat != my_src_fmt.fmt.pix.pixelformat) + convert = 1; + + if (data->flags & V4LCONVERT_ROTATE_90) + rotate += 90; + if (data->flags & V4LCONVERT_ROTATE_180) + rotate += 180; + + if (my_dest_fmt.fmt.pix.width != my_src_fmt.fmt.pix.width || + my_dest_fmt.fmt.pix.height != my_src_fmt.fmt.pix.height) + crop = 1; + + /* convert_pixfmt -> rotate -> crop, all steps are optional */ + if (convert && (rotate || crop)) { + convert_dest = v4lconvert_alloc_buffer(data, temp_needed, + &data->convert_buf, &data->convert_buf_size); + if (!convert_dest) + return -1; + + rotate_src = crop_src = convert_dest; } - return needed; + if (rotate && crop) { + rotate_dest = v4lconvert_alloc_buffer(data, temp_needed, + &data->rotate_buf, &data->rotate_buf_size); + if (!rotate_dest) + return -1; + + crop_src = rotate_dest; + } + + if (convert) { + res = v4lconvert_convert_pixfmt(data, src, src_size, convert_dest, + &my_src_fmt, + my_dest_fmt.fmt.pix.pixelformat); + if (res) + return res; + + my_src_fmt.fmt.pix.pixelformat = my_dest_fmt.fmt.pix.pixelformat; + v4lconvert_fixup_fmt(&my_src_fmt); + } + + if (rotate) + v4lconvert_rotate(rotate_src, rotate_dest, + my_src_fmt.fmt.pix.width, my_src_fmt.fmt.pix.height, + my_src_fmt.fmt.pix.pixelformat, rotate); + + if (crop) + v4lconvert_crop(crop_src, dest, &my_src_fmt, &my_dest_fmt); + + return dest_needed; } const char *v4lconvert_get_error_message(struct v4lconvert_data *data) @@ -619,7 +915,7 @@ const char *v4lconvert_get_error_message(struct v4lconvert_data *data) } static void v4lconvert_get_framesizes(struct v4lconvert_data *data, - unsigned int pixelformat) + unsigned int pixelformat, int index) { int i, j, match; struct v4l2_frmsizeenum frmsize = { .pixel_format = pixelformat }; @@ -631,7 +927,7 @@ static void v4lconvert_get_framesizes(struct v4lconvert_data *data, /* We got a framesize, check we don't have the same one already */ match = 0; - for (j = 0; j < data->no_framesizes && !match; j++) { + for (j = 0; j < data->no_framesizes; j++) { if (frmsize.type != data->framesizes[j].type) continue; @@ -648,6 +944,8 @@ static void v4lconvert_get_framesizes(struct v4lconvert_data *data, match = 1; break; } + if (match) + break; } /* Add this framesize if it is not already in our list */ if (!match) { @@ -657,6 +955,9 @@ static void v4lconvert_get_framesizes(struct v4lconvert_data *data, return; } data->framesizes[data->no_framesizes].type = frmsize.type; + /* We use the pixel_format member to store a bitmask of all + supported src_formats which can do this size */ + data->framesizes[data->no_framesizes].pixel_format = 1 << index; switch(frmsize.type) { case V4L2_FRMSIZE_TYPE_DISCRETE: data->framesizes[data->no_framesizes].discrete = frmsize.discrete; @@ -668,6 +969,8 @@ static void v4lconvert_get_framesizes(struct v4lconvert_data *data, } data->no_framesizes++; } + else + data->framesizes[j].pixel_format |= 1 << index; } } @@ -702,8 +1005,12 @@ int v4lconvert_enum_frameintervals(struct v4lconvert_data *data, int res; struct v4l2_format src_fmt, dest_fmt; - if (!v4lconvert_supported_dst_format(frmival->pixel_format)) - return syscall(SYS_ioctl, data->fd, VIDIOC_ENUM_FRAMEINTERVALS, frmival); + if (!v4lconvert_supported_dst_format(frmival->pixel_format)) { + res = syscall(SYS_ioctl, data->fd, VIDIOC_ENUM_FRAMEINTERVALS, frmival); + if (res) + V4LCONVERT_ERR("%s\n", strerror(errno)); + return res; + } /* Check which format we will be using to convert to frmival->pixel_format */ memset(&dest_fmt, 0, sizeof(dest_fmt)); @@ -711,13 +1018,30 @@ int v4lconvert_enum_frameintervals(struct v4lconvert_data *data, dest_fmt.fmt.pix.pixelformat = frmival->pixel_format; dest_fmt.fmt.pix.width = frmival->width; dest_fmt.fmt.pix.height = frmival->height; - if ((res = v4lconvert_try_format(data, &dest_fmt, &src_fmt))) + if ((res = v4lconvert_try_format(data, &dest_fmt, &src_fmt))) { + if (res) + V4LCONVERT_ERR("trying format: %s\n", strerror(errno)); return res; + } /* Check the requested format is supported exactly as requested */ if (dest_fmt.fmt.pix.pixelformat != frmival->pixel_format || dest_fmt.fmt.pix.width != frmival->width || dest_fmt.fmt.pix.height != frmival->height) { + int frmival_pixformat = frmival->pixel_format; + int dest_pixformat = dest_fmt.fmt.pix.pixelformat; + V4LCONVERT_ERR("Could not find matching framesize for: %c%c%c%c %dx%d " + "closest match: %c%c%c%c %dx%d\n", + frmival_pixformat & 0xff, + (frmival_pixformat >> 8) & 0xff, + (frmival_pixformat >> 16) & 0xff, + frmival_pixformat >> 24, + frmival->width, frmival->height, + dest_pixformat & 0xff, + (dest_pixformat >> 8) & 0xff, + (dest_pixformat >> 16) & 0xff, + dest_pixformat >> 24, + dest_fmt.fmt.pix.width , dest_fmt.fmt.pix.height); errno = EINVAL; return -1; } @@ -727,6 +1051,23 @@ int v4lconvert_enum_frameintervals(struct v4lconvert_data *data, frmival->width = src_fmt.fmt.pix.width; frmival->height = src_fmt.fmt.pix.height; res = syscall(SYS_ioctl, data->fd, VIDIOC_ENUM_FRAMEINTERVALS, frmival); + if (res) { + int dest_pixfmt = dest_fmt.fmt.pix.pixelformat; + int src_pixfmt = src_fmt.fmt.pix.pixelformat; + V4LCONVERT_ERR("Could not enum frameival index: %d for: %c%c%c%c %dx%d " + "using src: %c%c%c%c %dx%d, error: %s\n", + frmival->index, + dest_pixfmt & 0xff, + (dest_pixfmt >> 8) & 0xff, + (dest_pixfmt >> 16) & 0xff, + dest_pixfmt >> 24, + dest_fmt.fmt.pix.width , dest_fmt.fmt.pix.height, + src_pixfmt & 0xff, + (src_pixfmt >> 8) & 0xff, + (src_pixfmt >> 16) & 0xff, + src_pixfmt >> 24, + src_fmt.fmt.pix.width, src_fmt.fmt.pix.height, strerror(errno)); + } /* Restore the requested format in the frmival struct */ frmival->pixel_format = dest_fmt.fmt.pix.pixelformat; diff --git a/v4l2-apps/libv4l/libv4lconvert/mr97310a.c b/v4l2-apps/libv4l/libv4lconvert/mr97310a.c new file mode 100644 index 000000000..e6ce94b29 --- /dev/null +++ b/v4l2-apps/libv4l/libv4lconvert/mr97310a.c @@ -0,0 +1,172 @@ +/* + * MR97310A decoder + * + * Copyright (C) 2004 Theodore Kilgore <kilgota@auburn.edu> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include "libv4lconvert-priv.h" + +#define CLIP(x) ((x)<0?0:((x)>0xff)?0xff:(x)) + +/* FIXME not threadsafe */ +static int decoder_initialized = 0; + +static struct { + unsigned char is_abs; + unsigned char len; + signed char val; +} table[256]; + +static void init_mr97310a_decoder(void) +{ + int i; + int is_abs, val, len; + + for (i = 0; i < 256; ++i) { + is_abs = 0; + val = 0; + len = 0; + if ((i & 0x80) == 0) { + /* code 0 */ + val = 0; + len = 1; + } else if ((i & 0xe0) == 0xc0) { + /* code 110 */ + val = -3; + len = 3; + } else if ((i & 0xe0) == 0xa0) { + /* code 101 */ + val = +3; + len = 3; + } else if ((i & 0xf0) == 0x80) { + /* code 1000 */ + val = +7; + len = 4; + } else if ((i & 0xf0) == 0x90) { + /* code 1001 */ + val = -7; + len = 4; + } else if ((i & 0xf0) == 0xf0) { + /* code 1111 */ + val = -15; + len = 4; + } else if ((i & 0xf8) == 0xe0) { + /* code 11100 */ + val = +15; + len = 5; + } else if ((i & 0xf8) == 0xe8) { + /* code 11101xxxxx */ + is_abs = 1; + val = 0; /* value is calculated later */ + len = 5; + } + table[i].is_abs = is_abs; + table[i].val = val; + table[i].len = len; + } + decoder_initialized = 1; +} + +static inline unsigned char get_byte(const unsigned char *inp, + unsigned int bitpos) +{ + const unsigned char *addr; + addr = inp + (bitpos >> 3); + return (addr[0] << (bitpos & 7)) | (addr[1] >> (8 - (bitpos & 7))); +} + +void v4lconvert_decode_mr97310a(const unsigned char *inp, unsigned char *outp, + int width, int height) +{ + int row, col; + int val; + int bitpos; + unsigned char code; + unsigned char lp, tp, tlp, trp; + + if (!decoder_initialized) + init_mr97310a_decoder(); + + /* remove the header */ + inp += 12; + + bitpos = 0; + + /* main decoding loop */ + for (row = 0; row < height; ++row) { + col = 0; + + /* first two pixels in first two rows are stored as raw 8-bit */ + if (row < 2) { + code = get_byte(inp, bitpos); + bitpos += 8; + *outp++ = code; + + code = get_byte(inp, bitpos); + bitpos += 8; + *outp++ = code; + + col += 2; + } + + while (col < width) { + /* get bitcode */ + code = get_byte(inp, bitpos); + /* update bit position */ + bitpos += table[code].len; + + /* calculate pixel value */ + if (table[code].is_abs) { + /* get 5 more bits and use them as absolute value */ + code = get_byte(inp, bitpos); + val = (code & 0xf8); + bitpos += 5; + + } else { + /* value is relative to top or left pixel */ + val = table[code].val; + lp = outp[-2]; + if (row > 1) { + tlp = outp[-2*width-2]; + tp = outp[-2*width]; + trp = outp[-2*width+2]; + } + if (row < 2) { + /* top row: relative to left pixel */ + val += lp; + } else if (col < 2) { + /* left column: relative to top pixel */ + /* initial estimate */ + val += (2*tp + 2*trp + 1)/4; + } else if (col > width - 3) { + /* left column: relative to top pixel */ + val += (2*tp + 2*tlp + 1)/4; + /* main area: average of left and top pixel */ + } else { + /* initial estimate for predictor */ + val += (2*lp + tp + trp + 1)/4; + } + } + /* store pixel */ + *outp++ = CLIP(val); + ++col; + } + } + + return; +} diff --git a/v4l2-apps/libv4l/libv4lconvert/rgbyuv.c b/v4l2-apps/libv4l/libv4lconvert/rgbyuv.c index 0f26b227a..00706be9d 100644 --- a/v4l2-apps/libv4l/libv4lconvert/rgbyuv.c +++ b/v4l2-apps/libv4l/libv4lconvert/rgbyuv.c @@ -20,13 +20,65 @@ */ +#include <string.h> #include "libv4lconvert-priv.h" -#define RGB2YUV(r,g,b,y,u,v) \ - (y) = (( 8453*(r) + 16594*(g) + 3223*(b) + 524288) >> 15); \ +#define RGB2Y(r,g,b,y) \ + (y) = (( 8453*(r) + 16594*(g) + 3223*(b) + 524288) >> 15) + +#define RGB2UV(r,g,b,u,v) \ (u) = (( -4878*(r) - 9578*(g) + 14456*(b) + 4210688) >> 15); \ (v) = (( 14456*(r) - 12105*(g) - 2351*(b) + 4210688) >> 15) +void v4lconvert_rgb24_to_yuv420(const unsigned char *src, unsigned char *dest, + const struct v4l2_format *src_fmt, int bgr, int yvu) +{ + int x, y; + unsigned char *udest, *vdest; + + /* Y */ + for (y = 0; y < src_fmt->fmt.pix.height; y++) { + for (x = 0; x < src_fmt->fmt.pix.width; x++) { + if (bgr) { + RGB2Y(src[2], src[1], src[0], *dest++); + } else { + RGB2Y(src[0], src[1], src[2], *dest++); + } + src += 3; + } + src += src_fmt->fmt.pix.bytesperline - 3 * src_fmt->fmt.pix.width; + } + src -= src_fmt->fmt.pix.height * src_fmt->fmt.pix.bytesperline; + + /* U + V */ + if (yvu) { + vdest = dest; + udest = dest + src_fmt->fmt.pix.width * src_fmt->fmt.pix.height / 4; + } else { + udest = dest; + vdest = dest + src_fmt->fmt.pix.width * src_fmt->fmt.pix.height / 4; + } + + for (y = 0; y < src_fmt->fmt.pix.height / 2; y++) { + for (x = 0; x < src_fmt->fmt.pix.width / 2; x++) { + int avg_src[3]; + avg_src[0] = (src[0] + src[3] + src[src_fmt->fmt.pix.bytesperline] + + src[src_fmt->fmt.pix.bytesperline + 3]) / 4; + avg_src[1] = (src[1] + src[4] + src[src_fmt->fmt.pix.bytesperline + 1] + + src[src_fmt->fmt.pix.bytesperline + 4]) / 4; + avg_src[2] = (src[2] + src[5] + src[src_fmt->fmt.pix.bytesperline + 2] + + src[src_fmt->fmt.pix.bytesperline + 5]) / 4; + if (bgr) { + RGB2UV(avg_src[2], avg_src[1], avg_src[0], *udest++, *vdest++); + } else { + RGB2UV(avg_src[0], avg_src[1], avg_src[2], *udest++, *vdest++); + } + src += 6; + } + src += 2 * src_fmt->fmt.pix.bytesperline - 3 * src_fmt->fmt.pix.width; + } +} + #define YUV2R(y, u, v) ({ \ int r = (y) + ((((v)-128)*1436) >> 10); r > 255 ? 255 : r < 0 ? 0 : r; }) #define YUV2G(y, u, v) ({ \ @@ -37,13 +89,20 @@ #define CLIP(color) (unsigned char)(((color)>0xFF)?0xff:(((color)<0)?0:(color))) void v4lconvert_yuv420_to_bgr24(const unsigned char *src, unsigned char *dest, - int width, int height) + int width, int height, int yvu) { int i,j; const unsigned char *ysrc = src; - const unsigned char *usrc = src + width * height; - const unsigned char *vsrc = usrc + (width * height) / 4; + const unsigned char *usrc, *vsrc; + + if (yvu) { + vsrc = src + width * height; + usrc = vsrc + (width * height) / 4; + } else { + usrc = src + width * height; + vsrc = usrc + (width * height) / 4; + } for (i = 0; i < height; i++) { for (j = 0; j < width; j += 2) { @@ -84,13 +143,20 @@ void v4lconvert_yuv420_to_bgr24(const unsigned char *src, unsigned char *dest, } void v4lconvert_yuv420_to_rgb24(const unsigned char *src, unsigned char *dest, - int width, int height) + int width, int height, int yvu) { int i,j; const unsigned char *ysrc = src; - const unsigned char *usrc = src + width * height; - const unsigned char *vsrc = usrc + (width * height) / 4; + const unsigned char *usrc, *vsrc; + + if (yvu) { + vsrc = src + width * height; + usrc = vsrc + (width * height) / 4; + } else { + usrc = src + width * height; + vsrc = usrc + (width * height) / 4; + } for (i = 0; i < height; i++) { for (j = 0; j < width; j += 2) { @@ -183,11 +249,11 @@ void v4lconvert_yuyv_to_rgb24(const unsigned char *src, unsigned char *dest, } void v4lconvert_yuyv_to_yuv420(const unsigned char *src, unsigned char *dest, - int width, int height) + int width, int height, int yvu) { int i, j; const unsigned char *src1; - unsigned char *vdest; + unsigned char *udest, *vdest; /* copy the Y values */ src1 = src; @@ -202,10 +268,16 @@ void v4lconvert_yuyv_to_yuv420(const unsigned char *src, unsigned char *dest, /* copy the U and V values */ src++; /* point to V */ src1 = src + width * 2; /* next line */ - vdest = dest + width * height / 4; + if (yvu) { + vdest = dest; + udest = dest + width * height / 4; + } else { + udest = dest; + vdest = dest + width * height / 4; + } for (i = 0; i < height; i += 2) { for (j = 0; j < width; j += 2) { - *dest++ = ((int) src[0] + src1[0]) / 2; /* U */ + *udest++ = ((int) src[0] + src1[0]) / 2; /* U */ *vdest++ = ((int) src[2] + src1[2]) / 2; /* V */ src += 4; src1 += 4; @@ -267,19 +339,71 @@ void v4lconvert_yvyu_to_rgb24(const unsigned char *src, unsigned char *dest, } } -void v4lconvert_yvyu_to_yuv420(const unsigned char *src, unsigned char *dest, +void v4lconvert_uyvy_to_bgr24(const unsigned char *src, unsigned char *dest, + int width, int height) +{ + int j; + + while (--height >= 0) { + for (j = 0; j < width; j += 2) { + int u = src[0]; + int v = src[2]; + int u1 = (((u - 128) << 7) + (u - 128)) >> 6; + int rg = (((u - 128) << 1) + (u - 128) + + ((v - 128) << 2) + ((v - 128) << 1)) >> 3; + int v1 = (((v - 128) << 1) + (v - 128)) >> 1; + + *dest++ = CLIP(src[1] + u1); + *dest++ = CLIP(src[1] - rg); + *dest++ = CLIP(src[1] + v1); + + *dest++ = CLIP(src[3] + u1); + *dest++ = CLIP(src[3] - rg); + *dest++ = CLIP(src[3] + v1); + src += 4; + } + } +} + +void v4lconvert_uyvy_to_rgb24(const unsigned char *src, unsigned char *dest, int width, int height) { + int j; + + while (--height >= 0) { + for (j = 0; j < width; j += 2) { + int u = src[0]; + int v = src[2]; + int u1 = (((u - 128) << 7) + (u - 128)) >> 6; + int rg = (((u - 128) << 1) + (u - 128) + + ((v - 128) << 2) + ((v - 128) << 1)) >> 3; + int v1 = (((v - 128) << 1) + (v - 128)) >> 1; + + *dest++ = CLIP(src[1] + v1); + *dest++ = CLIP(src[1] - rg); + *dest++ = CLIP(src[1] + u1); + + *dest++ = CLIP(src[3] + v1); + *dest++ = CLIP(src[3] - rg); + *dest++ = CLIP(src[3] + u1); + src += 4; + } + } +} + +void v4lconvert_uyvy_to_yuv420(const unsigned char *src, unsigned char *dest, + int width, int height, int yvu) +{ int i, j; const unsigned char *src1; - unsigned char *vdest; + unsigned char *udest, *vdest; /* copy the Y values */ src1 = src; for (i = 0; i < height; i++) { for (j = 0; j < width; j += 2) { - *dest++ = src1[0]; - *dest++ = src1[2]; + *dest++ = src1[1]; + *dest++ = src1[3]; src1 += 4; } } @@ -287,11 +411,17 @@ void v4lconvert_yvyu_to_yuv420(const unsigned char *src, unsigned char *dest, /* copy the U and V values */ src++; /* point to V */ src1 = src + width * 2; /* next line */ - vdest = dest + width * height / 4; + if (yvu) { + vdest = dest; + udest = dest + width * height / 4; + } else { + udest = dest; + vdest = dest + width * height / 4; + } for (i = 0; i < height; i += 2) { for (j = 0; j < width; j += 2) { - *dest++ = ((int) src[2] + src1[2]) / 2; /* U */ - *vdest++ = ((int) src[0] + src1[0]) / 2; /* V */ + *udest++ = ((int) src[0] + src1[0]) / 2; /* U */ + *vdest++ = ((int) src[2] + src1[2]) / 2; /* V */ src += 4; src1 += 4; } @@ -314,3 +444,32 @@ void v4lconvert_swap_rgb(const unsigned char *src, unsigned char *dst, *dst++ = tmp0; } } + +void v4lconvert_swap_uv(const unsigned char *src, unsigned char *dest, + const struct v4l2_format *src_fmt) +{ + int y; + + /* Copy Y */ + for (y = 0; y < src_fmt->fmt.pix.height; y++) { + memcpy(dest, src, src_fmt->fmt.pix.width); + dest += src_fmt->fmt.pix.width; + src += src_fmt->fmt.pix.bytesperline; + } + + /* Copy component 2 */ + src += src_fmt->fmt.pix.height * src_fmt->fmt.pix.bytesperline / 4; + for (y = 0; y < src_fmt->fmt.pix.height / 2; y++) { + memcpy(dest, src, src_fmt->fmt.pix.width / 2); + dest += src_fmt->fmt.pix.width / 2; + src += src_fmt->fmt.pix.bytesperline / 2; + } + + /* Copy component 1 */ + src -= src_fmt->fmt.pix.height * src_fmt->fmt.pix.bytesperline / 2; + for (y = 0; y < src_fmt->fmt.pix.height / 2; y++) { + memcpy(dest, src, src_fmt->fmt.pix.width / 2); + dest += src_fmt->fmt.pix.width / 2; + src += src_fmt->fmt.pix.bytesperline / 2; + } +} diff --git a/v4l2-apps/libv4l/libv4lconvert/sn9c20x.c b/v4l2-apps/libv4l/libv4lconvert/sn9c20x.c new file mode 100644 index 000000000..19951300f --- /dev/null +++ b/v4l2-apps/libv4l/libv4lconvert/sn9c20x.c @@ -0,0 +1,137 @@ +/* + * Sonix SN9C20X decoder + * Vasily Khoruzhick, (C) 2008-2009 + * Algorithm based on Java code written by Jens on microdia google group + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Note this code was originally licensed under the GNU GPL instead of the + * GNU LGPL, its license has been changed by its author. + */ + +#include "libv4lconvert-priv.h" + +#define DO_SANITY_CHECKS 0 + +static const int UVTranslate[32] = {0, 1, 2, 3, + 8, 9, 10, 11, + 16, 17, 18, 19, + 24, 25, 26, 27, + 4, 5, 6, 7, + 12, 13, 14, 15, + 20, 21, 22, 23, + 28, 29, 30, 31}; + +static const int Y_coords_624x[128][2] = { +{ 0, 0}, { 1, 0}, { 2, 0}, { 3, 0}, { 4, 0}, { 5, 0}, { 6, 0}, { 7, 0}, +{ 0, 1}, { 1, 1}, { 2, 1}, { 3, 1}, { 4, 1}, { 5, 1}, { 6, 1}, { 7, 1}, +{ 0, 2}, { 1, 2}, { 2, 2}, { 3, 2}, { 4, 2}, { 5, 2}, { 6, 2}, { 7, 2}, +{ 0, 3}, { 1, 3}, { 2, 3}, { 3, 3}, { 4, 3}, { 5, 3}, { 6, 3}, { 7, 3}, + +{ 0, 4}, { 1, 4}, { 2, 4}, { 3, 4}, { 4, 4}, { 5, 4}, { 6, 4}, { 7, 4}, +{ 0, 5}, { 1, 5}, { 2, 5}, { 3, 5}, { 4, 5}, { 5, 5}, { 6, 5}, { 7, 5}, +{ 0, 6}, { 1, 6}, { 2, 6}, { 3, 6}, { 4, 6}, { 5, 6}, { 6, 6}, { 7, 6}, +{ 0, 7}, { 1, 7}, { 2, 7}, { 3, 7}, { 4, 7}, { 5, 7}, { 6, 7}, { 7, 7}, + +{ 8, 0}, { 9, 0}, {10, 0}, {11, 0}, {12, 0}, {13, 0}, {14, 0}, {15, 0}, +{ 8, 1}, { 9, 1}, {10, 1}, {11, 1}, {12, 1}, {13, 1}, {14, 1}, {15, 1}, +{ 8, 2}, { 9, 2}, {10, 2}, {11, 2}, {12, 2}, {13, 2}, {14, 2}, {15, 2}, +{ 8, 3}, { 9, 3}, {10, 3}, {11, 3}, {12, 3}, {13, 3}, {14, 3}, {15, 3}, + +{ 8, 4}, { 9, 4}, {10, 4}, {11, 4}, {12, 4}, {13, 4}, {14, 4}, {15, 4}, +{ 8, 5}, { 9, 5}, {10, 5}, {11, 5}, {12, 5}, {13, 5}, {14, 5}, {15, 5}, +{ 8, 6}, { 9, 6}, {10, 6}, {11, 6}, {12, 6}, {13, 6}, {14, 6}, {15, 6}, +{ 8, 7}, { 9, 7}, {10, 7}, {11, 7}, {12, 7}, {13, 7}, {14, 7}, {15, 7} +}; + +static void do_write_u(const unsigned char *buf, unsigned char *ptr, + int i, int j) +{ + *ptr = buf[i + 128 + j]; +} + +static void do_write_v(const unsigned char *buf, unsigned char *ptr, + int i, int j) +{ + *ptr = buf[i + 160 + j]; +} + +void v4lconvert_sn9c20x_to_yuv420(const unsigned char *raw, unsigned char *i420, + int width, int height, int yvu) +{ + int i = 0, x = 0, y = 0, j, relX, relY, x_div2, y_div2; + const unsigned char *buf = raw; + unsigned char *ptr; + int frame_size = width * height; + int frame_size_div2 = frame_size >> 1; + int frame_size_div4 = frame_size >> 2; + int width_div2 = width >> 1; + int height_div2 = height >> 1; + void (*do_write_uv1)(const unsigned char *buf, unsigned char *ptr, int i, + int j) = NULL; + void (*do_write_uv2)(const unsigned char *buf, unsigned char *ptr, int i, + int j) = NULL; + + if (yvu) { + do_write_uv1 = do_write_v; + do_write_uv2 = do_write_u; + } + else { + do_write_uv1 = do_write_u; + do_write_uv2 = do_write_v; + } + + while (i < (frame_size + frame_size_div2)) { + for (j = 0; j < 128; j++) { + relX = x + Y_coords_624x[j][0]; + relY = y + Y_coords_624x[j][1]; + +#if (DO_SANITY_CHECKS==1) + if ((relX < width) && (relY < height)) { +#endif + ptr = i420 + relY * width + relX; + *ptr = buf[i + j]; +#if (DO_SANITY_CHECKS==1) + } +#endif + + } + x_div2 = x >> 1; + y_div2 = y >> 1; + for (j = 0; j < 32; j++) { + relX = (x_div2) + (j & 0x07); + relY = (y_div2) + (j >> 3); + +#if (DO_SANITY_CHECKS==1) + if ((relX < width_div2) && (relY < height_div2)) { +#endif + ptr = i420 + frame_size + + relY * width_div2 + relX; + do_write_uv1(buf, ptr, i, j); + ptr += frame_size_div4; + do_write_uv2(buf, ptr, i, j); +#if (DO_SANITY_CHECKS==1) + } +#endif + } + + i += 192; + x += 16; + if (x >= width) { + x = 0; + y += 8; + } + } +} diff --git a/v4l2-apps/libv4l/libv4lconvert/spca501.c b/v4l2-apps/libv4l/libv4lconvert/spca501.c index 9157629e3..f491512e3 100644 --- a/v4l2-apps/libv4l/libv4lconvert/spca501.c +++ b/v4l2-apps/libv4l/libv4lconvert/spca501.c @@ -20,7 +20,7 @@ /* YUYV per line */ void v4lconvert_spca501_to_yuv420(const unsigned char *src, unsigned char *dst, - int width, int height) + int width, int height, int yvu) { int i,j; unsigned long *lsrc = (unsigned long *)src; @@ -34,7 +34,10 @@ void v4lconvert_spca501_to_yuv420(const unsigned char *src, unsigned char *dst, } /* -128 - 127 --> 0 - 255 and copy 1 line U */ - ldst = (unsigned long *)(dst + width * height + i * width / 4); + if (yvu) + ldst = (unsigned long *)(dst + (width * height * 5) / 4 + i * width / 4); + else + ldst = (unsigned long *)(dst + width * height + i * width / 4); for (j = 0; j < width/2; j += sizeof(long)) { *ldst = *lsrc++; *ldst++ ^= 0x8080808080808080ULL; @@ -48,7 +51,10 @@ void v4lconvert_spca501_to_yuv420(const unsigned char *src, unsigned char *dst, } /* -128 - 127 --> 0 - 255 and copy 1 line V */ - ldst = (unsigned long *)(dst + (width * height * 5) / 4 + i * width / 4); + if (yvu) + ldst = (unsigned long *)(dst + width * height + i * width / 4); + else + ldst = (unsigned long *)(dst + (width * height * 5) / 4 + i * width / 4); for (j = 0; j < width/2; j += sizeof(long)) { *ldst = *lsrc++; *ldst++ ^= 0x8080808080808080ULL; @@ -58,7 +64,7 @@ void v4lconvert_spca501_to_yuv420(const unsigned char *src, unsigned char *dst, /* YYUV per line */ void v4lconvert_spca505_to_yuv420(const unsigned char *src, unsigned char *dst, - int width, int height) + int width, int height, int yvu) { int i,j; unsigned long *lsrc = (unsigned long *)src; @@ -72,14 +78,20 @@ void v4lconvert_spca505_to_yuv420(const unsigned char *src, unsigned char *dst, } /* -128 - 127 --> 0 - 255 and copy 1 line U */ - ldst = (unsigned long *)(dst + width * height + i * width / 4); + if (yvu) + ldst = (unsigned long *)(dst + (width * height * 5) / 4 + i * width / 4); + else + ldst = (unsigned long *)(dst + width * height + i * width / 4); for (j = 0; j < width/2; j += sizeof(long)) { *ldst = *lsrc++; *ldst++ ^= 0x8080808080808080ULL; } /* -128 - 127 --> 0 - 255 and copy 1 line V */ - ldst = (unsigned long *)(dst + (width * height * 5) / 4 + i * width / 4); + if (yvu) + ldst = (unsigned long *)(dst + width * height + i * width / 4); + else + ldst = (unsigned long *)(dst + (width * height * 5) / 4 + i * width / 4); for (j = 0; j < width/2; j += sizeof(long)) { *ldst = *lsrc++; *ldst++ ^= 0x8080808080808080ULL; @@ -89,7 +101,7 @@ void v4lconvert_spca505_to_yuv420(const unsigned char *src, unsigned char *dst, /* YUVY per line */ void v4lconvert_spca508_to_yuv420(const unsigned char *src, unsigned char *dst, - int width, int height) + int width, int height, int yvu) { int i,j; unsigned long *lsrc = (unsigned long *)src; @@ -103,14 +115,20 @@ void v4lconvert_spca508_to_yuv420(const unsigned char *src, unsigned char *dst, } /* -128 - 127 --> 0 - 255 and copy 1 line U */ - ldst = (unsigned long *)(dst + width * height + i * width / 4); + if (yvu) + ldst = (unsigned long *)(dst + (width * height * 5) / 4 + i * width / 4); + else + ldst = (unsigned long *)(dst + width * height + i * width / 4); for (j = 0; j < width/2; j += sizeof(long)) { *ldst = *lsrc++; *ldst++ ^= 0x8080808080808080ULL; } /* -128 - 127 --> 0 - 255 and copy 1 line V */ - ldst = (unsigned long *)(dst + (width * height * 5) / 4 + i * width / 4); + if (yvu) + ldst = (unsigned long *)(dst + width * height + i * width / 4); + else + ldst = (unsigned long *)(dst + (width * height * 5) / 4 + i * width / 4); for (j = 0; j < width/2; j += sizeof(long)) { *ldst = *lsrc++; *ldst++ ^= 0x8080808080808080ULL; diff --git a/v4l2-apps/libv4l/libv4lconvert/sq905c.c b/v4l2-apps/libv4l/libv4lconvert/sq905c.c new file mode 100644 index 000000000..a73b4da93 --- /dev/null +++ b/v4l2-apps/libv4l/libv4lconvert/sq905c.c @@ -0,0 +1,217 @@ +/* + * sq905c.c + * + * Here is the decompression function for the SQ905C cameras. The functions + * used are adapted from the libgphoto2 functions for the same cameras, + * which was + * Copyright (c) 2005 and 2007 Theodore Kilgore <kilgota@auburn.edu> + * This version for libv4lconvert is + * Copyright (c) 2009 Theodore Kilgore <kilgota@auburn.edu> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include <stdlib.h> + +#include "libv4lconvert-priv.h" + + +#define CLIP(x) ((x) < 0 ? 0 : ((x) > 0xff) ? 0xff : (x)) + + +static int +sq905c_first_decompress(unsigned char *output, const unsigned char *input, + unsigned int outputsize) +{ + unsigned char parity = 0; + unsigned char nibble_to_keep[2]; + unsigned char temp1 = 0, temp2 = 0; + unsigned char input_byte; + unsigned char lookup = 0; + unsigned int i = 0; + unsigned int bytes_used = 0; + unsigned int bytes_done = 0; + unsigned int bit_counter = 8; + unsigned int cycles = 0; + int table[9] = { -1, 0, 2, 6, 0x0e, 0x0e, 0x0e, 0x0e, 0xfb}; + unsigned char lookup_table[16] + = {0, 2, 6, 0x0e, 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, + 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb}; + unsigned char translator[16] = {8, 7, 9, 6, 10, 11, 12, 13, + 14, 15, 5, 4, 3, 2, 1, 0}; + + nibble_to_keep[0] = 0; + nibble_to_keep[1] = 0; + + while (bytes_done < outputsize) { + while (parity < 2) { + while (lookup > table[cycles]) { + if (bit_counter == 8) { + input_byte = input[bytes_used]; + bytes_used++; + temp1 = input_byte; + bit_counter = 0; + } + input_byte = temp1; + temp2 = (temp2 << 1) & 0xFF; + input_byte = input_byte >> 7; + temp2 = temp2 | input_byte; + temp1 = (temp1 << 1) & 0xFF; + bit_counter++; + cycles++; + if (cycles > 9) + return -1; + lookup = temp2 & 0xff; + } + temp2 = 0; + for (i = 0; i < 17; i++) { + if (lookup == lookup_table[i]) { + nibble_to_keep[parity] = translator[i]; + break; + } + if (i == 16) + return -1; + } + cycles = 0; + parity++; + } + output[bytes_done] = (nibble_to_keep[0]<<4)|nibble_to_keep[1]; + bytes_done++; + parity = 0; + } + return 0; +} + +static int +sq905c_second_decompress(unsigned char *uncomp, unsigned char *in, + int width, int height) +{ + int diff = 0; + int tempval = 0; + int i, m, parity; + unsigned char delta_left = 0; + unsigned char delta_right = 0; + int input_counter = 0; + int delta_table[] = {-144, -110, -77, -53, -35, -21, -11, -3, + 2, 10, 20, 34, 52, 76, 110, 144}; + unsigned char *templine_red; + unsigned char *templine_green; + unsigned char *templine_blue; + templine_red = malloc(width); + if (!templine_red) { + free(templine_red); + return -1; + } + for (i = 0; i < width; i++) + templine_red[i] = 0x80; + templine_green = malloc(width); + if (!templine_green) { + free(templine_green); + return -1; + } + for (i = 0; i < width; i++) + templine_green[i] = 0x80; + templine_blue = malloc(width); + if (!templine_blue) { + free(templine_blue); + return -1; + } + for (i = 0; i < width; i++) + templine_blue[i] = 0x80; + for (m = 0; m < height/2; m++) { + /* First we do an even-numbered line */ + for (i = 0; i < width/2; i++) { + parity = i&1; + delta_right = in[input_counter] & 0x0f; + delta_left = (in[input_counter]>>4)&0xff; + input_counter++; + /* left pixel (red) */ + diff = delta_table[delta_left]; + if (!i) + tempval = templine_red[0] + diff; + else + tempval = (templine_red[i] + + uncomp[2*m*width+2*i-2])/2 + diff; + tempval = CLIP(tempval); + uncomp[2*m*width+2*i] = tempval; + templine_red[i] = tempval; + /* right pixel (green) */ + diff = delta_table[delta_right]; + if (!i) + tempval = templine_green[1] + diff; + else if (2*i == width - 2) + tempval = (templine_green[i] + + uncomp[2*m*width+2*i-1])/2 + + diff; + else + tempval = (templine_green[i+1] + + uncomp[2*m*width+2*i-1])/2 + + diff; + tempval = CLIP(tempval); + uncomp[2*m*width+2*i+1] = tempval; + templine_green[i] = tempval; + } + /* then an odd-numbered line */ + for (i = 0; i < width/2; i++) { + delta_right = in[input_counter] & 0x0f; + delta_left = (in[input_counter]>>4) & 0xff; + input_counter++; + /* left pixel (green) */ + diff = delta_table[delta_left]; + if (!i) + tempval = templine_green[0] + diff; + else + tempval = (templine_green[i] + + uncomp[(2*m+1)*width+2*i-2])/2 + + diff; + tempval = CLIP(tempval); + uncomp[(2*m+1)*width+2*i] = tempval; + templine_green[i] = tempval; + /* right pixel (blue) */ + diff = delta_table[delta_right]; + if (!i) + tempval = templine_blue[0] + diff; + else + tempval = (templine_blue[i] + + uncomp[(2*m+1)*width+2*i-1])/2 + + diff; + tempval = CLIP(tempval); + uncomp[(2*m+1)*width+2*i+1] = tempval; + templine_blue[i] = tempval; + } + } + free(templine_green); + free(templine_red); + free(templine_blue); + return 0; +} + +void v4lconvert_decode_sq905c(const unsigned char *src, unsigned char *dst, + int width, int height) +{ + int size; + unsigned char *temp_data; + const unsigned char *raw; + /* here we get rid of the 0x50 bytes of header in src. */ + raw = src + 0x50; + size = width*height/2; + temp_data = malloc(size); + if (!temp_data) + goto out; + sq905c_first_decompress(temp_data, raw, size); + sq905c_second_decompress(dst, temp_data, width, height); +out: + free(temp_data); +} diff --git a/v4l2-apps/util/v4l2-dbg.cpp b/v4l2-apps/util/v4l2-dbg.cpp index f427d4442..424b0fffe 100644 --- a/v4l2-apps/util/v4l2-dbg.cpp +++ b/v4l2-apps/util/v4l2-dbg.cpp @@ -713,6 +713,9 @@ int main(int argc, char **argv) case V4L2_IDENT_CX23418: name = "cx23418"; break; + case V4L2_IDENT_CAFE: + name = "cafe"; + break; default: if (get_reg.match.type == V4L2_CHIP_MATCH_I2C_DRIVER) name = get_reg.match.name; @@ -726,6 +729,8 @@ int main(int argc, char **argv) print_regs(fd, &get_reg, 0, 0xff, stride); } else if (name == "saa7127") { print_regs(fd, &get_reg, 0, 0x7f, stride); + } else if (name == "ov7670") { + print_regs(fd, &get_reg, 0, 0x89, stride); } else if (name == "cx25840") { print_regs(fd, &get_reg, 0, 2, stride); print_regs(fd, &get_reg, 0x100, 0x15f, stride); @@ -738,6 +743,11 @@ int main(int argc, char **argv) print_regs(fd, &get_reg, 0x02000000, 0x020000ff, stride); } else if (name == "cx23418") { print_regs(fd, &get_reg, 0x02c40000, 0x02c409c7, stride); + } else if (name == "cafe") { + print_regs(fd, &get_reg, 0, 0x43, stride); + print_regs(fd, &get_reg, 0x88, 0x8f, stride); + print_regs(fd, &get_reg, 0xb4, 0xbb, stride); + print_regs(fd, &get_reg, 0x3000, 0x300c, stride); } else { /* unknown chip, dump 0-0xff by default */ print_regs(fd, &get_reg, 0, 0xff, stride); diff --git a/v4l2-spec/Makefile b/v4l2-spec/Makefile index d0dde12f4..41dba1cdd 100644 --- a/v4l2-spec/Makefile +++ b/v4l2-spec/Makefile @@ -274,6 +274,7 @@ STRUCTS = \ v4l2_input \ v4l2_jpegcompression \ v4l2_modulator \ + v4l2_mpeg_vbi_fmt_ivtv \ v4l2_output \ v4l2_outputparm \ v4l2_pix_format \ diff --git a/v4l2-spec/README b/v4l2-spec/README index 6b0a3d0f1..9fe129642 100644 --- a/v4l2-spec/README +++ b/v4l2-spec/README @@ -15,3 +15,6 @@ html-single A single HTML file (default) html Tree of HTML files pdf A PDF file coffeebreak All of the above + +Note: the V4L1_API.html is here just for reference. The V4L2 API replaces +V4L1. diff --git a/v4l/API/V4L1_API.html b/v4l2-spec/V4L1_API.html index 50d282140..9f717fd50 100644 --- a/v4l/API/V4L1_API.html +++ b/v4l2-spec/V4L1_API.html @@ -10,7 +10,7 @@ <H3>Devices</H3> Video4Linux provides the following sets of device files. These live on the character device formerly known as "/dev/bttv". /dev/bttv should be a -symlink to /dev/video0 for most people. +symlink to /dev/video0 for most people. <P> <TABLE> <TR><TH>Device Name</TH><TH>Minor Range</TH><TH>Function</TH> @@ -21,7 +21,7 @@ symlink to /dev/video0 for most people. </TABLE> <P> Video4Linux programs open and scan the devices to find what they are looking -for. Capability queries define what each interface supports. The +for. Capability queries define what each interface supports. The described API is only defined for video capture cards. The relevant subset applies to radio cards. Teletext interfaces talk the existing VTX API. <P> @@ -63,17 +63,17 @@ The minimum and maximum sizes listed for a capture device do not imply all that all height/width ratios or sizes within the range are possible. A request to set a size will be honoured by the largest available capture size whose capture is no large than the requested rectangle in either -direction. For example the quickcam has 3 fixed settings. +direction. For example the quickcam has 3 fixed settings. <P> <H3>Frame Buffer</H3> Capture cards that drop data directly onto the frame buffer must be told the -base address of the frame buffer, its size and organisation. This is a +base address of the frame buffer, its size and organisation. This is a privileged ioctl and one that eventually X itself should set. <P> The <b>VIDIOCSFBUF</b> ioctl sets the frame buffer parameters for a capture card. If the card does not do direct writes to the frame buffer then this ioctl will be unsupported. The <b>VIDIOCGFBUF</b> ioctl returns the -currently used parameters. The structure used in both cases is a +currently used parameters. The structure used in both cases is a <b>struct video_buffer</b>. <P> <TABLE> @@ -84,7 +84,7 @@ currently used parameters. The structure used in both cases is a <TR><TD><b>int bytesperline</b></TD><TD>Number of bytes of memory between the start of two adjacent lines</TD> </TABLE> <P> -Note that these values reflect the physical layout of the frame buffer. +Note that these values reflect the physical layout of the frame buffer. The visible area may be smaller. In fact under XFree86 this is commonly the case. XFree86 DGA can provide the parameters required to set up this ioctl. Setting the base address to NULL indicates there is no physical frame buffer @@ -92,9 +92,9 @@ access. <P> <H3>Capture Windows</H3> The capture area is described by a <b>struct video_window</b>. This defines -a capture area and the clipping information if relevant. The -<b>VIDIOCGWIN</b> ioctl recovers the current settings and the -<b>VIDIOCSWIN</b> sets new values. A successful call to <b>VIDIOCSWIN</b> +a capture area and the clipping information if relevant. The +<b>VIDIOCGWIN</b> ioctl recovers the current settings and the +<b>VIDIOCSWIN</b> sets new values. A successful call to <b>VIDIOCSWIN</b> indicates that a suitable set of parameters have been chosen. They do not indicate that exactly what was requested was granted. The program should call <b>VIDIOCGWIN</b> to check if the nearest match was suitable. The @@ -124,7 +124,7 @@ fields available to the user. Merely setting the window does not enable capturing. Overlay capturing (i.e. PCI-PCI transfer to the frame buffer of the video card) is activated by passing the <b>VIDIOCCAPTURE</b> ioctl a value of 1, and -disabled by passing it a value of 0. +disabled by passing it a value of 0. <P> Some capture devices can capture a subfield of the image they actually see. This is indicated when VIDEO_TYPE_SUBCAPTURE is defined. @@ -148,8 +148,8 @@ The available flags are </TABLE> <P> <H3>Video Sources</H3> -Each video4linux video or audio device captures from one or more -source <b>channels</b>. Each channel can be queries with the +Each video4linux video or audio device captures from one or more +source <b>channels</b>. Each channel can be queries with the <b>VDIOCGCHAN</b> ioctl call. Before invoking this function the caller must set the channel field to the channel that is being queried. On return the <b>struct video_channel</b> is filled in with information about the @@ -158,7 +158,7 @@ nature of the channel itself. The <b>VIDIOCSCHAN</b> ioctl takes an integer argument and switches the capture to this input. It is not defined whether parameters such as colour settings or tuning are maintained across a channel switch. The caller should -maintain settings as desired for each channel. (This is reasonable as +maintain settings as desired for each channel. (This is reasonable as different video inputs may have different properties). <P> The <b>struct video_channel</b> consists of the following @@ -190,9 +190,9 @@ The types defined are <P> <H3>Image Properties</H3> The image properties of the picture can be queried with the <b>VIDIOCGPICT</b> -ioctl which fills in a <b>struct video_picture</b>. The <b>VIDIOCSPICT</b> +ioctl which fills in a <b>struct video_picture</b>. The <b>VIDIOCSPICT</b> ioctl allows values to be changed. All values except for the palette type -are scaled between 0-65535. +are scaled between 0-65535. <P> The <b>struct video_picture</b> consists of the following fields <P> @@ -232,7 +232,7 @@ tuners attached. <P> Tuners are described by a <b>struct video_tuner</b> which can be obtained by the <b>VIDIOCGTUNER</b> ioctl. Fill in the tuner number in the structure -then pass the structure to the ioctl to have the data filled in. The +then pass the structure to the ioctl to have the data filled in. The tuner can be switched using <b>VIDIOCSTUNER</b> which takes an integer argument giving the tuner to use. A struct tuner has the following fields <P> @@ -274,7 +274,7 @@ frequency is obtained as an unsigned long via the <b>VIDIOCGFREQ</b> ioctl and set by the <b>VIDIOCSFREQ</b> ioctl. <P> <H3>Audio</H3> -TV and Radio devices have one or more audio inputs that may be selected. +TV and Radio devices have one or more audio inputs that may be selected. The audio properties are queried by passing a <b>struct video_audio</b> to <b>VIDIOCGAUDIO</b> ioctl. The <b>VIDIOCSAUDIO</b> ioctl sets audio properties. <P> @@ -323,7 +323,7 @@ A second way to handle image capture is via the mmap interface if supported. To use the mmap interface a user first sets the desired image size and depth properties. Next the VIDIOCGMBUF ioctl is issued. This reports the size of buffer to mmap and the offset within the buffer for each frame. The -number of frames supported is device dependent and may only be one. +number of frames supported is device dependent and may only be one. <P> The video_mbuf structure contains the following fields <P> @@ -390,11 +390,11 @@ groups of three, as follows: <TR><TD>Second Octet</TD><TD>Most Significant Byte of RDS Block <TR><TD>Third Octet</TD><TD>Bit 7:</TD><TD>Error bit. Indicates that an uncorrectable error occurred during reception of this block.</TD></TR> -<TR><TD> </TD><TD>Bit 6:</TD><TD>Corrected bit. Indicates that +<TR><TD> </TD><TD>Bit 6:</TD><TD>Corrected bit. Indicates that an error was corrected for this data block.</TD></TR> -<TR><TD> </TD><TD>Bits 5-3:</TD><TD>Received Offset. Indicates the +<TR><TD> </TD><TD>Bits 5-3:</TD><TD>Received Offset. Indicates the offset received by the sync system.</TD></TR> -<TR><TD> </TD><TD>Bits 2-0:</TD><TD>Offset Name. Indicates the +<TR><TD> </TD><TD>Bits 2-0:</TD><TD>Offset Name. Indicates the offset applied to this data.</TD></TR> </TABLE> </BODY> diff --git a/v4l2-spec/dev-sliced-vbi.sgml b/v4l2-spec/dev-sliced-vbi.sgml index 5560650a6..3c260e3e3 100644 --- a/v4l2-spec/dev-sliced-vbi.sgml +++ b/v4l2-spec/dev-sliced-vbi.sgml @@ -48,7 +48,7 @@ vital to program a sliced VBI device, therefore must be supported.</para> </section> - <section> + <section id="sliced-vbi-format-negotitation"> <title>Sliced VBI Format Negotiation</title> <para>To find out which data services are supported by the @@ -386,6 +386,319 @@ video and VBI data by using buffer timestamps.</para> </section> + <section> + <title>Sliced VBI Data in MPEG Streams</title> + + <para>If a device can produce an MPEG output stream, it may be +capable of providing <link +linkend="sliced-vbi-format-negotitation">negotiated sliced VBI +services</link> as data embedded in the MPEG stream. Users or +applications control this sliced VBI data insertion with the <link +linkend="v4l2-mpeg-stream-vbi-fmt">V4L2_CID_MPEG_STREAM_VBI_FMT</link> +control.</para> + + <para>If the driver does not provide the <link +linkend="v4l2-mpeg-stream-vbi-fmt">V4L2_CID_MPEG_STREAM_VBI_FMT</link> +control, or only allows that control to be set to <link +linkend="v4l2-mpeg-stream-vbi-fmt"><constant> +V4L2_MPEG_STREAM_VBI_FMT_NONE</constant></link>, then the device +cannot embed sliced VBI data in the MPEG stream.</para> + + <para>The <link linkend="v4l2-mpeg-stream-vbi-fmt"> +V4L2_CID_MPEG_STREAM_VBI_FMT</link> control does not implicitly set +the device driver to capture nor cease capturing sliced VBI data. The +control only indicates to embed sliced VBI data in the MPEG stream, if +an application has negotiated sliced VBI service be captured.</para> + + <para>It may also be the case that a device can embed sliced VBI +data in only certain types of MPEG streams: for example in an MPEG-2 +PS but not an MPEG-2 TS. In this situation, if sliced VBI data +insertion is requested, the sliced VBI data will be embedded in MPEG +stream types when supported, and silently omitted from MPEG stream +types where sliced VBI data insertion is not supported by the device. +</para> + + <para>The following subsections specify the format of the +embedded sliced VBI data.</para> + + <section> + <title>MPEG Stream Embedded, Sliced VBI Data Format: NONE</title> + <para>The <link linkend="v4l2-mpeg-stream-vbi-fmt"><constant> +V4L2_MPEG_STREAM_VBI_FMT_NONE</constant></link> embedded sliced VBI +format shall be interpreted by drivers as a control to cease +embedding sliced VBI data in MPEG streams. Neither the device nor +driver shall insert "empty" embedded sliced VBI data packets in the +MPEG stream when this format is set. No MPEG stream data structures +are specified for this format.</para> + </section> + + <section> + <title>MPEG Stream Embedded, Sliced VBI Data Format: IVTV</title> + <para>The <link linkend="v4l2-mpeg-stream-vbi-fmt"><constant> +V4L2_MPEG_STREAM_VBI_FMT_IVTV</constant></link> embedded sliced VBI +format, when supported, indicates to the driver to embed up to 36 +lines of sliced VBI data per frame in an MPEG-2 <emphasis>Private +Stream 1 PES</emphasis> packet encapsulated in an MPEG-2 <emphasis> +Program Pack</emphasis> in the MPEG stream.</para> + + <para><emphasis>Historical context</emphasis>: This format +specification originates from a custom, embedded, sliced VBI data +format used by the <filename>ivtv</filename> driver. This format +has already been informally specified in the kernel sources in the +file <filename>Documentation/video4linux/cx2341x/README.vbi</filename> +. The maximum size of the payload and other aspects of this format +are driven by the CX23415 MPEG decoder's capabilities and limitations +with respect to extracting, decoding, and displaying sliced VBI data +embedded within an MPEG stream.</para> + + <para>This format's use is <emphasis>not</emphasis> exclusive to +the <filename>ivtv</filename> driver <emphasis>nor</emphasis> +exclusive to CX2341x devices, as the sliced VBI data packet insertion +into the MPEG stream is implemented in driver software. At least the +<filename>cx18</filename> driver provides sliced VBI data insertion +into an MPEG-2 PS in this format as well.</para> + + <para>The following definitions specify the payload of the +MPEG-2 <emphasis>Private Stream 1 PES</emphasis> packets that contain +sliced VBI data when <link linkend="v4l2-mpeg-stream-vbi-fmt"> +<constant>V4L2_MPEG_STREAM_VBI_FMT_IVTV</constant></link> is set. +(The MPEG-2 <emphasis>Private Stream 1 PES</emphasis> packet header +and encapsulating MPEG-2 <emphasis>Program Pack</emphasis> header are +not detailed here. Please refer to the MPEG-2 specifications for +details on those packet headers.)</para> + + <para>The payload of the MPEG-2 <emphasis>Private Stream 1 PES +</emphasis> packets that contain sliced VBI data is specified by +&v4l2-mpeg-vbi-fmt-ivtv;. The payload is variable +length, depending on the actual number of lines of sliced VBI data +present in a video frame. The payload may be padded at the end with +unspecified fill bytes to align the end of the payload to a 4-byte +boundary. The payload shall never exceed 1552 bytes (2 fields with +18 lines/field with 43 bytes of data/line and a 4 byte magic number). +</para> + + <table frame="none" pgwide="1" id="v4l2-mpeg-vbi-fmt-ivtv"> + <title>struct <structname>v4l2_mpeg_vbi_fmt_ivtv</structname> + </title> + <tgroup cols="4"> + &cs-ustr; + <tbody valign="top"> + <row> + <entry>__u8</entry> + <entry><structfield>magic</structfield>[4]</entry> + <entry></entry> + <entry>A "magic" constant from <xref + linkend="v4l2-mpeg-vbi-fmt-ivtv-magic"> that indicates +this is a valid sliced VBI data payload and also indicates which +member of the anonymous union, <structfield>itv0</structfield> or +<structfield>ITV0</structfield>, to use for the payload data.</entry> + </row> + <row> + <entry>union</entry> + <entry>(anonymous)</entry> + </row> + <row> + <entry></entry> + <entry>struct <link linkend="v4l2-mpeg-vbi-itv0"> + <structname>v4l2_mpeg_vbi_itv0</structname></link> + </entry> + <entry><structfield>itv0</structfield></entry> + <entry>The primary form of the sliced VBI data payload +that contains anywhere from 1 to 35 lines of sliced VBI data. +Line masks are provided in this form of the payload indicating +which VBI lines are provided.</entry> + </row> + <row> + <entry></entry> + <entry>struct <link linkend="v4l2-mpeg-vbi-ITV0-1"> + <structname>v4l2_mpeg_vbi_ITV0</structname></link> + </entry> + <entry><structfield>ITV0</structfield></entry> + <entry>An alternate form of the sliced VBI data payload +used when 36 lines of sliced VBI data are present. No line masks are +provided in this form of the payload; all valid line mask bits are +implcitly set.</entry> + </row> + </tbody> + </tgroup> + </table> + + <table frame="none" pgwide="1" id="v4l2-mpeg-vbi-fmt-ivtv-magic"> + <title>Magic Constants for &v4l2-mpeg-vbi-fmt-ivtv; + <structfield>magic</structfield> field</title> + <tgroup cols="3"> + &cs-def; + <thead> + <row> + <entry align="left">Defined Symbol</entry> + <entry align="left">Value</entry> + <entry align="left">Description</entry> + </row> + </thead> + <tbody valign="top"> + <row> + <entry><constant>V4L2_MPEG_VBI_IVTV_MAGIC0</constant> + </entry> + <entry>"itv0"</entry> + <entry>Indicates the <structfield>itv0</structfield> +member of the union in &v4l2-mpeg-vbi-fmt-ivtv; is valid.</entry> + </row> + <row> + <entry><constant>V4L2_MPEG_VBI_IVTV_MAGIC1</constant> + </entry> + <entry>"ITV0"</entry> + <entry>Indicates the <structfield>ITV0</structfield> +member of the union in &v4l2-mpeg-vbi-fmt-ivtv; is valid and +that 36 lines of sliced VBI data are present.</entry> + </row> + </tbody> + </tgroup> + </table> + + <table frame="none" pgwide="1" id="v4l2-mpeg-vbi-itv0"> + <title>struct <structname>v4l2_mpeg_vbi_itv0</structname> + </title> + <tgroup cols="3"> + &cs-str; + <tbody valign="top"> + <row> + <entry>__le32</entry> + <entry><structfield>linemask</structfield>[2]</entry> + <entry><para>Bitmasks indicating the VBI service lines +present. These <structfield>linemask</structfield> values are stored +in little endian byte order in the MPEG stream. Some reference +<structfield>linemask</structfield> bit positions with their +corresponding VBI line number and video field are given below. +b<subscript>0</subscript> indicates the least significant bit of a +<structfield>linemask</structfield> value:<screen> +<structfield>linemask</structfield>[0] b<subscript>0</subscript>: line 6 first field +<structfield>linemask</structfield>[0] b<subscript>17</subscript>: line 23 first field +<structfield>linemask</structfield>[0] b<subscript>18</subscript>: line 6 second field +<structfield>linemask</structfield>[0] b<subscript>31</subscript>: line 19 second field +<structfield>linemask</structfield>[1] b<subscript>0</subscript>: line 20 second field +<structfield>linemask</structfield>[1] b<subscript>3</subscript>: line 23 second field +<structfield>linemask</structfield>[1] b<subscript>4</subscript>-b<subscript>31</subscript>: unused and set to 0</screen></para></entry> + </row> + <row> + <entry>struct <link linkend="v4l2-mpeg-vbi-itv0-line"> + <structname>v4l2_mpeg_vbi_itv0_line</structname></link> + </entry> + <entry><structfield>line</structfield>[35]</entry> + <entry>This is a variable length array that holds from 1 +to 35 lines of sliced VBI data. The sliced VBI data lines present +correspond to the bits set in the <structfield>linemask</structfield> +array, starting from b<subscript>0</subscript> of <structfield> +linemask</structfield>[0] up through b<subscript>31</subscript> of +<structfield>linemask</structfield>[0], and from b<subscript>0 +</subscript> of <structfield>linemask</structfield>[1] up through b +<subscript>3</subscript> of <structfield>linemask</structfield>[1]. +<structfield>line</structfield>[0] corresponds to the first bit +found set in the <structfield>linemask</structfield> array, +<structfield>line</structfield>[1] corresponds to the second bit +found set in the <structfield>linemask</structfield> array, etc. +If no <structfield>linemask</structfield> array bits are set, then +<structfield>line</structfield>[0] may contain one line of +unspecified data that should be ignored by applications.</entry> + </row> + </tbody> + </tgroup> + </table> + + <table frame="none" pgwide="1" id="v4l2-mpeg-vbi-ITV0-1"> + <title>struct <structname>v4l2_mpeg_vbi_ITV0</structname> + </title> + <tgroup cols="3"> + &cs-str; + <tbody valign="top"> + <row> + <entry>struct <link linkend="v4l2-mpeg-vbi-itv0-line"> + <structname>v4l2_mpeg_vbi_itv0_line</structname></link> + </entry> + <entry><structfield>line</structfield>[36]</entry> + <entry>A fixed length array of 36 lines of sliced VBI +data. <structfield>line</structfield>[0] through <structfield>line +</structfield>[17] correspond to lines 6 through 23 of the +first field. <structfield>line</structfield>[18] through +<structfield>line</structfield>[35] corresponds to lines 6 +through 23 of the second field.</entry> + </row> + </tbody> + </tgroup> + </table> + + <table frame="none" pgwide="1" id="v4l2-mpeg-vbi-itv0-line"> + <title>struct <structname>v4l2_mpeg_vbi_itv0_line</structname> + </title> + <tgroup cols="3"> + &cs-str; + <tbody valign="top"> + <row> + <entry>__u8</entry> + <entry><structfield>id</structfield></entry> + <entry>A line identifier value from +<xref linkend="ITV0-Line-Identifier-Constants"> that indicates +the type of sliced VBI data stored on this line.</entry> + </row> + <row> + <entry>__u8</entry> + <entry><structfield>data</structfield>[42]</entry> + <entry>The sliced VBI data for the line.</entry> + </row> + </tbody> + </tgroup> + </table> + + <table frame="none" pgwide="1" id="ITV0-Line-Identifier-Constants"> + <title>Line Identifiers for struct <link + linkend="v4l2-mpeg-vbi-itv0-line"><structname> +v4l2_mpeg_vbi_itv0_line</structname></link> <structfield>id +</structfield> field</title> + <tgroup cols="3"> + &cs-def; + <thead> + <row> + <entry align="left">Defined Symbol</entry> + <entry align="left">Value</entry> + <entry align="left">Description</entry> + </row> + </thead> + <tbody valign="top"> + <row> + <entry><constant>V4L2_MPEG_VBI_IVTV_TELETEXT_B</constant> + </entry> + <entry>1</entry> + <entry>Refer to <link linkend="vbi-services2"> +Sliced VBI services</link> for a description of the line payload.</entry> + </row> + <row> + <entry><constant>V4L2_MPEG_VBI_IVTV_CAPTION_525</constant> + </entry> + <entry>4</entry> + <entry>Refer to <link linkend="vbi-services2"> +Sliced VBI services</link> for a description of the line payload.</entry> + </row> + <row> + <entry><constant>V4L2_MPEG_VBI_IVTV_WSS_625</constant> + </entry> + <entry>5</entry> + <entry>Refer to <link linkend="vbi-services2"> +Sliced VBI services</link> for a description of the line payload.</entry> + </row> + <row> + <entry><constant>V4L2_MPEG_VBI_IVTV_VPS</constant> + </entry> + <entry>7</entry> + <entry>Refer to <link linkend="vbi-services2"> +Sliced VBI services</link> for a description of the line payload.</entry> + </row> + </tbody> + </tgroup> + </table> + + </section> + </section> + + <!-- Local Variables: mode: sgml diff --git a/v4l2-spec/v4l2.sgml b/v4l2-spec/v4l2.sgml index 9f43b6d1e..a6cbae2bf 100644 --- a/v4l2-spec/v4l2.sgml +++ b/v4l2-spec/v4l2.sgml @@ -77,6 +77,19 @@ API.</contrib> <contrib>Designed and documented the VIDIOC_ENUM_FRAMESIZES and VIDIOC_ENUM_FRAMEINTERVALS ioctls.</contrib> </author> + + <author> + <firstname>Andy</firstname> + <surname>Walls</surname> + <contrib>Documented the fielded V4L2_MPEG_STREAM_VBI_FMT_IVTV +MPEG stream embedded, sliced VBI data format in this specification. +</contrib> + <affiliation> + <address> + <email>awalls@radix.net</email> + </address> + </affiliation> + </author> </authorgroup> <copyright> @@ -92,12 +105,12 @@ and VIDIOC_ENUM_FRAMEINTERVALS ioctls.</contrib> <year>2008</year> <year>2009</year> <holder>Bill Dirks, Michael H. Schimek, Hans Verkuil, Martin -Rubli</holder> +Rubli, Andy Walls</holder> </copyright> <legalnotice> <para>This document is copyrighted © 1999-2009 by Bill -Dirks, Michael H. Schimek, Hans Verkuil and Martin Rubli.</para> +Dirks, Michael H. Schimek, Hans Verkuil, Martin Rubli, and Andy Walls.</para> <para>Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, |