diff options
161 files changed, 20332 insertions, 41946 deletions
diff --git a/linux/Documentation/video4linux/CARDLIST.bttv b/linux/Documentation/video4linux/CARDLIST.bttv index 1da2c6271..e17750473 100644 --- a/linux/Documentation/video4linux/CARDLIST.bttv +++ b/linux/Documentation/video4linux/CARDLIST.bttv @@ -135,7 +135,7 @@ 134 -> Adlink RTV24 135 -> DViCO FusionHDTV 5 Lite [18ac:d500] 136 -> Acorp Y878F [9511:1540] -137 -> Conceptronic CTVFMi v2 +137 -> Conceptronic CTVFMi v2 [036e:109e] 138 -> Prolink Pixelview PV-BT878P+ (Rev.2E) 139 -> Prolink PixelView PlayTV MPEG2 PV-M4900 140 -> Osprey 440 [0070:ff07] diff --git a/linux/Documentation/video4linux/CARDLIST.cx88 b/linux/Documentation/video4linux/CARDLIST.cx88 index 0d08f1edc..71e9db0b2 100644 --- a/linux/Documentation/video4linux/CARDLIST.cx88 +++ b/linux/Documentation/video4linux/CARDLIST.cx88 @@ -77,3 +77,4 @@ 76 -> SATTRADE ST4200 DVB-S/S2 [b200:4200] 77 -> TBS 8910 DVB-S [8910:8888] 78 -> Prof 6200 DVB-S [b022:3022] + 79 -> Terratec Cinergy HT PCI MKII [153b:1177] diff --git a/linux/Documentation/video4linux/CARDLIST.saa7134 b/linux/Documentation/video4linux/CARDLIST.saa7134 index 325c69fe9..6dacf2825 100644 --- a/linux/Documentation/video4linux/CARDLIST.saa7134 +++ b/linux/Documentation/video4linux/CARDLIST.saa7134 @@ -153,5 +153,5 @@ 152 -> Asus Tiger Rev:1.00 [1043:4857] 153 -> Kworld Plus TV Analog Lite PCI [17de:7128] 154 -> Avermedia AVerTV GO 007 FM Plus [1461:f31d] -155 -> Hauppauge WinTV-HVR1150 [0070:6706,0070:6708] +155 -> Hauppauge WinTV-HVR1120 ATSC/QAM-Hybrid [0070:6706,0070:6708] 156 -> Hauppauge WinTV-HVR1110r3 [0070:6707,0070:6709,0070:670a] diff --git a/linux/Documentation/video4linux/Zoran b/linux/Documentation/video4linux/Zoran index 295462b23..0e89e7676 100644 --- a/linux/Documentation/video4linux/Zoran +++ b/linux/Documentation/video4linux/Zoran @@ -401,8 +401,7 @@ Additional notes for software developers: first set the correct norm. Well, it seems logically correct: TV standard is "more constant" for current country than geometry settings of a variety of TV capture cards which may work in ITU or - square pixel format. Remember that users now can lock the norm to - avoid any ambiguity. + square pixel format. -- Please note that lavplay/lavrec are also included in the MJPEG-tools (http://mjpeg.sf.net/). 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/v4l2-framework.txt b/linux/Documentation/video4linux/v4l2-framework.txt index accc376e9..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 @@ -359,8 +381,8 @@ This loads the given module (can be NULL if no module needs to be loaded) and calls i2c_new_device() with the given i2c_adapter and chip/address arguments. If all goes well, then it registers the subdev with the v4l2_device. It gets the v4l2_device by calling i2c_get_adapdata(adapter), so you should make sure -that adapdata is set to v4l2_device when you setup the i2c_adapter in your -driver. +to call i2c_set_adapdata(adapter, v4l2_device) when you setup the i2c_adapter +in your driver. You can also use v4l2_i2c_new_probed_subdev() which is very similar to v4l2_i2c_new_subdev(), except that it has an array of possible I2C addresses @@ -368,6 +390,14 @@ that it should probe. Internally it calls i2c_new_probed_device(). Both functions return NULL if something went wrong. +Note that the chipid you pass to v4l2_i2c_new_(probed_)subdev() is usually +the same as the module name. It allows you to specify a chip variant, e.g. +"saa7114" or "saa7115". In general though the i2c driver autodetects this. +The use of chipid is something that needs to be looked at more closely at a +later date. It differs between i2c drivers and as such can be confusing. +To see which chip variants are supported you can look in the i2c driver code +for the i2c_device_id table. This lists all the possibilities. + struct video_device ------------------- @@ -406,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/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/xc5000.c b/linux/drivers/media/common/tuners/xc5000.c index a64c52171..39c415df0 100644 --- a/linux/drivers/media/common/tuners/xc5000.c +++ b/linux/drivers/media/common/tuners/xc5000.c @@ -758,7 +758,10 @@ static int xc5000_set_analog_params(struct dvb_frontend *fe, dprintk(1, "%s() frequency=%d (in units of 62.5khz)\n", __func__, params->frequency); - priv->rf_mode = XC_RF_MODE_CABLE; /* Fix me: it could be air. */ + /* Fix me: it could be air. */ + priv->rf_mode = params->mode; + if (params->mode > XC_RF_MODE_CABLE) + priv->rf_mode = XC_RF_MODE_CABLE; /* params->frequency is in units of 62.5khz */ priv->freq_hz = params->frequency * 62500; diff --git a/linux/drivers/media/dvb/b2c2/flexcop-pci.c b/linux/drivers/media/dvb/b2c2/flexcop-pci.c index 2905ffccf..72710fee2 100644 --- a/linux/drivers/media/dvb/b2c2/flexcop-pci.c +++ b/linux/drivers/media/dvb/b2c2/flexcop-pci.c @@ -133,6 +133,7 @@ static void flexcop_pci_irq_check_work(struct work_struct *work) deb_chk("no IRQ since the last check\n"); if (fc_pci->stream_problem++ == 3) { struct dvb_demux_feed *feed; + deb_info("flexcop-pci: stream problem, resetting pid filter\n"); spin_lock_irq(&fc->demux.lock); list_for_each_entry(feed, &fc->demux.feed_list, diff --git a/linux/drivers/media/dvb/bt8xx/dst.c b/linux/drivers/media/dvb/bt8xx/dst.c index 29e8f1546..fec1d77fa 100644 --- a/linux/drivers/media/dvb/bt8xx/dst.c +++ b/linux/drivers/media/dvb/bt8xx/dst.c @@ -1683,7 +1683,7 @@ static int dst_tune_frontend(struct dvb_frontend* fe, static int dst_get_tuning_algo(struct dvb_frontend *fe) { - return dst_algo; + return dst_algo ? DVBFE_ALGO_HW : DVBFE_ALGO_SW; } static int dst_get_frontend(struct dvb_frontend *fe, struct dvb_frontend_parameters *p) 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-core/dvb_frontend.c b/linux/drivers/media/dvb/dvb-core/dvb_frontend.c index 05b327403..da2890b22 100644 --- a/linux/drivers/media/dvb/dvb-core/dvb_frontend.c +++ b/linux/drivers/media/dvb/dvb-core/dvb_frontend.c @@ -1396,9 +1396,6 @@ static int dtv_property_process_set(struct dvb_frontend *fe, dprintk("%s() Finalised property cache\n", __func__); dtv_property_cache_submit(fe); - /* Request the search algorithm to search */ - fepriv->algo_status |= DVBFE_ALGO_SEARCH_AGAIN; - r |= dvb_frontend_ioctl_legacy(inode, file, FE_SET_FRONTEND, &fepriv->parameters); break; @@ -1832,6 +1829,10 @@ static int dvb_frontend_ioctl_legacy(struct inode *inode, struct file *file, fepriv->min_delay = (dvb_override_tune_delay * HZ) / 1000; fepriv->state = FESTATE_RETUNE; + + /* Request the search algorithm to search */ + fepriv->algo_status |= DVBFE_ALGO_SEARCH_AGAIN; + dvb_frontend_wakeup(fe); dvb_frontend_add_event(fe, 0); fepriv->status = 0; diff --git a/linux/drivers/media/dvb/dvb-usb/Kconfig b/linux/drivers/media/dvb/dvb-usb/Kconfig index 64fa1d182..b899d509a 100644 --- a/linux/drivers/media/dvb/dvb-usb/Kconfig +++ b/linux/drivers/media/dvb/dvb-usb/Kconfig @@ -73,11 +73,13 @@ config DVB_USB_DIB0700 select DVB_DIB7000M if !DVB_FE_CUSTOMISE select DVB_DIB3000MC if !DVB_FE_CUSTOMISE 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 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 diff --git a/linux/drivers/media/dvb/dvb-usb/dib0700_devices.c b/linux/drivers/media/dvb/dvb-usb/dib0700_devices.c index 8877215cb..d8901f7a8 100644 --- a/linux/drivers/media/dvb/dvb-usb/dib0700_devices.c +++ b/linux/drivers/media/dvb/dvb-usb/dib0700_devices.c @@ -17,6 +17,8 @@ #include "xc5000.h" #include "s5h1411.h" #include "dib0070.h" +#include "lgdt3305.h" +#include "mxl5007t.h" static int force_lna_activation; module_param(force_lna_activation, int, 0644); @@ -1370,6 +1372,76 @@ static int xc5000_tuner_attach(struct dvb_usb_adapter *adap) == NULL ? -ENODEV : 0; } +static struct lgdt3305_config hcw_lgdt3305_config = { + .i2c_addr = 0x0e, + .mpeg_mode = LGDT3305_MPEG_PARALLEL, + .tpclk_edge = LGDT3305_TPCLK_FALLING_EDGE, + .tpvalid_polarity = LGDT3305_TP_VALID_LOW, + .deny_i2c_rptr = 0, + .spectral_inversion = 1, + .qam_if_khz = 6000, + .vsb_if_khz = 6000, + .usref_8vsb = 0x0500, +}; + +static struct mxl5007t_config hcw_mxl5007t_config = { + .xtal_freq_hz = MxL_XTAL_25_MHZ, + .if_freq_hz = MxL_IF_6_MHZ, + .invert_if = 1, +#if 0 + .loop_thru_enable = 1, + .clk_out_enable = 1, +#endif +}; + +/* TIGER-ATSC map: + GPIO0 - LNA_CTR (H: LNA power enabled, L: LNA power disabled) + GPIO1 - ANT_SEL (H: VPA, L: MCX) + GPIO4 - SCL2 + GPIO6 - EN_TUNER + GPIO7 - SDA2 + GPIO10 - DEM_RST + + MXL is behind LG's i2c repeater. LG is on SCL2/SDA2 gpios on the DIB + */ +static int lgdt3305_frontend_attach(struct dvb_usb_adapter *adap) +{ + struct dib0700_state *st = adap->dev->priv; + + /* Make use of the new i2c functions from FW 1.20 */ + st->fw_use_new_i2c_api = 1; + + st->disable_streaming_master_mode = 1; + + /* fe power enable */ + dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 0); + msleep(30); + dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1); + msleep(30); + + /* demod reset */ + dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1); + msleep(30); + dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0); + msleep(30); + dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1); + msleep(30); + + adap->fe = dvb_attach(lgdt3305_attach, + &hcw_lgdt3305_config, + &adap->dev->i2c_adap); + + return adap->fe == NULL ? -ENODEV : 0; +} + +static int mxl5007t_tuner_attach(struct dvb_usb_adapter *adap) +{ + return dvb_attach(mxl5007t_attach, adap->fe, + &adap->dev->i2c_adap, 0x60, + &hcw_mxl5007t_config) == NULL ? -ENODEV : 0; +} + + /* DVB-USB and USB stuff follows */ struct usb_device_id dib0700_usb_id_table[] = { /* 0 */ { USB_DEVICE(USB_VID_DIBCOM, USB_PID_DIBCOM_STK7700P) }, @@ -1421,6 +1493,8 @@ struct usb_device_id dib0700_usb_id_table[] = { USB_PID_TERRATEC_CINERGY_DT_XS_DIVERSITY_2) }, { USB_DEVICE(USB_VID_SONY, USB_PID_SONY_PLAYTV) }, /* 45 */{ USB_DEVICE(USB_VID_YUAN, USB_PID_YUAN_PD378S) }, + { USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_TIGER_ATSC) }, + { USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_TIGER_ATSC_B210) }, { 0 } /* Terminating entry */ }; MODULE_DEVICE_TABLE(usb, dib0700_usb_id_table); @@ -1796,6 +1870,31 @@ struct dvb_usb_device_properties dib0700_devices[] = { .rc_key_map = dib0700_rc_keys, .rc_key_map_size = ARRAY_SIZE(dib0700_rc_keys), .rc_query = dib0700_rc_query + }, { DIB0700_DEFAULT_DEVICE_PROPERTIES, + .num_adapters = 1, + .adapter = { + { + .frontend_attach = lgdt3305_frontend_attach, + .tuner_attach = mxl5007t_tuner_attach, + + DIB0700_DEFAULT_STREAMING_CONFIG(0x02), + + .size_of_priv = sizeof(struct + dib0700_adapter_state), + }, + }, + + .num_device_descs = 2, + .devices = { + { "Hauppauge ATSC MiniCard (B200)", + { &dib0700_usb_id_table[46], NULL }, + { NULL }, + }, + { "Hauppauge ATSC MiniCard (B210)", + { &dib0700_usb_id_table[47], NULL }, + { NULL }, + }, + }, }, }; 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 6d70576ad..3dfb27174 100644 --- a/linux/drivers/media/dvb/dvb-usb/dvb-usb-ids.h +++ b/linux/drivers/media/dvb/dvb-usb/dvb-usb-ids.h @@ -151,6 +151,8 @@ #define USB_PID_HAUPPAUGE_MYTV_T 0x7080 #define USB_PID_HAUPPAUGE_NOVA_TD_STICK 0x9580 #define USB_PID_HAUPPAUGE_NOVA_TD_STICK_52009 0x5200 +#define USB_PID_HAUPPAUGE_TIGER_ATSC 0xb200 +#define USB_PID_HAUPPAUGE_TIGER_ATSC_B210 0xb210 #define USB_PID_AVERMEDIA_EXPRESS 0xb568 #define USB_PID_AVERMEDIA_VOLAR 0xa807 #define USB_PID_AVERMEDIA_VOLAR_2 0xb808 diff --git a/linux/drivers/media/dvb/firewire/firedtv-avc.c b/linux/drivers/media/dvb/firewire/firedtv-avc.c index b55d9ccaf..d8dae2599 100644 --- a/linux/drivers/media/dvb/firewire/firedtv-avc.c +++ b/linux/drivers/media/dvb/firewire/firedtv-avc.c @@ -150,15 +150,20 @@ static void debug_fcp(const u8 *data, size_t length) subunit_type = data[1] >> 3; subunit_id = data[1] & 7; op = subunit_type == 0x1e || subunit_id == 5 ? ~0 : data[2]; - printk(KERN_INFO "%ssu=%x.%x l=%d: %-8s - %s\n", + printk(KERN_INFO "%ssu=%x.%x l=%zu: %-8s - %s\n", prefix, subunit_type, subunit_id, length, debug_fcp_ctype(data[0]), debug_fcp_opcode(op, data, length)); } if (avc_debug & AVC_DEBUG_FCP_PAYLOADS) +#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 22) print_hex_dump(KERN_INFO, prefix, DUMP_PREFIX_NONE, 16, 1, data, length, false); +#else + print_hex_dump(KERN_INFO, prefix, DUMP_PREFIX_NONE, 16, 1, + (void *)data, length, false); +#endif } static int __avc_write(struct firedtv *fdtv, diff --git a/linux/drivers/media/dvb/frontends/Kconfig b/linux/drivers/media/dvb/frontends/Kconfig index 2887d3398..5c78f6329 100644 --- a/linux/drivers/media/dvb/frontends/Kconfig +++ b/linux/drivers/media/dvb/frontends/Kconfig @@ -419,6 +419,14 @@ config DVB_LGDT3304 An ATSC 8VSB and QAM64/256 tuner module. Say Y when you want to support this frontend. +config DVB_LGDT3305 + tristate "LG Electronics LGDT3305 based" + depends on DVB_CORE && I2C + default m if DVB_FE_CUSTOMISE + help + An ATSC 8VSB and QAM64/256 tuner module. Say Y when you want + to support this frontend. + config DVB_S5H1409 tristate "Samsung S5H1409 based" depends on DVB_CORE && I2C diff --git a/linux/drivers/media/dvb/frontends/Makefile b/linux/drivers/media/dvb/frontends/Makefile index cffe25e2a..65a336aa1 100644 --- a/linux/drivers/media/dvb/frontends/Makefile +++ b/linux/drivers/media/dvb/frontends/Makefile @@ -44,6 +44,7 @@ obj-$(CONFIG_DVB_BCM3510) += bcm3510.o obj-$(CONFIG_DVB_S5H1420) += s5h1420.o obj-$(CONFIG_DVB_LGDT330X) += lgdt330x.o obj-$(CONFIG_DVB_LGDT3304) += lgdt3304.o +obj-$(CONFIG_DVB_LGDT3305) += lgdt3305.o obj-$(CONFIG_DVB_CX24123) += cx24123.o obj-$(CONFIG_DVB_LNBP21) += lnbp21.o obj-$(CONFIG_DVB_ISL6405) += isl6405.o diff --git a/linux/drivers/media/dvb/frontends/lgdt3305.c b/linux/drivers/media/dvb/frontends/lgdt3305.c new file mode 100644 index 000000000..f0c0c8199 --- /dev/null +++ b/linux/drivers/media/dvb/frontends/lgdt3305.c @@ -0,0 +1,1115 @@ +/* + * Support for LGDT3305 - VSB/QAM + * + * Copyright (C) 2008, 2009 Michael Krufky <mkrufky@linuxtv.org> + * + * 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 "compat.h" +#include <linux/dvb/frontend.h> +#include "dvb_math.h" +#include "lgdt3305.h" + +static int debug; +module_param(debug, int, 0644); +MODULE_PARM_DESC(debug, "set debug level (info=1, reg=2 (or-able))"); + +#define DBG_INFO 1 +#define DBG_REG 2 + +#define lg_printk(kern, fmt, arg...) \ + printk(kern "%s: " fmt, __func__, ##arg) + +#define lg_info(fmt, arg...) printk(KERN_INFO "lgdt3305: " fmt, ##arg) +#define lg_warn(fmt, arg...) lg_printk(KERN_WARNING, fmt, ##arg) +#define lg_err(fmt, arg...) lg_printk(KERN_ERR, fmt, ##arg) +#define lg_dbg(fmt, arg...) if (debug & DBG_INFO) \ + lg_printk(KERN_DEBUG, fmt, ##arg) +#define lg_reg(fmt, arg...) if (debug & DBG_REG) \ + lg_printk(KERN_DEBUG, fmt, ##arg) + +#define lg_fail(ret) \ +({ \ + int __ret; \ + __ret = (ret < 0); \ + if (__ret) \ + lg_err("error %d on line %d\n", ret, __LINE__); \ + __ret; \ +}) + +struct lgdt3305_state { + struct i2c_adapter *i2c_adap; + const struct lgdt3305_config *cfg; + + struct dvb_frontend frontend; + + fe_modulation_t current_modulation; + u32 current_frequency; + u32 snr; +}; + +/* ------------------------------------------------------------------------ */ + +#define LGDT3305_GEN_CTRL_1 0x0000 +#define LGDT3305_GEN_CTRL_2 0x0001 +#define LGDT3305_GEN_CTRL_3 0x0002 +#define LGDT3305_GEN_STATUS 0x0003 +#define LGDT3305_GEN_CONTROL 0x0007 +#define LGDT3305_GEN_CTRL_4 0x000a +#define LGDT3305_DGTL_AGC_REF_1 0x0012 +#define LGDT3305_DGTL_AGC_REF_2 0x0013 +#define LGDT3305_CR_CTR_FREQ_1 0x0106 +#define LGDT3305_CR_CTR_FREQ_2 0x0107 +#define LGDT3305_CR_CTR_FREQ_3 0x0108 +#define LGDT3305_CR_CTR_FREQ_4 0x0109 +#define LGDT3305_CR_MSE_1 0x011b +#define LGDT3305_CR_MSE_2 0x011c +#define LGDT3305_CR_LOCK_STATUS 0x011d +#define LGDT3305_CR_CTRL_7 0x0126 +#define LGDT3305_AGC_POWER_REF_1 0x0300 +#define LGDT3305_AGC_POWER_REF_2 0x0301 +#define LGDT3305_AGC_DELAY_PT_1 0x0302 +#define LGDT3305_AGC_DELAY_PT_2 0x0303 +#define LGDT3305_RFAGC_LOOP_FLTR_BW_1 0x0306 +#define LGDT3305_RFAGC_LOOP_FLTR_BW_2 0x0307 +#define LGDT3305_IFBW_1 0x0308 +#define LGDT3305_IFBW_2 0x0309 +#define LGDT3305_AGC_CTRL_1 0x030c +#define LGDT3305_AGC_CTRL_4 0x0314 +#define LGDT3305_EQ_MSE_1 0x0413 +#define LGDT3305_EQ_MSE_2 0x0414 +#define LGDT3305_EQ_MSE_3 0x0415 +#define LGDT3305_PT_MSE_1 0x0417 +#define LGDT3305_PT_MSE_2 0x0418 +#define LGDT3305_PT_MSE_3 0x0419 +#define LGDT3305_FEC_BLOCK_CTRL 0x0504 +#define LGDT3305_FEC_LOCK_STATUS 0x050a +#define LGDT3305_FEC_PKT_ERR_1 0x050c +#define LGDT3305_FEC_PKT_ERR_2 0x050d +#define LGDT3305_TP_CTRL_1 0x050e +#define LGDT3305_BERT_PERIOD 0x0801 +#define LGDT3305_BERT_ERROR_COUNT_1 0x080a +#define LGDT3305_BERT_ERROR_COUNT_2 0x080b +#define LGDT3305_BERT_ERROR_COUNT_3 0x080c +#define LGDT3305_BERT_ERROR_COUNT_4 0x080d + +static int lgdt3305_write_reg(struct lgdt3305_state *state, u16 reg, u8 val) +{ + int ret; + u8 buf[] = { reg >> 8, reg & 0xff, val }; + struct i2c_msg msg = { + .addr = state->cfg->i2c_addr, .flags = 0, + .buf = buf, .len = 3, + }; + + lg_reg("reg: 0x%04x, val: 0x%02x\n", reg, val); + + ret = i2c_transfer(state->i2c_adap, &msg, 1); + + if (ret != 1) { + lg_err("error (addr %02x %02x <- %02x, err = %i)\n", + msg.buf[0], msg.buf[1], msg.buf[2], ret); + if (ret < 0) + return ret; + else + return -EREMOTEIO; + } + return 0; +} + +static int lgdt3305_read_reg(struct lgdt3305_state *state, u16 reg, u8 *val) +{ + int ret; + u8 reg_buf[] = { reg >> 8, reg & 0xff }; + struct i2c_msg msg[] = { + { .addr = state->cfg->i2c_addr, + .flags = 0, .buf = reg_buf, .len = 2 }, + { .addr = state->cfg->i2c_addr, + .flags = I2C_M_RD, .buf = val, .len = 1 }, + }; + + lg_reg("reg: 0x%04x\n", reg); + + ret = i2c_transfer(state->i2c_adap, msg, 2); + + if (ret != 2) { + lg_err("error (addr %02x reg %04x error (ret == %i)\n", + state->cfg->i2c_addr, reg, ret); + if (ret < 0) + return ret; + else + return -EREMOTEIO; + } + return 0; +} + +#define read_reg(state, reg) \ +({ \ + u8 __val; \ + int ret = lgdt3305_read_reg(state, reg, &__val); \ + if (lg_fail(ret)) \ + __val = 0; \ + __val; \ +}) + +static int lgdt3305_set_reg_bit(struct lgdt3305_state *state, + u16 reg, int bit, int onoff) +{ + u8 val; + int ret; + + lg_reg("reg: 0x%04x, bit: %d, level: %d\n", reg, bit, onoff); + + ret = lgdt3305_read_reg(state, reg, &val); + if (lg_fail(ret)) + goto fail; + + val &= ~(1 << bit); + val |= (onoff & 1) << bit; + + ret = lgdt3305_write_reg(state, reg, val); +fail: + return ret; +} + +struct lgdt3305_reg { + u16 reg; + u8 val; +}; + +static int lgdt3305_write_regs(struct lgdt3305_state *state, + struct lgdt3305_reg *regs, int len) +{ + int i, ret; + + lg_reg("writing %d registers...\n", len); + + for (i = 0; i < len - 1; i++) { + ret = lgdt3305_write_reg(state, regs[i].reg, regs[i].val); + if (lg_fail(ret)) + return ret; + } + return 0; +} + +/* ------------------------------------------------------------------------ */ + +static int lgdt3305_soft_reset(struct lgdt3305_state *state) +{ + int ret; + + lg_dbg("\n"); + + ret = lgdt3305_set_reg_bit(state, LGDT3305_GEN_CTRL_3, 0, 0); + if (lg_fail(ret)) + goto fail; + + msleep(20); + ret = lgdt3305_set_reg_bit(state, LGDT3305_GEN_CTRL_3, 0, 1); +fail: + return ret; +} + +static inline int lgdt3305_mpeg_mode(struct lgdt3305_state *state, + enum lgdt3305_mpeg_mode mode) +{ + lg_dbg("(%d)\n", mode); + return lgdt3305_set_reg_bit(state, LGDT3305_TP_CTRL_1, 5, mode); +} + +static int lgdt3305_mpeg_mode_polarity(struct lgdt3305_state *state, + enum lgdt3305_tp_clock_edge edge, + enum lgdt3305_tp_valid_polarity valid) +{ + u8 val; + int ret; + + lg_dbg("edge = %d, valid = %d\n", edge, valid); + + ret = lgdt3305_read_reg(state, LGDT3305_TP_CTRL_1, &val); + if (lg_fail(ret)) + goto fail; + + val &= ~0x09; + + if (edge) + val |= 0x08; + if (valid) + val |= 0x01; + + ret = lgdt3305_write_reg(state, LGDT3305_TP_CTRL_1, val); + if (lg_fail(ret)) + goto fail; + + ret = lgdt3305_soft_reset(state); +fail: + return ret; +} + +static int lgdt3305_set_modulation(struct lgdt3305_state *state, + struct dvb_frontend_parameters *param) +{ + u8 opermode; + int ret; + + lg_dbg("\n"); + + ret = lgdt3305_read_reg(state, LGDT3305_GEN_CTRL_1, &opermode); + if (lg_fail(ret)) + goto fail; + + opermode &= ~0x03; + + switch (param->u.vsb.modulation) { + case VSB_8: + opermode |= 0x03; + break; + case QAM_64: + opermode |= 0x00; + break; + case QAM_256: + opermode |= 0x01; + break; + default: + return -EINVAL; + } + ret = lgdt3305_write_reg(state, LGDT3305_GEN_CTRL_1, opermode); +fail: + return ret; +} + +static int lgdt3305_set_filter_extension(struct lgdt3305_state *state, + struct dvb_frontend_parameters *param) +{ + int val; + + switch (param->u.vsb.modulation) { + case VSB_8: + val = 0; + break; + case QAM_64: + case QAM_256: + val = 1; + break; + default: + return -EINVAL; + } + lg_dbg("val = %d\n", val); + + return lgdt3305_set_reg_bit(state, 0x043f, 2, val); +} + +/* ------------------------------------------------------------------------ */ + +static int lgdt3305_passband_digital_agc(struct lgdt3305_state *state, + struct dvb_frontend_parameters *param) +{ + u16 agc_ref; + + switch (param->u.vsb.modulation) { + case VSB_8: + agc_ref = 0x32c4; + break; + case QAM_64: + agc_ref = 0x2a00; + break; + case QAM_256: + agc_ref = 0x2a80; + break; + default: + return -EINVAL; + } + + lg_dbg("agc ref: 0x%04x\n", agc_ref); + + lgdt3305_write_reg(state, LGDT3305_DGTL_AGC_REF_1, agc_ref >> 8); + lgdt3305_write_reg(state, LGDT3305_DGTL_AGC_REF_2, agc_ref & 0xff); + + return 0; +} + +static int lgdt3305_rfagc_loop(struct lgdt3305_state *state, + struct dvb_frontend_parameters *param) +{ + u16 ifbw, rfbw, agcdelay; + + switch (param->u.vsb.modulation) { + case VSB_8: + agcdelay = 0x04c0; + rfbw = 0x8000; + ifbw = 0x8000; + break; + case QAM_64: + case QAM_256: + agcdelay = 0x046b; + rfbw = 0x8889; + ifbw = 0x8888; + break; + default: + return -EINVAL; + } + + if (state->cfg->rf_agc_loop) { + lg_dbg("agcdelay: 0x%04x, rfbw: 0x%04x\n", agcdelay, rfbw); + + /* rf agc loop filter bandwidth */ + lgdt3305_write_reg(state, LGDT3305_AGC_DELAY_PT_1, + agcdelay >> 8); + lgdt3305_write_reg(state, LGDT3305_AGC_DELAY_PT_2, + agcdelay & 0xff); + + lgdt3305_write_reg(state, LGDT3305_RFAGC_LOOP_FLTR_BW_1, + rfbw >> 8); + lgdt3305_write_reg(state, LGDT3305_RFAGC_LOOP_FLTR_BW_2, + rfbw & 0xff); + } else { + lg_dbg("ifbw: 0x%04x\n", ifbw); + + /* if agc loop filter bandwidth */ + lgdt3305_write_reg(state, LGDT3305_IFBW_1, ifbw >> 8); + lgdt3305_write_reg(state, LGDT3305_IFBW_2, ifbw & 0xff); + } + + return 0; +} + +static int lgdt3305_agc_setup(struct lgdt3305_state *state, + struct dvb_frontend_parameters *param) +{ + int lockdten, acqen; + + switch (param->u.vsb.modulation) { + case VSB_8: + lockdten = 0; + acqen = 0; + break; + case QAM_64: + case QAM_256: + lockdten = 1; + acqen = 1; + break; + default: + return -EINVAL; + } + + lg_dbg("lockdten = %d, acqen = %d\n", lockdten, acqen); + + /* control agc function */ + lgdt3305_write_reg(state, LGDT3305_AGC_CTRL_4, 0xe1 | lockdten << 1); + lgdt3305_set_reg_bit(state, LGDT3305_AGC_CTRL_1, 2, acqen); + + return lgdt3305_rfagc_loop(state, param); +} + +static int lgdt3305_set_agc_power_ref(struct lgdt3305_state *state, + struct dvb_frontend_parameters *param) +{ + u16 usref = 0; + + switch (param->u.vsb.modulation) { + case VSB_8: + if (state->cfg->usref_8vsb) + usref = state->cfg->usref_8vsb; + break; + case QAM_64: + if (state->cfg->usref_qam64) + usref = state->cfg->usref_qam64; + break; + case QAM_256: + if (state->cfg->usref_qam256) + usref = state->cfg->usref_qam256; + break; + default: + return -EINVAL; + } + + if (usref) { + lg_dbg("set manual mode: 0x%04x\n", usref); + + lgdt3305_set_reg_bit(state, LGDT3305_AGC_CTRL_1, 3, 1); + + lgdt3305_write_reg(state, LGDT3305_AGC_POWER_REF_1, + 0xff & (usref >> 8)); + lgdt3305_write_reg(state, LGDT3305_AGC_POWER_REF_2, + 0xff & (usref >> 0)); + } + return 0; +} + +/* ------------------------------------------------------------------------ */ + +static int lgdt3305_spectral_inversion(struct lgdt3305_state *state, + struct dvb_frontend_parameters *param, + int inversion) +{ + int ret; + + lg_dbg("(%d)\n", inversion); + + switch (param->u.vsb.modulation) { + case VSB_8: + ret = lgdt3305_write_reg(state, LGDT3305_CR_CTRL_7, + inversion ? 0xf9 : 0x79); + break; + case QAM_64: + case QAM_256: + ret = lgdt3305_write_reg(state, LGDT3305_FEC_BLOCK_CTRL, + inversion ? 0xfd : 0xff); + break; + default: + ret = -EINVAL; + } + return ret; +} + +static int lgdt3305_set_if(struct lgdt3305_state *state, + struct dvb_frontend_parameters *param) +{ + u16 if_freq_khz; + u8 nco1, nco2, nco3, nco4; + u64 nco; + + switch (param->u.vsb.modulation) { + case VSB_8: + if_freq_khz = state->cfg->vsb_if_khz; + break; + case QAM_64: + case QAM_256: + if_freq_khz = state->cfg->qam_if_khz; + break; + default: + return -EINVAL; + } + + nco = if_freq_khz / 10; + +#define LGDT3305_64BIT_DIVISION_ENABLED 0 + /* FIXME: 64bit division disabled to avoid linking error: + * WARNING: "__udivdi3" [lgdt3305.ko] undefined! + */ + switch (param->u.vsb.modulation) { + case VSB_8: +#if LGDT3305_64BIT_DIVISION_ENABLED + nco <<= 24; + nco /= 625; +#else + nco *= ((1 << 24) / 625); +#endif + break; + case QAM_64: + case QAM_256: +#if LGDT3305_64BIT_DIVISION_ENABLED + nco <<= 28; + nco /= 625; +#else + nco *= ((1 << 28) / 625); +#endif + break; + default: + return -EINVAL; + } + + nco1 = (nco >> 24) & 0x3f; + nco1 |= 0x40; + nco2 = (nco >> 16) & 0xff; + nco3 = (nco >> 8) & 0xff; + nco4 = nco & 0xff; + + lgdt3305_write_reg(state, LGDT3305_CR_CTR_FREQ_1, nco1); + lgdt3305_write_reg(state, LGDT3305_CR_CTR_FREQ_2, nco2); + lgdt3305_write_reg(state, LGDT3305_CR_CTR_FREQ_3, nco3); + lgdt3305_write_reg(state, LGDT3305_CR_CTR_FREQ_4, nco4); + + lg_dbg("%d KHz -> [%02x%02x%02x%02x]\n", + if_freq_khz, nco1, nco2, nco3, nco4); + + return 0; +} + +/* ------------------------------------------------------------------------ */ + +static int lgdt3305_i2c_gate_ctrl(struct dvb_frontend *fe, int enable) +{ + struct lgdt3305_state *state = fe->demodulator_priv; + + if (state->cfg->deny_i2c_rptr) + return 0; + + lg_dbg("(%d)\n", enable); + + return lgdt3305_set_reg_bit(state, LGDT3305_GEN_CTRL_2, 5, + enable ? 0 : 1); +} + +static int lgdt3305_sleep(struct dvb_frontend *fe) +{ + struct lgdt3305_state *state = fe->demodulator_priv; + u8 gen_ctrl_3, gen_ctrl_4; + + lg_dbg("\n"); + + gen_ctrl_3 = read_reg(state, LGDT3305_GEN_CTRL_3); + gen_ctrl_4 = read_reg(state, LGDT3305_GEN_CTRL_4); + + /* hold in software reset while sleeping */ + gen_ctrl_3 &= ~0x01; + /* tristate the IF-AGC pin */ + gen_ctrl_3 |= 0x02; + /* tristate the RF-AGC pin */ + gen_ctrl_3 |= 0x04; + + /* disable vsb/qam module */ + gen_ctrl_4 &= ~0x01; + /* disable adc module */ + gen_ctrl_4 &= ~0x02; + + lgdt3305_write_reg(state, LGDT3305_GEN_CTRL_3, gen_ctrl_3); + lgdt3305_write_reg(state, LGDT3305_GEN_CTRL_4, gen_ctrl_4); + + return 0; +} + +static int lgdt3305_init(struct dvb_frontend *fe) +{ + struct lgdt3305_state *state = fe->demodulator_priv; + int ret; + + static struct lgdt3305_reg lgdt3305_init_data[] = { + { .reg = LGDT3305_GEN_CTRL_1, + .val = 0x03, }, + { .reg = LGDT3305_GEN_CTRL_2, + .val = 0xb0, }, + { .reg = LGDT3305_GEN_CTRL_3, + .val = 0x01, }, + { .reg = LGDT3305_GEN_CONTROL, + .val = 0x6f, }, + { .reg = LGDT3305_GEN_CTRL_4, + .val = 0x03, }, + { .reg = LGDT3305_DGTL_AGC_REF_1, + .val = 0x32, }, + { .reg = LGDT3305_DGTL_AGC_REF_2, + .val = 0xc4, }, + { .reg = LGDT3305_CR_CTR_FREQ_1, + .val = 0x00, }, + { .reg = LGDT3305_CR_CTR_FREQ_2, + .val = 0x00, }, + { .reg = LGDT3305_CR_CTR_FREQ_3, + .val = 0x00, }, + { .reg = LGDT3305_CR_CTR_FREQ_4, + .val = 0x00, }, + { .reg = LGDT3305_CR_CTRL_7, + .val = 0x79, }, + { .reg = LGDT3305_AGC_POWER_REF_1, + .val = 0x32, }, + { .reg = LGDT3305_AGC_POWER_REF_2, + .val = 0xc4, }, + { .reg = LGDT3305_AGC_DELAY_PT_1, + .val = 0x0d, }, + { .reg = LGDT3305_AGC_DELAY_PT_2, + .val = 0x30, }, + { .reg = LGDT3305_RFAGC_LOOP_FLTR_BW_1, + .val = 0x80, }, + { .reg = LGDT3305_RFAGC_LOOP_FLTR_BW_2, + .val = 0x00, }, + { .reg = LGDT3305_IFBW_1, + .val = 0x80, }, + { .reg = LGDT3305_IFBW_2, + .val = 0x00, }, + { .reg = LGDT3305_AGC_CTRL_1, + .val = 0x30, }, + { .reg = LGDT3305_AGC_CTRL_4, + .val = 0x61, }, + { .reg = LGDT3305_FEC_BLOCK_CTRL, + .val = 0xff, }, + { .reg = LGDT3305_TP_CTRL_1, + .val = 0x1b, }, + }; + + lg_dbg("\n"); + + ret = lgdt3305_write_regs(state, lgdt3305_init_data, + ARRAY_SIZE(lgdt3305_init_data)); + if (lg_fail(ret)) + goto fail; + + ret = lgdt3305_soft_reset(state); +fail: + return ret; +} + +static int lgdt3305_set_parameters(struct dvb_frontend *fe, + struct dvb_frontend_parameters *param) +{ + struct lgdt3305_state *state = fe->demodulator_priv; + int ret; + + lg_dbg("(%d, %d)\n", param->frequency, param->u.vsb.modulation); + + if (fe->ops.tuner_ops.set_params) { + ret = fe->ops.tuner_ops.set_params(fe, param); + if (fe->ops.i2c_gate_ctrl) + fe->ops.i2c_gate_ctrl(fe, 0); + if (lg_fail(ret)) + goto fail; + state->current_frequency = param->frequency; + } + + ret = lgdt3305_set_modulation(state, param); + if (lg_fail(ret)) + goto fail; + + ret = lgdt3305_passband_digital_agc(state, param); + if (lg_fail(ret)) + goto fail; + ret = lgdt3305_set_agc_power_ref(state, param); + if (lg_fail(ret)) + goto fail; + ret = lgdt3305_agc_setup(state, param); + if (lg_fail(ret)) + goto fail; + + /* low if */ + ret = lgdt3305_write_reg(state, LGDT3305_GEN_CONTROL, 0x2f); + if (lg_fail(ret)) + goto fail; + ret = lgdt3305_set_reg_bit(state, LGDT3305_CR_CTR_FREQ_1, 6, 1); + if (lg_fail(ret)) + goto fail; + + ret = lgdt3305_set_if(state, param); + if (lg_fail(ret)) + goto fail; + ret = lgdt3305_spectral_inversion(state, param, + state->cfg->spectral_inversion + ? 1 : 0); + if (lg_fail(ret)) + goto fail; + + ret = lgdt3305_set_filter_extension(state, param); + if (lg_fail(ret)) + goto fail; + + state->current_modulation = param->u.vsb.modulation; + + ret = lgdt3305_mpeg_mode(state, state->cfg->mpeg_mode); + if (lg_fail(ret)) + goto fail; + + /* lgdt3305_mpeg_mode_polarity calls lgdt3305_soft_reset */ + ret = lgdt3305_mpeg_mode_polarity(state, + state->cfg->tpclk_edge, + state->cfg->tpvalid_polarity); +fail: + return ret; +} + +static int lgdt3305_get_frontend(struct dvb_frontend *fe, + struct dvb_frontend_parameters *param) +{ + struct lgdt3305_state *state = fe->demodulator_priv; + + lg_dbg("\n"); + + param->u.vsb.modulation = state->current_modulation; + param->frequency = state->current_frequency; + return 0; +} + +/* ------------------------------------------------------------------------ */ + +static int lgdt3305_read_cr_lock_status(struct lgdt3305_state *state, + int *locked) +{ + u8 val; + int ret; + char *cr_lock_state = ""; + + *locked = 0; + + ret = lgdt3305_read_reg(state, LGDT3305_CR_LOCK_STATUS, &val); + if (lg_fail(ret)) + goto fail; + + switch (state->current_modulation) { + case QAM_256: + case QAM_64: + if (val & (1 << 1)) + *locked = 1; + + switch (val & 0x07) { + case 0: + cr_lock_state = "QAM UNLOCK"; + break; + case 4: + cr_lock_state = "QAM 1stLock"; + break; + case 6: + cr_lock_state = "QAM 2ndLock"; + break; + case 7: + cr_lock_state = "QAM FinalLock"; + break; + default: + cr_lock_state = "CLOCKQAM-INVALID!"; + break; + } + break; + case VSB_8: + if (val & (1 << 7)) { + *locked = 1; + cr_lock_state = "CLOCKVSB"; + } + break; + default: + ret = -EINVAL; + } + lg_dbg("(%d) %s\n", *locked, cr_lock_state); +fail: + return ret; +} + +static int lgdt3305_read_fec_lock_status(struct lgdt3305_state *state, + int *locked) +{ + u8 val; + int ret, mpeg_lock, fec_lock, viterbi_lock; + + *locked = 0; + + switch (state->current_modulation) { + case QAM_256: + case QAM_64: + ret = lgdt3305_read_reg(state, + LGDT3305_FEC_LOCK_STATUS, &val); + if (lg_fail(ret)) + goto fail; + + mpeg_lock = (val & (1 << 0)) ? 1 : 0; + fec_lock = (val & (1 << 2)) ? 1 : 0; + viterbi_lock = (val & (1 << 3)) ? 1 : 0; + + *locked = mpeg_lock && fec_lock && viterbi_lock; + + lg_dbg("(%d) %s%s%s\n", *locked, + mpeg_lock ? "mpeg lock " : "", + fec_lock ? "fec lock " : "", + viterbi_lock ? "viterbi lock" : ""); + break; + case VSB_8: + default: + ret = -EINVAL; + } +fail: + return ret; +} + +static int lgdt3305_read_status(struct dvb_frontend *fe, fe_status_t *status) +{ + struct lgdt3305_state *state = fe->demodulator_priv; + u8 val; + int ret, signal, inlock, nofecerr, snrgood, + cr_lock, fec_lock, sync_lock; + + *status = 0; + + ret = lgdt3305_read_reg(state, LGDT3305_GEN_STATUS, &val); + if (lg_fail(ret)) + goto fail; + + signal = (val & (1 << 4)) ? 1 : 0; + inlock = (val & (1 << 3)) ? 0 : 1; + sync_lock = (val & (1 << 2)) ? 1 : 0; + nofecerr = (val & (1 << 1)) ? 1 : 0; + snrgood = (val & (1 << 0)) ? 1 : 0; + + lg_dbg("%s%s%s%s%s\n", + signal ? "SIGNALEXIST " : "", + inlock ? "INLOCK " : "", + sync_lock ? "SYNCLOCK " : "", + nofecerr ? "NOFECERR " : "", + snrgood ? "SNRGOOD " : ""); + + ret = lgdt3305_read_cr_lock_status(state, &cr_lock); + if (lg_fail(ret)) + goto fail; + + if (signal) + *status |= FE_HAS_SIGNAL; + if (cr_lock) + *status |= FE_HAS_CARRIER; + if (nofecerr) + *status |= FE_HAS_VITERBI; + if (sync_lock) + *status |= FE_HAS_SYNC; + + switch (state->current_modulation) { + case QAM_256: + case QAM_64: + ret = lgdt3305_read_fec_lock_status(state, &fec_lock); + if (lg_fail(ret)) + goto fail; + + if (fec_lock) + *status |= FE_HAS_LOCK; + break; + case VSB_8: + if (inlock) + *status |= FE_HAS_LOCK; + break; + default: + ret = -EINVAL; + } +fail: + return ret; +} + +/* ------------------------------------------------------------------------ */ + +/* borrowed from lgdt330x.c */ +static u32 calculate_snr(u32 mse, u32 c) +{ + if (mse == 0) /* no signal */ + return 0; + + mse = intlog10(mse); + if (mse > c) { + /* Negative SNR, which is possible, but realisticly the + demod will lose lock before the signal gets this bad. The + API only allows for unsigned values, so just return 0 */ + return 0; + } + return 10*(c - mse); +} + +static int lgdt3305_read_snr(struct dvb_frontend *fe, u16 *snr) +{ + struct lgdt3305_state *state = fe->demodulator_priv; + u32 noise; /* noise value */ + u32 c; /* per-modulation SNR calculation constant */ + + switch (state->current_modulation) { + case VSB_8: +#ifdef USE_PTMSE + /* Use Phase Tracker Mean-Square Error Register */ + /* SNR for ranges from -13.11 to +44.08 */ + noise = ((read_reg(state, LGDT3305_PT_MSE_1) & 0x07) << 16) | + (read_reg(state, LGDT3305_PT_MSE_2) << 8) | + (read_reg(state, LGDT3305_PT_MSE_3) & 0xff); + c = 73957994; /* log10(25*32^2)*2^24 */ +#else + /* Use Equalizer Mean-Square Error Register */ + /* SNR for ranges from -16.12 to +44.08 */ + noise = ((read_reg(state, LGDT3305_EQ_MSE_1) & 0x0f) << 16) | + (read_reg(state, LGDT3305_EQ_MSE_2) << 8) | + (read_reg(state, LGDT3305_EQ_MSE_3) & 0xff); + c = 73957994; /* log10(25*32^2)*2^24 */ +#endif + break; + case QAM_64: + case QAM_256: + noise = (read_reg(state, LGDT3305_CR_MSE_1) << 8) | + (read_reg(state, LGDT3305_CR_MSE_2) & 0xff); + + c = (state->current_modulation == QAM_64) ? + 97939837 : 98026066; + /* log10(688128)*2^24 and log10(696320)*2^24 */ + break; + default: + return -EINVAL; + } + state->snr = calculate_snr(noise, c); +#if 0 + /* convert from 8.24 fixed-point to 8.8 */ + *snr = (state->snr) >> 16; +#else + /* report SNR in dB * 10 */ + *snr = (state->snr / ((1 << 24) / 10)); +#endif + lg_dbg("noise = 0x%08x, snr = %d.%02d dB\n", noise, + state->snr >> 24, (((state->snr >> 8) & 0xffff) * 100) >> 16); + + return 0; +} + +static int lgdt3305_read_signal_strength(struct dvb_frontend *fe, + u16 *strength) +{ + /* borrowed from lgdt330x.c + * + * Calculate strength from SNR up to 35dB + * Even though the SNR can go higher than 35dB, + * there is some comfort factor in having a range of + * strong signals that can show at 100% + */ + struct lgdt3305_state *state = fe->demodulator_priv; + u16 snr; + int ret; + + *strength = 0; + + ret = fe->ops.read_snr(fe, &snr); + if (lg_fail(ret)) + goto fail; + /* Rather than use the 8.8 value snr, use state->snr which is 8.24 */ + /* scale the range 0 - 35*2^24 into 0 - 65535 */ + if (state->snr >= 8960 * 0x10000) + *strength = 0xffff; + else + *strength = state->snr / 8960; +fail: + return ret; +} + +/* ------------------------------------------------------------------------ */ + +static int lgdt3305_read_ber(struct dvb_frontend *fe, u32 *ber) +{ +#if 0 + struct lgdt3305_state *state = fe->demodulator_priv; + u32 period, biterror; + u8 bertperd; + + bertperd = read_reg(state, LGDT3305_BERT_PERIOD) & 0x1f; + if (bertperd < 4) + bertperd = 4; + period = (1 << bertperd); + + biterror = + (read_reg(state, LGDT3305_BERT_ERROR_COUNT_1) << 24) | + (read_reg(state, LGDT3305_BERT_ERROR_COUNT_2) << 16) | + (read_reg(state, LGDT3305_BERT_ERROR_COUNT_3) << 8) | + (read_reg(state, LGDT3305_BERT_ERROR_COUNT_4) & 0xff); + + *ber = (biterror) / period; + + lg_dbg("biterror = %d, period = %d, ber = 0x%x\n", + biterror, period, *ber); +#else + *ber = 0; +#endif + return 0; +} + +static int lgdt3305_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks) +{ + struct lgdt3305_state *state = fe->demodulator_priv; + + *ucblocks = + (read_reg(state, LGDT3305_FEC_PKT_ERR_1) << 8) | + (read_reg(state, LGDT3305_FEC_PKT_ERR_2) & 0xff); + + return 0; +} + +static int lgdt3305_get_tune_settings(struct dvb_frontend *fe, + struct dvb_frontend_tune_settings + *fe_tune_settings) +{ + fe_tune_settings->min_delay_ms = 500; + lg_dbg("\n"); + return 0; +} + +static void lgdt3305_release(struct dvb_frontend *fe) +{ + struct lgdt3305_state *state = fe->demodulator_priv; + lg_dbg("\n"); + kfree(state); +} + +static struct dvb_frontend_ops lgdt3305_ops; + +struct dvb_frontend *lgdt3305_attach(const struct lgdt3305_config *config, + struct i2c_adapter *i2c_adap) +{ + struct lgdt3305_state *state = NULL; + int ret; + u8 val; + + lg_dbg("(%d-%04x)\n", + i2c_adap ? i2c_adapter_id(i2c_adap) : 0, + config ? config->i2c_addr : 0); + + state = kzalloc(sizeof(struct lgdt3305_state), GFP_KERNEL); + if (state == NULL) + goto fail; + + state->cfg = config; + state->i2c_adap = i2c_adap; + + memcpy(&state->frontend.ops, &lgdt3305_ops, + sizeof(struct dvb_frontend_ops)); + state->frontend.demodulator_priv = state; + + /* verify that we're talking to a lg dt3305 */ + ret = lgdt3305_read_reg(state, LGDT3305_GEN_CTRL_2, &val); + if ((lg_fail(ret)) | (val == 0)) + goto fail; + ret = lgdt3305_write_reg(state, 0x0808, 0x80); + if (lg_fail(ret)) + goto fail; + ret = lgdt3305_read_reg(state, 0x0808, &val); + if ((lg_fail(ret)) | (val != 0x80)) + goto fail; + ret = lgdt3305_write_reg(state, 0x0808, 0x00); + if (lg_fail(ret)) + goto fail; + + state->current_frequency = -1; + state->current_modulation = -1; + + return &state->frontend; +fail: + lg_warn("unable to detect LGDT3305 hardware\n"); + kfree(state); + return NULL; +} +EXPORT_SYMBOL(lgdt3305_attach); + +static struct dvb_frontend_ops lgdt3305_ops = { + .info = { + .name = "LG Electronics LGDT3305 VSB/QAM Frontend", + .type = FE_ATSC, + .frequency_min = 54000000, + .frequency_max = 858000000, + .frequency_stepsize = 62500, + .caps = FE_CAN_QAM_64 | FE_CAN_QAM_256 | FE_CAN_8VSB + }, + .i2c_gate_ctrl = lgdt3305_i2c_gate_ctrl, + .init = lgdt3305_init, + .sleep = lgdt3305_sleep, + .set_frontend = lgdt3305_set_parameters, + .get_frontend = lgdt3305_get_frontend, + .get_tune_settings = lgdt3305_get_tune_settings, + .read_status = lgdt3305_read_status, + .read_ber = lgdt3305_read_ber, + .read_signal_strength = lgdt3305_read_signal_strength, + .read_snr = lgdt3305_read_snr, + .read_ucblocks = lgdt3305_read_ucblocks, + .release = lgdt3305_release, +}; + +MODULE_DESCRIPTION("LG Electronics LGDT3305 ATSC/QAM-B Demodulator Driver"); +MODULE_AUTHOR("Michael Krufky <mkrufky@linuxtv.org>"); +MODULE_LICENSE("GPL"); +MODULE_VERSION("0.1"); + +/* + * Local variables: + * c-basic-offset: 8 + * End: + */ diff --git a/linux/drivers/media/dvb/frontends/lgdt3305.h b/linux/drivers/media/dvb/frontends/lgdt3305.h new file mode 100644 index 000000000..4fa6e52d1 --- /dev/null +++ b/linux/drivers/media/dvb/frontends/lgdt3305.h @@ -0,0 +1,85 @@ +/* + * Support for LGDT3305 - VSB/QAM + * + * Copyright (C) 2008, 2009 Michael Krufky <mkrufky@linuxtv.org> + * + * 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 _LGDT3305_H_ +#define _LGDT3305_H_ + +#include <linux/i2c.h> +#include "dvb_frontend.h" + + +enum lgdt3305_mpeg_mode { + LGDT3305_MPEG_PARALLEL = 0, + LGDT3305_MPEG_SERIAL = 1, +}; + +enum lgdt3305_tp_clock_edge { + LGDT3305_TPCLK_RISING_EDGE = 0, + LGDT3305_TPCLK_FALLING_EDGE = 1, +}; + +enum lgdt3305_tp_valid_polarity { + LGDT3305_TP_VALID_LOW = 0, + LGDT3305_TP_VALID_HIGH = 1, +}; + +struct lgdt3305_config { + u8 i2c_addr; + + /* user defined IF frequency in KHz */ + u16 qam_if_khz; + u16 vsb_if_khz; + + /* AGC Power reference - defaults are used if left unset */ + u16 usref_8vsb; /* default: 0x32c4 */ + u16 usref_qam64; /* default: 0x5400 */ + u16 usref_qam256; /* default: 0x2a80 */ + + /* disable i2c repeater - 0:repeater enabled 1:repeater disabled */ + int deny_i2c_rptr:1; + + /* spectral inversion - 0:disabled 1:enabled */ + int spectral_inversion:1; + + /* use RF AGC loop - 0:disabled 1:enabled */ + int rf_agc_loop:1; + + enum lgdt3305_mpeg_mode mpeg_mode; + enum lgdt3305_tp_clock_edge tpclk_edge; + enum lgdt3305_tp_valid_polarity tpvalid_polarity; +}; + +#if defined(CONFIG_DVB_LGDT3305) || (defined(CONFIG_DVB_LGDT3305_MODULE) && \ + defined(MODULE)) +extern +struct dvb_frontend *lgdt3305_attach(const struct lgdt3305_config *config, + struct i2c_adapter *i2c_adap); +#else +static inline +struct dvb_frontend *lgdt3305_attach(const struct lgdt3305_config *config, + struct i2c_adapter *i2c_adap) +{ + printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__); + return NULL; +} +#endif /* CONFIG_DVB_LGDT3305 */ + +#endif /* _LGDT3305_H_ */ diff --git a/linux/drivers/media/dvb/frontends/stb0899_algo.c b/linux/drivers/media/dvb/frontends/stb0899_algo.c index 3d13968a7..72012ce11 100644 --- a/linux/drivers/media/dvb/frontends/stb0899_algo.c +++ b/linux/drivers/media/dvb/frontends/stb0899_algo.c @@ -156,7 +156,7 @@ static void stb0899_first_subrange(struct stb0899_state *state) } if (range > 0) - internal->sub_range = MIN(internal->srch_range, range); + internal->sub_range = min(internal->srch_range, range); else internal->sub_range = 0; @@ -185,7 +185,7 @@ static enum stb0899_status stb0899_check_tmg(struct stb0899_state *state) timing = stb0899_read_reg(state, STB0899_RTF); if (lock >= 42) { - if ((lock > 48) && (ABS(timing) >= 110)) { + if ((lock > 48) && (abs(timing) >= 110)) { internal->status = ANALOGCARRIER; dprintk(state->verbose, FE_DEBUG, 1, "-->ANALOG Carrier !"); } else { @@ -222,7 +222,7 @@ static enum stb0899_status stb0899_search_tmg(struct stb0899_state *state) index++; derot_freq += index * internal->direction * derot_step; /* next derot zig zag position */ - if (ABS(derot_freq) > derot_limit) + if (abs(derot_freq) > derot_limit) next_loop--; if (next_loop) { @@ -298,7 +298,7 @@ static enum stb0899_status stb0899_search_carrier(struct stb0899_state *state) last_derot_freq = derot_freq; derot_freq += index * internal->direction * internal->derot_step; /* next zig zag derotator position */ - if(ABS(derot_freq) > derot_limit) + if(abs(derot_freq) > derot_limit) next_loop--; if (next_loop) { @@ -400,7 +400,7 @@ static enum stb0899_status stb0899_search_data(struct stb0899_state *state) if ((internal->status != CARRIEROK) || (stb0899_check_data(state) != DATAOK)) { derot_freq += index * internal->direction * derot_step; /* next zig zag derotator position */ - if (ABS(derot_freq) > derot_limit) + if (abs(derot_freq) > derot_limit) next_loop--; if (next_loop) { @@ -467,7 +467,7 @@ static void next_sub_range(struct stb0899_state *state) if (internal->sub_dir > 0) { old_sub_range = internal->sub_range; - internal->sub_range = MIN((internal->srch_range / 2) - + internal->sub_range = min((internal->srch_range / 2) - (internal->tuner_offst + internal->sub_range / 2), internal->sub_range); @@ -771,7 +771,7 @@ static long Log2Int(int number) int i; i = 0; - while ((1 << i) <= ABS(number)) + while ((1 << i) <= abs(number)) i++; if (number == 0) diff --git a/linux/drivers/media/dvb/frontends/stb0899_drv.c b/linux/drivers/media/dvb/frontends/stb0899_drv.c index 1e38abee5..32841ade0 100644 --- a/linux/drivers/media/dvb/frontends/stb0899_drv.c +++ b/linux/drivers/media/dvb/frontends/stb0899_drv.c @@ -794,7 +794,7 @@ static int stb0899_send_diseqc_burst(struct dvb_frontend *fe, fe_sec_mini_cmd_t reg = stb0899_read_reg(state, STB0899_DISCNTRL1); old_state = reg; /* set to burst mode */ - STB0899_SETFIELD_VAL(DISEQCMODE, reg, 0x02); + STB0899_SETFIELD_VAL(DISEQCMODE, reg, 0x03); STB0899_SETFIELD_VAL(DISPRECHARGE, reg, 0x01); stb0899_write_reg(state, STB0899_DISCNTRL1, reg); switch (burst) { diff --git a/linux/drivers/media/dvb/frontends/stb0899_priv.h b/linux/drivers/media/dvb/frontends/stb0899_priv.h index e57ff227b..d2a69d0a3 100644 --- a/linux/drivers/media/dvb/frontends/stb0899_priv.h +++ b/linux/drivers/media/dvb/frontends/stb0899_priv.h @@ -59,10 +59,6 @@ #define MAKEWORD32(a, b, c, d) (((a) << 24) | ((b) << 16) | ((c) << 8) | (d)) #define MAKEWORD16(a, b) (((a) << 8) | (b)) -#define MIN(x, y) ((x) <= (y) ? (x) : (y)) -#define MAX(x, y) ((x) >= (y) ? (x) : (y)) -#define ABS(x) ((x) >= 0 ? (x) : -(x)) - #define LSB(x) ((x & 0xff)) #define MSB(y) ((y >> 8) & 0xff) @@ -168,10 +164,10 @@ struct stb0899_internal { u32 freq; /* Demod internal Frequency */ u32 srate; /* Demod internal Symbol rate */ enum stb0899_fec fecrate; /* Demod internal FEC rate */ - u32 srch_range; /* Demod internal Search Range */ - u32 sub_range; /* Demod current sub range (Hz) */ - u32 tuner_step; /* Tuner step (Hz) */ - u32 tuner_offst; /* Relative offset to carrier (Hz) */ + s32 srch_range; /* Demod internal Search Range */ + s32 sub_range; /* Demod current sub range (Hz) */ + s32 tuner_step; /* Tuner step (Hz) */ + s32 tuner_offst; /* Relative offset to carrier (Hz) */ u32 tuner_bw; /* Current bandwidth of the tuner (Hz) */ s32 mclk; /* Masterclock Divider factor (binary) */ diff --git a/linux/drivers/media/dvb/frontends/stb6100.c b/linux/drivers/media/dvb/frontends/stb6100.c index 29bc07b86..2b1af36b8 100644 --- a/linux/drivers/media/dvb/frontends/stb6100.c +++ b/linux/drivers/media/dvb/frontends/stb6100.c @@ -434,11 +434,11 @@ static int stb6100_init(struct dvb_frontend *fe) status->refclock = 27000000; /* Hz */ status->iqsense = 1; status->bandwidth = 36000; /* kHz */ - state->bandwidth = status->bandwidth * 1000; /* MHz */ + state->bandwidth = status->bandwidth * 1000; /* Hz */ state->reference = status->refclock / 1000; /* kHz */ /* Set default bandwidth. */ - return stb6100_set_bandwidth(fe, status->bandwidth); + return stb6100_set_bandwidth(fe, state->bandwidth); } static int stb6100_get_state(struct dvb_frontend *fe, 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 be5d7ef7c..96ccc1720 100644 --- a/linux/drivers/media/dvb/frontends/zl10353.c +++ b/linux/drivers/media/dvb/frontends/zl10353.c @@ -601,7 +601,7 @@ static int zl10353_i2c_gate_ctrl(struct dvb_frontend* fe, int enable) struct zl10353_state *state = fe->demodulator_priv; u8 val = 0x0a; - if (state->config.no_tuner) { + if (state->config.disable_i2c_gate_ctrl) { /* No tuner attached to the internal I2C bus */ /* If set enable I2C bridge, the main I2C bus stopped hardly */ return 0; diff --git a/linux/drivers/media/dvb/frontends/zl10353.h b/linux/drivers/media/dvb/frontends/zl10353.h index fdbb88ff7..2287bac46 100644 --- a/linux/drivers/media/dvb/frontends/zl10353.h +++ b/linux/drivers/media/dvb/frontends/zl10353.h @@ -38,6 +38,9 @@ struct zl10353_config /* set if parallel ts output is required */ int parallel_ts; + + /* set if i2c_gate_ctrl disable is required */ + u8 disable_i2c_gate_ctrl:1; }; #if defined(CONFIG_DVB_ZL10353) || (defined(CONFIG_DVB_ZL10353_MODULE) && defined(MODULE)) diff --git a/linux/drivers/media/radio/radio-aimslab.c b/linux/drivers/media/radio/radio-aimslab.c index 7c3a81ad9..29834df05 100644 --- a/linux/drivers/media/radio/radio-aimslab.c +++ b/linux/drivers/media/radio/radio-aimslab.c @@ -35,7 +35,6 @@ #include <linux/videodev2.h> /* kernel radio structs */ #include <linux/version.h> /* for KERNEL_VERSION MACRO */ #include <linux/io.h> /* outb, outb_p */ -#include <linux/uaccess.h> /* copy to/from user */ #include <media/v4l2-device.h> #include <media/v4l2-ioctl.h> #include "compat.h" diff --git a/linux/drivers/media/radio/radio-aztech.c b/linux/drivers/media/radio/radio-aztech.c index 8826b90a3..6b4081a51 100644 --- a/linux/drivers/media/radio/radio-aztech.c +++ b/linux/drivers/media/radio/radio-aztech.c @@ -32,7 +32,6 @@ #include <linux/videodev2.h> /* kernel radio structs */ #include <linux/version.h> /* for KERNEL_VERSION MACRO */ #include <linux/io.h> /* outb, outb_p */ -#include <linux/uaccess.h> /* copy to/from user */ #include <media/v4l2-device.h> #include <media/v4l2-ioctl.h> #include "compat.h" diff --git a/linux/drivers/media/radio/radio-cadet.c b/linux/drivers/media/radio/radio-cadet.c index 373a34fde..2fd4aae2e 100644 --- a/linux/drivers/media/radio/radio-cadet.c +++ b/linux/drivers/media/radio/radio-cadet.c @@ -39,7 +39,6 @@ #include <linux/param.h> #include <linux/pnp.h> #include <linux/io.h> /* outb, outb_p */ -#include <linux/uaccess.h> /* copy to/from user */ #include <media/v4l2-device.h> #include <media/v4l2-ioctl.h> #include "compat.h" diff --git a/linux/drivers/media/radio/radio-gemtek-pci.c b/linux/drivers/media/radio/radio-gemtek-pci.c index b68e2ba4c..13972c431 100644 --- a/linux/drivers/media/radio/radio-gemtek-pci.c +++ b/linux/drivers/media/radio/radio-gemtek-pci.c @@ -48,7 +48,6 @@ #include <linux/errno.h> #include <linux/version.h> /* for KERNEL_VERSION MACRO */ #include <linux/io.h> -#include <linux/uaccess.h> #include <media/v4l2-device.h> #include <media/v4l2-ioctl.h> #include "compat.h" diff --git a/linux/drivers/media/radio/radio-gemtek.c b/linux/drivers/media/radio/radio-gemtek.c index 0cb1cb0a1..d991476e8 100644 --- a/linux/drivers/media/radio/radio-gemtek.c +++ b/linux/drivers/media/radio/radio-gemtek.c @@ -24,7 +24,6 @@ #include <linux/version.h> /* for KERNEL_VERSION MACRO */ #include <linux/mutex.h> #include <linux/io.h> /* outb, outb_p */ -#include <linux/uaccess.h> /* copy to/from user */ #include <media/v4l2-ioctl.h> #include <media/v4l2-device.h> #include "compat.h" diff --git a/linux/drivers/media/radio/radio-maestro.c b/linux/drivers/media/radio/radio-maestro.c index b35092f30..387bf416b 100644 --- a/linux/drivers/media/radio/radio-maestro.c +++ b/linux/drivers/media/radio/radio-maestro.c @@ -26,7 +26,6 @@ #include <linux/pci.h> #include <linux/videodev2.h> #include <linux/io.h> -#include <linux/uaccess.h> #include <media/v4l2-device.h> #include <media/v4l2-ioctl.h> #include "compat.h" diff --git a/linux/drivers/media/radio/radio-maxiradio.c b/linux/drivers/media/radio/radio-maxiradio.c index fa2c5f1ef..a31ea2f5e 100644 --- a/linux/drivers/media/radio/radio-maxiradio.c +++ b/linux/drivers/media/radio/radio-maxiradio.c @@ -42,7 +42,6 @@ #include <linux/videodev2.h> #include <linux/version.h> /* for KERNEL_VERSION MACRO */ #include <linux/io.h> -#include <linux/uaccess.h> #include <media/v4l2-device.h> #include <media/v4l2-ioctl.h> #include "compat.h" diff --git a/linux/drivers/media/radio/radio-rtrack2.c b/linux/drivers/media/radio/radio-rtrack2.c index 93b3da04a..20153db92 100644 --- a/linux/drivers/media/radio/radio-rtrack2.c +++ b/linux/drivers/media/radio/radio-rtrack2.c @@ -17,7 +17,6 @@ #include <linux/mutex.h> #include <linux/version.h> /* for KERNEL_VERSION MACRO */ #include <linux/io.h> /* outb, outb_p */ -#include <linux/uaccess.h> /* copy to/from user */ #include <media/v4l2-device.h> #include <media/v4l2-ioctl.h> #include "compat.h" @@ -61,7 +60,6 @@ static void rt_mute(struct rtrack2 *dev) mutex_lock(&dev->lock); outb(1, dev->io); mutex_unlock(&dev->lock); - mutex_unlock(&dev->lock); dev->muted = 1; } diff --git a/linux/drivers/media/radio/radio-sf16fmi.c b/linux/drivers/media/radio/radio-sf16fmi.c index 392aa27e0..b517b3671 100644 --- a/linux/drivers/media/radio/radio-sf16fmi.c +++ b/linux/drivers/media/radio/radio-sf16fmi.c @@ -26,7 +26,6 @@ #include <linux/mutex.h> #include <linux/videodev2.h> /* kernel radio structs */ #include <linux/io.h> /* outb, outb_p */ -#include <linux/uaccess.h> /* copy to/from user */ #include <media/v4l2-device.h> #include <media/v4l2-ioctl.h> #include "compat.h" diff --git a/linux/drivers/media/radio/radio-sf16fmr2.c b/linux/drivers/media/radio/radio-sf16fmr2.c index 34de92f82..65e303dba 100644 --- a/linux/drivers/media/radio/radio-sf16fmr2.c +++ b/linux/drivers/media/radio/radio-sf16fmr2.c @@ -22,7 +22,6 @@ #include <linux/mutex.h> #include <linux/version.h> /* for KERNEL_VERSION MACRO */ #include <linux/io.h> /* outb, outb_p */ -#include <linux/uaccess.h> /* copy to/from user */ #include <media/v4l2-device.h> #include <media/v4l2-ioctl.h> #include "compat.h" 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/radio/radio-terratec.c b/linux/drivers/media/radio/radio-terratec.c index 9bb1773ca..0bec5f7e2 100644 --- a/linux/drivers/media/radio/radio-terratec.c +++ b/linux/drivers/media/radio/radio-terratec.c @@ -27,12 +27,10 @@ #include <linux/module.h> /* Modules */ #include <linux/init.h> /* Initdata */ #include <linux/ioport.h> /* request_region */ -#include <linux/delay.h> /* udelay */ #include <linux/videodev2.h> /* kernel radio structs */ #include <linux/mutex.h> #include <linux/version.h> /* for KERNEL_VERSION MACRO */ #include <linux/io.h> /* outb, outb_p */ -#include <linux/uaccess.h> /* copy to/from user */ #include <media/v4l2-device.h> #include <media/v4l2-ioctl.h> #include "compat.h" diff --git a/linux/drivers/media/radio/radio-trust.c b/linux/drivers/media/radio/radio-trust.c index 9d2dcb0a7..8b925adb5 100644 --- a/linux/drivers/media/radio/radio-trust.c +++ b/linux/drivers/media/radio/radio-trust.c @@ -22,7 +22,6 @@ #include <linux/version.h> /* for KERNEL_VERSION MACRO */ #include <linux/videodev2.h> #include <linux/io.h> -#include <linux/uaccess.h> #include <media/v4l2-device.h> #include <media/v4l2-ioctl.h> #include "compat.h" diff --git a/linux/drivers/media/radio/radio-typhoon.c b/linux/drivers/media/radio/radio-typhoon.c index 11e3775ab..98e4ce142 100644 --- a/linux/drivers/media/radio/radio-typhoon.c +++ b/linux/drivers/media/radio/radio-typhoon.c @@ -37,7 +37,6 @@ #include <linux/version.h> /* for KERNEL_VERSION MACRO */ #include <linux/videodev2.h> /* kernel radio structs */ #include <linux/io.h> /* outb, outb_p */ -#include <linux/uaccess.h> /* copy to/from user */ #include <media/v4l2-device.h> #include <media/v4l2-ioctl.h> #include "compat.h" diff --git a/linux/drivers/media/radio/radio-zoltrix.c b/linux/drivers/media/radio/radio-zoltrix.c index 3662f68da..0ae5f0d19 100644 --- a/linux/drivers/media/radio/radio-zoltrix.c +++ b/linux/drivers/media/radio/radio-zoltrix.c @@ -37,7 +37,6 @@ #include <linux/mutex.h> #include <linux/version.h> /* for KERNEL_VERSION MACRO */ #include <linux/io.h> /* outb, outb_p */ -#include <linux/uaccess.h> /* copy to/from user */ #include <media/v4l2-device.h> #include <media/v4l2-ioctl.h> #include "compat.h" diff --git a/linux/drivers/media/video/Kconfig b/linux/drivers/media/video/Kconfig index 534a022c4..42562e348 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 @@ -805,6 +791,8 @@ source "drivers/media/video/pvrusb2/Kconfig" source "drivers/media/video/em28xx/Kconfig" +source "drivers/media/video/cx231xx/Kconfig" + source "drivers/media/video/usbvision/Kconfig" source "drivers/media/video/usbvideo/Kconfig" diff --git a/linux/drivers/media/video/Makefile b/linux/drivers/media/video/Makefile index 08a0675fe..99b448e6c 100644 --- a/linux/drivers/media/video/Makefile +++ b/linux/drivers/media/video/Makefile @@ -67,6 +67,7 @@ obj-$(CONFIG_VIDEO_MEYE) += meye.o obj-$(CONFIG_VIDEO_SAA7134) += saa7134/ obj-$(CONFIG_VIDEO_CX88) += cx88/ obj-$(CONFIG_VIDEO_EM28XX) += em28xx/ +obj-$(CONFIG_VIDEO_CX231XX) += cx231xx/ obj-$(CONFIG_VIDEO_USBVISION) += usbvision/ obj-$(CONFIG_VIDEO_TVP5150) += tvp5150.o obj-$(CONFIG_VIDEO_TVP514X) += tvp514x.o 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 6868de9bd..40dac4b95 100644 --- a/linux/drivers/media/video/bt8xx/bttv-cards.c +++ b/linux/drivers/media/video/bt8xx/bttv-cards.c @@ -299,6 +299,8 @@ static struct CARD { /* Duplicate PCI ID, reconfigure for this board during the eeprom read. * { 0x13eb0070, BTTV_BOARD_HAUPPAUGE_IMPACTVCB, "Hauppauge ImpactVCB" }, */ + { 0x109e036e, BTTV_BOARD_CONCEPTRONIC_CTVFMI2, "Conceptronic CTVFMi v2"}, + /* DVB cards (using pci function .1 for mpeg data xfer) */ { 0x001c11bd, BTTV_BOARD_PINNACLESAT, "Pinnacle PCTV Sat" }, { 0x01010071, BTTV_BOARD_NEBULA_DIGITV, "Nebula Electronics DigiTV" }, @@ -2951,7 +2953,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..da7690fa8 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> @@ -197,6 +198,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 +206,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/cx231xx/Kconfig b/linux/drivers/media/video/cx231xx/Kconfig new file mode 100644 index 000000000..aba05d3bd --- /dev/null +++ b/linux/drivers/media/video/cx231xx/Kconfig @@ -0,0 +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 + + ---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 + +config VIDEO_CX231XX_ALSA + 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. + + 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. diff --git a/linux/drivers/media/video/cx231xx/Makefile b/linux/drivers/media/video/cx231xx/Makefile new file mode 100644 index 000000000..755dd0ce6 --- /dev/null +++ b/linux/drivers/media/video/cx231xx/Makefile @@ -0,0 +1,14 @@ +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-alsa.o +obj-$(CONFIG_VIDEO_CX231XX_DVB) += cx231xx-dvb.o + +EXTRA_CFLAGS += -Idrivers/media/video +EXTRA_CFLAGS += -Idrivers/media/common/tuners +EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core +EXTRA_CFLAGS += -Idrivers/media/dvb/frontends + diff --git a/linux/drivers/media/video/cx231xx/cx231xx-audio.c b/linux/drivers/media/video/cx231xx/cx231xx-audio.c new file mode 100644 index 000000000..b6f099042 --- /dev/null +++ b/linux/drivers/media/video/cx231xx/cx231xx-audio.c @@ -0,0 +1,667 @@ +/* + * Conexant Cx231xx audio extension + * + * Copyright (C) 2008 <srinivasa.deevi at conexant dot com> + * Based on em28xx driver + * + * + * 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/usb.h> +#include <linux/init.h> +#include <linux/sound.h> +#include <linux/spinlock.h> +#include <linux/soundcard.h> +#include <linux/slab.h> +#include <linux/vmalloc.h> +#include <linux/proc_fs.h> +#include <linux/module.h> +#include "compat.h" +#include <sound/core.h> +#include <sound/pcm.h> +#include <sound/pcm_params.h> +#include <sound/info.h> +#include <sound/initval.h> +#include <sound/control.h> +#include <media/v4l2-common.h> +#include "cx231xx.h" + +static int debug; +module_param(debug, int, 0644); +MODULE_PARM_DESC(debug, "activates debug info"); + +#define dprintk(fmt, arg...) do { \ + if (debug) \ + printk(KERN_INFO "cx231xx-audio %s: " fmt, \ + __func__, ##arg); \ + } while (0) + +static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; + +static int cx231xx_isoc_audio_deinit(struct cx231xx *dev) +{ + int i; + + dprintk("Stopping isoc\n"); + + for (i = 0; i < CX231XX_AUDIO_BUFS; i++) { + if (dev->adev.urb[i]) { + if (!irqs_disabled()) + usb_kill_urb(dev->adev.urb[i]); + else + usb_unlink_urb(dev->adev.urb[i]); + + usb_free_urb(dev->adev.urb[i]); + dev->adev.urb[i] = NULL; + + kfree(dev->adev.transfer_buffer[i]); + dev->adev.transfer_buffer[i] = NULL; + } + } + + return 0; +} + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 19) +static void cx231xx_audio_isocirq(struct urb *urb, struct pt_regs *regs) +#else +static void cx231xx_audio_isocirq(struct urb *urb) +#endif +{ + struct cx231xx *dev = urb->context; + int i; + unsigned int oldptr; +#ifdef NO_PCM_LOCK + unsigned long flags; +#endif + int period_elapsed = 0; + int status; + unsigned char *cp; + unsigned int stride; +#if LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 16) + snd_pcm_substream_t *substream; + snd_pcm_runtime_t *runtime; +#else + struct snd_pcm_substream *substream; + struct snd_pcm_runtime *runtime; +#endif + + switch (urb->status) { + case 0: /* success */ + case -ETIMEDOUT: /* NAK */ + break; + case -ECONNRESET: /* kill */ + case -ENOENT: + case -ESHUTDOWN: + return; + default: /* error */ + dprintk("urb completition error %d.\n", urb->status); + break; + } + + if (dev->adev.capture_pcm_substream) { + substream = dev->adev.capture_pcm_substream; + runtime = substream->runtime; + stride = runtime->frame_bits >> 3; + + for (i = 0; i < urb->number_of_packets; i++) { + int length = urb->iso_frame_desc[i].actual_length / + stride; + cp = (unsigned char *)urb->transfer_buffer + + urb->iso_frame_desc[i].offset; + + if (!length) + continue; + +#ifdef NO_PCM_LOCK + spin_lock_irqsave(&dev->adev.slock, flags); +#endif + oldptr = dev->adev.hwptr_done_capture; + if (oldptr + length >= runtime->buffer_size) { + unsigned int cnt; + + cnt = runtime->buffer_size - oldptr; + memcpy(runtime->dma_area + oldptr * stride, cp, + cnt * stride); + memcpy(runtime->dma_area, cp + cnt * stride, + length * stride - cnt * stride); + } else { + memcpy(runtime->dma_area + oldptr * stride, cp, + length * stride); + } + +#ifndef NO_PCM_LOCK + snd_pcm_stream_lock(substream); +#endif + + dev->adev.hwptr_done_capture += length; + if (dev->adev.hwptr_done_capture >= + runtime->buffer_size) + dev->adev.hwptr_done_capture -= + runtime->buffer_size; + + dev->adev.capture_transfer_done += length; + if (dev->adev.capture_transfer_done >= + runtime->period_size) { + dev->adev.capture_transfer_done -= + runtime->period_size; + period_elapsed = 1; + } +#ifdef NO_PCM_LOCK + spin_unlock_irqrestore(&dev->adev.slock, flags); +#else + snd_pcm_stream_unlock(substream); +#endif + } + if (period_elapsed) + snd_pcm_period_elapsed(substream); + } + urb->status = 0; + + status = usb_submit_urb(urb, GFP_ATOMIC); + if (status < 0) { + cx231xx_errdev("resubmit of audio urb failed (error=%i)\n", + status); + } + return; +} + +static int cx231xx_init_audio_isoc(struct cx231xx *dev) +{ + int i, errCode; + int sb_size; + + cx231xx_info("%s: Starting AUDIO transfers\n", __func__); + + sb_size = CX231XX_NUM_AUDIO_PACKETS * dev->adev.max_pkt_size; + + for (i = 0; i < CX231XX_AUDIO_BUFS; i++) { + struct urb *urb; + int j, k; + + dev->adev.transfer_buffer[i] = kmalloc(sb_size, GFP_ATOMIC); + if (!dev->adev.transfer_buffer[i]) + return -ENOMEM; + + memset(dev->adev.transfer_buffer[i], 0x80, sb_size); + urb = usb_alloc_urb(CX231XX_NUM_AUDIO_PACKETS, GFP_ATOMIC); + if (!urb) { + cx231xx_errdev("usb_alloc_urb failed!\n"); + for (j = 0; j < i; j++) { + usb_free_urb(dev->adev.urb[j]); + kfree(dev->adev.transfer_buffer[j]); + } + return -ENOMEM; + } + + urb->dev = dev->udev; + urb->context = dev; + urb->pipe = usb_rcvisocpipe(dev->udev, + dev->adev.end_point_addr); + urb->transfer_flags = URB_ISO_ASAP; + urb->transfer_buffer = dev->adev.transfer_buffer[i]; + urb->interval = 1; + urb->complete = cx231xx_audio_isocirq; + urb->number_of_packets = CX231XX_NUM_AUDIO_PACKETS; + urb->transfer_buffer_length = sb_size; + + for (j = k = 0; j < CX231XX_NUM_AUDIO_PACKETS; + j++, k += dev->adev.max_pkt_size) { + urb->iso_frame_desc[j].offset = k; + urb->iso_frame_desc[j].length = dev->adev.max_pkt_size; + } + dev->adev.urb[i] = urb; + } + + for (i = 0; i < CX231XX_AUDIO_BUFS; i++) { + errCode = usb_submit_urb(dev->adev.urb[i], GFP_ATOMIC); + if (errCode < 0) { + cx231xx_isoc_audio_deinit(dev); + return errCode; + } + } + + return errCode; +} + +static int cx231xx_cmd(struct cx231xx *dev, int cmd, int arg) +{ + dprintk("%s transfer\n", (dev->adev.capture_stream == STREAM_ON) ? + "stop" : "start"); + + switch (cmd) { + case CX231XX_CAPTURE_STREAM_EN: + if (dev->adev.capture_stream == STREAM_OFF && arg == 1) { + dev->adev.capture_stream = STREAM_ON; + cx231xx_init_audio_isoc(dev); + } else if (dev->adev.capture_stream == STREAM_ON && arg == 0) { + dev->adev.capture_stream = STREAM_OFF; + cx231xx_isoc_audio_deinit(dev); + } else { + cx231xx_errdev("An underrun very likely occurred. " + "Ignoring it.\n"); + } + return 0; + default: + return -EINVAL; + } +} + +#if LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 16) +static int snd_pcm_alloc_vmalloc_buffer(snd_pcm_substream_t *subs, size_t size) +#else +static int snd_pcm_alloc_vmalloc_buffer(struct snd_pcm_substream *subs, + size_t size) +#endif +{ +#if LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 16) + snd_pcm_runtime_t *runtime = subs->runtime; +#else + struct snd_pcm_runtime *runtime = subs->runtime; +#endif + + dprintk("Allocating vbuffer\n"); + if (runtime->dma_area) { + if (runtime->dma_bytes > size) + return 0; + + vfree(runtime->dma_area); + } + runtime->dma_area = vmalloc(size); + if (!runtime->dma_area) + return -ENOMEM; + + runtime->dma_bytes = size; + + return 0; +} + +#if LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 16) +static snd_pcm_hardware_t snd_cx231xx_hw_capture = { +#else +static struct snd_pcm_hardware snd_cx231xx_hw_capture = { +#endif + .info = SNDRV_PCM_INFO_BLOCK_TRANSFER | + SNDRV_PCM_INFO_MMAP | + SNDRV_PCM_INFO_INTERLEAVED | + SNDRV_PCM_INFO_MMAP_VALID, + + .formats = SNDRV_PCM_FMTBIT_S16_LE, + + .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_KNOT, + + .rate_min = 48000, + .rate_max = 48000, + .channels_min = 2, + .channels_max = 2, + .buffer_bytes_max = 62720 * 8, /* just about the value in usbaudio.c */ + .period_bytes_min = 64, /* 12544/2, */ + .period_bytes_max = 12544, + .periods_min = 2, + .periods_max = 98, /* 12544, */ +}; + +#if LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 16) +static int snd_cx231xx_capture_open(snd_pcm_substream_t *substream) +#else +static int snd_cx231xx_capture_open(struct snd_pcm_substream *substream) +#endif +{ + struct cx231xx *dev = snd_pcm_substream_chip(substream); +#if LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 16) + snd_pcm_runtime_t *runtime = substream->runtime; +#else + struct snd_pcm_runtime *runtime = substream->runtime; +#endif + int ret = 0; + + dprintk("opening device and trying to acquire exclusive lock\n"); + + if (!dev) { + cx231xx_errdev("BUG: cx231xx can't find device struct." + " Can't proceed with open\n"); + return -ENODEV; + } + + /* Sets volume, mute, etc */ + dev->mute = 0; + + /* set alternate setting for audio interface */ + /* 1 - 48000 samples per sec */ + ret = cx231xx_set_alt_setting(dev, INDEX_AUDIO, 1); + if (ret < 0) { + cx231xx_errdev("failed to set alternate setting !\n"); + + return ret; + } + + /* inform hardware to start streaming */ + ret = cx231xx_capture_start(dev, 1, Audio); + + runtime->hw = snd_cx231xx_hw_capture; + + mutex_lock(&dev->lock); + dev->adev.users++; + mutex_unlock(&dev->lock); + + snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS); + dev->adev.capture_pcm_substream = substream; + runtime->private_data = dev; + + return 0; +} + +#if LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 16) +static int snd_cx231xx_pcm_close(snd_pcm_substream_t *substream) +#else +static int snd_cx231xx_pcm_close(struct snd_pcm_substream *substream) +#endif +{ + int ret; + struct cx231xx *dev = snd_pcm_substream_chip(substream); + + dprintk("closing device\n"); + + /* set alternate setting for audio interface */ + /* 1 - 48000 samples per sec */ + ret = cx231xx_set_alt_setting(dev, INDEX_AUDIO, 0); + if (ret < 0) { + cx231xx_errdev("failed to set alternate setting !\n"); + + return ret; + } + + /* inform hardware to start streaming */ + ret = cx231xx_capture_start(dev, 0, Audio); + + dev->mute = 1; + mutex_lock(&dev->lock); + dev->adev.users--; + mutex_unlock(&dev->lock); + + if (dev->adev.users == 0 && dev->adev.shutdown == 1) { + dprintk("audio users: %d\n", dev->adev.users); + dprintk("disabling audio stream!\n"); + dev->adev.shutdown = 0; + dprintk("released lock\n"); + cx231xx_cmd(dev, CX231XX_CAPTURE_STREAM_EN, 0); + } + return 0; +} + +#if LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 16) +static int snd_cx231xx_hw_capture_params(snd_pcm_substream_t *substream, + snd_pcm_hw_params_t *hw_params) +#else +static int snd_cx231xx_hw_capture_params(struct snd_pcm_substream *substream, + struct snd_pcm_hw_params *hw_params) +#endif +{ + unsigned int channels, rate, format; + int ret; + + dprintk("Setting capture parameters\n"); + + ret = snd_pcm_alloc_vmalloc_buffer(substream, + params_buffer_bytes(hw_params)); + format = params_format(hw_params); + rate = params_rate(hw_params); + channels = params_channels(hw_params); + + /* TODO: set up cx231xx audio chip to deliver the correct audio format, + current default is 48000hz multiplexed => 96000hz mono + which shouldn't matter since analogue TV only supports mono */ + return 0; +} + +#if LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 16) +static int snd_cx231xx_hw_capture_free(snd_pcm_substream_t *substream) +#else +static int snd_cx231xx_hw_capture_free(struct snd_pcm_substream *substream) +#endif +{ + struct cx231xx *dev = snd_pcm_substream_chip(substream); + + dprintk("Stop capture, if needed\n"); + + if (dev->adev.capture_stream == STREAM_ON) + cx231xx_cmd(dev, CX231XX_CAPTURE_STREAM_EN, CX231XX_STOP_AUDIO); + + return 0; +} + +#if LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 16) +static int snd_cx231xx_prepare(snd_pcm_substream_t *substream) +#else +static int snd_cx231xx_prepare(struct snd_pcm_substream *substream) +#endif +{ + return 0; +} + +#if LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 16) +static int snd_cx231xx_capture_trigger(snd_pcm_substream_t *substream, int cmd) +#else +static int snd_cx231xx_capture_trigger(struct snd_pcm_substream *substream, + int cmd) +#endif +{ + struct cx231xx *dev = snd_pcm_substream_chip(substream); + int retval; + + dprintk("Should %s capture\n", (cmd == SNDRV_PCM_TRIGGER_START) ? + "start" : "stop"); + + spin_lock(&dev->adev.slock); + switch (cmd) { + case SNDRV_PCM_TRIGGER_START: + cx231xx_cmd(dev, CX231XX_CAPTURE_STREAM_EN, + CX231XX_START_AUDIO); + retval = 0; + break; + case SNDRV_PCM_TRIGGER_STOP: + cx231xx_cmd(dev, CX231XX_CAPTURE_STREAM_EN, CX231XX_STOP_AUDIO); + retval = 0; + break; + default: + retval = -EINVAL; + } + + spin_unlock(&dev->adev.slock); + return retval; +} + +#if LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 16) +static snd_pcm_uframes_t snd_cx231xx_capture_pointer(snd_pcm_substream_t + *substream) +#else +static snd_pcm_uframes_t snd_cx231xx_capture_pointer(struct snd_pcm_substream + *substream) +#endif +{ + struct cx231xx *dev; + unsigned long flags; + snd_pcm_uframes_t hwptr_done; + + dev = snd_pcm_substream_chip(substream); + + spin_lock_irqsave(&dev->adev.slock, flags); + hwptr_done = dev->adev.hwptr_done_capture; + spin_unlock_irqrestore(&dev->adev.slock, flags); + + return hwptr_done; +} + +#if LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 16) +static struct page *snd_pcm_get_vmalloc_page(snd_pcm_substream_t * subs, + unsigned long offset) +#else +static struct page *snd_pcm_get_vmalloc_page(struct snd_pcm_substream *subs, + unsigned long offset) +#endif +{ + void *pageptr = subs->runtime->dma_area + offset; + + return vmalloc_to_page(pageptr); +} + +#if LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 16) +static snd_pcm_ops_t snd_cx231xx_pcm_capture = { +#else +static struct snd_pcm_ops snd_cx231xx_pcm_capture = { +#endif + .open = snd_cx231xx_capture_open, + .close = snd_cx231xx_pcm_close, + .ioctl = snd_pcm_lib_ioctl, + .hw_params = snd_cx231xx_hw_capture_params, + .hw_free = snd_cx231xx_hw_capture_free, + .prepare = snd_cx231xx_prepare, + .trigger = snd_cx231xx_capture_trigger, + .pointer = snd_cx231xx_capture_pointer, + .page = snd_pcm_get_vmalloc_page, +}; + +static int cx231xx_audio_init(struct cx231xx *dev) +{ + struct cx231xx_audio *adev = &dev->adev; +#if LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 16) + snd_pcm_t *pcm; + snd_card_t *card; +#else + struct snd_pcm *pcm; + struct snd_card *card; +#endif + static int devnr; + int err; + struct usb_interface *uif; + int i, isoc_pipe = 0; + + if (dev->has_alsa_audio != 1) { + /* This device does not support the extension (in this case + the device is expecting the snd-usb-audio module or + doesn't have analog audio support at all) */ + return 0; + } + + cx231xx_info("cx231xx-audio.c: probing for cx231xx " + "non standard usbaudio\n"); + + card = snd_card_new(index[devnr], "Cx231xx Audio", THIS_MODULE, 0); + if (card == NULL) + return -ENOMEM; + + spin_lock_init(&adev->slock); + err = snd_pcm_new(card, "Cx231xx Audio", 0, 0, 1, &pcm); + if (err < 0) { + snd_card_free(card); + return err; + } + + snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, + &snd_cx231xx_pcm_capture); + pcm->info_flags = 0; + pcm->private_data = dev; + strcpy(pcm->name, "Conexant cx231xx Capture"); + strcpy(card->driver, "Conexant cx231xx Audio"); + strcpy(card->shortname, "Cx231xx Audio"); + strcpy(card->longname, "Conexant cx231xx Audio"); + + err = snd_card_register(card); + if (err < 0) { + snd_card_free(card); + return err; + } + adev->sndcard = card; + adev->udev = dev->udev; + + /* compute alternate max packet sizes for Audio */ + uif = + dev->udev->actconfig->interface[dev->current_pcb_config. + hs_config_info[0].interface_info. + audio_index + 1]; + + adev->end_point_addr = + le16_to_cpu(uif->altsetting[0].endpoint[isoc_pipe].desc. + bEndpointAddress); + + adev->num_alt = uif->num_altsetting; + 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); + + if (adev->alt_max_pkt_size == NULL) { + cx231xx_errdev("out of memory!\n"); + return -ENOMEM; + } + + for (i = 0; i < adev->num_alt; i++) { + u16 tmp = + le16_to_cpu(uif->altsetting[i].endpoint[isoc_pipe].desc. + wMaxPacketSize); + adev->alt_max_pkt_size[i] = + (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1); + cx231xx_info("Alternate setting %i, max size= %i\n", i, + adev->alt_max_pkt_size[i]); + } + + return 0; +} + +static int cx231xx_audio_fini(struct cx231xx *dev) +{ + if (dev == NULL) + return 0; + + if (dev->has_alsa_audio != 1) { + /* This device does not support the extension (in this case + the device is expecting the snd-usb-audio module or + doesn't have analog audio support at all) */ + return 0; + } + + if (dev->adev.sndcard) { + snd_card_free(dev->adev.sndcard); + kfree(dev->adev.alt_max_pkt_size); + dev->adev.sndcard = NULL; + } + + return 0; +} + +static struct cx231xx_ops audio_ops = { + .id = CX231XX_AUDIO, + .name = "Cx231xx Audio Extension", + .init = cx231xx_audio_init, + .fini = cx231xx_audio_fini, +}; + +static int __init cx231xx_alsa_register(void) +{ + return cx231xx_register_extension(&audio_ops); +} + +static void __exit cx231xx_alsa_unregister(void) +{ + cx231xx_unregister_extension(&audio_ops); +} + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Srinivasa Deevi <srinivasa.deevi@conexant.com>"); +MODULE_DESCRIPTION("Cx231xx Audio driver"); + +module_init(cx231xx_alsa_register); +module_exit(cx231xx_alsa_unregister); diff --git a/linux/drivers/media/video/cx231xx/cx231xx-avcore.c b/linux/drivers/media/video/cx231xx/cx231xx-avcore.c new file mode 100644 index 000000000..226299d62 --- /dev/null +++ b/linux/drivers/media/video/cx231xx/cx231xx-avcore.c @@ -0,0 +1,2780 @@ +/* + cx231xx_avcore.c - driver for Conexant Cx23100/101/102 + USB video capture devices + + Copyright (C) 2008 <srinivasa.deevi at conexant dot com> + + This program contains the specific code to control the avdecoder chip and + other related usb control functions for cx231xx based chipset. + + 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/init.h> +#include <linux/list.h> +#include <linux/module.h> +#include <linux/kernel.h> +#include <linux/bitmap.h> +#include <linux/usb.h> +#include <linux/i2c.h> +#include <linux/version.h> +#include <linux/mm.h> +#include <linux/mutex.h> + +#include <media/v4l2-common.h> +#include <media/v4l2-ioctl.h> +#include <media/v4l2-chip-ident.h> + +#include "cx231xx.h" + +/****************************************************************************** + * C O L I B R I - B L O C K C O N T R O L functions * + ******************************************************************************/ +int cx231xx_colibri_init_super_block(struct cx231xx *dev, u32 ref_count) +{ + int status = 0; + u8 temp = 0; + u32 colibri_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); + if (status < 0) + return status; + + status = cx231xx_read_i2c_data(dev, Colibri_DEVICE_ADDRESS, + SUP_BLK_TUNE2, 2, + &colibri_power_status, 1); + 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); + if (status < 0) + return status; + + status = cx231xx_write_i2c_data(dev, Colibri_DEVICE_ADDRESS, + SUP_BLK_PLL2, 2, 0x0f, 1); + 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); + 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; + if (status < 0) { + cx231xx_info( + ": Init Super Block failed in receive cmd\n"); + break; + } + i++; + if (i == 10) { + cx231xx_info( + ": Init Super Block force break in loop !!!!\n"); + status = -1; + break; + } + } + + if (status < 0) + return status; + + /* start tuning filter */ + status = cx231xx_write_i2c_data(dev, Colibri_DEVICE_ADDRESS, + SUP_BLK_TUNE3, 2, 0x40, 1); + if (status < 0) + return status; + + msleep(5); + + /* exit tuning */ + status = + cx231xx_write_i2c_data(dev, Colibri_DEVICE_ADDRESS, SUP_BLK_TUNE3, + 2, 0x00, 1); + + return status; +} + +int cx231xx_colibri_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); + + /* Enable quantizer calibration */ + status = cx231xx_write_i2c_data(dev, Colibri_DEVICE_ADDRESS, + ADC_COM_QUANT, 2, 0x02, 1); + + /* 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); + + /* 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); + 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); + + /* 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); + + /* 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, + ADC_QGAIN_RES_TRM_CH1, 3, 7, 0x00); + status = cx231xx_reg_mask_write(dev, Colibri_DEVICE_ADDRESS, 8, + ADC_QGAIN_RES_TRM_CH2, 3, 7, 0x00); + status = cx231xx_reg_mask_write(dev, Colibri_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); + + return status; +} + +int cx231xx_colibri_setup_AFE_for_baseband(struct cx231xx *dev) +{ + u32 c_value = 0; + int status = 0; + + status = + cx231xx_read_i2c_data(dev, Colibri_DEVICE_ADDRESS, + ADC_PWRDN_CLAMP_CH2, 2, &c_value, 1); + c_value &= (~(0x50)); + status = + cx231xx_write_i2c_data(dev, Colibri_DEVICE_ADDRESS, + ADC_PWRDN_CLAMP_CH2, 2, c_value, 1); + + return status; +} + +/* + The Analog Front End in Cx231xx has 3 channels. These + channels are used to share between different inputs + like tuner, s-video and composite inputs. + + channel 1 ----- pin 1 to pin4(in reg is 1-4) + 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) +{ + 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; + + if (ch1_setting != 0) { + status = + cx231xx_read_i2c_data(dev, Colibri_DEVICE_ADDRESS, + ADC_INPUT_CH1, 2, &value, 1); + 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); + } + + if (ch2_setting != 0) { + status = + cx231xx_read_i2c_data(dev, Colibri_DEVICE_ADDRESS, + ADC_INPUT_CH2, 2, &value, 1); + 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); + } + + /* 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); + 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); + } + + return status; +} + +int cx231xx_colibri_set_mode(struct cx231xx *dev, enum AFE_MODE mode) +{ + int status = 0; + + /* + * FIXME: We need to implement the AFE code for LOW IF and for HI IF. + * Currently, only baseband works. + */ + + switch (mode) { + case AFE_MODE_LOW_IF: + /* SetupAFEforLowIF(); */ + break; + case AFE_MODE_BASEBAND: + status = cx231xx_colibri_setup_AFE_for_baseband(dev); + break; + case AFE_MODE_EU_HI_IF: + /* SetupAFEforEuHiIF(); */ + break; + case AFE_MODE_US_HI_IF: + /* SetupAFEforUsHiIF(); */ + break; + case AFE_MODE_JAPAN_HI_IF: + /* SetupAFEforJapanHiIF(); */ + break; + } + + if ((mode != dev->colibri_mode) && + (dev->video_input == CX231XX_VMUX_TELEVISION)) + status = cx231xx_colibri_adjust_ref_count(dev, + CX231XX_VMUX_TELEVISION); + + dev->colibri_mode = mode; + + return status; +} + +int cx231xx_colibri_update_power_control(struct cx231xx *dev, + enum AV_MODE avmode) +{ + u32 colibri_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 | + FLD_PWRDN_ENABLE_PLL)) { + status = cx231xx_write_i2c_data(dev, + Colibri_DEVICE_ADDRESS, + SUP_BLK_PWRDN, 2, + 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); + 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); + } 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 | + 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); + } else if (avmode == POLARIS_AVMODE_ENXTERNAL_AV) { + while (colibri_power_status != (FLD_PWRDN_TUNING_BIAS | + FLD_PWRDN_ENABLE_PLL)) { + status = cx231xx_write_i2c_data(dev, + Colibri_DEVICE_ADDRESS, + SUP_BLK_PWRDN, 2, + 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); + 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); + } else { + cx231xx_info("Invalid AV mode input\n"); + status = -1; + } + break; + default: + if (avmode == POLARIS_AVMODE_ANALOGT_TV) { + while (colibri_power_status != (FLD_PWRDN_TUNING_BIAS | + FLD_PWRDN_ENABLE_PLL)) { + status = cx231xx_write_i2c_data(dev, + Colibri_DEVICE_ADDRESS, + SUP_BLK_PWRDN, 2, + 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); + 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); + } 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 | + 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); + } else if (avmode == POLARIS_AVMODE_ENXTERNAL_AV) { + while (colibri_power_status != (FLD_PWRDN_TUNING_BIAS | + FLD_PWRDN_ENABLE_PLL)) { + status = cx231xx_write_i2c_data(dev, + Colibri_DEVICE_ADDRESS, + SUP_BLK_PWRDN, 2, + 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); + 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); + } else { + cx231xx_info("Invalid AV mode input\n"); + status = -1; + } + } /* switch */ + + return status; +} + +int cx231xx_colibri_adjust_ref_count(struct cx231xx *dev, u32 video_input) +{ + u32 input_mode = 0; + u32 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); + } 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); + } + + input_mode = (ntf_mode & 0x3) | ((input_mode & 0x6) << 1); + + switch (input_mode) { + case SINGLE_ENDED: + dev->colibri_ref_count = 0x23C; + break; + case LOW_IF: + dev->colibri_ref_count = 0x24C; + break; + case EU_IF: + dev->colibri_ref_count = 0x258; + break; + case US_IF: + dev->colibri_ref_count = 0x260; + break; + default: + break; + } + + status = cx231xx_colibri_init_super_block(dev, dev->colibri_ref_count); + + return status; +} + +/****************************************************************************** + * 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 * + ******************************************************************************/ +int cx231xx_set_video_input_mux(struct cx231xx *dev, u8 input) +{ + int status = 0; + + switch (INPUT(input)->type) { + case CX231XX_VMUX_COMPOSITE1: + case CX231XX_VMUX_SVIDEO: + if ((dev->current_pcb_config.type == USB_BUS_POWER) && + (dev->power_mode != POLARIS_AVMODE_ENXTERNAL_AV)) { + /* External AV */ + status = cx231xx_set_power_mode(dev, + POLARIS_AVMODE_ENXTERNAL_AV); + if (status < 0) { + cx231xx_errdev("%s: set_power_mode : Failed to" + " set Power - errCode [%d]!\n", + __func__, status); + return status; + } + } + status = cx231xx_set_decoder_video_input(dev, + INPUT(input)->type, + INPUT(input)->vmux); + break; + case CX231XX_VMUX_TELEVISION: + case CX231XX_VMUX_CABLE: + if ((dev->current_pcb_config.type == USB_BUS_POWER) && + (dev->power_mode != POLARIS_AVMODE_ANALOGT_TV)) { + /* Tuner */ + status = cx231xx_set_power_mode(dev, + POLARIS_AVMODE_ANALOGT_TV); + if (status < 0) { + cx231xx_errdev("%s: set_power_mode:Failed" + " to set Power - errCode [%d]!\n", + __func__, status); + return status; + } + } + status = cx231xx_set_decoder_video_input(dev, + CX231XX_VMUX_COMPOSITE1, + INPUT(input)->vmux); + break; + default: + cx231xx_errdev("%s: set_power_mode : Unknown Input %d !\n", + __func__, INPUT(input)->type); + break; + } + + /* save the selection */ + dev->video_input = input; + + return status; +} + +int cx231xx_set_decoder_video_input(struct cx231xx *dev, + u8 pin_type, u8 input) +{ + int status = 0; + u32 value = 0; + + if (pin_type != dev->video_input) { + status = cx231xx_colibri_adjust_ref_count(dev, pin_type); + if (status < 0) { + cx231xx_errdev("%s: adjust_ref_count :Failed to set" + "Colibri input mux - errCode [%d]!\n", + __func__, status); + return status; + } + } + + /* call colibri block to set video inputs */ + status = cx231xx_colibri_set_input_mux(dev, input); + if (status < 0) { + cx231xx_errdev("%s: set_input_mux :Failed to set" + " Colibri 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); + value |= (0 << 13) | (1 << 4); + value &= ~(1 << 5); + + /* set [24:23] [22:15] to 0 */ + 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); + value |= (1 << 7); + status = cx231xx_write_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, + OUT_CTRL1, 2, value, 4); + + /* Set vip 1.1 output mode */ + status = cx231xx_read_modify_write_i2c_dword(dev, + HAMMERHEAD_I2C_ADDRESS, + OUT_CTRL1, + FLD_OUT_MODE, + OUT_MODE_VIP11); + + /* Tell DIF object to go to baseband mode */ + status = cx231xx_dif_set_standard(dev, DIF_USE_BASEBAND); + if (status < 0) { + cx231xx_errdev("%s: cx231xx_dif set to By pass" + " mode- errCode [%d]!\n", + __func__, status); + return status; + } + + /* Read the DFE_CTRL1 register */ + status = cx231xx_read_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, + DFE_CTRL1, 2, &value, 4); + + /* enable the VBI_GATE_EN */ + value |= FLD_VBI_GATE_EN; + + /* Enable the auto-VGA enable */ + value |= FLD_VGA_AUTO_EN; + + /* Write it back */ + status = cx231xx_write_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, + DFE_CTRL1, 2, value, 4); + + /* Disable auto config of registers */ + status = cx231xx_read_modify_write_i2c_dword(dev, + HAMMERHEAD_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, + 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); + + /* 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); + + /* Tell DIF object to go to baseband mode */ + status = cx231xx_dif_set_standard(dev, DIF_USE_BASEBAND); + if (status < 0) { + cx231xx_errdev("%s: cx231xx_dif set to By pass" + " mode- errCode [%d]!\n", + __func__, status); + return status; + } + + /* Read the DFE_CTRL1 register */ + status = cx231xx_read_i2c_data(dev, + HAMMERHEAD_I2C_ADDRESS, + DFE_CTRL1, 2, &value, 4); + + /* enable the VBI_GATE_EN */ + value |= FLD_VBI_GATE_EN; + + /* Enable the auto-VGA enable */ + value |= FLD_VGA_AUTO_EN; + + /* Write it back */ + status = cx231xx_write_i2c_data(dev, + HAMMERHEAD_I2C_ADDRESS, + DFE_CTRL1, 2, value, 4); + + /* Disable auto config of registers */ + status = cx231xx_read_modify_write_i2c_dword(dev, + HAMMERHEAD_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, + 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); + value |= FLD_CHROMA_IN_SEL; /* set the chroma in select */ + + /* Clear VGA_SEL_CH2 and VGA_SEL_CH3 (bits 7 and 8) + This sets them to use video + 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 = cx231xx_colibri_set_mode(dev, AFE_MODE_BASEBAND); + break; + case CX231XX_VMUX_TELEVISION: + case CX231XX_VMUX_CABLE: + default: + switch (dev->model) { + case CX231XX_BOARD_CNXT_RDE_250: + 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); + value |= (0 << 13) | (1 << 4); + value &= ~(1 << 5); + + /* set [24:23] [22:15] to 0 */ + 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); + value |= (1 << 7); + status = cx231xx_write_i2c_data(dev, + HAMMERHEAD_I2C_ADDRESS, + OUT_CTRL1, 2, + value, 4); + + /* Set vip 1.1 output mode */ + status = cx231xx_read_modify_write_i2c_dword(dev, + HAMMERHEAD_I2C_ADDRESS, + OUT_CTRL1, FLD_OUT_MODE, + OUT_MODE_VIP11); + + /* Tell DIF object to go to baseband mode */ + status = cx231xx_dif_set_standard(dev, + DIF_USE_BASEBAND); + if (status < 0) { + cx231xx_errdev("%s: cx231xx_dif set to By pass" + " mode- errCode [%d]!\n", + __func__, status); + return status; + } + + /* Read the DFE_CTRL1 register */ + status = cx231xx_read_i2c_data(dev, + HAMMERHEAD_I2C_ADDRESS, + DFE_CTRL1, 2, + &value, 4); + + /* enable the VBI_GATE_EN */ + value |= FLD_VBI_GATE_EN; + + /* Enable the auto-VGA enable */ + value |= FLD_VGA_AUTO_EN; + + /* Write it back */ + status = cx231xx_write_i2c_data(dev, + HAMMERHEAD_I2C_ADDRESS, + DFE_CTRL1, 2, + value, 4); + + /* Disable auto config of registers */ + status = cx231xx_read_modify_write_i2c_dword(dev, + HAMMERHEAD_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, + MODE_CTRL, FLD_INPUT_MODE, + cx231xx_set_field(FLD_INPUT_MODE, + INPUT_MODE_CVBS_0)); + break; + default: + /* Enable the DIF for the tuner */ + + /* Reinitialize the DIF */ + status = cx231xx_dif_set_standard(dev, dev->norm); + if (status < 0) { + cx231xx_errdev("%s: cx231xx_dif set to By pass" + " mode- errCode [%d]!\n", + __func__, status); + return status; + } + + /* Make sure bypass is cleared */ + status = cx231xx_read_i2c_data(dev, + HAMMERHEAD_I2C_ADDRESS, + DIF_MISC_CTRL, + 2, &value, 4); + + /* 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); + + /* Read the DFE_CTRL1 register */ + status = cx231xx_read_i2c_data(dev, + HAMMERHEAD_I2C_ADDRESS, + DFE_CTRL1, 2, + &value, 4); + + /* Disable the VBI_GATE_EN */ + value &= ~FLD_VBI_GATE_EN; + + /* Enable the auto-VGA enable, AGC, and + set the skip count to 2 */ + 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); + + /* Wait until AGC locks up */ + msleep(1); + + /* Disable the auto-VGA enable AGC */ + value &= ~(FLD_VGA_AUTO_EN); + + /* Write it back */ + status = cx231xx_write_i2c_data(dev, + HAMMERHEAD_I2C_ADDRESS, + DFE_CTRL1, 2, + value, 4); + + /* Enable Polaris B0 AGC output */ + status = cx231xx_read_i2c_data(dev, + HAMMERHEAD_I2C_ADDRESS, + PIN_CTRL, 2, + &value, 4); + 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); + + /* Set vip 1.1 output mode */ + status = cx231xx_read_modify_write_i2c_dword(dev, + HAMMERHEAD_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, + 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, + MODE_CTRL, FLD_INPUT_MODE, + cx231xx_set_field(FLD_INPUT_MODE, + INPUT_MODE_CVBS_0)); + + /* Set some bits in AFE_CTRL so that channel 2 or 3 + * is ready to receive audio */ + /* 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); + + value |= FLD_VGA_SEL_CH3 | FLD_VGA_SEL_CH2; + + status = cx231xx_write_i2c_data(dev, + HAMMERHEAD_I2C_ADDRESS, + AFE_CTRL, 2, + value, 4); + break; + + } + break; + } + + /* Set raw VBI mode */ + status = cx231xx_read_modify_write_i2c_dword(dev, + HAMMERHEAD_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); + if (value & 0x02) { + value |= (1 << 19); + status = cx231xx_write_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, + OUT_CTRL1, 2, value, 4); + } + + return status; +} + +/* + * Handle any video-mode specific overrides that are different + * on a per video standards basis after touching the MODE_CTRL + * register which resets many values for autodetect + */ +int cx231xx_do_mode_ctrl_overrides(struct cx231xx *dev) +{ + int status = 0; + + cx231xx_info("do_mode_ctrl_overrides : 0x%x\n", + (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); + + if (dev->norm & (V4L2_STD_NTSC | V4L2_STD_PAL_M)) { + cx231xx_info("do_mode_ctrl_overrides NTSC\n"); + + /* 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, + VERT_TIM_CTRL, + FLD_VBLANK_CNT, 0x18); + status = cx231xx_read_modify_write_i2c_dword(dev, + HAMMERHEAD_I2C_ADDRESS, + VERT_TIM_CTRL, + FLD_VACTIVE_CNT, + 0x1E6000); + status = cx231xx_read_modify_write_i2c_dword(dev, + HAMMERHEAD_I2C_ADDRESS, + VERT_TIM_CTRL, + FLD_V656BLANK_CNT, + 0x1E000000); + + status = cx231xx_read_modify_write_i2c_dword(dev, + HAMMERHEAD_I2C_ADDRESS, + HORIZ_TIM_CTRL, + FLD_HBLANK_CNT, + cx231xx_set_field + (FLD_HBLANK_CNT, 0x79)); + } 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, + 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, + HORIZ_TIM_CTRL, + FLD_HBLANK_CNT, + cx231xx_set_field + (FLD_HBLANK_CNT, 0x85)); + } else { + cx231xx_info("do_mode_ctrl_overrides PAL\n"); + status = cx231xx_read_modify_write_i2c_dword(dev, + HAMMERHEAD_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, + HORIZ_TIM_CTRL, + FLD_HBLANK_CNT, + cx231xx_set_field + (FLD_HBLANK_CNT, 0x85)); + } + + return status; +} + +int cx231xx_set_audio_input(struct cx231xx *dev, u8 input) +{ + int status = 0; + enum AUDIO_INPUT ainput = AUDIO_INPUT_LINE; + + switch (INPUT(input)->amux) { + case CX231XX_AMUX_VIDEO: + ainput = AUDIO_INPUT_TUNER_TV; + break; + case CX231XX_AMUX_LINE_IN: + status = cx231xx_flatiron_set_audio_input(dev, input); + ainput = AUDIO_INPUT_LINE; + break; + default: + break; + } + + status = cx231xx_set_audio_decoder_input(dev, ainput); + + return status; +} + +int cx231xx_set_audio_decoder_input(struct cx231xx *dev, + enum AUDIO_INPUT audio_input) +{ + u32 dwval; + int status; + u32 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); + gen_ctrl |= 1; + status = cx231xx_write_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, + GENERAL_CTL, 2, gen_ctrl, 1); + + 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); + + /* 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 = cx231xx_write_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, + AC97_CTL, 2, + (dwval | FLD_AC97_UP2X_BYPASS), 4); + + /* select the parallel1 and SRC3 */ + status = cx231xx_write_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, + BAND_OUT_SEL, 2, + 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); + + /* unmute all, AC97 in, independence mode + adr 08d0, data 0x00063073 */ + status = cx231xx_write_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, + PATH1_CTL1, 2, 0x00063073, 4); + + /* 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); + + /* 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); + 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, + cx231xx_set_field(FLD_SRC6_IN_SEL, 0x00) | + cx231xx_set_field(FLD_SRC6_CLK_SEL, 0x01) | + cx231xx_set_field(FLD_SRC5_IN_SEL, 0x00) | + cx231xx_set_field(FLD_SRC5_CLK_SEL, 0x02) | + cx231xx_set_field(FLD_SRC4_IN_SEL, 0x02) | + cx231xx_set_field(FLD_SRC4_CLK_SEL, 0x03) | + cx231xx_set_field(FLD_SRC3_IN_SEL, 0x00) | + cx231xx_set_field(FLD_SRC3_CLK_SEL, 0x00) | + cx231xx_set_field(FLD_BASEBAND_BYPASS_CTL, 0x00) | + 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); + + /* Setup the AUD_IO control */ + status = cx231xx_write_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, + AUD_IO_CTRL, 2, + 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); + + status = cx231xx_write_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, + PATH1_CTL1, 2, 0x1F063870, 4); + + /* setAudioStandard(_audio_standard); */ + + status = cx231xx_write_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, + PATH1_CTL1, 2, 0x00063870, 4); + 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, + CHIP_CTRL, + FLD_SIF_EN, + cx231xx_set_field(FLD_SIF_EN, 1)); + break; + default: + break; + } + break; + + case AUDIO_INPUT_TUNER_FM: + /* use SIF for FM radio + setupFM(); + setAudioStandard(_audio_standard); + */ + break; + + case AUDIO_INPUT_MUTE: + status = cx231xx_write_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, + PATH1_CTL1, 2, 0x1F011012, 4); + break; + } + + /* Take it out of soft reset */ + status = cx231xx_read_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, + GENERAL_CTL, 2, &gen_ctrl, 1); + gen_ctrl &= ~1; + status = cx231xx_write_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, + GENERAL_CTL, 2, gen_ctrl, 1); + + return status; +} + +/* Set resolution of the video */ +int cx231xx_resolution_set(struct cx231xx *dev) +{ + int width, height; + u32 hscale, vscale; + int status = 0; + + width = dev->width; + height = dev->height; + + get_scale(dev, width, height, &hscale, &vscale); + + /* set horzontal scale */ + status = cx231xx_write_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, + HSCALE_CTRL, 2, hscale, 4); + + /* set vertical scale */ + status = cx231xx_write_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, + VSCALE_CTRL, 2, vscale, 4); + + return status; +} + +/****************************************************************************** + * C H I P Specific C O N T R O L functions * + ******************************************************************************/ +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); + value |= (~dev->board.ctl_pin_status_mask); + status = cx231xx_write_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, PIN_CTRL, + 2, value, 4); + + return status; +} + +int cx231xx_set_agc_analog_digital_mux_select(struct cx231xx *dev, + u8 analog_or_digital) +{ + int status = 0; + + /* first set the direction to output */ + status = cx231xx_set_gpio_direction(dev, + dev->board. + agc_analog_digital_select_gpio, 1); + + /* 0 - demod ; 1 - Analog mode */ + status = cx231xx_set_gpio_value(dev, + dev->board.agc_analog_digital_select_gpio, + analog_or_digital); + + return status; +} + +int cx231xx_enable_i2c_for_tuner(struct cx231xx *dev, u8 I2CIndex) +{ + u8 value[4] = { 0, 0, 0, 0 }; + int status = 0; + + cx231xx_info("Changing the i2c port for tuner to %d\n", I2CIndex); + + status = cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER, + PWR_CTL_EN, value, 4); + if (status < 0) + return status; + + if (I2CIndex == I2C_1) { + if (value[0] & I2C_DEMOD_EN) { + value[0] &= ~I2C_DEMOD_EN; + status = cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER, + PWR_CTL_EN, value, 4); + } + } else { + if (!(value[0] & I2C_DEMOD_EN)) { + value[0] |= I2C_DEMOD_EN; + status = cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER, + PWR_CTL_EN, value, 4); + } + } + + return status; + +} + +/****************************************************************************** + * D I F - B L O C K C O N T R O L functions * + ******************************************************************************/ +int cx231xx_dif_configure_C2HH_for_low_IF(struct cx231xx *dev, u32 mode, + u32 function_mode, u32 standard) +{ + int status = 0; + + if (mode == V4L2_TUNER_RADIO) { + /* C2HH */ + /* lo if big signal */ + status = cx231xx_reg_mask_write(dev, + HAMMERHEAD_I2C_ADDRESS, 32, + AFE_CTRL_C2HH_SRC_CTRL, 30, 31, 0x1); + /* FUNC_MODE = DIF */ + status = cx231xx_reg_mask_write(dev, + HAMMERHEAD_I2C_ADDRESS, 32, + AFE_CTRL_C2HH_SRC_CTRL, 23, 24, function_mode); + /* IF_MODE */ + status = cx231xx_reg_mask_write(dev, + HAMMERHEAD_I2C_ADDRESS, 32, + AFE_CTRL_C2HH_SRC_CTRL, 15, 22, 0xFF); + /* no inv */ + status = cx231xx_reg_mask_write(dev, + HAMMERHEAD_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, + AFE_CTRL_C2HH_SRC_CTRL, 30, 31, 0x1); + /* FUNC_MODE = DIF */ + status = cx231xx_reg_mask_write(dev, + HAMMERHEAD_I2C_ADDRESS, 32, + AFE_CTRL_C2HH_SRC_CTRL, 23, 24, + function_mode); + /* IF_MODE */ + status = cx231xx_reg_mask_write(dev, + HAMMERHEAD_I2C_ADDRESS, 32, + AFE_CTRL_C2HH_SRC_CTRL, 15, 22, 0xb); + /* no inv */ + status = cx231xx_reg_mask_write(dev, + HAMMERHEAD_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, + 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, + AFE_CTRL_C2HH_SRC_CTRL, 30, 31, 0x1); + /* FUNC_MODE = DIF */ + status = cx231xx_reg_mask_write(dev, + HAMMERHEAD_I2C_ADDRESS, 32, + AFE_CTRL_C2HH_SRC_CTRL, 23, 24, + function_mode); + /* IF_MODE */ + status = cx231xx_reg_mask_write(dev, + HAMMERHEAD_I2C_ADDRESS, 32, + AFE_CTRL_C2HH_SRC_CTRL, 15, 22, 0xF); + /* no inv */ + status = cx231xx_reg_mask_write(dev, + HAMMERHEAD_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, + AFE_CTRL_C2HH_SRC_CTRL, 30, 31, 0x1); + /* FUNC_MODE = DIF */ + status = cx231xx_reg_mask_write(dev, + HAMMERHEAD_I2C_ADDRESS, 32, + AFE_CTRL_C2HH_SRC_CTRL, 23, 24, + function_mode); + /* IF_MODE */ + status = cx231xx_reg_mask_write(dev, + HAMMERHEAD_I2C_ADDRESS, 32, + AFE_CTRL_C2HH_SRC_CTRL, 15, 22, 0xE); + /* no inv */ + status = cx231xx_reg_mask_write(dev, + HAMMERHEAD_I2C_ADDRESS, 32, + AFE_CTRL_C2HH_SRC_CTRL, 9, 9, 0x1); + } + } + + return status; +} + +int cx231xx_dif_set_standard(struct cx231xx *dev, u32 standard) +{ + int status = 0; + u32 dif_misc_ctrl_value = 0; + u32 func_mode = 0; + + 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); + if (standard != DIF_USE_BASEBAND) + dev->norm = standard; + + switch (dev->model) { + case CX231XX_BOARD_CNXT_RDE_250: + case CX231XX_BOARD_CNXT_RDU_250: + func_mode = 0x03; + break; + default: + func_mode = 0x01; + } + + status = cx231xx_dif_configure_C2HH_for_low_IF(dev, dev->active_mode, + func_mode, 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); + 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); + } else if (standard & V4L2_STD_PAL_D) { + status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + DIF_PLL_CTRL, 0, 31, 0x6503bc0c); + status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + DIF_PLL_CTRL1, 0, 31, 0xbd038c85); + status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + DIF_PLL_CTRL2, 0, 31, 0x1db4640a); + status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + DIF_PLL_CTRL3, 0, 31, 0x00008800); + status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + DIF_AGC_IF_REF, 0, 31, 0x444C1380); + status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + DIF_AGC_CTRL_IF, 0, 31, 0xDA302600); + status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + DIF_AGC_CTRL_INT, 0, 31, 0xDA261700); + status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + DIF_AGC_CTRL_RF, 0, 31, 0xDA262600); + status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + DIF_AGC_IF_INT_CURRENT, 0, 31, + 0x26001700); + status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + DIF_AGC_RF_CURRENT, 0, 31, + 0x00002660); + status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + DIF_VIDEO_AGC_CTRL, 0, 31, + 0x72500800); + status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + DIF_VID_AUD_OVERRIDE, 0, 31, + 0x27000100); + status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + DIF_AV_SEP_CTRL, 0, 31, 0x3F3934EA); + status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + DIF_COMP_FLT_CTRL, 0, 31, + 0x00000000); + status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + DIF_SRC_PHASE_INC, 0, 31, + 0x1befbf06); + status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + DIF_SRC_GAIN_CONTROL, 0, 31, + 0x000035e8); + status = cx231xx_reg_mask_write(dev, HAMMERHEAD_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, + DIF_PLL_CTRL, 0, 31, 0x6503bc0c); + status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + DIF_PLL_CTRL1, 0, 31, 0xbd038c85); + status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + DIF_PLL_CTRL2, 0, 31, 0x1db4640a); + status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + DIF_PLL_CTRL3, 0, 31, 0x00008800); + status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + DIF_AGC_IF_REF, 0, 31, 0x444C1380); + status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + DIF_AGC_CTRL_IF, 0, 31, 0xDA302600); + status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + DIF_AGC_CTRL_INT, 0, 31, 0xDA261700); + status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + DIF_AGC_CTRL_RF, 0, 31, 0xDA262600); + status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + DIF_AGC_IF_INT_CURRENT, 0, 31, + 0x26001700); + status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + DIF_AGC_RF_CURRENT, 0, 31, + 0x00002660); + status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + DIF_VIDEO_AGC_CTRL, 0, 31, + 0x72500800); + status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + DIF_VID_AUD_OVERRIDE, 0, 31, + 0x27000100); + status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + DIF_AV_SEP_CTRL, 0, 31, 0x5F39A934); + status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + DIF_COMP_FLT_CTRL, 0, 31, + 0x00000000); + status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + DIF_SRC_PHASE_INC, 0, 31, + 0x1befbf06); + status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + DIF_SRC_GAIN_CONTROL, 0, 31, + 0x000035e8); + status = cx231xx_reg_mask_write(dev, HAMMERHEAD_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); + /* 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); + /* Save the Spec Inversion value */ + dif_misc_ctrl_value &= FLD_DIF_SPEC_INV; + dif_misc_ctrl_value = 0x3A093F10; + } else if (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, + DIF_PLL_CTRL, 0, 31, 0x6503bc0c); + status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + DIF_PLL_CTRL1, 0, 31, 0xbd038c85); + status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + DIF_PLL_CTRL2, 0, 31, 0x1db4640a); + status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + DIF_PLL_CTRL3, 0, 31, 0x00008800); + status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + DIF_AGC_IF_REF, 0, 31, 0x888C0380); + status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + DIF_AGC_CTRL_IF, 0, 31, 0xe0262600); + status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + DIF_AGC_CTRL_INT, 0, 31, 0xc2171700); + status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + DIF_AGC_CTRL_RF, 0, 31, 0xc2262600); + status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + DIF_AGC_IF_INT_CURRENT, 0, 31, + 0x26001700); + status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + DIF_AGC_RF_CURRENT, 0, 31, + 0x00002660); + status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + DIF_VID_AUD_OVERRIDE, 0, 31, + 0x27000100); + status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + DIF_AV_SEP_CTRL, 0, 31, 0x3F3530ec); + status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + DIF_COMP_FLT_CTRL, 0, 31, + 0x00000000); + status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + DIF_SRC_PHASE_INC, 0, 31, + 0x1befbf06); + status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + DIF_SRC_GAIN_CONTROL, 0, 31, + 0x000035e8); + status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + DIF_RPT_VARIANCE, 0, 31, 0x00000000); + status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + DIF_VIDEO_AGC_CTRL, 0, 31, + 0xf4000000); + + /* Save the Spec Inversion value */ + dif_misc_ctrl_value &= FLD_DIF_SPEC_INV; + 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, + DIF_PLL_CTRL, 0, 31, 0x6503bc0c); + status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + DIF_PLL_CTRL1, 0, 31, 0xbd038c85); + status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + DIF_PLL_CTRL2, 0, 31, 0x1db4640a); + status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + DIF_PLL_CTRL3, 0, 31, 0x00008800); + status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + DIF_AGC_IF_REF, 0, 31, 0x888C0380); + status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + DIF_AGC_CTRL_IF, 0, 31, 0xe0262600); + status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + DIF_AGC_CTRL_INT, 0, 31, 0xc2171700); + status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + DIF_AGC_CTRL_RF, 0, 31, 0xc2262600); + status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + DIF_AGC_IF_INT_CURRENT, 0, 31, + 0x26001700); + status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + DIF_AGC_RF_CURRENT, 0, 31, + 0x00002660); + status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + DIF_VID_AUD_OVERRIDE, 0, 31, + 0x27000100); + status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + DIF_AV_SEP_CTRL, 0, 31, 0x3F3530ec); + status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + DIF_COMP_FLT_CTRL, 0, 31, + 0x00000000); + status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + DIF_SRC_PHASE_INC, 0, 31, + 0x1befbf06); + status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + DIF_SRC_GAIN_CONTROL, 0, 31, + 0x000035e8); + status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + DIF_RPT_VARIANCE, 0, 31, 0x00000000); + status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + DIF_VIDEO_AGC_CTRL, 0, 31, + 0xf2560000); + + /* Save the Spec Inversion value */ + dif_misc_ctrl_value &= FLD_DIF_SPEC_INV; + dif_misc_ctrl_value |= 0x3a023F11; + + } else if (standard & V4L2_STD_NTSC_M) { + /* V4L2_STD_NTSC_M (75 IRE Setup) Or + V4L2_STD_NTSC_M_JP (Japan, 0 IRE Setup) */ + + /* For NTSC the centre frequency of video coming out of + sidewinder is around 7.1MHz or 3.6MHz depending on the + spectral inversion. so for a non spectrally inverted channel + 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); + + /* 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, + DIF_PLL_CTRL, 0, 31, 0x6503bc0c); + status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + DIF_PLL_CTRL1, 0, 31, 0xbd038c85); + status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + DIF_PLL_CTRL2, 0, 31, 0x1db4640a); + status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + DIF_PLL_CTRL3, 0, 31, 0x00008800); + status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + DIF_AGC_IF_REF, 0, 31, 0x444C1380); + status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + DIF_AGC_CTRL_IF, 0, 31, 0xDA302600); + status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + DIF_AGC_CTRL_INT, 0, 31, 0xDA261700); + status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + DIF_AGC_CTRL_RF, 0, 31, 0xDA262600); + status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + DIF_AGC_IF_INT_CURRENT, 0, 31, + 0x26001700); + status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + DIF_AGC_RF_CURRENT, 0, 31, + 0x00002660); + status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + DIF_VIDEO_AGC_CTRL, 0, 31, + 0x72500800); + status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + DIF_VID_AUD_OVERRIDE, 0, 31, + 0x27000100); + status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + DIF_AV_SEP_CTRL, 0, 31, 0x3F3530EC); + status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + DIF_COMP_FLT_CTRL, 0, 31, + 0x00A653A8); + status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + DIF_SRC_PHASE_INC, 0, 31, + 0x1befbf06); + status = cx231xx_reg_mask_write(dev, HAMMERHEAD_I2C_ADDRESS, 32, + DIF_SRC_GAIN_CONTROL, 0, 31, + 0x000035e8); + status = cx231xx_reg_mask_write(dev, HAMMERHEAD_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 |= 0x3a013F11; + } + + /* The AGC values should be the same for all standards, + AUD_SRC_SEL[19] should always be disabled */ + dif_misc_ctrl_value &= ~FLD_DIF_AUD_SRC_SEL; + + /* It is still possible to get Set Standard calls even when we + are in FM mode. + This is done to override the value for FM. */ + if (dev->active_mode == V4L2_TUNER_RADIO) + 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); + + return status; +} + +int cx231xx_tuner_pre_channel_change(struct cx231xx *dev) +{ + int status = 0; + 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); + 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); + + return status; +} + +int cx231xx_tuner_post_channel_change(struct cx231xx *dev) +{ + int status = 0; + u32 dwval; + + /* 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); + dwval &= ~(FLD_DIF_K_AGC_RF | FLD_DIF_K_AGC_IF); + + if (dev->norm & (V4L2_STD_SECAM_L | V4L2_STD_SECAM_B | + V4L2_STD_SECAM_D)) + dwval |= 0x88000000; + else + dwval |= 0x44000000; + + status = cx231xx_write_i2c_data(dev, HAMMERHEAD_I2C_ADDRESS, + DIF_AGC_IF_REF, 2, dwval, 4); + + return status; +} + +/****************************************************************************** + * F L A T I R O N - B L O C K C O N T R O L functions * + ******************************************************************************/ +int cx231xx_flatiron_initialize(struct cx231xx *dev) +{ + int status = 0; + u32 value; + + status = cx231xx_read_i2c_data(dev, Flatrion_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, + CH_PWR_CTRL1, 1, value, 1); + /* power up all channel */ + status = cx231xx_write_i2c_data(dev, Flatrion_DEVICE_ADDRESS, + CH_PWR_CTRL2, 1, 0x00, 1); + + return status; +} + +int cx231xx_flatiron_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, + CH_PWR_CTRL2, 1, &value, 1); + value |= 0xfe; + status = cx231xx_write_i2c_data(dev, Flatrion_DEVICE_ADDRESS, + CH_PWR_CTRL2, 1, value, 1); + } else { + status = cx231xx_write_i2c_data(dev, Flatrion_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) +{ + int status = 0; + + switch (audio_input) { + case CX231XX_AMUX_LINE_IN: + status = cx231xx_write_i2c_data(dev, Flatrion_DEVICE_ADDRESS, + CH_PWR_CTRL2, 1, 0x00, 1); + status = cx231xx_write_i2c_data(dev, Flatrion_DEVICE_ADDRESS, + CH_PWR_CTRL1, 1, 0x80, 1); + break; + case CX231XX_AMUX_VIDEO: + default: + break; + } + + dev->ctl_ainput = audio_input; + + return status; +} + +/****************************************************************************** + * P O W E R C O N T R O L functions * + ******************************************************************************/ +int cx231xx_set_power_mode(struct cx231xx *dev, enum AV_MODE mode) +{ + u8 value[4] = { 0, 0, 0, 0 }; + u32 tmp = 0; + int status = 0; + + if (dev->power_mode != mode) + dev->power_mode = mode; + else { + cx231xx_info(" setPowerMode::mode = %d, No Change req.\n", + mode); + return 0; + } + + cx231xx_info(" setPowerMode::mode = %d\n", mode); + + status = cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER, PWR_CTL_EN, value, + 4); + if (status < 0) + return status; + + tmp = *((u32 *) value); + + switch (mode) { + case POLARIS_AVMODE_ENXTERNAL_AV: + + tmp &= (~PWR_MODE_MASK); + + tmp |= PWR_AV_EN; + value[0] = (u8) tmp; + value[1] = (u8) (tmp >> 8); + value[2] = (u8) (tmp >> 16); + value[3] = (u8) (tmp >> 24); + status = cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER, + PWR_CTL_EN, value, 4); + msleep(PWR_SLEEP_INTERVAL); + + tmp |= PWR_ISO_EN; + value[0] = (u8) tmp; + value[1] = (u8) (tmp >> 8); + value[2] = (u8) (tmp >> 16); + value[3] = (u8) (tmp >> 24); + status = + cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER, PWR_CTL_EN, + value, 4); + msleep(PWR_SLEEP_INTERVAL); + + tmp |= POLARIS_AVMODE_ENXTERNAL_AV; + value[0] = (u8) tmp; + value[1] = (u8) (tmp >> 8); + value[2] = (u8) (tmp >> 16); + value[3] = (u8) (tmp >> 24); + status = cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER, + PWR_CTL_EN, value, 4); + + /* reset state of xceive tuner */ + dev->xc_fw_load_done = 0; + break; + + case POLARIS_AVMODE_ANALOGT_TV: + + tmp &= (~PWR_DEMOD_EN); + tmp |= (I2C_DEMOD_EN); + value[0] = (u8) tmp; + value[1] = (u8) (tmp >> 8); + value[2] = (u8) (tmp >> 16); + value[3] = (u8) (tmp >> 24); + status = cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER, + PWR_CTL_EN, value, 4); + msleep(PWR_SLEEP_INTERVAL); + + if (!(tmp & PWR_TUNER_EN)) { + tmp |= (PWR_TUNER_EN); + value[0] = (u8) tmp; + value[1] = (u8) (tmp >> 8); + value[2] = (u8) (tmp >> 16); + value[3] = (u8) (tmp >> 24); + status = cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER, + PWR_CTL_EN, value, 4); + msleep(PWR_SLEEP_INTERVAL); + } + + if (!(tmp & PWR_AV_EN)) { + tmp |= PWR_AV_EN; + value[0] = (u8) tmp; + value[1] = (u8) (tmp >> 8); + value[2] = (u8) (tmp >> 16); + value[3] = (u8) (tmp >> 24); + status = cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER, + PWR_CTL_EN, value, 4); + msleep(PWR_SLEEP_INTERVAL); + } + if (!(tmp & PWR_ISO_EN)) { + tmp |= PWR_ISO_EN; + value[0] = (u8) tmp; + value[1] = (u8) (tmp >> 8); + value[2] = (u8) (tmp >> 16); + value[3] = (u8) (tmp >> 24); + status = cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER, + PWR_CTL_EN, value, 4); + msleep(PWR_SLEEP_INTERVAL); + } + + if (!(tmp & POLARIS_AVMODE_ANALOGT_TV)) { + tmp |= POLARIS_AVMODE_ANALOGT_TV; + value[0] = (u8) tmp; + value[1] = (u8) (tmp >> 8); + value[2] = (u8) (tmp >> 16); + value[3] = (u8) (tmp >> 24); + status = cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER, + PWR_CTL_EN, value, 4); + msleep(PWR_SLEEP_INTERVAL); + } + + if ((dev->model == CX231XX_BOARD_CNXT_RDE_250) || + (dev->model == CX231XX_BOARD_CNXT_RDU_250)) { + /* tuner path to channel 1 from port 3 */ + cx231xx_enable_i2c_for_tuner(dev, I2C_3); + + if (dev->cx231xx_reset_analog_tuner) + dev->cx231xx_reset_analog_tuner(dev); + } + break; + + case POLARIS_AVMODE_DIGITAL: + if (!(tmp & PWR_TUNER_EN)) { + tmp |= (PWR_TUNER_EN); + value[0] = (u8) tmp; + value[1] = (u8) (tmp >> 8); + value[2] = (u8) (tmp >> 16); + value[3] = (u8) (tmp >> 24); + status = cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER, + PWR_CTL_EN, value, 4); + msleep(PWR_SLEEP_INTERVAL); + } + if (!(tmp & PWR_AV_EN)) { + tmp |= PWR_AV_EN; + value[0] = (u8) tmp; + value[1] = (u8) (tmp >> 8); + value[2] = (u8) (tmp >> 16); + value[3] = (u8) (tmp >> 24); + status = cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER, + PWR_CTL_EN, value, 4); + msleep(PWR_SLEEP_INTERVAL); + } + if (!(tmp & PWR_ISO_EN)) { + tmp |= PWR_ISO_EN; + value[0] = (u8) tmp; + value[1] = (u8) (tmp >> 8); + value[2] = (u8) (tmp >> 16); + value[3] = (u8) (tmp >> 24); + status = cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER, + PWR_CTL_EN, value, 4); + msleep(PWR_SLEEP_INTERVAL); + } + + tmp |= POLARIS_AVMODE_DIGITAL | I2C_DEMOD_EN; + value[0] = (u8) tmp; + value[1] = (u8) (tmp >> 8); + value[2] = (u8) (tmp >> 16); + value[3] = (u8) (tmp >> 24); + status = cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER, + PWR_CTL_EN, value, 4); + msleep(PWR_SLEEP_INTERVAL); + + if (!(tmp & PWR_DEMOD_EN)) { + tmp |= PWR_DEMOD_EN; + value[0] = (u8) tmp; + value[1] = (u8) (tmp >> 8); + value[2] = (u8) (tmp >> 16); + value[3] = (u8) (tmp >> 24); + status = cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER, + PWR_CTL_EN, value, 4); + msleep(PWR_SLEEP_INTERVAL); + } + + if ((dev->model == CX231XX_BOARD_CNXT_RDE_250) || + (dev->model == CX231XX_BOARD_CNXT_RDU_250)) { + /* tuner path to channel 1 from port 3 */ + cx231xx_enable_i2c_for_tuner(dev, I2C_3); + + if (dev->cx231xx_reset_analog_tuner) + dev->cx231xx_reset_analog_tuner(dev); + } + break; + + default: + break; + } + + msleep(PWR_SLEEP_INTERVAL); + + /* For power saving, only enable Pwr_resetout_n + when digital TV is selected. */ + if (mode == POLARIS_AVMODE_DIGITAL) { + tmp |= PWR_RESETOUT_EN; + value[0] = (u8) tmp; + value[1] = (u8) (tmp >> 8); + value[2] = (u8) (tmp >> 16); + value[3] = (u8) (tmp >> 24); + status = cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER, + PWR_CTL_EN, value, 4); + msleep(PWR_SLEEP_INTERVAL); + } + + /* update power control for colibri */ + status = cx231xx_colibri_update_power_control(dev, mode); + + /* update power control for flatiron */ + status = cx231xx_flatiron_update_power_control(dev, mode); + + status = cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER, PWR_CTL_EN, value, + 4); + cx231xx_info(" The data of PWR_CTL_EN register 0x74" + "=0x%0x,0x%0x,0x%0x,0x%0x\n", + value[0], value[1], value[2], value[3]); + + return status; +} + +int cx231xx_power_suspend(struct cx231xx *dev) +{ + u8 value[4] = { 0, 0, 0, 0 }; + u32 tmp = 0; + int status = 0; + + status = cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER, PWR_CTL_EN, + value, 4); + if (status > 0) + return status; + + tmp = *((u32 *) value); + tmp &= (~PWR_MODE_MASK); + + value[0] = (u8) tmp; + value[1] = (u8) (tmp >> 8); + value[2] = (u8) (tmp >> 16); + value[3] = (u8) (tmp >> 24); + status = cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER, PWR_CTL_EN, + value, 4); + + return status; +} + +/****************************************************************************** + * S T R E A M C O N T R O L functions * + ******************************************************************************/ +int cx231xx_start_stream(struct cx231xx *dev, u32 ep_mask) +{ + u8 value[4] = { 0x0, 0x0, 0x0, 0x0 }; + u32 tmp = 0; + int status = 0; + + cx231xx_info("cx231xx_start_stream():: ep_mask = %x\n", ep_mask); + status = cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER, EP_MODE_SET, + value, 4); + if (status < 0) + return status; + + tmp = *((u32 *) value); + tmp |= ep_mask; + value[0] = (u8) tmp; + value[1] = (u8) (tmp >> 8); + value[2] = (u8) (tmp >> 16); + value[3] = (u8) (tmp >> 24); + + status = cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER, EP_MODE_SET, + value, 4); + + return status; +} + +int cx231xx_stop_stream(struct cx231xx *dev, u32 ep_mask) +{ + u8 value[4] = { 0x0, 0x0, 0x0, 0x0 }; + u32 tmp = 0; + int status = 0; + + cx231xx_info("cx231xx_stop_stream():: ep_mask = %x\n", ep_mask); + status = + cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER, EP_MODE_SET, value, 4); + if (status < 0) + return status; + + tmp = *((u32 *) value); + tmp &= (~ep_mask); + value[0] = (u8) tmp; + value[1] = (u8) (tmp >> 8); + value[2] = (u8) (tmp >> 16); + value[3] = (u8) (tmp >> 24); + + status = cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER, EP_MODE_SET, + value, 4); + + return status; +} + +int cx231xx_initialize_stream_xfer(struct cx231xx *dev, u32 media_type) +{ + int status = 0; + + if (dev->udev->speed == USB_SPEED_HIGH) { + switch (media_type) { + case 81: /* audio */ + cx231xx_info("%s: Audio enter HANC\n", __func__); + status = + cx231xx_mode_register(dev, TS_MODE_REG, 0x9300); + break; + + case 2: /* vbi */ + cx231xx_info("%s: set vanc registers\n", __func__); + status = cx231xx_mode_register(dev, TS_MODE_REG, 0x300); + break; + + case 3: /* sliced cc */ + cx231xx_info("%s: set hanc registers\n", __func__); + status = + cx231xx_mode_register(dev, TS_MODE_REG, 0x1300); + break; + + case 0: /* video */ + cx231xx_info("%s: set video registers\n", __func__); + status = cx231xx_mode_register(dev, TS_MODE_REG, 0x100); + break; + + case 4: /* ts1 */ + cx231xx_info("%s: set ts1 registers\n", __func__); + status = cx231xx_mode_register(dev, TS_MODE_REG, 0x101); + status = cx231xx_mode_register(dev, TS1_CFG_REG, 0x400); + break; + case 6: /* ts1 parallel mode */ + cx231xx_info("%s: set ts1 parrallel mode registers\n", + __func__); + status = cx231xx_mode_register(dev, TS_MODE_REG, 0x100); + status = cx231xx_mode_register(dev, TS1_CFG_REG, 0x400); + break; + } + } else { + status = cx231xx_mode_register(dev, TS_MODE_REG, 0x101); + } + + return status; +} + +int cx231xx_capture_start(struct cx231xx *dev, int start, u8 media_type) +{ + int rc; + u32 ep_mask = -1; + struct pcb_config *pcb_config; + + /* get EP for media type */ + pcb_config = (struct pcb_config *)&dev->current_pcb_config; + + if (pcb_config->config_num == 1) { + switch (media_type) { + case 0: /* Video */ + ep_mask = ENABLE_EP4; /* ep4 [00:1000] */ + break; + case 1: /* Audio */ + ep_mask = ENABLE_EP3; /* ep3 [00:0100] */ + break; + case 2: /* Vbi */ + ep_mask = ENABLE_EP5; /* ep5 [01:0000] */ + break; + case 3: /* Sliced_cc */ + ep_mask = ENABLE_EP6; /* ep6 [10:0000] */ + break; + case 4: /* ts1 */ + case 6: /* ts1 parallel mode */ + ep_mask = ENABLE_EP1; /* ep1 [00:0001] */ + break; + case 5: /* ts2 */ + ep_mask = ENABLE_EP2; /* ep2 [00:0010] */ + break; + } + + } else if (pcb_config->config_num > 1) { + switch (media_type) { + case 0: /* Video */ + ep_mask = ENABLE_EP4; /* ep4 [00:1000] */ + break; + case 1: /* Audio */ + ep_mask = ENABLE_EP3; /* ep3 [00:0100] */ + break; + case 2: /* Vbi */ + ep_mask = ENABLE_EP5; /* ep5 [01:0000] */ + break; + case 3: /* Sliced_cc */ + ep_mask = ENABLE_EP6; /* ep6 [10:0000] */ + break; + case 4: /* ts1 */ + case 6: /* ts1 parallel mode */ + ep_mask = ENABLE_EP1; /* ep1 [00:0001] */ + break; + case 5: /* ts2 */ + ep_mask = ENABLE_EP2; /* ep2 [00:0010] */ + break; + } + + } + + if (start) { + rc = cx231xx_initialize_stream_xfer(dev, media_type); + + if (rc < 0) + return rc; + + /* enable video capture */ + if (ep_mask > 0) + rc = cx231xx_start_stream(dev, ep_mask); + } else { + /* disable video capture */ + if (ep_mask > 0) + rc = cx231xx_stop_stream(dev, ep_mask); + } + + if (dev->mode == CX231XX_ANALOG_MODE) + ;/* do any in Analog mode */ + else + ;/* do any in digital mode */ + + return rc; +} +EXPORT_SYMBOL_GPL(cx231xx_capture_start); + +/***************************************************************************** +* G P I O B I T control functions * +******************************************************************************/ +int cx231xx_set_gpio_bit(struct cx231xx *dev, u32 gpio_bit, u8 * gpio_val) +{ + int status = 0; + + status = cx231xx_send_gpio_cmd(dev, gpio_bit, gpio_val, 4, 0, 0); + + return status; +} + +int cx231xx_get_gpio_bit(struct cx231xx *dev, u32 gpio_bit, u8 * gpio_val) +{ + int status = 0; + + status = cx231xx_send_gpio_cmd(dev, gpio_bit, gpio_val, 4, 0, 1); + + return status; +} + +/* +* cx231xx_set_gpio_direction +* Sets the direction of the GPIO pin to input or output +* +* Parameters : +* pin_number : The GPIO Pin number to program the direction for +* from 0 to 31 +* pin_value : The Direction of the GPIO Pin under reference. +* 0 = Input direction +* 1 = Output direction +*/ +int cx231xx_set_gpio_direction(struct cx231xx *dev, + int pin_number, int pin_value) +{ + int status = 0; + u32 value = 0; + + /* Check for valid pin_number - if 32 , bail out */ + if (pin_number >= 32) + return -EINVAL; + + /* input */ + if (pin_value == 0) + value = dev->gpio_dir & (~(1 << pin_number)); /* clear */ + else + value = dev->gpio_dir | (1 << pin_number); + + status = cx231xx_set_gpio_bit(dev, value, (u8 *) &dev->gpio_val); + + /* cache the value for future */ + dev->gpio_dir = value; + + return status; +} + +/* +* cx231xx_set_gpio_value +* Sets the value of the GPIO pin to Logic high or low. The Pin under +* reference should ALREADY BE SET IN OUTPUT MODE !!!!!!!!! +* +* Parameters : +* pin_number : The GPIO Pin number to program the direction for +* pin_value : The value of the GPIO Pin under reference. +* 0 = set it to 0 +* 1 = set it to 1 +*/ +int cx231xx_set_gpio_value(struct cx231xx *dev, int pin_number, int pin_value) +{ + int status = 0; + u32 value = 0; + + /* Check for valid pin_number - if 0xFF , bail out */ + if (pin_number >= 32) + return -EINVAL; + + /* first do a sanity check - if the Pin is not output, make it output */ + if ((dev->gpio_dir & (1 << pin_number)) == 0x00) { + /* It was in input mode */ + value = dev->gpio_dir | (1 << pin_number); + dev->gpio_dir = value; + status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, + (u8 *) &dev->gpio_val); + value = 0; + } + + if (pin_value == 0) + value = dev->gpio_val & (~(1 << pin_number)); + else + value = dev->gpio_val | (1 << pin_number); + + /* store the value */ + dev->gpio_val = value; + + /* toggle bit0 of GP_IO */ + status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, (u8 *)&dev->gpio_val); + + return status; +} + +/***************************************************************************** +* G P I O I2C related functions * +******************************************************************************/ +int cx231xx_gpio_i2c_start(struct cx231xx *dev) +{ + int status = 0; + + /* set SCL to output 1 ; set SDA to output 1 */ + dev->gpio_dir |= 1 << dev->board.tuner_scl_gpio; + dev->gpio_dir |= 1 << dev->board.tuner_sda_gpio; + dev->gpio_val |= 1 << dev->board.tuner_scl_gpio; + dev->gpio_val |= 1 << dev->board.tuner_sda_gpio; + + status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, (u8 *)&dev->gpio_val); + if (status < 0) + return -EINVAL; + + /* set SCL to output 1; set SDA to output 0 */ + dev->gpio_val |= 1 << dev->board.tuner_scl_gpio; + dev->gpio_val &= ~(1 << dev->board.tuner_sda_gpio); + + status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, (u8 *)&dev->gpio_val); + if (status < 0) + return -EINVAL; + + /* set SCL to output 0; set SDA to output 0 */ + dev->gpio_val &= ~(1 << dev->board.tuner_scl_gpio); + dev->gpio_val &= ~(1 << dev->board.tuner_sda_gpio); + + status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, (u8 *)&dev->gpio_val); + if (status < 0) + return -EINVAL; + + return status; +} + +int cx231xx_gpio_i2c_end(struct cx231xx *dev) +{ + int status = 0; + + /* set SCL to output 0; set SDA to output 0 */ + dev->gpio_dir |= 1 << dev->board.tuner_scl_gpio; + dev->gpio_dir |= 1 << dev->board.tuner_sda_gpio; + + dev->gpio_val &= ~(1 << dev->board.tuner_scl_gpio); + dev->gpio_val &= ~(1 << dev->board.tuner_sda_gpio); + + status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, (u8 *)&dev->gpio_val); + if (status < 0) + return -EINVAL; + + /* set SCL to output 1; set SDA to output 0 */ + dev->gpio_val |= 1 << dev->board.tuner_scl_gpio; + dev->gpio_val &= ~(1 << dev->board.tuner_sda_gpio); + + status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, (u8 *)&dev->gpio_val); + if (status < 0) + return -EINVAL; + + /* set SCL to input ,release SCL cable control + set SDA to input ,release SDA cable control */ + dev->gpio_dir &= ~(1 << dev->board.tuner_scl_gpio); + dev->gpio_dir &= ~(1 << dev->board.tuner_sda_gpio); + + status = + cx231xx_set_gpio_bit(dev, dev->gpio_dir, (u8 *)&dev->gpio_val); + if (status < 0) + return -EINVAL; + + return status; +} + +int cx231xx_gpio_i2c_write_byte(struct cx231xx *dev, u8 data) +{ + int status = 0; + u8 i; + + /* set SCL to output ; set SDA to output */ + dev->gpio_dir |= 1 << dev->board.tuner_scl_gpio; + dev->gpio_dir |= 1 << dev->board.tuner_sda_gpio; + + for (i = 0; i < 8; i++) { + if (((data << i) & 0x80) == 0) { + /* set SCL to output 0; set SDA to output 0 */ + dev->gpio_val &= ~(1 << dev->board.tuner_scl_gpio); + dev->gpio_val &= ~(1 << dev->board.tuner_sda_gpio); + status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, + (u8 *)&dev->gpio_val); + + /* set SCL to output 1; set SDA to output 0 */ + dev->gpio_val |= 1 << dev->board.tuner_scl_gpio; + status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, + (u8 *)&dev->gpio_val); + + /* set SCL to output 0; set SDA to output 0 */ + dev->gpio_val &= ~(1 << dev->board.tuner_scl_gpio); + status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, + (u8 *)&dev->gpio_val); + } else { + /* set SCL to output 0; set SDA to output 1 */ + dev->gpio_val &= ~(1 << dev->board.tuner_scl_gpio); + dev->gpio_val |= 1 << dev->board.tuner_sda_gpio; + status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, + (u8 *)&dev->gpio_val); + + /* set SCL to output 1; set SDA to output 1 */ + dev->gpio_val |= 1 << dev->board.tuner_scl_gpio; + status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, + (u8 *)&dev->gpio_val); + + /* set SCL to output 0; set SDA to output 1 */ + dev->gpio_val &= ~(1 << dev->board.tuner_scl_gpio); + status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, + (u8 *)&dev->gpio_val); + } + } + return status; +} + +int cx231xx_gpio_i2c_read_byte(struct cx231xx *dev, u8 * buf) +{ + u8 value = 0; + int status = 0; + u32 gpio_logic_value = 0; + u8 i; + + /* read byte */ + for (i = 0; i < 8; i++) { /* send write I2c addr */ + + /* set SCL to output 0; set SDA to input */ + dev->gpio_val &= ~(1 << dev->board.tuner_scl_gpio); + status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, + (u8 *)&dev->gpio_val); + + /* set SCL to output 1; set SDA to input */ + dev->gpio_val |= 1 << dev->board.tuner_scl_gpio; + status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, + (u8 *)&dev->gpio_val); + + /* get SDA data bit */ + gpio_logic_value = dev->gpio_val; + status = cx231xx_get_gpio_bit(dev, dev->gpio_dir, + (u8 *)&dev->gpio_val); + if ((dev->gpio_val & (1 << dev->board.tuner_sda_gpio)) != 0) + value |= (1 << (8 - i - 1)); + + dev->gpio_val = gpio_logic_value; + } + + /* set SCL to output 0,finish the read latest SCL signal. + !!!set SDA to input, never to modify SDA direction at + the same times */ + dev->gpio_val &= ~(1 << dev->board.tuner_scl_gpio); + status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, (u8 *)&dev->gpio_val); + + /* store the value */ + *buf = value & 0xff; + + return status; +} + +int cx231xx_gpio_i2c_read_ack(struct cx231xx *dev) +{ + int status = 0; + u32 gpio_logic_value = 0; + int nCnt = 10; + int nInit = nCnt; + + /* clock stretch; set SCL to input; set SDA to input; + get SCL value till SCL = 1 */ + dev->gpio_dir &= ~(1 << dev->board.tuner_sda_gpio); + dev->gpio_dir &= ~(1 << dev->board.tuner_scl_gpio); + + gpio_logic_value = dev->gpio_val; + status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, (u8 *)&dev->gpio_val); + + do { + msleep(2); + status = cx231xx_get_gpio_bit(dev, dev->gpio_dir, + (u8 *)&dev->gpio_val); + nCnt--; + } while (((dev->gpio_val & + (1 << dev->board.tuner_scl_gpio)) == 0) && + (nCnt > 0)); + + if (nCnt == 0) + cx231xx_info("No ACK after %d msec -GPIO I2C failed!", + nInit * 10); + + /* readAck + throuth clock stretch ,slave has given a SCL signal, + so the SDA data can be directly read. */ + status = cx231xx_get_gpio_bit(dev, dev->gpio_dir, (u8 *)&dev->gpio_val); + + if ((dev->gpio_val & 1 << dev->board.tuner_sda_gpio) == 0) { + dev->gpio_val = gpio_logic_value; + dev->gpio_val &= ~(1 << dev->board.tuner_sda_gpio); + status = 0; + } else { + dev->gpio_val = gpio_logic_value; + dev->gpio_val |= (1 << dev->board.tuner_sda_gpio); + } + + /* read SDA end, set the SCL to output 0, after this operation, + SDA direction can be changed. */ + dev->gpio_val = gpio_logic_value; + dev->gpio_dir |= (1 << dev->board.tuner_scl_gpio); + dev->gpio_val &= ~(1 << dev->board.tuner_scl_gpio); + status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, (u8 *)&dev->gpio_val); + + return status; +} + +int cx231xx_gpio_i2c_write_ack(struct cx231xx *dev) +{ + int status = 0; + + /* set SDA to ouput */ + dev->gpio_dir |= 1 << dev->board.tuner_sda_gpio; + status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, (u8 *)&dev->gpio_val); + + /* set SCL = 0 (output); set SDA = 0 (output) */ + dev->gpio_val &= ~(1 << dev->board.tuner_sda_gpio); + dev->gpio_val &= ~(1 << dev->board.tuner_scl_gpio); + status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, (u8 *)&dev->gpio_val); + + /* set SCL = 1 (output); set SDA = 0 (output) */ + dev->gpio_val |= 1 << dev->board.tuner_scl_gpio; + status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, (u8 *)&dev->gpio_val); + + /* set SCL = 0 (output); set SDA = 0 (output) */ + dev->gpio_val &= ~(1 << dev->board.tuner_scl_gpio); + status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, (u8 *)&dev->gpio_val); + + /* set SDA to input,and then the slave will read data from SDA. */ + dev->gpio_dir &= ~(1 << dev->board.tuner_sda_gpio); + status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, (u8 *)&dev->gpio_val); + + return status; +} + +int cx231xx_gpio_i2c_write_nak(struct cx231xx *dev) +{ + int status = 0; + + /* set scl to output ; set sda to input */ + dev->gpio_dir |= 1 << dev->board.tuner_scl_gpio; + dev->gpio_dir &= ~(1 << dev->board.tuner_sda_gpio); + status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, (u8 *)&dev->gpio_val); + + /* set scl to output 0; set sda to input */ + dev->gpio_val &= ~(1 << dev->board.tuner_scl_gpio); + status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, (u8 *)&dev->gpio_val); + + /* set scl to output 1; set sda to input */ + dev->gpio_val |= 1 << dev->board.tuner_scl_gpio; + status = cx231xx_set_gpio_bit(dev, dev->gpio_dir, (u8 *)&dev->gpio_val); + + return status; +} + +/***************************************************************************** +* G P I O I2C related functions * +******************************************************************************/ +/* cx231xx_gpio_i2c_read + * Function to read data from gpio based I2C interface + */ +int cx231xx_gpio_i2c_read(struct cx231xx *dev, u8 dev_addr, u8 * buf, u8 len) +{ + int status = 0; + int i = 0; + + /* get the lock */ + mutex_lock(&dev->gpio_i2c_lock); + + /* start */ + status = cx231xx_gpio_i2c_start(dev); + + /* write dev_addr */ + status = cx231xx_gpio_i2c_write_byte(dev, (dev_addr << 1) + 1); + + /* readAck */ + status = cx231xx_gpio_i2c_read_ack(dev); + + /* read data */ + for (i = 0; i < len; i++) { + /* read data */ + buf[i] = 0; + status = cx231xx_gpio_i2c_read_byte(dev, &buf[i]); + + if ((i + 1) != len) { + /* only do write ack if we more length */ + status = cx231xx_gpio_i2c_write_ack(dev); + } + } + + /* write NAK - inform reads are complete */ + status = cx231xx_gpio_i2c_write_nak(dev); + + /* write end */ + status = cx231xx_gpio_i2c_end(dev); + + /* release the lock */ + mutex_unlock(&dev->gpio_i2c_lock); + + return status; +} + +/* cx231xx_gpio_i2c_write + * Function to write data to gpio based I2C interface + */ +int cx231xx_gpio_i2c_write(struct cx231xx *dev, u8 dev_addr, u8 * buf, u8 len) +{ + int status = 0; + int i = 0; + + /* get the lock */ + mutex_lock(&dev->gpio_i2c_lock); + + /* start */ + status = cx231xx_gpio_i2c_start(dev); + + /* write dev_addr */ + status = cx231xx_gpio_i2c_write_byte(dev, dev_addr << 1); + + /* read Ack */ + status = cx231xx_gpio_i2c_read_ack(dev); + + for (i = 0; i < len; i++) { + /* Write data */ + status = cx231xx_gpio_i2c_write_byte(dev, buf[i]); + + /* read Ack */ + status = cx231xx_gpio_i2c_read_ack(dev); + } + + /* write End */ + status = cx231xx_gpio_i2c_end(dev); + + /* release the lock */ + mutex_unlock(&dev->gpio_i2c_lock); + + return 0; +} diff --git a/linux/drivers/media/video/cx231xx/cx231xx-cards.c b/linux/drivers/media/video/cx231xx/cx231xx-cards.c new file mode 100644 index 000000000..435ecf58d --- /dev/null +++ b/linux/drivers/media/video/cx231xx/cx231xx-cards.c @@ -0,0 +1,953 @@ +/* + cx231xx-cards.c - driver for Conexant Cx23100/101/102 + USB video capture devices + + Copyright (C) 2008 <srinivasa.deevi at conexant dot com> + Based on em28xx driver + + 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/init.h> +#include <linux/module.h> +#include <linux/delay.h> +#include <linux/i2c.h> +#include <linux/usb.h> +#include "compat.h" +#include <media/tuner.h> +#include <media/tveeprom.h> +#include <media/v4l2-common.h> +#include <media/v4l2-chip-ident.h> + +#include <media/cx25840.h> +#include "xc5000.h" + +#include "cx231xx.h" + +static int tuner = -1; +module_param(tuner, int, 0444); +MODULE_PARM_DESC(tuner, "tuner type"); + +static unsigned int disable_ir; +module_param(disable_ir, int, 0444); +MODULE_PARM_DESC(disable_ir, "disable infrared remote support"); + +/* Bitmask marking allocated devices from 0 to CX231XX_MAXBOARDS */ +static unsigned long cx231xx_devused; + +/* + * Reset sequences for analog/digital modes + */ + +static struct cx231xx_reg_seq RDE250_XCV_TUNER[] = { + {0x03, 0x01, 10}, + {0x03, 0x00, 30}, + {0x03, 0x01, 10}, + {-1, -1, -1}, +}; + +/* + * Board definitions + */ +struct cx231xx_board cx231xx_boards[] = { + [CX231XX_BOARD_UNKNOWN] = { + .name = "Unknown CX231xx video grabber", + .tuner_type = TUNER_ABSENT, + .input = {{ + .type = CX231XX_VMUX_TELEVISION, + .vmux = CX231XX_VIN_3_1, + .amux = CX231XX_AMUX_VIDEO, + .gpio = 0, + }, { + .type = CX231XX_VMUX_COMPOSITE1, + .vmux = CX231XX_VIN_2_1, + .amux = CX231XX_AMUX_LINE_IN, + .gpio = 0, + }, { + .type = CX231XX_VMUX_SVIDEO, + .vmux = CX231XX_VIN_1_1 | + (CX231XX_VIN_1_2 << 8) | + CX25840_SVIDEO_ON, + .amux = CX231XX_AMUX_LINE_IN, + .gpio = 0, + } + }, + }, + [CX231XX_BOARD_CNXT_RDE_250] = { + .name = "Conexant Hybrid TV - RDE250", + .tuner_type = TUNER_XC5000, + .tuner_addr = 0x61, + .tuner_gpio = RDE250_XCV_TUNER, + .tuner_sif_gpio = 0x05, + .tuner_scl_gpio = 0x1a, + .tuner_sda_gpio = 0x1b, + .decoder = CX231XX_AVDECODER, + .demod_xfer_mode = 0, + .ctl_pin_status_mask = 0xFFFFFFC4, + .agc_analog_digital_select_gpio = 0x0c, + .gpio_pin_status_mask = 0x4001000, + .tuner_i2c_master = 1, + .demod_i2c_master = 2, + .has_dvb = 1, + .demod_addr = 0x02, + .norm = V4L2_STD_PAL, + + .input = {{ + .type = CX231XX_VMUX_TELEVISION, + .vmux = CX231XX_VIN_3_1, + .amux = CX231XX_AMUX_VIDEO, + .gpio = 0, + }, { + .type = CX231XX_VMUX_COMPOSITE1, + .vmux = CX231XX_VIN_2_1, + .amux = CX231XX_AMUX_LINE_IN, + .gpio = 0, + }, { + .type = CX231XX_VMUX_SVIDEO, + .vmux = CX231XX_VIN_1_1 | + (CX231XX_VIN_1_2 << 8) | + CX25840_SVIDEO_ON, + .amux = CX231XX_AMUX_LINE_IN, + .gpio = 0, + } + }, + }, + + [CX231XX_BOARD_CNXT_RDU_250] = { + .name = "Conexant Hybrid TV - RDU250", + .tuner_type = TUNER_XC5000, + .tuner_addr = 0x61, + .tuner_gpio = RDE250_XCV_TUNER, + .tuner_sif_gpio = 0x05, + .tuner_scl_gpio = 0x1a, + .tuner_sda_gpio = 0x1b, + .decoder = CX231XX_AVDECODER, + .demod_xfer_mode = 0, + .ctl_pin_status_mask = 0xFFFFFFC4, + .agc_analog_digital_select_gpio = 0x0c, + .gpio_pin_status_mask = 0x4001000, + .tuner_i2c_master = 1, + .demod_i2c_master = 2, + .has_dvb = 1, + .demod_addr = 0x32, + .norm = V4L2_STD_NTSC, + + .input = {{ + .type = CX231XX_VMUX_TELEVISION, + .vmux = CX231XX_VIN_3_1, + .amux = CX231XX_AMUX_VIDEO, + .gpio = 0, + }, { + .type = CX231XX_VMUX_COMPOSITE1, + .vmux = CX231XX_VIN_2_1, + .amux = CX231XX_AMUX_LINE_IN, + .gpio = 0, + }, { + .type = CX231XX_VMUX_SVIDEO, + .vmux = CX231XX_VIN_1_1 | + (CX231XX_VIN_1_2 << 8) | + CX25840_SVIDEO_ON, + .amux = CX231XX_AMUX_LINE_IN, + .gpio = 0, + } + }, + }, +}; +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, 0x5A3C), + .driver_info = CX231XX_BOARD_UNKNOWN}, + {USB_DEVICE(0x0572, 0x58A2), + .driver_info = CX231XX_BOARD_CNXT_RDE_250}, + {USB_DEVICE(0x0572, 0x58A1), + .driver_info = CX231XX_BOARD_CNXT_RDU_250}, + {}, +}; + +MODULE_DEVICE_TABLE(usb, cx231xx_id_table); + +/* cx231xx_tuner_callback + * will be used to reset XC5000 tuner using GPIO pin + */ + +int cx231xx_tuner_callback(void *ptr, int component, int command, int arg) +{ + int rc = 0; + struct cx231xx *dev = ptr; + + if (dev->tuner_type == TUNER_XC5000) { + if (command == XC5000_TUNER_RESET) { + cx231xx_info + ("Tuner CB: RESET: cmd %d : tuner type %d \n", + command, dev->tuner_type); + cx231xx_set_gpio_value(dev, dev->board.tuner_gpio->bit, + 1); + msleep(10); + cx231xx_set_gpio_value(dev, dev->board.tuner_gpio->bit, + 0); + msleep(330); + cx231xx_set_gpio_value(dev, dev->board.tuner_gpio->bit, + 1); + msleep(10); + } + } + return rc; +} +EXPORT_SYMBOL_GPL(cx231xx_tuner_callback); + +static inline void cx231xx_set_model(struct cx231xx *dev) +{ + memcpy(&dev->board, &cx231xx_boards[dev->model], sizeof(dev->board)); +} + +/* Since cx231xx_pre_card_setup() requires a proper dev->model, + * this won't work for boards with generic PCI IDs + */ +void cx231xx_pre_card_setup(struct cx231xx *dev) +{ + + cx231xx_set_model(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); + cx231xx_set_gpio_direction(dev, dev->board.tuner_sif_gpio, 1); + + /* request some modules if any required */ + + /* reset the Tuner */ + cx231xx_gpio_set(dev, dev->board.tuner_gpio); + + /* set the mode to Analog mode initially */ + cx231xx_set_mode(dev, CX231XX_ANALOG_MODE); + + /* Unlock device */ + /* cx231xx_set_mode(dev, CX231XX_SUSPEND); */ + +} + +#if 0 /* Keep */ + +static void cx231xx_config_tuner(struct cx231xx *dev) +{ + struct tuner_setup tun_setup; + struct v4l2_frequency f; + + if (dev->tuner_type == TUNER_ABSENT) + return; + + tun_setup.mode_mask = T_ANALOG_TV | T_RADIO; + tun_setup.type = dev->tuner_type; + 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); +#if 0 /* Keep */ + if (tun_setup.type == TUNER_XC5000) { + static struct xc2028_ctrl ctrl = { + .fname = XC5000_DEFAULT_FIRMWARE, + .max_len = 64, + .demod = 0; + }; + struct v4l2_priv_tun_config cfg = { + .tuner = dev->tuner_type, + .priv = &ctrl, + }; + cx231xx_i2c_call_clients(&dev->i2c_bus[1], TUNER_SET_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); +} + +#endif + +/* ----------------------------------------------------------------------- */ +void cx231xx_set_ir(struct cx231xx *dev, struct IR_i2c *ir) +{ + if (disable_ir) { + ir->get_key = NULL; + return; + } + + /* detect & configure */ + switch (dev->model) { + + case CX231XX_BOARD_CNXT_RDE_250: + break; + case CX231XX_BOARD_CNXT_RDU_250: + break; + default: + break; + } +} + +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 Conexant RDE 250\n"); + break; + case CX231XX_BOARD_CNXT_RDU_250: + /* do card specific GPIO settings if required */ + cx231xx_info("Board is Conexant RDU 250\n"); + break; + } + + /* request some modules */ + if (dev->board.decoder == CX231XX_AVDECODER) { + cx231xx_info(": Requesting cx25840 module\n"); + request_module("cx25840"); + } +#if 0 /* Keep */ + if (dev->board.tuner_type != TUNER_ABSENT) { + cx231xx_info(": Requesting Tuner module\n"); + request_module("tuner"); + } + + cx231xx_config_tuner(dev); + + /* TBD IR will be added later */ + cx231xx_ir_init(dev); +#endif +} + +/* + * cx231xx_config() + * inits registers with sane defaults + */ +int cx231xx_config(struct cx231xx *dev) +{ + /* TBD need to add cx231xx specific code */ + dev->mute = 1; /* maybe not the right place... */ + dev->volume = 0x1f; + + return 0; +} + +/* + * cx231xx_config_i2c() + * configure i2c attached devices + */ +void cx231xx_config_i2c(struct cx231xx *dev) +{ + struct v4l2_routing route; + + route.input = INPUT(dev->video_input)->vmux; + route.output = 0; + + cx231xx_i2c_call_clients(&dev->i2c_bus[0], VIDIOC_STREAMON, NULL); +} + +/* + * cx231xx_realease_resources() + * unregisters the v4l2,i2c and usb devices + * called when the device gets disconected or at module unload +*/ +void cx231xx_release_resources(struct cx231xx *dev) +{ + +#if 0 /* Keep */ /* TBD IR related */ + if (dev->ir) + cx231xx_ir_fini(dev); +#endif + + cx231xx_release_analog_resources(dev); + + cx231xx_remove_from_devlist(dev); + + cx231xx_dev_uninit(dev); + + usb_put_dev(dev->udev); + + /* Mark device as unused */ + cx231xx_devused &= ~(1 << dev->devno); +} + +/* + * cx231xx_init_dev() + * allocates and inits the device structs, registers i2c bus and v4l device + */ +static int cx231xx_init_dev(struct cx231xx **devhandle, struct usb_device *udev, + int minor) +{ + struct cx231xx *dev = *devhandle; + int retval = -ENOMEM; + int errCode; + unsigned int maxh, maxw; + + dev->udev = udev; + mutex_init(&dev->lock); + mutex_init(&dev->ctrl_urb_lock); + mutex_init(&dev->gpio_i2c_lock); + + spin_lock_init(&dev->video_mode.slock); + spin_lock_init(&dev->vbi_mode.slock); + spin_lock_init(&dev->sliced_cc_mode.slock); + + init_waitqueue_head(&dev->open); + init_waitqueue_head(&dev->wait_frame); + init_waitqueue_head(&dev->wait_stream); + + dev->cx231xx_read_ctrl_reg = cx231xx_read_ctrl_reg; + dev->cx231xx_write_ctrl_reg = cx231xx_write_ctrl_reg; + dev->cx231xx_send_usb_command = cx231xx_send_usb_command; + dev->cx231xx_gpio_i2c_read = cx231xx_gpio_i2c_read; + dev->cx231xx_gpio_i2c_write = cx231xx_gpio_i2c_write; + + /* Query cx231xx to find what pcb config it is related to */ + initialize_cx231xx(dev); + + /* Cx231xx pre card setup */ + cx231xx_pre_card_setup(dev); + + errCode = cx231xx_config(dev); + if (errCode) { + cx231xx_errdev("error configuring device\n"); + return -ENOMEM; + } + + /* set default norm */ + dev->norm = dev->board.norm; + + /* register i2c bus */ + errCode = cx231xx_dev_init(dev); + if (errCode < 0) { + cx231xx_errdev("%s: cx231xx_i2c_register - errCode [%d]!\n", + __func__, errCode); + return errCode; + } + + /* Do board specific init */ + cx231xx_card_setup(dev); + + /* configure the device */ + cx231xx_config_i2c(dev); + + maxw = norm_maxw(dev); + maxh = norm_maxh(dev); + + /* set default image size */ + dev->width = maxw; + dev->height = maxh; + dev->interlaced = 0; + dev->hscale = 0; + dev->vscale = 0; + dev->video_input = 0; + + errCode = cx231xx_config(dev); + if (errCode < 0) { + cx231xx_errdev("%s: cx231xx_config - errCode [%d]!\n", + __func__, errCode); + return errCode; + } + + /* init video dma queues */ + INIT_LIST_HEAD(&dev->video_mode.vidq.active); + INIT_LIST_HEAD(&dev->video_mode.vidq.queued); + + /* init vbi dma queues */ + INIT_LIST_HEAD(&dev->vbi_mode.vidq.active); + INIT_LIST_HEAD(&dev->vbi_mode.vidq.queued); + + /* Reset other chips required if they are tied up with GPIO pins */ + + cx231xx_add_into_devlist(dev); + + retval = cx231xx_register_analog_devices(dev); + if (retval < 0) { + cx231xx_release_resources(dev); + goto fail_reg_devices; + } + + cx231xx_init_extension(dev); + + return 0; + +fail_reg_devices: + mutex_unlock(&dev->lock); + return retval; +} + +#if defined(CONFIG_MODULES) && defined(MODULE) +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 20) +static void request_module_async(void *ptr) +{ + struct cx231xx *dev = (struct cx231xx *)ptr; +#else +static void request_module_async(struct work_struct *work) +{ + struct cx231xx *dev = container_of(work, + struct cx231xx, request_module_wk); +#endif + + if (dev->has_alsa_audio) + request_module("cx231xx-alsa"); + + if (dev->board.has_dvb) + request_module("cx231xx-dvb"); + +} + +static void request_modules(struct cx231xx *dev) +{ +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 20) + INIT_WORK(&dev->request_module_wk, request_module_async, (void *)dev); +#else + INIT_WORK(&dev->request_module_wk, request_module_async); +#endif + schedule_work(&dev->request_module_wk); +} +#else +#define request_modules(dev) +#endif /* CONFIG_MODULES */ + +/* + * cx231xx_usb_probe() + * checks for supported devices + */ +static int cx231xx_usb_probe(struct usb_interface *interface, + const struct usb_device_id *id) +{ + struct usb_device *udev; + struct usb_interface *uif; + struct cx231xx *dev = NULL; + int retval = -ENODEV; + int nr = 0, ifnum; + int i, isoc_pipe = 0; + char *speed; + char descr[255] = ""; + struct usb_interface *lif = NULL; + int skip_interface = 0; + struct usb_interface_assoc_descriptor *assoc_desc; + + 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) { + /* 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_MAXBOARDS); + cx231xx_devused &= ~(1 << nr); + return -ENOMEM; + } + + /* allocate memory for our device state and initialize it */ + dev = kzalloc(sizeof(*dev), GFP_KERNEL); + if (dev == NULL) { + cx231xx_err(DRIVER_NAME ": out of memory!\n"); + cx231xx_devused &= ~(1 << nr); + return -ENOMEM; + } + + snprintf(dev->name, 29, "cx231xx #%d", nr); + dev->devno = nr; + dev->model = id->driver_info; + dev->video_mode.alt = -1; + dev->interface_count++; + + /* reset gpio dir and value */ + dev->gpio_dir = 0; + dev->gpio_val = 0; + dev->xc_fw_load_done = 0; + dev->has_alsa_audio = 1; + dev->power_mode = -1; + + /* 0 - vbi ; 1 -sliced cc mode */ + dev->vbi_or_sliced_cc_mode = 0; + + /* 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; + } + + /* store the interface 0 back */ + lif = udev->actconfig->interface[0]; + + /* increment interface count */ + dev->interface_count++; + + /* get device number */ + nr = dev->devno; + + 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; + } + + } else if (ifnum >= 2) { + /* 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; + } + + /* store the interface 0 back */ + lif = udev->actconfig->interface[0]; + + /* increment interface count */ + dev->interface_count++; + + /* 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"); + } + } + + 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 (udev->manufacturer) + strlcpy(descr, udev->manufacturer, sizeof(descr)); + + if (udev->product) { + if (*descr) + strlcat(descr, " ", sizeof(descr)); + strlcat(descr, udev->product, sizeof(descr)); + } + if (*descr) + strlcat(descr, " ", sizeof(descr)); + + 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); + + return retval; + } + + /* compute alternate max packet sizes for video */ + uif = + udev->actconfig->interface[dev->current_pcb_config. + hs_config_info[0].interface_info. + video_index + 1]; + + dev->video_mode.end_point_addr = + le16_to_cpu(uif->altsetting[0].endpoint[isoc_pipe].desc. + bEndpointAddress); + + 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); + + if (dev->video_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->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]); + } + + /* 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); + 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]); + } + + /* 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); + 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]. + 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]); + } + } + + } + + /* 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; + } + + return 0; +} + +/* + * cx231xx_usb_disconnect() + * called when the device gets diconencted + * video device will be unregistered on v4l2_close in case it is still open + */ +static void cx231xx_usb_disconnect(struct usb_interface *interface) +{ + struct cx231xx *dev; + + dev = usb_get_intfdata(interface); + usb_set_intfdata(interface, NULL); + + if (!dev) + return; + + /* wait until all current v4l2 io is finished then deallocate + resources */ + mutex_lock(&dev->lock); + + wake_up_interruptible_all(&dev->open); + + if (dev->users) { + cx231xx_warn + ("device /dev/video%d is open! Deregistration and memory " + "deallocation are deferred on close.\n", dev->vdev->num); + + dev->state |= DEV_MISCONFIGURED; + cx231xx_uninit_isoc(dev); + dev->state |= DEV_DISCONNECTED; + wake_up_interruptible(&dev->wait_frame); + wake_up_interruptible(&dev->wait_stream); + } else { + dev->state |= DEV_DISCONNECTED; + cx231xx_release_resources(dev); + } + + cx231xx_close_extension(dev); + + mutex_unlock(&dev->lock); + + if (!dev->users) { + kfree(dev->video_mode.alt_max_pkt_size); + kfree(dev->vbi_mode.alt_max_pkt_size); + kfree(dev->sliced_cc_mode.alt_max_pkt_size); + kfree(dev->ts1_mode.alt_max_pkt_size); + kfree(dev); + } +} + +static struct usb_driver cx231xx_usb_driver = { + .name = "cx231xx", + .probe = cx231xx_usb_probe, + .disconnect = cx231xx_usb_disconnect, + .id_table = cx231xx_id_table, +}; + +static int __init cx231xx_module_init(void) +{ + int result; + + printk(KERN_INFO DRIVER_NAME " v4l2 driver loaded.\n"); + + /* register this driver with the USB subsystem */ + result = usb_register(&cx231xx_usb_driver); + if (result) + cx231xx_err(DRIVER_NAME + " usb_register failed. Error number %d.\n", result); + + return result; +} + +static void __exit cx231xx_module_exit(void) +{ + /* deregister this driver with the USB subsystem */ + usb_deregister(&cx231xx_usb_driver); +} + +module_init(cx231xx_module_init); +module_exit(cx231xx_module_exit); diff --git a/linux/drivers/media/video/cx231xx/cx231xx-conf-reg.h b/linux/drivers/media/video/cx231xx/cx231xx-conf-reg.h new file mode 100644 index 000000000..a6f398a17 --- /dev/null +++ b/linux/drivers/media/video/cx231xx/cx231xx-conf-reg.h @@ -0,0 +1,494 @@ +/* + cx231xx_conf-reg.h - driver for Conexant Cx23100/101/102 USB + video capture devices + + Copyright (C) 2008 <srinivasa.deevi at conexant dot 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, 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 _POLARIS_REG_H_ +#define _POLARIS_REG_H_ + +#define BOARD_CFG_STAT 0x0 +#define TS_MODE_REG 0x4 +#define TS1_CFG_REG 0x8 +#define TS1_LENGTH_REG 0xc +#define TS2_CFG_REG 0x10 +#define TS2_LENGTH_REG 0x14 +#define EP_MODE_SET 0x18 +#define CIR_PWR_PTN1 0x1c +#define CIR_PWR_PTN2 0x20 +#define CIR_PWR_PTN3 0x24 +#define CIR_PWR_MASK0 0x28 +#define CIR_PWR_MASK1 0x2c +#define CIR_PWR_MASK2 0x30 +#define CIR_GAIN 0x34 +#define CIR_CAR_REG 0x38 +#define CIR_OT_CFG1 0x40 +#define CIR_OT_CFG2 0x44 +#define PWR_CTL_EN 0x74 + +/* Polaris Endpoints capture mask for register EP_MODE_SET */ +#define ENABLE_EP1 0x01 /* Bit[0]=1 */ +#define ENABLE_EP2 0x02 /* Bit[1]=1 */ +#define ENABLE_EP3 0x04 /* Bit[2]=1 */ +#define ENABLE_EP4 0x08 /* Bit[3]=1 */ +#define ENABLE_EP5 0x10 /* Bit[4]=1 */ +#define ENABLE_EP6 0x20 /* Bit[5]=1 */ + +/* Bit definition for register PWR_CTL_EN */ +#define PWR_MODE_MASK 0x17f +#define PWR_AV_EN 0x08 /* bit3 */ +#define PWR_ISO_EN 0x40 /* bit6 */ +#define PWR_AV_MODE 0x30 /* bit4,5 */ +#define PWR_TUNER_EN 0x04 /* bit2 */ +#define PWR_DEMOD_EN 0x02 /* bit1 */ +#define I2C_DEMOD_EN 0x01 /* bit0 */ +#define PWR_RESETOUT_EN 0x100 /* bit8 */ + +enum AV_MODE{ + POLARIS_AVMODE_DEFAULT = 0, + POLARIS_AVMODE_DIGITAL = 0x10, + POLARIS_AVMODE_ANALOGT_TV = 0x20, + POLARIS_AVMODE_ENXTERNAL_AV = 0x30, + +}; + +/* Colibri Registers */ + +#define SINGLE_ENDED 0x0 +#define LOW_IF 0x4 +#define EU_IF 0x9 +#define US_IF 0xa + +#define SUP_BLK_TUNE1 0x00 +#define SUP_BLK_TUNE2 0x01 +#define SUP_BLK_TUNE3 0x02 +#define SUP_BLK_XTAL 0x03 +#define SUP_BLK_PLL1 0x04 +#define SUP_BLK_PLL2 0x05 +#define SUP_BLK_PLL3 0x06 +#define SUP_BLK_REF 0x07 +#define SUP_BLK_PWRDN 0x08 +#define SUP_BLK_TESTPAD 0x09 +#define ADC_COM_INT5_STAB_REF 0x0a +#define ADC_COM_QUANT 0x0b +#define ADC_COM_BIAS1 0x0c +#define ADC_COM_BIAS2 0x0d +#define ADC_COM_BIAS3 0x0e +#define TESTBUS_CTRL 0x12 + +#define FLD_PWRDN_TUNING_BIAS 0x10 +#define FLD_PWRDN_ENABLE_PLL 0x08 +#define FLD_PWRDN_PD_BANDGAP 0x04 +#define FLD_PWRDN_PD_BIAS 0x02 +#define FLD_PWRDN_PD_TUNECK 0x01 + + +#define ADC_STATUS_CH1 0x20 +#define ADC_STATUS_CH2 0x40 +#define ADC_STATUS_CH3 0x60 + +#define ADC_STATUS2_CH1 0x21 +#define ADC_STATUS2_CH2 0x41 +#define ADC_STATUS2_CH3 0x61 + +#define ADC_CAL_ATEST_CH1 0x22 +#define ADC_CAL_ATEST_CH2 0x42 +#define ADC_CAL_ATEST_CH3 0x62 + +#define ADC_PWRDN_CLAMP_CH1 0x23 +#define ADC_PWRDN_CLAMP_CH2 0x43 +#define ADC_PWRDN_CLAMP_CH3 0x63 + +#define ADC_CTRL_DAC23_CH1 0x24 +#define ADC_CTRL_DAC23_CH2 0x44 +#define ADC_CTRL_DAC23_CH3 0x64 + +#define ADC_CTRL_DAC1_CH1 0x25 +#define ADC_CTRL_DAC1_CH2 0x45 +#define ADC_CTRL_DAC1_CH3 0x65 + +#define ADC_DCSERVO_DEM_CH1 0x26 +#define ADC_DCSERVO_DEM_CH2 0x46 +#define ADC_DCSERVO_DEM_CH3 0x66 + +#define ADC_FB_FRCRST_CH1 0x27 +#define ADC_FB_FRCRST_CH2 0x47 +#define ADC_FB_FRCRST_CH3 0x67 + +#define ADC_INPUT_CH1 0x28 +#define ADC_INPUT_CH2 0x48 +#define ADC_INPUT_CH3 0x68 +#define INPUT_SEL_MASK 0x30 /* [5:4] in_sel */ + +#define ADC_NTF_PRECLMP_EN_CH1 0x29 +#define ADC_NTF_PRECLMP_EN_CH2 0x49 +#define ADC_NTF_PRECLMP_EN_CH3 0x69 + +#define ADC_QGAIN_RES_TRM_CH1 0x2a +#define ADC_QGAIN_RES_TRM_CH2 0x4a +#define ADC_QGAIN_RES_TRM_CH3 0x6a + +#define ADC_SOC_PRECLMP_TERM_CH1 0x2b +#define ADC_SOC_PRECLMP_TERM_CH2 0x4b +#define ADC_SOC_PRECLMP_TERM_CH3 0x6b + +#define TESTBUS_CTRL_CH1 0x32 +#define TESTBUS_CTRL_CH2 0x52 +#define TESTBUS_CTRL_CH3 0x72 + +/****************************************************************************** + * DIF registers * + ******************************************************************************/ +#define DIRECT_IF_REVB_BASE 0x00300 + +/*****************************************************************************/ +#define DIF_PLL_FREQ_WORD (DIRECT_IF_REVB_BASE + 0x00000000) +/*****************************************************************************/ +#define FLD_DIF_PLL_LOCK 0x80000000 +/* Reserved [30:29] */ +#define FLD_DIF_PLL_FREE_RUN 0x10000000 +#define FLD_DIF_PLL_FREQ 0x0fffffff + +/*****************************************************************************/ +#define DIF_PLL_CTRL (DIRECT_IF_REVB_BASE + 0x00000004) +/*****************************************************************************/ +#define FLD_DIF_KD_PD 0xff000000 +/* Reserved [23:20] */ +#define FLD_DIF_KDS_PD 0x000f0000 +#define FLD_DIF_KI_PD 0x0000ff00 +/* Reserved [7:4] */ +#define FLD_DIF_KIS_PD 0x0000000f + +/*****************************************************************************/ +#define DIF_PLL_CTRL1 (DIRECT_IF_REVB_BASE + 0x00000008) +/*****************************************************************************/ +#define FLD_DIF_KD_FD 0xff000000 +/* Reserved [23:20] */ +#define FLD_DIF_KDS_FD 0x000f0000 +#define FLD_DIF_KI_FD 0x0000ff00 +#define FLD_DIF_SIG_PROP_SZ 0x000000f0 +#define FLD_DIF_KIS_FD 0x0000000f + +/*****************************************************************************/ +#define DIF_PLL_CTRL2 (DIRECT_IF_REVB_BASE + 0x0000000c) +/*****************************************************************************/ +#define FLD_DIF_PLL_AGC_REF 0xfff00000 +#define FLD_DIF_PLL_AGC_KI 0x000f0000 +/* Reserved [15] */ +#define FLD_DIF_FREQ_LIMIT 0x00007000 +#define FLD_DIF_K_FD 0x00000f00 +#define FLD_DIF_DOWNSMPL_FD 0x000000ff + +/*****************************************************************************/ +#define DIF_PLL_CTRL3 (DIRECT_IF_REVB_BASE + 0x00000010) +/*****************************************************************************/ +/* Reserved [31:16] */ +#define FLD_DIF_PLL_AGC_EN 0x00008000 +/* Reserved [14:12] */ +#define FLD_DIF_PLL_MAN_GAIN 0x00000fff + +/*****************************************************************************/ +#define DIF_AGC_IF_REF (DIRECT_IF_REVB_BASE + 0x00000014) +/*****************************************************************************/ +#define FLD_DIF_K_AGC_RF 0xf0000000 +#define FLD_DIF_K_AGC_IF 0x0f000000 +#define FLD_DIF_K_AGC_INT 0x00f00000 +/* Reserved [19:12] */ +#define FLD_DIF_IF_REF 0x00000fff + +/*****************************************************************************/ +#define DIF_AGC_CTRL_IF (DIRECT_IF_REVB_BASE + 0x00000018) +/*****************************************************************************/ +#define FLD_DIF_IF_MAX 0xff000000 +#define FLD_DIF_IF_MIN 0x00ff0000 +#define FLD_DIF_IF_AGC 0x0000ffff + +/*****************************************************************************/ +#define DIF_AGC_CTRL_INT (DIRECT_IF_REVB_BASE + 0x0000001c) +/*****************************************************************************/ +#define FLD_DIF_INT_MAX 0xff000000 +#define FLD_DIF_INT_MIN 0x00ff0000 +#define FLD_DIF_INT_AGC 0x0000ffff + +/*****************************************************************************/ +#define DIF_AGC_CTRL_RF (DIRECT_IF_REVB_BASE + 0x00000020) +/*****************************************************************************/ +#define FLD_DIF_RF_MAX 0xff000000 +#define FLD_DIF_RF_MIN 0x00ff0000 +#define FLD_DIF_RF_AGC 0x0000ffff + +/*****************************************************************************/ +#define DIF_AGC_IF_INT_CURRENT (DIRECT_IF_REVB_BASE + 0x00000024) +/*****************************************************************************/ +#define FLD_DIF_IF_AGC_IN 0xffff0000 +#define FLD_DIF_INT_AGC_IN 0x0000ffff + +/*****************************************************************************/ +#define DIF_AGC_RF_CURRENT (DIRECT_IF_REVB_BASE + 0x00000028) +/*****************************************************************************/ +/* Reserved [31:16] */ +#define FLD_DIF_RF_AGC_IN 0x0000ffff + +/*****************************************************************************/ +#define DIF_VIDEO_AGC_CTRL (DIRECT_IF_REVB_BASE + 0x0000002c) +/*****************************************************************************/ +#define FLD_DIF_AFD 0xc0000000 +#define FLD_DIF_K_VID_AGC 0x30000000 +#define FLD_DIF_LINE_LENGTH 0x0fff0000 +#define FLD_DIF_AGC_GAIN 0x0000ffff + +/*****************************************************************************/ +#define DIF_VID_AUD_OVERRIDE (DIRECT_IF_REVB_BASE + 0x00000030) +/*****************************************************************************/ +#define FLD_DIF_AUDIO_AGC_OVERRIDE 0x80000000 +/* Reserved [30:30] */ +#define FLD_DIF_AUDIO_MAN_GAIN 0x3f000000 +/* Reserved [23:17] */ +#define FLD_DIF_VID_AGC_OVERRIDE 0x00010000 +#define FLD_DIF_VID_MAN_GAIN 0x0000ffff + +/*****************************************************************************/ +#define DIF_AV_SEP_CTRL (DIRECT_IF_REVB_BASE + 0x00000034) +/*****************************************************************************/ +#define FLD_DIF_LPF_FREQ 0xc0000000 +#define FLD_DIF_AV_PHASE_INC 0x3f000000 +#define FLD_DIF_AUDIO_FREQ 0x00ffffff + +/*****************************************************************************/ +#define DIF_COMP_FLT_CTRL (DIRECT_IF_REVB_BASE + 0x00000038) +/*****************************************************************************/ +/* Reserved [31:24] */ +#define FLD_DIF_IIR23_R2 0x00ff0000 +#define FLD_DIF_IIR23_R1 0x0000ff00 +#define FLD_DIF_IIR1_R1 0x000000ff + +/*****************************************************************************/ +#define DIF_MISC_CTRL (DIRECT_IF_REVB_BASE + 0x0000003c) +/*****************************************************************************/ +#define FLD_DIF_DIF_BYPASS 0x80000000 +#define FLD_DIF_FM_NYQ_GAIN 0x40000000 +#define FLD_DIF_RF_AGC_ENA 0x20000000 +#define FLD_DIF_INT_AGC_ENA 0x10000000 +#define FLD_DIF_IF_AGC_ENA 0x08000000 +#define FLD_DIF_FORCE_RF_IF_LOCK 0x04000000 +#define FLD_DIF_VIDEO_AGC_ENA 0x02000000 +#define FLD_DIF_RF_AGC_INV 0x01000000 +#define FLD_DIF_INT_AGC_INV 0x00800000 +#define FLD_DIF_IF_AGC_INV 0x00400000 +#define FLD_DIF_SPEC_INV 0x00200000 +#define FLD_DIF_AUD_FULL_BW 0x00100000 +#define FLD_DIF_AUD_SRC_SEL 0x00080000 +/* Reserved [18] */ +#define FLD_DIF_IF_FREQ 0x00030000 +/* Reserved [15:14] */ +#define FLD_DIF_TIP_OFFSET 0x00003f00 +/* Reserved [7:5] */ +#define FLD_DIF_DITHER_ENA 0x00000010 +/* Reserved [3:1] */ +#define FLD_DIF_RF_IF_LOCK 0x00000001 + +/*****************************************************************************/ +#define DIF_SRC_PHASE_INC (DIRECT_IF_REVB_BASE + 0x00000040) +/*****************************************************************************/ +/* Reserved [31:29] */ +#define FLD_DIF_PHASE_INC 0x1fffffff + +/*****************************************************************************/ +#define DIF_SRC_GAIN_CONTROL (DIRECT_IF_REVB_BASE + 0x00000044) +/*****************************************************************************/ +/* Reserved [31:16] */ +#define FLD_DIF_SRC_KI 0x0000ff00 +#define FLD_DIF_SRC_KD 0x000000ff + +/*****************************************************************************/ +#define DIF_BPF_COEFF01 (DIRECT_IF_REVB_BASE + 0x00000048) +/*****************************************************************************/ +/* Reserved [31:19] */ +#define FLD_DIF_BPF_COEFF_0 0x00070000 +/* Reserved [15:4] */ +#define FLD_DIF_BPF_COEFF_1 0x0000000f + +/*****************************************************************************/ +#define DIF_BPF_COEFF23 (DIRECT_IF_REVB_BASE + 0x0000004c) +/*****************************************************************************/ +/* Reserved [31:22] */ +#define FLD_DIF_BPF_COEFF_2 0x003f0000 +/* Reserved [15:7] */ +#define FLD_DIF_BPF_COEFF_3 0x0000007f + +/*****************************************************************************/ +#define DIF_BPF_COEFF45 (DIRECT_IF_REVB_BASE + 0x00000050) +/*****************************************************************************/ +/* Reserved [31:24] */ +#define FLD_DIF_BPF_COEFF_4 0x00ff0000 +/* Reserved [15:8] */ +#define FLD_DIF_BPF_COEFF_5 0x000000ff + +/*****************************************************************************/ +#define DIF_BPF_COEFF67 (DIRECT_IF_REVB_BASE + 0x00000054) +/*****************************************************************************/ +/* Reserved [31:25] */ +#define FLD_DIF_BPF_COEFF_6 0x01ff0000 +/* Reserved [15:9] */ +#define FLD_DIF_BPF_COEFF_7 0x000001ff + +/*****************************************************************************/ +#define DIF_BPF_COEFF89 (DIRECT_IF_REVB_BASE + 0x00000058) +/*****************************************************************************/ +/* Reserved [31:26] */ +#define FLD_DIF_BPF_COEFF_8 0x03ff0000 +/* Reserved [15:10] */ +#define FLD_DIF_BPF_COEFF_9 0x000003ff + +/*****************************************************************************/ +#define DIF_BPF_COEFF1011 (DIRECT_IF_REVB_BASE + 0x0000005c) +/*****************************************************************************/ +/* Reserved [31:27] */ +#define FLD_DIF_BPF_COEFF_10 0x07ff0000 +/* Reserved [15:11] */ +#define FLD_DIF_BPF_COEFF_11 0x000007ff + +/*****************************************************************************/ +#define DIF_BPF_COEFF1213 (DIRECT_IF_REVB_BASE + 0x00000060) +/*****************************************************************************/ +/* Reserved [31:27] */ +#define FLD_DIF_BPF_COEFF_12 0x07ff0000 +/* Reserved [15:12] */ +#define FLD_DIF_BPF_COEFF_13 0x00000fff + +/*****************************************************************************/ +#define DIF_BPF_COEFF1415 (DIRECT_IF_REVB_BASE + 0x00000064) +/*****************************************************************************/ +/* Reserved [31:28] */ +#define FLD_DIF_BPF_COEFF_14 0x0fff0000 +/* Reserved [15:12] */ +#define FLD_DIF_BPF_COEFF_15 0x00000fff + +/*****************************************************************************/ +#define DIF_BPF_COEFF1617 (DIRECT_IF_REVB_BASE + 0x00000068) +/*****************************************************************************/ +/* Reserved [31:29] */ +#define FLD_DIF_BPF_COEFF_16 0x1fff0000 +/* Reserved [15:13] */ +#define FLD_DIF_BPF_COEFF_17 0x00001fff + +/*****************************************************************************/ +#define DIF_BPF_COEFF1819 (DIRECT_IF_REVB_BASE + 0x0000006c) +/*****************************************************************************/ +/* Reserved [31:29] */ +#define FLD_DIF_BPF_COEFF_18 0x1fff0000 +/* Reserved [15:13] */ +#define FLD_DIF_BPF_COEFF_19 0x00001fff + +/*****************************************************************************/ +#define DIF_BPF_COEFF2021 (DIRECT_IF_REVB_BASE + 0x00000070) +/*****************************************************************************/ +/* Reserved [31:29] */ +#define FLD_DIF_BPF_COEFF_20 0x1fff0000 +/* Reserved [15:14] */ +#define FLD_DIF_BPF_COEFF_21 0x00003fff + +/*****************************************************************************/ +#define DIF_BPF_COEFF2223 (DIRECT_IF_REVB_BASE + 0x00000074) +/*****************************************************************************/ +/* Reserved [31:30] */ +#define FLD_DIF_BPF_COEFF_22 0x3fff0000 +/* Reserved [15:14] */ +#define FLD_DIF_BPF_COEFF_23 0x00003fff + +/*****************************************************************************/ +#define DIF_BPF_COEFF2425 (DIRECT_IF_REVB_BASE + 0x00000078) +/*****************************************************************************/ +/* Reserved [31:30] */ +#define FLD_DIF_BPF_COEFF_24 0x3fff0000 +/* Reserved [15:14] */ +#define FLD_DIF_BPF_COEFF_25 0x00003fff + +/*****************************************************************************/ +#define DIF_BPF_COEFF2627 (DIRECT_IF_REVB_BASE + 0x0000007c) +/*****************************************************************************/ +/* Reserved [31:30] */ +#define FLD_DIF_BPF_COEFF_26 0x3fff0000 +/* Reserved [15:14] */ +#define FLD_DIF_BPF_COEFF_27 0x00003fff + +/*****************************************************************************/ +#define DIF_BPF_COEFF2829 (DIRECT_IF_REVB_BASE + 0x00000080) +/*****************************************************************************/ +/* Reserved [31:30] */ +#define FLD_DIF_BPF_COEFF_28 0x3fff0000 +/* Reserved [15:14] */ +#define FLD_DIF_BPF_COEFF_29 0x00003fff + +/*****************************************************************************/ +#define DIF_BPF_COEFF3031 (DIRECT_IF_REVB_BASE + 0x00000084) +/*****************************************************************************/ +/* Reserved [31:30] */ +#define FLD_DIF_BPF_COEFF_30 0x3fff0000 +/* Reserved [15:14] */ +#define FLD_DIF_BPF_COEFF_31 0x00003fff + +/*****************************************************************************/ +#define DIF_BPF_COEFF3233 (DIRECT_IF_REVB_BASE + 0x00000088) +/*****************************************************************************/ +/* Reserved [31:30] */ +#define FLD_DIF_BPF_COEFF_32 0x3fff0000 +/* Reserved [15:14] */ +#define FLD_DIF_BPF_COEFF_33 0x00003fff + +/*****************************************************************************/ +#define DIF_BPF_COEFF3435 (DIRECT_IF_REVB_BASE + 0x0000008c) +/*****************************************************************************/ +/* Reserved [31:30] */ +#define FLD_DIF_BPF_COEFF_34 0x3fff0000 +/* Reserved [15:14] */ +#define FLD_DIF_BPF_COEFF_35 0x00003fff + +/*****************************************************************************/ +#define DIF_BPF_COEFF36 (DIRECT_IF_REVB_BASE + 0x00000090) +/*****************************************************************************/ +/* Reserved [31:30] */ +#define FLD_DIF_BPF_COEFF_36 0x3fff0000 +/* Reserved [15:0] */ + +/*****************************************************************************/ +#define DIF_RPT_VARIANCE (DIRECT_IF_REVB_BASE + 0x00000094) +/*****************************************************************************/ +/* Reserved [31:20] */ +#define FLD_DIF_RPT_VARIANCE 0x000fffff + +/*****************************************************************************/ +#define DIF_SOFT_RST_CTRL_REVB (DIRECT_IF_REVB_BASE + 0x00000098) +/*****************************************************************************/ +/* Reserved [31:8] */ +#define FLD_DIF_DIF_SOFT_RST 0x00000080 +#define FLD_DIF_DIF_REG_RST_MSK 0x00000040 +#define FLD_DIF_AGC_RST_MSK 0x00000020 +#define FLD_DIF_CMP_RST_MSK 0x00000010 +#define FLD_DIF_AVS_RST_MSK 0x00000008 +#define FLD_DIF_NYQ_RST_MSK 0x00000004 +#define FLD_DIF_DIF_SRC_RST_MSK 0x00000002 +#define FLD_DIF_PLL_RST_MSK 0x00000001 + +/*****************************************************************************/ +#define DIF_PLL_FREQ_ERR (DIRECT_IF_REVB_BASE + 0x0000009c) +/*****************************************************************************/ +/* Reserved [31:25] */ +#define FLD_DIF_CTL_IP 0x01ffffff + +#endif diff --git a/linux/drivers/media/video/cx231xx/cx231xx-core.c b/linux/drivers/media/video/cx231xx/cx231xx-core.c new file mode 100644 index 000000000..2aec3a842 --- /dev/null +++ b/linux/drivers/media/video/cx231xx/cx231xx-core.c @@ -0,0 +1,1231 @@ +/* + cx231xx-core.c - driver for Conexant Cx23100/101/102 + USB video capture devices + + Copyright (C) 2008 <srinivasa.deevi at conexant dot com> + Based on em28xx driver + + 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/init.h> +#include <linux/list.h> +#include <linux/module.h> +#include <linux/usb.h> +#include <linux/vmalloc.h> +#include <media/v4l2-common.h> + +#include "cx231xx.h" +#include "cx231xx-reg.h" + +/* #define ENABLE_DEBUG_ISOC_FRAMES */ + +static unsigned int core_debug; +module_param(core_debug, int, 0644); +MODULE_PARM_DESC(core_debug, "enable debug messages [core]"); + +#define cx231xx_coredbg(fmt, arg...) do {\ + if (core_debug) \ + printk(KERN_INFO "%s %s :"fmt, \ + dev->name, __func__ , ##arg); } while (0) + +static unsigned int reg_debug; +module_param(reg_debug, int, 0644); +MODULE_PARM_DESC(reg_debug, "enable debug messages [URB reg]"); + +#define cx231xx_regdbg(fmt, arg...) do {\ + if (reg_debug) \ + printk(KERN_INFO "%s %s :"fmt, \ + dev->name, __func__ , ##arg); } while (0) + +static int alt = CX231XX_PINOUT; +module_param(alt, int, 0644); +MODULE_PARM_DESC(alt, "alternate setting to use for video endpoint"); + +#define cx231xx_isocdbg(fmt, arg...) do {\ + if (core_debug) \ + printk(KERN_INFO "%s %s :"fmt, \ + dev->name, __func__ , ##arg); } while (0) + +/***************************************************************** +* Device control list functions * +******************************************************************/ + +static LIST_HEAD(cx231xx_devlist); +static DEFINE_MUTEX(cx231xx_devlist_mutex); + +struct cx231xx *cx231xx_get_device(int minor, + enum v4l2_buf_type *fh_type, int *has_radio) +{ + struct cx231xx *h, *dev = NULL; + + *fh_type = V4L2_BUF_TYPE_VIDEO_CAPTURE; + *has_radio = 0; + + mutex_lock(&cx231xx_devlist_mutex); + list_for_each_entry(h, &cx231xx_devlist, devlist) { + if (h->vdev->minor == minor) + dev = h; + if (h->vbi_dev->minor == minor) { + dev = h; + *fh_type = V4L2_BUF_TYPE_VBI_CAPTURE; + } + if (h->radio_dev && h->radio_dev->minor == minor) { + dev = h; + *has_radio = 1; + } + } + mutex_unlock(&cx231xx_devlist_mutex); + + return dev; +} + +/* + * cx231xx_realease_resources() + * unregisters the v4l2,i2c and usb devices + * called when the device gets disconected or at module unload +*/ +void cx231xx_remove_from_devlist(struct cx231xx *dev) +{ + mutex_lock(&cx231xx_devlist_mutex); + list_del(&dev->devlist); + mutex_unlock(&cx231xx_devlist_mutex); +}; + +void cx231xx_add_into_devlist(struct cx231xx *dev) +{ + mutex_lock(&cx231xx_devlist_mutex); + list_add_tail(&dev->devlist, &cx231xx_devlist); + mutex_unlock(&cx231xx_devlist_mutex); +}; + +static LIST_HEAD(cx231xx_extension_devlist); +static DEFINE_MUTEX(cx231xx_extension_devlist_lock); + +int cx231xx_register_extension(struct cx231xx_ops *ops) +{ + struct cx231xx *dev = NULL; + + mutex_lock(&cx231xx_devlist_mutex); + mutex_lock(&cx231xx_extension_devlist_lock); + list_add_tail(&ops->next, &cx231xx_extension_devlist); + list_for_each_entry(dev, &cx231xx_devlist, devlist) { + if (dev) + ops->init(dev); + } + cx231xx_info("Cx231xx: Initialized (%s) extension\n", ops->name); + mutex_unlock(&cx231xx_extension_devlist_lock); + mutex_unlock(&cx231xx_devlist_mutex); + return 0; +} +EXPORT_SYMBOL(cx231xx_register_extension); + +void cx231xx_unregister_extension(struct cx231xx_ops *ops) +{ + struct cx231xx *dev = NULL; + + mutex_lock(&cx231xx_devlist_mutex); + list_for_each_entry(dev, &cx231xx_devlist, devlist) { + if (dev) + ops->fini(dev); + } + + mutex_lock(&cx231xx_extension_devlist_lock); + cx231xx_info("Cx231xx: Removed (%s) extension\n", ops->name); + list_del(&ops->next); + mutex_unlock(&cx231xx_extension_devlist_lock); + mutex_unlock(&cx231xx_devlist_mutex); +} +EXPORT_SYMBOL(cx231xx_unregister_extension); + +void cx231xx_init_extension(struct cx231xx *dev) +{ + struct cx231xx_ops *ops = NULL; + + mutex_lock(&cx231xx_extension_devlist_lock); + if (!list_empty(&cx231xx_extension_devlist)) { + list_for_each_entry(ops, &cx231xx_extension_devlist, next) { + if (ops->init) + ops->init(dev); + } + } + mutex_unlock(&cx231xx_extension_devlist_lock); +} + +void cx231xx_close_extension(struct cx231xx *dev) +{ + struct cx231xx_ops *ops = NULL; + + mutex_lock(&cx231xx_extension_devlist_lock); + if (!list_empty(&cx231xx_extension_devlist)) { + list_for_each_entry(ops, &cx231xx_extension_devlist, next) { + if (ops->fini) + ops->fini(dev); + } + } + mutex_unlock(&cx231xx_extension_devlist_lock); +} + +/**************************************************************** +* U S B related functions * +*****************************************************************/ +int cx231xx_send_usb_command(struct cx231xx_i2c *i2c_bus, + struct cx231xx_i2c_xfer_data *req_data) +{ + int status = 0; + struct cx231xx *dev = i2c_bus->dev; + struct VENDOR_REQUEST_IN ven_req; + + u8 saddr_len = 0; + u8 _i2c_period = 0; + u8 _i2c_nostop = 0; + u8 _i2c_reserve = 0; + + /* Get the I2C period, nostop and reserve parameters */ + _i2c_period = i2c_bus->i2c_period; + _i2c_nostop = i2c_bus->i2c_nostop; + _i2c_reserve = i2c_bus->i2c_reserve; + + saddr_len = req_data->saddr_len; + + /* Set wValue */ + if (saddr_len == 1) /* need check saddr_len == 0 */ + ven_req.wValue = + req_data-> + dev_addr << 9 | _i2c_period << 4 | saddr_len << 2 | + _i2c_nostop << 1 | I2C_SYNC | _i2c_reserve << 6; + else + ven_req.wValue = + req_data-> + dev_addr << 9 | _i2c_period << 4 | saddr_len << 2 | + _i2c_nostop << 1 | I2C_SYNC | _i2c_reserve << 6; + + /* set channel number */ + if (req_data->direction & I2C_M_RD) { + /* channel number, for read,spec required channel_num +4 */ + ven_req.bRequest = i2c_bus->nr + 4; + } else + ven_req.bRequest = i2c_bus->nr; /* channel number, */ + + /* set index value */ + switch (saddr_len) { + case 0: + ven_req.wIndex = 0; /* need check */ + break; + case 1: + ven_req.wIndex = (req_data->saddr_dat & 0xff); + break; + case 2: + ven_req.wIndex = req_data->saddr_dat; + break; + } + + /* set wLength value */ + ven_req.wLength = req_data->buf_size; + + /* set bData value */ + ven_req.bData = 0; + + /* set the direction */ + if (req_data->direction) { + ven_req.direction = USB_DIR_IN; + memset(req_data->p_buffer, 0x00, ven_req.wLength); + } else + ven_req.direction = USB_DIR_OUT; + + /* set the buffer for read / write */ + ven_req.pBuff = req_data->p_buffer; + +#if 0 + { + int i = 0; + + cx231xx_isocdbg(": USB Control Pipe Request: I2C Bus#%d\n", + i2c_bus->nr); + cx231xx_isocdbg("bRequest = %x : ", ven_req.bRequest); + cx231xx_isocdbg("wValue = %x : ", ven_req.wValue); + cx231xx_isocdbg("wIndex = %x : ", ven_req.wIndex); + cx231xx_isocdbg("wLength = %x\n", ven_req.wLength); + cx231xx_isocdbg("pBuff : "); + for (i = 0; i < ven_req.wLength; i++) { + cx231xx_isocdbg(" %2x", ven_req.pBuff[i]); + if ((i > 0) && (i % 10 == 0)) + cx231xx_isocdbg("\n "); + } + cx231xx_isocdbg("\n\n"); + } +#endif + + /* call common vendor command request */ + status = cx231xx_send_vendor_cmd(dev, &ven_req); + if (status < 0) { + cx231xx_info + ("UsbInterface::sendCommand, failed with status -%d\n", + status); + } + + return status; +} +EXPORT_SYMBOL_GPL(cx231xx_send_usb_command); + +/* + * cx231xx_read_ctrl_reg() + * reads data from the usb device specifying bRequest and wValue + */ +int cx231xx_read_ctrl_reg(struct cx231xx *dev, u8 req, u16 reg, + char *buf, int len) +{ + u8 val = 0; + int ret; + int pipe = usb_rcvctrlpipe(dev->udev, 0); + + if (dev->state & DEV_DISCONNECTED) + return -ENODEV; + + if (len > URB_MAX_CTRL_SIZE) + return -EINVAL; + + switch (len) { + case 1: + val = ENABLE_ONE_BYTE; + break; + case 2: + val = ENABLE_TWE_BYTE; + break; + case 3: + val = ENABLE_THREE_BYTE; + break; + case 4: + val = ENABLE_FOUR_BYTE; + break; + default: + val = 0xFF; /* invalid option */ + } + + if (val == 0xFF) + return -EINVAL; + + if (reg_debug) { + cx231xx_isocdbg("(pipe 0x%08x): " + "IN: %02x %02x %02x %02x %02x %02x %02x %02x ", + pipe, + USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, + req, 0, val, + reg & 0xff, reg >> 8, len & 0xff, len >> 8); + } + + mutex_lock(&dev->ctrl_urb_lock); + ret = usb_control_msg(dev->udev, pipe, req, + USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, + val, reg, dev->urb_buf, len, HZ); + if (ret < 0) { + cx231xx_isocdbg(" failed!\n"); + /* mutex_unlock(&dev->ctrl_urb_lock); */ + return ret; + } + + if (len) + memcpy(buf, dev->urb_buf, len); + + mutex_unlock(&dev->ctrl_urb_lock); + + if (reg_debug) { + int byte; + + cx231xx_isocdbg("<<<"); + for (byte = 0; byte < len; byte++) + cx231xx_isocdbg(" %02x", (unsigned char)buf[byte]); + cx231xx_isocdbg("\n"); + } + + return ret; +} + +int cx231xx_send_vendor_cmd(struct cx231xx *dev, + struct VENDOR_REQUEST_IN *ven_req) +{ + int ret; + int pipe = 0; + + if (dev->state & DEV_DISCONNECTED) + return -ENODEV; + + if ((ven_req->wLength > URB_MAX_CTRL_SIZE)) + return -EINVAL; + + if (ven_req->direction) + pipe = usb_rcvctrlpipe(dev->udev, 0); + else + pipe = usb_sndctrlpipe(dev->udev, 0); + + if (reg_debug) { + int byte; + + cx231xx_isocdbg("(pipe 0x%08x): " + "OUT: %02x %02x %02x %04x %04x %04x >>>", + pipe, + ven_req-> + direction | USB_TYPE_VENDOR | USB_RECIP_DEVICE, + ven_req->bRequest, 0, ven_req->wValue, + ven_req->wIndex, ven_req->wLength); + + for (byte = 0; byte < ven_req->wLength; byte++) + cx231xx_isocdbg(" %02x", + (unsigned char)ven_req->pBuff[byte]); + cx231xx_isocdbg("\n"); + } + + mutex_lock(&dev->ctrl_urb_lock); + ret = usb_control_msg(dev->udev, pipe, ven_req->bRequest, + ven_req-> + direction | USB_TYPE_VENDOR | USB_RECIP_DEVICE, + ven_req->wValue, ven_req->wIndex, ven_req->pBuff, + ven_req->wLength, HZ); + mutex_unlock(&dev->ctrl_urb_lock); + + return ret; +} + +/* + * cx231xx_write_ctrl_reg() + * sends data to the usb device, specifying bRequest + */ +int cx231xx_write_ctrl_reg(struct cx231xx *dev, u8 req, u16 reg, char *buf, + int len) +{ + u8 val = 0; + int ret; + int pipe = usb_sndctrlpipe(dev->udev, 0); + + if (dev->state & DEV_DISCONNECTED) + return -ENODEV; + + if ((len < 1) || (len > URB_MAX_CTRL_SIZE)) + return -EINVAL; + + switch (len) { + case 1: + val = ENABLE_ONE_BYTE; + break; + case 2: + val = ENABLE_TWE_BYTE; + break; + case 3: + val = ENABLE_THREE_BYTE; + break; + case 4: + val = ENABLE_FOUR_BYTE; + break; + default: + val = 0xFF; /* invalid option */ + } + + if (val == 0xFF) + return -EINVAL; + + if (reg_debug) { + int byte; + + cx231xx_isocdbg("(pipe 0x%08x): " + "OUT: %02x %02x %02x %02x %02x %02x %02x %02x >>>", + pipe, + USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, + req, 0, val, reg & 0xff, + reg >> 8, len & 0xff, len >> 8); + + for (byte = 0; byte < len; byte++) + cx231xx_isocdbg(" %02x", (unsigned char)buf[byte]); + cx231xx_isocdbg("\n"); + } + + mutex_lock(&dev->ctrl_urb_lock); + memcpy(dev->urb_buf, buf, len); + ret = usb_control_msg(dev->udev, pipe, req, + USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, + val, reg, dev->urb_buf, len, HZ); + mutex_unlock(&dev->ctrl_urb_lock); + + return ret; +} + +/**************************************************************** +* USB Alternate Setting functions * +*****************************************************************/ + +int cx231xx_set_video_alternate(struct cx231xx *dev) +{ + int errCode, prev_alt = dev->video_mode.alt; + unsigned int min_pkt_size = dev->width * 2 + 4; + u32 usb_interface_index = 0; + + /* When image size is bigger than a certain value, + the frame size should be increased, otherwise, only + green screen will be received. + */ + if (dev->width * 2 * dev->height > 720 * 240 * 2) + min_pkt_size *= 2; + + if (dev->width > 360) { + /* resolutions: 720,704,640 */ + dev->video_mode.alt = 3; + } else if (dev->width > 180) { + /* resolutions: 360,352,320,240 */ + dev->video_mode.alt = 2; + } else if (dev->width > 0) { + /* resolutions: 180,176,160,128,88 */ + dev->video_mode.alt = 1; + } else { + /* Change to alt0 BULK to release USB bandwidth */ + dev->video_mode.alt = 0; + } + + /* Get the correct video interface Index */ + usb_interface_index = + dev->current_pcb_config.hs_config_info[0].interface_info. + video_index + 1; + + if (dev->video_mode.alt != prev_alt) { + cx231xx_coredbg("minimum isoc packet size: %u (alt=%d)\n", + min_pkt_size, dev->video_mode.alt); + dev->video_mode.max_pkt_size = + dev->video_mode.alt_max_pkt_size[dev->video_mode.alt]; + cx231xx_coredbg("setting alternate %d with wMaxPacketSize=%u\n", + dev->video_mode.alt, + dev->video_mode.max_pkt_size); + cx231xx_info + (" setting alt %d with wMaxPktSize=%u , Interface = %d\n", + dev->video_mode.alt, dev->video_mode.max_pkt_size, + usb_interface_index); + errCode = + usb_set_interface(dev->udev, usb_interface_index, + dev->video_mode.alt); + if (errCode < 0) { + cx231xx_errdev + ("cannot change alt number to %d (error=%i)\n", + dev->video_mode.alt, errCode); + return errCode; + } + } + return 0; +} + +int cx231xx_set_alt_setting(struct cx231xx *dev, u8 index, u8 alt) +{ + int status = 0; + u32 usb_interface_index = 0; + u32 max_pkt_size = 0; + + switch (index) { + case INDEX_TS1: + usb_interface_index = + dev->current_pcb_config.hs_config_info[0].interface_info. + ts1_index + 1; + dev->video_mode.alt = alt; + if (dev->ts1_mode.alt_max_pkt_size != NULL) + max_pkt_size = dev->ts1_mode.max_pkt_size = + dev->ts1_mode.alt_max_pkt_size[dev->ts1_mode.alt]; + break; + case INDEX_TS2: + usb_interface_index = + dev->current_pcb_config.hs_config_info[0].interface_info. + ts2_index + 1; + break; + case INDEX_AUDIO: + usb_interface_index = + dev->current_pcb_config.hs_config_info[0].interface_info. + audio_index + 1; + dev->adev.alt = alt; + if (dev->adev.alt_max_pkt_size != NULL) + max_pkt_size = dev->adev.max_pkt_size = + dev->adev.alt_max_pkt_size[dev->adev.alt]; + break; + case INDEX_VIDEO: + usb_interface_index = + dev->current_pcb_config.hs_config_info[0].interface_info. + video_index + 1; + dev->video_mode.alt = alt; + if (dev->video_mode.alt_max_pkt_size != NULL) + max_pkt_size = dev->video_mode.max_pkt_size = + dev->video_mode.alt_max_pkt_size[dev->video_mode. + alt]; + break; + case INDEX_VANC: + usb_interface_index = + dev->current_pcb_config.hs_config_info[0].interface_info. + vanc_index + 1; + dev->vbi_mode.alt = alt; + if (dev->vbi_mode.alt_max_pkt_size != NULL) + max_pkt_size = dev->vbi_mode.max_pkt_size = + dev->vbi_mode.alt_max_pkt_size[dev->vbi_mode.alt]; + break; + case INDEX_HANC: + usb_interface_index = + dev->current_pcb_config.hs_config_info[0].interface_info. + hanc_index + 1; + dev->sliced_cc_mode.alt = alt; + if (dev->sliced_cc_mode.alt_max_pkt_size != NULL) + max_pkt_size = dev->sliced_cc_mode.max_pkt_size = + dev->sliced_cc_mode.alt_max_pkt_size[dev-> + sliced_cc_mode. + alt]; + break; + default: + break; + } + + if (alt > 0 && max_pkt_size == 0) { + cx231xx_errdev + ("can't change interface %d alt no. to %d: Max. Pkt size = 0\n", + usb_interface_index, alt); + return -1; + } + + cx231xx_info + (" setting alternate %d with wMaxPacketSize=%u , Interface = %d\n", + alt, max_pkt_size, usb_interface_index); + + if (usb_interface_index > 0) { + status = usb_set_interface(dev->udev, usb_interface_index, alt); + if (status < 0) { + cx231xx_errdev + ("can't change interface %d alt no. to %d (err=%i)\n", + usb_interface_index, alt, status); + return status; + } + } + + return status; +} +EXPORT_SYMBOL_GPL(cx231xx_set_alt_setting); + +int cx231xx_gpio_set(struct cx231xx *dev, struct cx231xx_reg_seq *gpio) +{ + int rc = 0; + + if (!gpio) + return rc; + + /* Send GPIO reset sequences specified at board entry */ + while (gpio->sleep >= 0) { + rc = cx231xx_set_gpio_value(dev, gpio->bit, gpio->val); + if (rc < 0) + return rc; + + if (gpio->sleep > 0) + msleep(gpio->sleep); + + gpio++; + } + return rc; +} + +int cx231xx_set_mode(struct cx231xx *dev, enum cx231xx_mode set_mode) +{ + if (dev->mode == set_mode) + return 0; + + if (set_mode == CX231XX_SUSPEND) { + /* Set the chip in power saving mode */ + dev->mode = set_mode; + } + + /* Resource is locked */ + if (dev->mode != CX231XX_SUSPEND) + return -EINVAL; + + dev->mode = set_mode; + + if (dev->mode == CX231XX_DIGITAL_MODE) + ;/* Set Digital power mode */ + else + ;/* Set Analog Power mode */ + + return 0; +} +EXPORT_SYMBOL_GPL(cx231xx_set_mode); + +/***************************************************************** +* URB Streaming functions * +******************************************************************/ + +/* + * IRQ callback, called by URB callback + */ +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 19) +static void cx231xx_irq_callback(struct urb *urb, struct pt_regs *regs) +#else +static void cx231xx_irq_callback(struct urb *urb) +#endif +{ + struct cx231xx_dmaqueue *dma_q = urb->context; + struct cx231xx_video_mode *vmode = + container_of(dma_q, struct cx231xx_video_mode, vidq); + struct cx231xx *dev = container_of(vmode, struct cx231xx, video_mode); + int rc, i; + + switch (urb->status) { + case 0: /* success */ + case -ETIMEDOUT: /* NAK */ + break; + case -ECONNRESET: /* kill */ + case -ENOENT: + case -ESHUTDOWN: + return; + default: /* error */ + cx231xx_isocdbg("urb completition error %d.\n", urb->status); + break; + } + + /* Copy data from URB */ + spin_lock(&dev->video_mode.slock); + rc = dev->video_mode.isoc_ctl.isoc_copy(dev, urb); + spin_unlock(&dev->video_mode.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) { + cx231xx_isocdbg("urb resubmit failed (error=%i)\n", + urb->status); + } +} + +/* + * Stop and Deallocate URBs + */ +void cx231xx_uninit_isoc(struct cx231xx *dev) +{ + struct urb *urb; + int i; + + cx231xx_isocdbg("cx231xx: called cx231xx_uninit_isoc\n"); + + dev->video_mode.isoc_ctl.nfields = -1; + for (i = 0; i < dev->video_mode.isoc_ctl.num_bufs; i++) { + urb = dev->video_mode.isoc_ctl.urb[i]; + if (urb) { + if (!irqs_disabled()) + usb_kill_urb(urb); + else + usb_unlink_urb(urb); + + if (dev->video_mode.isoc_ctl.transfer_buffer[i]) { + usb_buffer_free(dev->udev, + urb->transfer_buffer_length, + dev->video_mode.isoc_ctl. + transfer_buffer[i], + urb->transfer_dma); + } + usb_free_urb(urb); + dev->video_mode.isoc_ctl.urb[i] = NULL; + } + dev->video_mode.isoc_ctl.transfer_buffer[i] = NULL; + } + + kfree(dev->video_mode.isoc_ctl.urb); + kfree(dev->video_mode.isoc_ctl.transfer_buffer); + + dev->video_mode.isoc_ctl.urb = NULL; + dev->video_mode.isoc_ctl.transfer_buffer = NULL; + dev->video_mode.isoc_ctl.num_bufs = 0; + + cx231xx_capture_start(dev, 0, Raw_Video); +} +EXPORT_SYMBOL_GPL(cx231xx_uninit_isoc); + +/* + * Allocate URBs and start IRQ + */ +int cx231xx_init_isoc(struct cx231xx *dev, int max_packets, + int num_bufs, int max_pkt_size, + int (*isoc_copy) (struct cx231xx *dev, struct urb *urb)) +{ + struct cx231xx_dmaqueue *dma_q = &dev->video_mode.vidq; + int i; + int sb_size, pipe; + struct urb *urb; + int j, k; + int rc; + + cx231xx_isocdbg("cx231xx: called cx231xx_prepare_isoc\n"); + + dev->video_input = dev->video_input > 2 ? 2 : dev->video_input; + + cx231xx_info("Setting Video mux to %d\n", dev->video_input); + video_mux(dev, dev->video_input); + + /* De-allocates all pending stuff */ + cx231xx_uninit_isoc(dev); + + dev->video_mode.isoc_ctl.isoc_copy = isoc_copy; + dev->video_mode.isoc_ctl.num_bufs = num_bufs; + dma_q->pos = 0; + dma_q->is_partial_line = 0; + dma_q->last_sav = 0; + dma_q->current_field = -1; + dma_q->field1_done = 0; + dma_q->lines_per_field = dev->height / 2; + dma_q->bytes_left_in_line = dev->width << 1; + dma_q->lines_completed = 0; + for (i = 0; i < 8; i++) + dma_q->partial_buf[i] = 0; + + dev->video_mode.isoc_ctl.urb = + kzalloc(sizeof(void *) * num_bufs, GFP_KERNEL); + if (!dev->video_mode.isoc_ctl.urb) { + cx231xx_errdev("cannot alloc memory for usb buffers\n"); + return -ENOMEM; + } + + dev->video_mode.isoc_ctl.transfer_buffer = + kzalloc(sizeof(void *) * num_bufs, GFP_KERNEL); + if (!dev->video_mode.isoc_ctl.transfer_buffer) { + cx231xx_errdev("cannot allocate memory for usbtransfer\n"); + kfree(dev->video_mode.isoc_ctl.urb); + return -ENOMEM; + } + + dev->video_mode.isoc_ctl.max_pkt_size = max_pkt_size; + dev->video_mode.isoc_ctl.buf = NULL; + + sb_size = max_packets * dev->video_mode.isoc_ctl.max_pkt_size; + + /* allocate urbs and transfer buffers */ + for (i = 0; i < dev->video_mode.isoc_ctl.num_bufs; i++) { + urb = usb_alloc_urb(max_packets, GFP_KERNEL); + if (!urb) { + cx231xx_err("cannot alloc isoc_ctl.urb %i\n", i); + cx231xx_uninit_isoc(dev); + return -ENOMEM; + } + dev->video_mode.isoc_ctl.urb[i] = urb; + + dev->video_mode.isoc_ctl.transfer_buffer[i] = + usb_buffer_alloc(dev->udev, sb_size, GFP_KERNEL, + &urb->transfer_dma); + if (!dev->video_mode.isoc_ctl.transfer_buffer[i]) { + cx231xx_err("unable to allocate %i bytes for transfer" + " buffer %i%s\n", + sb_size, i, + in_interrupt() ? " while in int" : ""); + cx231xx_uninit_isoc(dev); + return -ENOMEM; + } + memset(dev->video_mode.isoc_ctl.transfer_buffer[i], 0, sb_size); + + pipe = + usb_rcvisocpipe(dev->udev, dev->video_mode.end_point_addr); + + usb_fill_int_urb(urb, dev->udev, pipe, + dev->video_mode.isoc_ctl.transfer_buffer[i], + sb_size, cx231xx_irq_callback, dma_q, 1); + + urb->number_of_packets = max_packets; + urb->transfer_flags = URB_ISO_ASAP; + + k = 0; + for (j = 0; j < max_packets; j++) { + urb->iso_frame_desc[j].offset = k; + urb->iso_frame_desc[j].length = + dev->video_mode.isoc_ctl.max_pkt_size; + k += dev->video_mode.isoc_ctl.max_pkt_size; + } + } + + init_waitqueue_head(&dma_q->wq); + + /* submit urbs and enables IRQ */ + for (i = 0; i < dev->video_mode.isoc_ctl.num_bufs; i++) { + rc = usb_submit_urb(dev->video_mode.isoc_ctl.urb[i], + GFP_ATOMIC); + if (rc) { + cx231xx_err("submit of urb %i failed (error=%i)\n", i, + rc); + cx231xx_uninit_isoc(dev); + return rc; + } + } + + cx231xx_capture_start(dev, 1, Raw_Video); + + return 0; +} +EXPORT_SYMBOL_GPL(cx231xx_init_isoc); + +/***************************************************************** +* Device Init/UnInit functions * +******************************************************************/ +int cx231xx_dev_init(struct cx231xx *dev) +{ + int errCode = 0; + + /* Initialize I2C bus */ + + /* External Master 1 Bus */ + dev->i2c_bus[0].nr = 0; + dev->i2c_bus[0].dev = dev; + dev->i2c_bus[0].i2c_period = I2C_SPEED_1M; /* 1MHz */ + dev->i2c_bus[0].i2c_nostop = 0; + dev->i2c_bus[0].i2c_reserve = 0; + + /* External Master 2 Bus */ + dev->i2c_bus[1].nr = 1; + dev->i2c_bus[1].dev = dev; + dev->i2c_bus[1].i2c_period = I2C_SPEED_1M; /* 1MHz */ + dev->i2c_bus[1].i2c_nostop = 0; + dev->i2c_bus[1].i2c_reserve = 0; + + /* Internal Master 3 Bus */ + dev->i2c_bus[2].nr = 2; + dev->i2c_bus[2].dev = dev; + dev->i2c_bus[2].i2c_period = I2C_SPEED_400K; /* 400kHz */ + dev->i2c_bus[2].i2c_nostop = 0; + dev->i2c_bus[2].i2c_reserve = 0; + + /* register I2C buses */ + cx231xx_i2c_register(&dev->i2c_bus[0]); + cx231xx_i2c_register(&dev->i2c_bus[1]); + cx231xx_i2c_register(&dev->i2c_bus[2]); + + /* init hardware */ + /* Note : with out calling set power mode function, + colibri can not be set up correctly */ + errCode = cx231xx_set_power_mode(dev, POLARIS_AVMODE_ANALOGT_TV); + if (errCode < 0) { + cx231xx_errdev + ("%s: Failed to set Power - errCode [%d]!\n", + __func__, errCode); + return errCode; + } + + /* initialize Colibri block */ + errCode = cx231xx_colibri_init_super_block(dev, 0x23c); + if (errCode < 0) { + cx231xx_errdev + ("%s: cx231xx_colibri init super block - errCode [%d]!\n", + __func__, errCode); + return errCode; + } + errCode = cx231xx_colibri_init_channels(dev); + if (errCode < 0) { + cx231xx_errdev + ("%s: cx231xx_colibri init channels - errCode [%d]!\n", + __func__, errCode); + return errCode; + } + + /* Set DIF in By pass mode */ + errCode = cx231xx_dif_set_standard(dev, DIF_USE_BASEBAND); + if (errCode < 0) { + cx231xx_errdev + ("%s: cx231xx_dif set to By pass mode - errCode [%d]!\n", + __func__, errCode); + return errCode; + } + + /* flatiron related functions */ + errCode = cx231xx_flatiron_initialize(dev); + if (errCode < 0) { + cx231xx_errdev + ("%s: cx231xx_flatiron initialize - errCode [%d]!\n", + __func__, errCode); + return errCode; + } + + /* init control pins */ + errCode = cx231xx_init_ctrl_pin_status(dev); + if (errCode < 0) { + cx231xx_errdev("%s: cx231xx_init ctrl pins - errCode [%d]!\n", + __func__, errCode); + return errCode; + } + + /* set AGC mode to Analog */ + errCode = cx231xx_set_agc_analog_digital_mux_select(dev, 1); + if (errCode < 0) { + cx231xx_errdev + ("%s: cx231xx_AGC mode to Analog - errCode [%d]!\n", + __func__, errCode); + return errCode; + } + + /* set all alternate settings to zero initially */ + cx231xx_set_alt_setting(dev, INDEX_VIDEO, 0); + cx231xx_set_alt_setting(dev, INDEX_VANC, 0); + cx231xx_set_alt_setting(dev, INDEX_HANC, 0); + if (dev->board.has_dvb) + cx231xx_set_alt_setting(dev, INDEX_TS1, 0); + + /* set the I2C master port to 3 on channel 1 */ + errCode = cx231xx_enable_i2c_for_tuner(dev, I2C_3); + + return errCode; +} +EXPORT_SYMBOL_GPL(cx231xx_dev_init); + +void cx231xx_dev_uninit(struct cx231xx *dev) +{ + /* Un Initialize I2C bus */ + cx231xx_i2c_unregister(&dev->i2c_bus[2]); + cx231xx_i2c_unregister(&dev->i2c_bus[1]); + cx231xx_i2c_unregister(&dev->i2c_bus[0]); +} +EXPORT_SYMBOL_GPL(cx231xx_dev_uninit); + +/***************************************************************** +* G P I O related functions * +******************************************************************/ +int cx231xx_send_gpio_cmd(struct cx231xx *dev, u32 gpio_bit, u8 * gpio_val, + u8 len, u8 request, u8 direction) +{ + int status = 0; + struct VENDOR_REQUEST_IN ven_req; + + /* Set wValue */ + ven_req.wValue = (u16) (gpio_bit >> 16 & 0xffff); + + /* set request */ + if (!request) { + if (direction) + ven_req.bRequest = VRT_GET_GPIO; /* 0x8 gpio */ + else + ven_req.bRequest = VRT_SET_GPIO; /* 0x9 gpio */ + } else { + if (direction) + ven_req.bRequest = VRT_GET_GPIE; /* 0xa gpie */ + else + ven_req.bRequest = VRT_SET_GPIE; /* 0xb gpie */ + } + + /* set index value */ + ven_req.wIndex = (u16) (gpio_bit & 0xffff); + + /* set wLength value */ + ven_req.wLength = len; + + /* set bData value */ + ven_req.bData = 0; + + /* set the buffer for read / write */ + ven_req.pBuff = gpio_val; + + /* set the direction */ + if (direction) { + ven_req.direction = USB_DIR_IN; + memset(ven_req.pBuff, 0x00, ven_req.wLength); + } else + ven_req.direction = USB_DIR_OUT; + +#if 0 + cx231xx_isocdbg("bRequest = %x\n", ven_req.bRequest); + cx231xx_isocdbg("wValue = %x\n", ven_req.wValue); + cx231xx_isocdbg("wIndex = %x\n", ven_req.wIndex); + cx231xx_isocdbg("wLength = %x\n", ven_req.wLength); + for (int i = 0; i < ven_req.wLength; i++) + cx231xx_isocdbg("pBuff[i] = %x\n", ven_req.pBuff[i]); +#endif + + /* call common vendor command request */ + status = cx231xx_send_vendor_cmd(dev, &ven_req); + if (status < 0) { + cx231xx_info + ("UsbInterface::sendCommand, failed with status -%d\n", + status); + } + + return status; +} +EXPORT_SYMBOL_GPL(cx231xx_send_gpio_cmd); + +/***************************************************************** + * C O N T R O L - Register R E A D / W R I T E functions * + *****************************************************************/ +int cx231xx_mode_register(struct cx231xx *dev, u16 address, u32 mode) +{ + u8 value[4] = { 0x0, 0x0, 0x0, 0x0 }; + u32 tmp = 0; + int status = 0; + + status = + cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER, address, value, 4); + if (status < 0) + return status; + + tmp = *((u32 *) value); + tmp |= mode; + + value[0] = (u8) tmp; + value[1] = (u8) (tmp >> 8); + value[2] = (u8) (tmp >> 16); + value[3] = (u8) (tmp >> 24); + + status = + cx231xx_write_ctrl_reg(dev, VRT_SET_REGISTER, address, value, 4); + + return status; +} + +/***************************************************************** + * I 2 C Internal C O N T R O L functions * + *****************************************************************/ +int cx231xx_read_i2c_data(struct cx231xx *dev, u8 dev_addr, u16 saddr, + u8 saddr_len, u32 *data, u8 data_len) +{ + int status = 0; + struct cx231xx_i2c_xfer_data req_data; + u8 value[4] = { 0, 0, 0, 0 }; + + if (saddr_len == 0) + saddr = 0; + else if (saddr_len == 0) + saddr &= 0xff; + + /* prepare xfer_data struct */ + req_data.dev_addr = dev_addr >> 1; + req_data.direction = I2C_M_RD; + req_data.saddr_len = saddr_len; + req_data.saddr_dat = saddr; + req_data.buf_size = data_len; + req_data.p_buffer = (u8 *) value; + + /* usb send command */ + status = dev->cx231xx_send_usb_command(&dev->i2c_bus[0], &req_data); + + if (status >= 0) { + /* Copy the data read back to main buffer */ + if (data_len == 1) + *data = value[0]; + else + *data = + value[0] | value[1] << 8 | value[2] << 16 | value[3] + << 24; + } + + return status; +} + +int cx231xx_write_i2c_data(struct cx231xx *dev, u8 dev_addr, u16 saddr, + u8 saddr_len, u32 data, u8 data_len) +{ + int status = 0; + u8 value[4] = { 0, 0, 0, 0 }; + struct cx231xx_i2c_xfer_data req_data; + + value[0] = (u8) data; + value[1] = (u8) (data >> 8); + value[2] = (u8) (data >> 16); + value[3] = (u8) (data >> 24); + + if (saddr_len == 0) + saddr = 0; + else if (saddr_len == 0) + saddr &= 0xff; + + /* prepare xfer_data struct */ + req_data.dev_addr = dev_addr >> 1; + req_data.direction = 0; + req_data.saddr_len = saddr_len; + req_data.saddr_dat = saddr; + req_data.buf_size = data_len; + req_data.p_buffer = value; + + /* usb send command */ + status = dev->cx231xx_send_usb_command(&dev->i2c_bus[0], &req_data); + + return status; +} + +int cx231xx_reg_mask_write(struct cx231xx *dev, u8 dev_addr, u8 size, + u16 register_address, u8 bit_start, u8 bit_end, + u32 value) +{ + int status = 0; + u32 tmp; + u32 mask = 0; + int i; + + if (bit_start > (size - 1) || bit_end > (size - 1)) + return -1; + + if (size == 8) { + status = + cx231xx_read_i2c_data(dev, dev_addr, register_address, 2, + &tmp, 1); + } else { + status = + cx231xx_read_i2c_data(dev, dev_addr, register_address, 2, + &tmp, 4); + } + + if (status < 0) + return status; + + mask = 1 << bit_end; + for (i = bit_end; i > bit_start && i > 0; i--) + mask = mask + (1 << (i - 1)); + + value <<= bit_start; + + if (size == 8) { + tmp &= ~mask; + tmp |= value; + tmp &= 0xff; + status = + cx231xx_write_i2c_data(dev, dev_addr, register_address, 2, + tmp, 1); + } else { + tmp &= ~mask; + tmp |= value; + status = + cx231xx_write_i2c_data(dev, dev_addr, register_address, 2, + tmp, 4); + } + + return status; +} + +int cx231xx_read_modify_write_i2c_dword(struct cx231xx *dev, u8 dev_addr, + u16 saddr, u32 mask, u32 value) +{ + u32 temp; + int status = 0; + + status = cx231xx_read_i2c_data(dev, dev_addr, saddr, 2, &temp, 4); + + if (status < 0) + return status; + + temp &= ~mask; + temp |= value; + + status = cx231xx_write_i2c_data(dev, dev_addr, saddr, 2, temp, 4); + + return status; +} + +u32 cx231xx_set_field(u32 field_mask, u32 data) +{ + u32 temp; + + for (temp = field_mask; (temp & 1) == 0; temp >>= 1) + data <<= 1; + + return data; +} diff --git a/linux/drivers/media/video/cx231xx/cx231xx-dvb.c b/linux/drivers/media/video/cx231xx/cx231xx-dvb.c new file mode 100644 index 000000000..9ff097055 --- /dev/null +++ b/linux/drivers/media/video/cx231xx/cx231xx-dvb.c @@ -0,0 +1,560 @@ +/* + DVB device driver for cx231xx + + Copyright (C) 2008 <srinivasa.deevi at conexant dot com> + Based on em28xx driver + + 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/usb.h> +#include "compat.h" + +#include "cx231xx.h" +#include <media/v4l2-common.h> +#include <media/videobuf-vmalloc.h> + +#include "xc5000.h" +#include "dvb_dummy_fe.h" + +MODULE_DESCRIPTION("driver for cx231xx based DVB cards"); +MODULE_AUTHOR("Srinivasa Deevi <srinivasa.deevi@conexant.com>"); +MODULE_LICENSE("GPL"); + +static unsigned int debug; +module_param(debug, int, 0644); +MODULE_PARM_DESC(debug, "enable debug messages [dvb]"); + +DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); + +#define dprintk(level, fmt, arg...) do { \ +if (debug >= level) \ + printk(KERN_DEBUG "%s/2-dvb: " fmt, dev->name, ## arg); \ +} while (0) + +#define CX231XX_DVB_NUM_BUFS 5 +#define CX231XX_DVB_MAX_PACKETSIZE 564 +#define CX231XX_DVB_MAX_PACKETS 64 + +struct cx231xx_dvb { + struct dvb_frontend *frontend; + + /* feed count management */ + struct mutex lock; + int nfeeds; + + /* general boilerplate stuff */ + struct dvb_adapter adapter; + struct dvb_demux demux; + struct dmxdev dmxdev; + struct dmx_frontend fe_hw; + struct dmx_frontend fe_mem; + struct dvb_net net; +}; + +static inline void print_err_status(struct cx231xx *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) { + dprintk(1, "URB status %d [%s].\n", status, errmsg); + } else { + dprintk(1, "URB packet %d, status %d [%s].\n", + packet, status, errmsg); + } +} + +static inline int dvb_isoc_copy(struct cx231xx *dev, struct urb *urb) +{ + int i; + + if (!dev) + return 0; + + if ((dev->state & DEV_DISCONNECTED) || (dev->state & DEV_MISCONFIGURED)) + return 0; + + if (urb->status < 0) { + print_err_status(dev, -1, urb->status); + if (urb->status == -ENOENT) + return 0; + } + + 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; + } + + dvb_dmx_swfilter(&dev->dvb->demux, urb->transfer_buffer + + urb->iso_frame_desc[i].offset, + urb->iso_frame_desc[i].actual_length); + } + + return 0; +} + +static int start_streaming(struct cx231xx_dvb *dvb) +{ + int rc; + struct cx231xx *dev = dvb->adapter.priv; + + usb_set_interface(dev->udev, 0, 1); + rc = cx231xx_set_mode(dev, CX231XX_DIGITAL_MODE); + if (rc < 0) + return rc; + + return cx231xx_init_isoc(dev, CX231XX_DVB_MAX_PACKETS, + CX231XX_DVB_NUM_BUFS, + CX231XX_DVB_MAX_PACKETSIZE, dvb_isoc_copy); +} + +static int stop_streaming(struct cx231xx_dvb *dvb) +{ + struct cx231xx *dev = dvb->adapter.priv; + + cx231xx_uninit_isoc(dev); + + cx231xx_set_mode(dev, CX231XX_SUSPEND); + + return 0; +} + +static int start_feed(struct dvb_demux_feed *feed) +{ + struct dvb_demux *demux = feed->demux; + struct cx231xx_dvb *dvb = demux->priv; + int rc, ret; + + if (!demux->dmx.frontend) + return -EINVAL; + + mutex_lock(&dvb->lock); + dvb->nfeeds++; + rc = dvb->nfeeds; + + if (dvb->nfeeds == 1) { + ret = start_streaming(dvb); + if (ret < 0) + rc = ret; + } + + mutex_unlock(&dvb->lock); + return rc; +} + +static int stop_feed(struct dvb_demux_feed *feed) +{ + struct dvb_demux *demux = feed->demux; + struct cx231xx_dvb *dvb = demux->priv; + int err = 0; + + mutex_lock(&dvb->lock); + dvb->nfeeds--; + + if (0 == dvb->nfeeds) + err = stop_streaming(dvb); + + mutex_unlock(&dvb->lock); + return err; +} + +/* ------------------------------------------------------------------ */ +static int cx231xx_dvb_bus_ctrl(struct dvb_frontend *fe, int acquire) +{ + struct cx231xx *dev = fe->dvb->priv; + + if (acquire) + return cx231xx_set_mode(dev, CX231XX_DIGITAL_MODE); + else + return cx231xx_set_mode(dev, CX231XX_SUSPEND); +} + +/* ------------------------------------------------------------------ */ + +static struct xc5000_config cnxt_rde250_tunerconfig = { + .i2c_address = 0x61, + .if_khz = 5380, +}; + +/* ------------------------------------------------------------------ */ +#if 0 /* Keep */ +static int attach_xc5000(u8 addr, struct cx231xx *dev) +{ + + struct dvb_frontend *fe; + struct xc5000_config cfg; + + memset(&cfg, 0, sizeof(cfg)); + cfg.i2c_adap = &dev->i2c_bus[1].i2c_adap; + cfg.i2c_addr = addr; + + if (!dev->dvb->frontend) { + printk(KERN_ERR "%s/2: dvb frontend not attached. " + "Can't attach xc5000\n", dev->name); + return -EINVAL; + } + + fe = dvb_attach(xc5000_attach, dev->dvb->frontend, &cfg); + if (!fe) { + printk(KERN_ERR "%s/2: xc5000 attach failed\n", dev->name); + dvb_frontend_detach(dev->dvb->frontend); + dev->dvb->frontend = NULL; + return -EINVAL; + } + + printk(KERN_INFO "%s/2: xc5000 attached\n", dev->name); + + return 0; +} +#endif + +int cx231xx_set_analog_freq(struct cx231xx *dev, u32 freq) +{ + int status = 0; + + if ((dev->dvb != NULL) && (dev->dvb->frontend != NULL)) { + + struct dvb_tuner_ops *dops = &dev->dvb->frontend->ops.tuner_ops; + + if (dops->set_analog_params != NULL) { + struct analog_parameters params; + + params.frequency = freq; + params.std = dev->norm; + params.mode = 0; /* 0- Air; 1 - cable */ + /*params.audmode = ; */ + + /* Set the analog parameters to set the frequency */ + cx231xx_info("Setting Frequency for XC5000\n"); + dops->set_analog_params(dev->dvb->frontend, ¶ms); + } + + } + + return status; +} + +int cx231xx_reset_analog_tuner(struct cx231xx *dev) +{ + int status = 0; + + if ((dev->dvb != NULL) && (dev->dvb->frontend != NULL)) { + + struct dvb_tuner_ops *dops = &dev->dvb->frontend->ops.tuner_ops; + + if (dops->init != NULL && !dev->xc_fw_load_done) { + + cx231xx_info("Reloading firmware for XC5000\n"); + status = dops->init(dev->dvb->frontend); + if (status == 0) { + dev->xc_fw_load_done = 1; + cx231xx_info + ("XC5000 firmware download completed\n"); + } else { + dev->xc_fw_load_done = 0; + cx231xx_info + ("XC5000 firmware download failed !!!\n"); + } + } + + } + + return status; +} + +/* ------------------------------------------------------------------ */ + +static int register_dvb(struct cx231xx_dvb *dvb, + struct module *module, + struct cx231xx *dev, struct device *device) +{ + int result; + + mutex_init(&dvb->lock); + + /* register adapter */ + result = dvb_register_adapter(&dvb->adapter, dev->name, module, device, + adapter_nr); + if (result < 0) { + printk(KERN_WARNING + "%s: dvb_register_adapter failed (errno = %d)\n", + dev->name, result); + goto fail_adapter; + } + + /* Ensure all frontends negotiate bus access */ + dvb->frontend->ops.ts_bus_ctrl = cx231xx_dvb_bus_ctrl; + + dvb->adapter.priv = dev; + + /* register frontend */ + result = dvb_register_frontend(&dvb->adapter, dvb->frontend); + if (result < 0) { + printk(KERN_WARNING + "%s: dvb_register_frontend failed (errno = %d)\n", + dev->name, result); + goto fail_frontend; + } + + /* register demux stuff */ + dvb->demux.dmx.capabilities = + DMX_TS_FILTERING | DMX_SECTION_FILTERING | + DMX_MEMORY_BASED_FILTERING; + dvb->demux.priv = dvb; + dvb->demux.filternum = 256; + dvb->demux.feednum = 256; + dvb->demux.start_feed = start_feed; + dvb->demux.stop_feed = stop_feed; + + result = dvb_dmx_init(&dvb->demux); + if (result < 0) { + printk(KERN_WARNING "%s: dvb_dmx_init failed (errno = %d)\n", + dev->name, result); + goto fail_dmx; + } + + dvb->dmxdev.filternum = 256; + dvb->dmxdev.demux = &dvb->demux.dmx; + dvb->dmxdev.capabilities = 0; + result = dvb_dmxdev_init(&dvb->dmxdev, &dvb->adapter); + if (result < 0) { + printk(KERN_WARNING "%s: dvb_dmxdev_init failed (errno = %d)\n", + dev->name, result); + goto fail_dmxdev; + } + + dvb->fe_hw.source = DMX_FRONTEND_0; + result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_hw); + if (result < 0) { + printk(KERN_WARNING + "%s: add_frontend failed (DMX_FRONTEND_0, errno = %d)\n", + dev->name, result); + goto fail_fe_hw; + } + + dvb->fe_mem.source = DMX_MEMORY_FE; + result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_mem); + if (result < 0) { + printk(KERN_WARNING + "%s: add_frontend failed (DMX_MEMORY_FE, errno = %d)\n", + dev->name, result); + goto fail_fe_mem; + } + + result = dvb->demux.dmx.connect_frontend(&dvb->demux.dmx, &dvb->fe_hw); + if (result < 0) { + printk(KERN_WARNING + "%s: connect_frontend failed (errno = %d)\n", dev->name, + result); + goto fail_fe_conn; + } + + /* register network adapter */ + dvb_net_init(&dvb->adapter, &dvb->net, &dvb->demux.dmx); + return 0; + +fail_fe_conn: + dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem); +fail_fe_mem: + dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw); +fail_fe_hw: + dvb_dmxdev_release(&dvb->dmxdev); +fail_dmxdev: + dvb_dmx_release(&dvb->demux); +fail_dmx: + dvb_unregister_frontend(dvb->frontend); +fail_frontend: + dvb_frontend_detach(dvb->frontend); + dvb_unregister_adapter(&dvb->adapter); +fail_adapter: + return result; +} + +static void unregister_dvb(struct cx231xx_dvb *dvb) +{ + dvb_net_release(&dvb->net); + dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem); + dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw); + dvb_dmxdev_release(&dvb->dmxdev); + dvb_dmx_release(&dvb->demux); + dvb_unregister_frontend(dvb->frontend); + dvb_frontend_detach(dvb->frontend); + dvb_unregister_adapter(&dvb->adapter); +} + +static int dvb_init(struct cx231xx *dev) +{ + int result = 0; + struct cx231xx_dvb *dvb; + + if (!dev->board.has_dvb) { + /* This device does not support the extension */ + return 0; + } + + dvb = kzalloc(sizeof(struct cx231xx_dvb), GFP_KERNEL); + + if (dvb == NULL) { + printk(KERN_INFO "cx231xx_dvb: memory allocation failed\n"); + return -ENOMEM; + } + dev->dvb = dvb; + dev->cx231xx_set_analog_freq = cx231xx_set_analog_freq; + dev->cx231xx_reset_analog_tuner = cx231xx_reset_analog_tuner; + + cx231xx_set_mode(dev, CX231XX_DIGITAL_MODE); + /* init frontend */ + switch (dev->model) { + case CX231XX_BOARD_CNXT_RDE_250: + + /* dev->dvb->frontend = dvb_attach(s5h1411_attach, + &dvico_s5h1411_config, + &dev->i2c_bus[1].i2c_adap); */ + dev->dvb->frontend = dvb_attach(dvb_dummy_fe_ofdm_attach); + + if (dev->dvb->frontend == NULL) { + printk(DRIVER_NAME + ": Failed to attach dummy front end\n"); + result = -EINVAL; + goto out_free; + } + + /* define general-purpose callback pointer */ + dvb->frontend->callback = cx231xx_tuner_callback; + + if (dvb_attach(xc5000_attach, dev->dvb->frontend, + &dev->i2c_bus[1].i2c_adap, + &cnxt_rde250_tunerconfig) < 0) { + result = -EINVAL; + goto out_free; + } + + break; + case CX231XX_BOARD_CNXT_RDU_250: + + dev->dvb->frontend = dvb_attach(dvb_dummy_fe_ofdm_attach); + + if (dev->dvb->frontend == NULL) { + printk(DRIVER_NAME + ": Failed to attach dummy front end\n"); + result = -EINVAL; + goto out_free; + } + + /* define general-purpose callback pointer */ + dvb->frontend->callback = cx231xx_tuner_callback; + + if (dvb_attach(xc5000_attach, dev->dvb->frontend, + &dev->i2c_bus[1].i2c_adap, + &cnxt_rde250_tunerconfig) < 0) { + result = -EINVAL; + goto out_free; + } + break; + + default: + printk(KERN_ERR "%s/2: The frontend of your DVB/ATSC card" + " isn't supported yet\n", dev->name); + break; + } + if (NULL == dvb->frontend) { + printk(KERN_ERR + "%s/2: frontend initialization failed\n", dev->name); + result = -EINVAL; + goto out_free; + } + + /* register everything */ + result = register_dvb(dvb, THIS_MODULE, dev, &dev->udev->dev); + + if (result < 0) + goto out_free; + + cx231xx_set_mode(dev, CX231XX_SUSPEND); + printk(KERN_INFO "Successfully loaded cx231xx-dvb\n"); + return 0; + +out_free: + cx231xx_set_mode(dev, CX231XX_SUSPEND); + kfree(dvb); + dev->dvb = NULL; + return result; +} + +static int dvb_fini(struct cx231xx *dev) +{ + if (!dev->board.has_dvb) { + /* This device does not support the extension */ + return 0; + } + + if (dev->dvb) { + unregister_dvb(dev->dvb); + dev->dvb = NULL; + } + + return 0; +} + +static struct cx231xx_ops dvb_ops = { + .id = CX231XX_DVB, + .name = "Cx231xx dvb Extension", + .init = dvb_init, + .fini = dvb_fini, +}; + +static int __init cx231xx_dvb_register(void) +{ + return cx231xx_register_extension(&dvb_ops); +} + +static void __exit cx231xx_dvb_unregister(void) +{ + cx231xx_unregister_extension(&dvb_ops); +} + +module_init(cx231xx_dvb_register); +module_exit(cx231xx_dvb_unregister); diff --git a/linux/drivers/media/video/cx231xx/cx231xx-i2c.c b/linux/drivers/media/video/cx231xx/cx231xx-i2c.c new file mode 100644 index 000000000..87dbd4e4e --- /dev/null +++ b/linux/drivers/media/video/cx231xx/cx231xx-i2c.c @@ -0,0 +1,601 @@ +/* + cx231xx-i2c.c - driver for Conexant Cx23100/101/102 USB video capture devices + + Copyright (C) 2008 <srinivasa.deevi at conexant dot com> + Based on em28xx driver + Based on Cx23885 driver + + 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/module.h> +#include <linux/kernel.h> +#include <linux/usb.h> +#include <linux/i2c.h> +#include <media/v4l2-common.h> +#include <media/tuner.h> + +#include "cx231xx.h" + +/* ----------------------------------------------------------- */ + +static unsigned int i2c_scan; +module_param(i2c_scan, int, 0444); +MODULE_PARM_DESC(i2c_scan, "scan i2c bus at insmod time"); + +static unsigned int i2c_debug; +module_param(i2c_debug, int, 0644); +MODULE_PARM_DESC(i2c_debug, "enable debug messages [i2c]"); + +#define dprintk1(lvl, fmt, args...) \ +do { \ + if (i2c_debug >= lvl) { \ + printk(fmt, ##args); \ + } \ +} while (0) + +#define dprintk2(lvl, fmt, args...) \ +do { \ + if (i2c_debug >= lvl) { \ + printk(KERN_DEBUG "%s at %s: " fmt, \ + dev->name, __func__ , ##args); \ + } \ +} while (0) + +/* + * cx231xx_i2c_send_bytes() + */ +int cx231xx_i2c_send_bytes(struct i2c_adapter *i2c_adap, + const struct i2c_msg *msg) +{ + struct cx231xx_i2c *bus = i2c_adap->algo_data; + struct cx231xx *dev = bus->dev; + struct cx231xx_i2c_xfer_data req_data; + int status = 0; + u16 size = 0; + u8 loop = 0; + u8 saddr_len = 1; + u8 *buf_ptr = NULL; + u16 saddr = 0; + u8 need_gpio = 0; + + if ((bus->nr == 1) && (msg->addr == 0x61) + && (dev->tuner_type == TUNER_XC5000)) { + + size = msg->len; + + if (size == 2) { /* register write sub addr */ + /* Just writing sub address will cause problem + * to XC5000. So ignore the request */ + return 0; + } else if (size == 4) { /* register write with sub addr */ + if (msg->len >= 2) + saddr = msg->buf[0] << 8 | msg->buf[1]; + else if (msg->len == 1) + saddr = msg->buf[0]; + + switch (saddr) { + case 0x0000: /* start tuner calibration mode */ + need_gpio = 1; + /* FW Loading is done */ + dev->xc_fw_load_done = 1; + break; + case 0x000D: /* Set signal source */ + case 0x0001: /* Set TV standard - Video */ + case 0x0002: /* Set TV standard - Audio */ + case 0x0003: /* Set RF Frequency */ + need_gpio = 1; + break; + default: + if (dev->xc_fw_load_done) + need_gpio = 1; + break; + } + + if (need_gpio) { + dprintk1(1, + "GPIO WRITE: addr 0x%x, len %d, saddr 0x%x\n", + msg->addr, msg->len, saddr); + + return dev->cx231xx_gpio_i2c_write(dev, + msg->addr, + msg->buf, + msg->len); + } + } + + /* special case for Xc5000 tuner case */ + saddr_len = 1; + + /* adjust the length to correct length */ + size -= saddr_len; + buf_ptr = (u8 *) (msg->buf + 1); + + do { + /* prepare xfer_data struct */ + req_data.dev_addr = msg->addr; + req_data.direction = msg->flags; + req_data.saddr_len = saddr_len; + req_data.saddr_dat = msg->buf[0]; + req_data.buf_size = size > 16 ? 16 : size; + req_data.p_buffer = (u8 *) (buf_ptr + loop * 16); + + bus->i2c_nostop = (size > 16) ? 1 : 0; + bus->i2c_reserve = (loop == 0) ? 0 : 1; + + /* usb send command */ + status = dev->cx231xx_send_usb_command(bus, &req_data); + loop++; + + if (size >= 16) + size -= 16; + else + size = 0; + + } while (size > 0); + + bus->i2c_nostop = 0; + bus->i2c_reserve = 0; + + } else { /* regular case */ + + /* prepare xfer_data struct */ + req_data.dev_addr = msg->addr; + req_data.direction = msg->flags; + req_data.saddr_len = 0; + req_data.saddr_dat = 0; + req_data.buf_size = msg->len; + req_data.p_buffer = msg->buf; + + /* usb send command */ + status = dev->cx231xx_send_usb_command(bus, &req_data); + } + + return status < 0 ? status : 0; +} + +/* + * cx231xx_i2c_recv_bytes() + * read a byte from the i2c device + */ +static int cx231xx_i2c_recv_bytes(struct i2c_adapter *i2c_adap, + const struct i2c_msg *msg) +{ + struct cx231xx_i2c *bus = i2c_adap->algo_data; + struct cx231xx *dev = bus->dev; + struct cx231xx_i2c_xfer_data req_data; + int status = 0; + u16 saddr = 0; + u8 need_gpio = 0; + + if ((bus->nr == 1) && (msg->addr == 0x61) + && dev->tuner_type == TUNER_XC5000) { + + if (msg->len == 2) + saddr = msg->buf[0] << 8 | msg->buf[1]; + else if (msg->len == 1) + saddr = msg->buf[0]; + + if (dev->xc_fw_load_done) { + + switch (saddr) { + case 0x0009: /* BUSY check */ + dprintk1(1, + "GPIO R E A D: Special case BUSY check \n"); + /*Try read BUSY register, just set it to zero*/ + msg->buf[0] = 0; + if (msg->len == 2) + msg->buf[1] = 0; + return 0; + case 0x0004: /* read Lock status */ + need_gpio = 1; + break; + + } + + if (need_gpio) { + /* this is a special case to handle Xceive tuner + clock stretch issue with gpio based I2C */ + + dprintk1(1, + "GPIO R E A D: addr 0x%x, len %d, saddr 0x%x\n", + msg->addr, msg->len, + msg->buf[0] << 8 | msg->buf[1]); + + status = + dev->cx231xx_gpio_i2c_write(dev, msg->addr, + msg->buf, + msg->len); + status = + dev->cx231xx_gpio_i2c_read(dev, msg->addr, + msg->buf, + msg->len); + return status; + } + } + + /* prepare xfer_data struct */ + req_data.dev_addr = msg->addr; + req_data.direction = msg->flags; + req_data.saddr_len = msg->len; + req_data.saddr_dat = msg->buf[0] << 8 | msg->buf[1]; + req_data.buf_size = msg->len; + req_data.p_buffer = msg->buf; + + /* usb send command */ + status = dev->cx231xx_send_usb_command(bus, &req_data); + + } else { + + /* prepare xfer_data struct */ + req_data.dev_addr = msg->addr; + req_data.direction = msg->flags; + req_data.saddr_len = 0; + req_data.saddr_dat = 0; + req_data.buf_size = msg->len; + req_data.p_buffer = msg->buf; + + /* usb send command */ + status = dev->cx231xx_send_usb_command(bus, &req_data); + } + + return status < 0 ? status : 0; +} + +/* + * cx231xx_i2c_recv_bytes_with_saddr() + * read a byte from the i2c device + */ +static int cx231xx_i2c_recv_bytes_with_saddr(struct i2c_adapter *i2c_adap, + const struct i2c_msg *msg1, + const struct i2c_msg *msg2) +{ + struct cx231xx_i2c *bus = i2c_adap->algo_data; + struct cx231xx *dev = bus->dev; + struct cx231xx_i2c_xfer_data req_data; + int status = 0; + u16 saddr = 0; + u8 need_gpio = 0; + + if (msg1->len == 2) + saddr = msg1->buf[0] << 8 | msg1->buf[1]; + else if (msg1->len == 1) + saddr = msg1->buf[0]; + + if ((bus->nr == 1) && (msg2->addr == 0x61) + && dev->tuner_type == TUNER_XC5000) { + + if ((msg2->len < 16)) { + + dprintk1(1, + "i2c_read: addr 0x%x, len %d, saddr 0x%x, len %d\n", + msg2->addr, msg2->len, saddr, msg1->len); + + switch (saddr) { + case 0x0008: /* read FW load status */ + need_gpio = 1; + break; + case 0x0004: /* read Lock status */ + need_gpio = 1; + break; + } + + if (need_gpio) { + status = + dev->cx231xx_gpio_i2c_write(dev, msg1->addr, + msg1->buf, + msg1->len); + status = + dev->cx231xx_gpio_i2c_read(dev, msg2->addr, + msg2->buf, + msg2->len); + return status; + } + } + } + + /* prepare xfer_data struct */ + req_data.dev_addr = msg2->addr; + req_data.direction = msg2->flags; + req_data.saddr_len = msg1->len; + req_data.saddr_dat = saddr; + req_data.buf_size = msg2->len; + req_data.p_buffer = msg2->buf; + + /* usb send command */ + status = dev->cx231xx_send_usb_command(bus, &req_data); + + return status < 0 ? status : 0; +} + +/* + * cx231xx_i2c_check_for_device() + * check if there is a i2c_device at the supplied address + */ +static int cx231xx_i2c_check_for_device(struct i2c_adapter *i2c_adap, + const struct i2c_msg *msg) +{ + struct cx231xx_i2c *bus = i2c_adap->algo_data; + struct cx231xx *dev = bus->dev; + struct cx231xx_i2c_xfer_data req_data; + int status = 0; + + /* prepare xfer_data struct */ + req_data.dev_addr = msg->addr; + req_data.direction = msg->flags; + req_data.saddr_len = 0; + req_data.saddr_dat = 0; + req_data.buf_size = 0; + req_data.p_buffer = NULL; + + /* usb send command */ + status = dev->cx231xx_send_usb_command(bus, &req_data); + + return status < 0 ? status : 0; +} + +/* + * cx231xx_i2c_xfer() + * the main i2c transfer function + */ +static int cx231xx_i2c_xfer(struct i2c_adapter *i2c_adap, + struct i2c_msg msgs[], int num) +{ + struct cx231xx_i2c *bus = i2c_adap->algo_data; + struct cx231xx *dev = bus->dev; + int addr, rc, i, byte; + + if (num <= 0) + return 0; + + for (i = 0; i < num; i++) { + + addr = msgs[i].addr >> 1; + + dprintk2(2, "%s %s addr=%x len=%d:", + (msgs[i].flags & I2C_M_RD) ? "read" : "write", + i == num - 1 ? "stop" : "nonstop", addr, msgs[i].len); + if (!msgs[i].len) { + /* no len: check only for device presence */ + rc = cx231xx_i2c_check_for_device(i2c_adap, &msgs[i]); + if (rc < 0) { + dprintk2(2, " no device\n"); + return rc; + } + + } else if (msgs[i].flags & I2C_M_RD) { + /* read bytes */ + rc = cx231xx_i2c_recv_bytes(i2c_adap, &msgs[i]); + if (i2c_debug >= 2) { + for (byte = 0; byte < msgs[i].len; byte++) + printk(" %02x", msgs[i].buf[byte]); + } + } else if (i + 1 < num && (msgs[i + 1].flags & I2C_M_RD) && + msgs[i].addr == msgs[i + 1].addr + && (msgs[i].len <= 2) && (bus->nr < 2)) { + /* read bytes */ + rc = cx231xx_i2c_recv_bytes_with_saddr(i2c_adap, + &msgs[i], + &msgs[i + 1]); + if (i2c_debug >= 2) { + for (byte = 0; byte < msgs[i].len; byte++) + printk(" %02x", msgs[i].buf[byte]); + } + i++; + } else { + /* write bytes */ + if (i2c_debug >= 2) { + for (byte = 0; byte < msgs[i].len; byte++) + printk(" %02x", msgs[i].buf[byte]); + } + rc = cx231xx_i2c_send_bytes(i2c_adap, &msgs[i]); + } + if (rc < 0) + goto err; + if (i2c_debug >= 2) + printk("\n"); + } + + return num; +err: + dprintk2(2, " ERROR: %i\n", rc); + return rc; +} + +/* ----------------------------------------------------------- */ + +/* + * functionality() + */ +static u32 functionality(struct i2c_adapter *adap) +{ + return I2C_FUNC_SMBUS_EMUL | I2C_FUNC_I2C; +} + +/* + * attach_inform() + * gets called when a device attaches to the i2c bus + * does some basic configuration + */ +static int attach_inform(struct i2c_client *client) +{ + struct cx231xx_i2c *bus = i2c_get_adapdata(client->adapter); + 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); + dprintk1(1, "attach_inform: IR detected (%s).\n", + ir->phys); + 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); + } + + 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, +#ifdef NEED_ALGO_CONTROL + .algo_control = dummy_algo_control, +#endif +}; + +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 = { + .name = "cx231xx internal", +}; + +/* ----------------------------------------------------------- */ + +/* + * i2c_devs + * incomplete list of known devices + */ +static char *i2c_devs[128] = { + [0x60 >> 1] = "colibri", + [0x88 >> 1] = "hammerhead", + [0x8e >> 1] = "CIR", + [0x32 >> 1] = "GeminiIII", + [0x02 >> 1] = "Aquarius", + [0xa0 >> 1] = "eeprom", + [0xc0 >> 1] = "tuner/XC3028", + [0xc2 >> 1] = "tuner/XC5000", +}; + +/* + * cx231xx_do_i2c_scan() + * check i2c address range for devices + */ +void cx231xx_do_i2c_scan(struct cx231xx *dev, struct i2c_client *c) +{ + unsigned char buf; + int i, rc; + + cx231xx_info(": Checking for I2C devices ..\n"); + for (i = 0; i < 128; i++) { + c->addr = i; + rc = i2c_master_recv(c, &buf, 0); + if (rc < 0) + continue; + cx231xx_info("%s: i2c scan: found device @ 0x%x [%s]\n", + dev->name, i << 1, + i2c_devs[i] ? i2c_devs[i] : "???"); + } + cx231xx_info(": Completed Checking for I2C devices.\n"); +} + +/* + * 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 + */ +int cx231xx_i2c_register(struct cx231xx_i2c *bus) +{ + struct cx231xx *dev = bus->dev; + + 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, + sizeof(bus->i2c_client)); + + bus->i2c_adap.dev.parent = &dev->udev->dev; + + strlcpy(bus->i2c_adap.name, bus->dev->name, sizeof(bus->i2c_adap.name)); + + bus->i2c_algo.data = bus; + bus->i2c_adap.algo_data = bus; + i2c_set_adapdata(&bus->i2c_adap, bus); + 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 + cx231xx_warn("%s: i2c bus %d register FAILED\n", + dev->name, bus->nr); + + return bus->i2c_rc; +} + +/* + * cx231xx_i2c_unregister() + * unregister i2c_bus + */ +int cx231xx_i2c_unregister(struct cx231xx_i2c *bus) +{ + i2c_del_adapter(&bus->i2c_adap); + return 0; +} diff --git a/linux/drivers/media/video/cx231xx/cx231xx-input.c b/linux/drivers/media/video/cx231xx/cx231xx-input.c new file mode 100644 index 000000000..04d954cca --- /dev/null +++ b/linux/drivers/media/video/cx231xx/cx231xx-input.c @@ -0,0 +1,263 @@ +/* + handle cx231xx IR remotes via linux kernel input layer. + + Copyright (C) 2008 <srinivasa.deevi at conexant dot com> + Based on em28xx driver + + < This is a place holder for IR now.> + + 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include <linux/module.h> +#include <linux/init.h> +#include <linux/delay.h> +#include <linux/interrupt.h> +#include <linux/input.h> +#include <linux/usb.h> + +#include "compat.h" +#include "cx231xx.h" + +static unsigned int ir_debug; +module_param(ir_debug, int, 0644); +MODULE_PARM_DESC(ir_debug, "enable debug messages [IR]"); + +#define i2cdprintk(fmt, arg...) \ + if (ir_debug) { \ + printk(KERN_DEBUG "%s/ir: " fmt, ir->c.name , ## arg); \ + } + +#define dprintk(fmt, arg...) \ + if (ir_debug) { \ + printk(KERN_DEBUG "%s/ir: " fmt, ir->name , ## arg); \ + } + +/********************************************************** + Polling structure used by cx231xx IR's + **********************************************************/ + +struct cx231xx_ir_poll_result { + unsigned int toggle_bit:1; + unsigned int read_count:7; + u8 rc_address; + u8 rc_data[4]; +}; + +struct cx231xx_IR { + struct cx231xx *dev; + struct input_dev *input; + struct ir_input_state ir; + char name[32]; + char phys[32]; + + /* poll external decoder */ + int polling; + struct work_struct work; + struct timer_list timer; + unsigned int last_toggle:1; + unsigned int last_readcount; + unsigned int repeat_interval; + + int (*get_key) (struct cx231xx_IR *, struct cx231xx_ir_poll_result *); +}; + +/********************************************************** + Polling code for cx231xx + **********************************************************/ + +static void cx231xx_ir_handle_key(struct cx231xx_IR *ir) +{ + int result; + int do_sendkey = 0; + struct cx231xx_ir_poll_result poll_result; + + /* read the registers containing the IR status */ + result = ir->get_key(ir, &poll_result); + if (result < 0) { + dprintk("ir->get_key() failed %d\n", result); + return; + } + + dprintk("ir->get_key result tb=%02x rc=%02x lr=%02x data=%02x\n", + poll_result.toggle_bit, poll_result.read_count, + ir->last_readcount, poll_result.rc_data[0]); + + if (ir->dev->chip_id == CHIP_ID_EM2874) { + /* The em2874 clears the readcount field every time the + register is read. The em2860/2880 datasheet says that it + is supposed to clear the readcount, but it doesn't. So with + the em2874, we are looking for a non-zero read count as + opposed to a readcount that is incrementing */ + ir->last_readcount = 0; + } + + if (poll_result.read_count == 0) { + /* The button has not been pressed since the last read */ + } else if (ir->last_toggle != poll_result.toggle_bit) { + /* A button has been pressed */ + dprintk("button has been pressed\n"); + ir->last_toggle = poll_result.toggle_bit; + ir->repeat_interval = 0; + do_sendkey = 1; + } else if (poll_result.toggle_bit == ir->last_toggle && + poll_result.read_count > 0 && + poll_result.read_count != ir->last_readcount) { + /* The button is still being held down */ + dprintk("button being held down\n"); + + /* Debouncer for first keypress */ + if (ir->repeat_interval++ > 9) { + /* Start repeating after 1 second */ + do_sendkey = 1; + } + } + + if (do_sendkey) { + dprintk("sending keypress\n"); + ir_input_keydown(ir->input, &ir->ir, poll_result.rc_data[0], + poll_result.rc_data[0]); + ir_input_nokey(ir->input, &ir->ir); + } + + ir->last_readcount = poll_result.read_count; + return; +} + +static void ir_timer(unsigned long data) +{ + struct cx231xx_IR *ir = (struct cx231xx_IR *)data; + + schedule_work(&ir->work); +} + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 20) +static void cx231xx_ir_work(void *data) +#else +static void cx231xx_ir_work(struct work_struct *work) +#endif +{ +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 20) + struct cx231xx_IR *ir = data; +#else + struct cx231xx_IR *ir = container_of(work, struct cx231xx_IR, work); +#endif + + cx231xx_ir_handle_key(ir); + mod_timer(&ir->timer, jiffies + msecs_to_jiffies(ir->polling)); +} + +void cx231xx_ir_start(struct cx231xx_IR *ir) +{ + setup_timer(&ir->timer, ir_timer, (unsigned long)ir); +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 20) + INIT_WORK(&ir->work, cx231xx_ir_work, ir); +#else + INIT_WORK(&ir->work, cx231xx_ir_work); +#endif + schedule_work(&ir->work); +} + +static void cx231xx_ir_stop(struct cx231xx_IR *ir) +{ + del_timer_sync(&ir->timer); + flush_scheduled_work(); +} + +int cx231xx_ir_init(struct cx231xx *dev) +{ + struct cx231xx_IR *ir; + struct input_dev *input_dev; + u8 ir_config; + int err = -ENOMEM; + + if (dev->board.ir_codes == NULL) { + /* No remote control support */ + return 0; + } + + ir = kzalloc(sizeof(*ir), GFP_KERNEL); + input_dev = input_allocate_device(); + if (!ir || !input_dev) + goto err_out_free; + + ir->input = input_dev; + + /* Setup the proper handler based on the chip */ + switch (dev->chip_id) { + default: + printk("Unrecognized cx231xx chip id: IR not supported\n"); + goto err_out_free; + } + + /* This is how often we ask the chip for IR information */ + ir->polling = 100; /* ms */ + + /* init input device */ + snprintf(ir->name, sizeof(ir->name), "cx231xx IR (%s)", dev->name); + + usb_make_path(dev->udev, ir->phys, sizeof(ir->phys)); + strlcat(ir->phys, "/input0", sizeof(ir->phys)); + + ir_input_init(input_dev, &ir->ir, IR_TYPE_OTHER, dev->board.ir_codes); + input_dev->name = ir->name; + input_dev->phys = ir->phys; + input_dev->id.bustype = BUS_USB; + input_dev->id.version = 1; + input_dev->id.vendor = le16_to_cpu(dev->udev->descriptor.idVendor); + input_dev->id.product = le16_to_cpu(dev->udev->descriptor.idProduct); + +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 22) + input_dev->dev.parent = &dev->udev->dev; +#else + input_dev->cdev.dev = &dev->udev->dev; +#endif + /* record handles to ourself */ + ir->dev = dev; + dev->ir = ir; + + cx231xx_ir_start(ir); + + /* all done */ + err = input_register_device(ir->input); + if (err) + goto err_out_stop; + + return 0; +err_out_stop: + cx231xx_ir_stop(ir); + dev->ir = NULL; +err_out_free: + input_free_device(input_dev); + kfree(ir); + return err; +} + +int cx231xx_ir_fini(struct cx231xx *dev) +{ + struct cx231xx_IR *ir = dev->ir; + + /* skip detach on non attached boards */ + if (!ir) + return 0; + + cx231xx_ir_stop(ir); + input_unregister_device(ir->input); + kfree(ir); + + /* done */ + dev->ir = NULL; + return 0; +} diff --git a/linux/drivers/media/video/cx231xx/cx231xx-pcb-cfg.c b/linux/drivers/media/video/cx231xx/cx231xx-pcb-cfg.c new file mode 100644 index 000000000..c00f51eae --- /dev/null +++ b/linux/drivers/media/video/cx231xx/cx231xx-pcb-cfg.c @@ -0,0 +1,793 @@ +/* + cx231xx-pcb-config.c - driver for Conexant + Cx23100/101/102 USB video capture devices + + Copyright (C) 2008 <srinivasa.deevi at conexant dot 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, 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 "cx231xx.h" +#include "cx231xx-conf-reg.h" + +/******************************************************************************/ + +struct pcb_config cx231xx_Scenario[] = { + { + INDEX_SELFPOWER_DIGITAL_ONLY, /* index */ + USB_SELF_POWER, /* power_type */ + 0, /* speed , not decide yet */ + MOD_DIGITAL, /* mode */ + SOURCE_TS_BDA, /* ts1_source, digital tv only */ + NOT_SUPPORTED, /* ts2_source */ + NOT_SUPPORTED, /* analog source */ + + 0, /* digital_index */ + 0, /* analog index */ + 0, /* dif_index */ + 0, /* external_index */ + + 1, /* only one configuration */ + { + { + 0, /* config index */ + { + 0, /* interrupt ep index */ + 1, /* ts1 index */ + NOT_SUPPORTED, /* TS2 index */ + NOT_SUPPORTED, /* AUDIO */ + NOT_SUPPORTED, /* VIDEO */ + NOT_SUPPORTED, /* VANC */ + NOT_SUPPORTED, /* HANC */ + NOT_SUPPORTED /* ir_index */ + } + , + } + , + {NOT_SUPPORTED, {NOT_SUPPORTED, NOT_SUPPORTED, NOT_SUPPORTED, + NOT_SUPPORTED, NOT_SUPPORTED, NOT_SUPPORTED, + NOT_SUPPORTED} + } + , + {NOT_SUPPORTED, {NOT_SUPPORTED, NOT_SUPPORTED, NOT_SUPPORTED, + NOT_SUPPORTED, NOT_SUPPORTED, NOT_SUPPORTED, + NOT_SUPPORTED} + } + } + , + /* full-speed config */ + { + { + 0, /* config index */ + { + 0, /* interrupt ep index */ + 1, /* ts1 index */ + NOT_SUPPORTED, /* TS2 index */ + NOT_SUPPORTED, /* AUDIO */ + NOT_SUPPORTED, /* VIDEO */ + NOT_SUPPORTED, /* VANC */ + NOT_SUPPORTED, /* HANC */ + NOT_SUPPORTED /* ir_index */ + } + } + , + {NOT_SUPPORTED, {NOT_SUPPORTED, NOT_SUPPORTED, NOT_SUPPORTED, + NOT_SUPPORTED, NOT_SUPPORTED, NOT_SUPPORTED, + NOT_SUPPORTED} + } + , + {NOT_SUPPORTED, {NOT_SUPPORTED, NOT_SUPPORTED, NOT_SUPPORTED, + NOT_SUPPORTED, NOT_SUPPORTED, NOT_SUPPORTED, + NOT_SUPPORTED} + } + } + } + , + + { + INDEX_SELFPOWER_DUAL_DIGITAL, /* index */ + USB_SELF_POWER, /* power_type */ + 0, /* speed , not decide yet */ + MOD_DIGITAL, /* mode */ + SOURCE_TS_BDA, /* ts1_source, digital tv only */ + 0, /* ts2_source,need update from register */ + NOT_SUPPORTED, /* analog source */ + 0, /* digital_index */ + 0, /* analog index */ + 0, /* dif_index */ + 0, /* external_index */ + + 1, /* only one configuration */ + { + { + 0, /* config index */ + { + 0, /* interrupt ep index */ + 1, /* ts1 index */ + 2, /* TS2 index */ + NOT_SUPPORTED, /* AUDIO */ + NOT_SUPPORTED, /* VIDEO */ + NOT_SUPPORTED, /* VANC */ + NOT_SUPPORTED, /* HANC */ + NOT_SUPPORTED /* ir_index */ + } + } + , + {NOT_SUPPORTED, {NOT_SUPPORTED, NOT_SUPPORTED, NOT_SUPPORTED, + NOT_SUPPORTED, NOT_SUPPORTED, NOT_SUPPORTED, + NOT_SUPPORTED} + } + , + {NOT_SUPPORTED, {NOT_SUPPORTED, NOT_SUPPORTED, NOT_SUPPORTED, + NOT_SUPPORTED, NOT_SUPPORTED, NOT_SUPPORTED, + NOT_SUPPORTED} + } + } + , + /* full-speed */ + { + { + 0, /* config index */ + { + 0, /* interrupt ep index */ + 1, /* ts1 index */ + 2, /* TS2 index */ + NOT_SUPPORTED, /* AUDIO */ + NOT_SUPPORTED, /* VIDEO */ + NOT_SUPPORTED, /* VANC */ + NOT_SUPPORTED, /* HANC */ + NOT_SUPPORTED /* ir_index */ + } + } + , + {NOT_SUPPORTED, {NOT_SUPPORTED, NOT_SUPPORTED, NOT_SUPPORTED, + NOT_SUPPORTED, NOT_SUPPORTED, NOT_SUPPORTED, + NOT_SUPPORTED} + } + , + {NOT_SUPPORTED, {NOT_SUPPORTED, NOT_SUPPORTED, NOT_SUPPORTED, + NOT_SUPPORTED, NOT_SUPPORTED, NOT_SUPPORTED, + NOT_SUPPORTED} + } + } + } + , + + { + INDEX_SELFPOWER_ANALOG_ONLY, /* index */ + USB_SELF_POWER, /* power_type */ + 0, /* speed , not decide yet */ + MOD_ANALOG | MOD_DIF | MOD_EXTERNAL, /* mode ,analog tv only */ + NOT_SUPPORTED, /* ts1_source, NOT SUPPORT */ + NOT_SUPPORTED, /* ts2_source,NOT SUPPORT */ + 0, /* analog source, need update */ + + 0, /* digital_index */ + 0, /* analog index */ + 0, /* dif_index */ + 0, /* external_index */ + + 1, /* only one configuration */ + { + { + 0, /* config index */ + { + 0, /* interrupt ep index */ + NOT_SUPPORTED, /* ts1 index */ + NOT_SUPPORTED, /* TS2 index */ + 1, /* AUDIO */ + 2, /* VIDEO */ + 3, /* VANC */ + 4, /* HANC */ + NOT_SUPPORTED /* ir_index */ + } + } + , + {NOT_SUPPORTED, {NOT_SUPPORTED, NOT_SUPPORTED, NOT_SUPPORTED, + NOT_SUPPORTED, NOT_SUPPORTED, NOT_SUPPORTED, + NOT_SUPPORTED} + } + , + {NOT_SUPPORTED, {NOT_SUPPORTED, NOT_SUPPORTED, NOT_SUPPORTED, + NOT_SUPPORTED, NOT_SUPPORTED, NOT_SUPPORTED, + NOT_SUPPORTED} + } + } + , + /* full-speed */ + { + { + 0, /* config index */ + { + 0, /* interrupt ep index */ + NOT_SUPPORTED, /* ts1 index */ + NOT_SUPPORTED, /* TS2 index */ + 1, /* AUDIO */ + 2, /* VIDEO */ + NOT_SUPPORTED, /* VANC */ + NOT_SUPPORTED, /* HANC */ + NOT_SUPPORTED /* ir_index */ + } + } + , + {NOT_SUPPORTED, {NOT_SUPPORTED, NOT_SUPPORTED, NOT_SUPPORTED, + NOT_SUPPORTED, NOT_SUPPORTED, NOT_SUPPORTED, + NOT_SUPPORTED} + } + , + {NOT_SUPPORTED, {NOT_SUPPORTED, NOT_SUPPORTED, NOT_SUPPORTED, + NOT_SUPPORTED, NOT_SUPPORTED, NOT_SUPPORTED, + NOT_SUPPORTED} + } + } + } + , + + { + INDEX_SELFPOWER_DUAL, /* index */ + USB_SELF_POWER, /* power_type */ + 0, /* speed , not decide yet */ + /* mode ,analog tv and digital path */ + MOD_ANALOG | MOD_DIF | MOD_DIGITAL | MOD_EXTERNAL, + 0, /* ts1_source,will update in register */ + NOT_SUPPORTED, /* ts2_source,NOT SUPPORT */ + 0, /* analog source need update */ + 0, /* digital_index */ + 0, /* analog index */ + 0, /* dif_index */ + 0, /* external_index */ + 1, /* only one configuration */ + { + { + 0, /* config index */ + { + 0, /* interrupt ep index */ + 1, /* ts1 index */ + NOT_SUPPORTED, /* TS2 index */ + 2, /* AUDIO */ + 3, /* VIDEO */ + 4, /* VANC */ + 5, /* HANC */ + NOT_SUPPORTED /* ir_index */ + } + } + , + {NOT_SUPPORTED, {NOT_SUPPORTED, NOT_SUPPORTED, NOT_SUPPORTED, + NOT_SUPPORTED, NOT_SUPPORTED, NOT_SUPPORTED, + NOT_SUPPORTED} + } + , + {NOT_SUPPORTED, {NOT_SUPPORTED, NOT_SUPPORTED, NOT_SUPPORTED, + NOT_SUPPORTED, NOT_SUPPORTED, NOT_SUPPORTED, + NOT_SUPPORTED} + } + } + , + /* full-speed */ + { + { + 0, /* config index */ + { + 0, /* interrupt ep index */ + 1, /* ts1 index */ + NOT_SUPPORTED, /* TS2 index */ + 2, /* AUDIO */ + 3, /* VIDEO */ + NOT_SUPPORTED, /* VANC */ + NOT_SUPPORTED, /* HANC */ + NOT_SUPPORTED /* ir_index */ + } + } + , + {NOT_SUPPORTED, {NOT_SUPPORTED, NOT_SUPPORTED, NOT_SUPPORTED, + NOT_SUPPORTED, NOT_SUPPORTED, NOT_SUPPORTED, + NOT_SUPPORTED} + } + , + {NOT_SUPPORTED, {NOT_SUPPORTED, NOT_SUPPORTED, NOT_SUPPORTED, + NOT_SUPPORTED, NOT_SUPPORTED, NOT_SUPPORTED, + NOT_SUPPORTED} + } + } + } + , + + { + INDEX_SELFPOWER_TRIPLE, /* index */ + USB_SELF_POWER, /* power_type */ + 0, /* speed , not decide yet */ + /* mode ,analog tv and digital path */ + MOD_ANALOG | MOD_DIF | MOD_DIGITAL | MOD_EXTERNAL, + 0, /* ts1_source, update in register */ + 0, /* ts2_source,update in register */ + 0, /* analog source, need update */ + + 0, /* digital_index */ + 0, /* analog index */ + 0, /* dif_index */ + 0, /* external_index */ + 1, /* only one configuration */ + { + { + 0, /* config index */ + { + 0, /* interrupt ep index */ + 1, /* ts1 index */ + 2, /* TS2 index */ + 3, /* AUDIO */ + 4, /* VIDEO */ + 5, /* VANC */ + 6, /* HANC */ + NOT_SUPPORTED /* ir_index */ + } + } + , + {NOT_SUPPORTED, {NOT_SUPPORTED, NOT_SUPPORTED, NOT_SUPPORTED, + NOT_SUPPORTED, NOT_SUPPORTED, NOT_SUPPORTED, + NOT_SUPPORTED} + } + , + {NOT_SUPPORTED, {NOT_SUPPORTED, NOT_SUPPORTED, NOT_SUPPORTED, + NOT_SUPPORTED, NOT_SUPPORTED, NOT_SUPPORTED, + NOT_SUPPORTED} + } + } + , + /* full-speed */ + { + { + 0, /* config index */ + { + 0, /* interrupt ep index */ + 1, /* ts1 index */ + 2, /* TS2 index */ + 3, /* AUDIO */ + 4, /* VIDEO */ + NOT_SUPPORTED, /* VANC */ + NOT_SUPPORTED, /* HANC */ + NOT_SUPPORTED /* ir_index */ + } + } + , + {NOT_SUPPORTED, {NOT_SUPPORTED, NOT_SUPPORTED, NOT_SUPPORTED, + NOT_SUPPORTED, NOT_SUPPORTED, NOT_SUPPORTED, + NOT_SUPPORTED} + } + , + {NOT_SUPPORTED, {NOT_SUPPORTED, NOT_SUPPORTED, NOT_SUPPORTED, + NOT_SUPPORTED, NOT_SUPPORTED, NOT_SUPPORTED, + NOT_SUPPORTED} + } + } + } + , + + { + INDEX_SELFPOWER_COMPRESSOR, /* index */ + USB_SELF_POWER, /* power_type */ + 0, /* speed , not decide yet */ + /* mode ,analog tv AND DIGITAL path */ + MOD_ANALOG | MOD_DIF | MOD_DIGITAL | MOD_EXTERNAL, + NOT_SUPPORTED, /* ts1_source, disable */ + SOURCE_TS_BDA, /* ts2_source */ + 0, /* analog source,need update */ + 0, /* digital_index */ + 0, /* analog index */ + 0, /* dif_index */ + 0, /* external_index */ + 1, /* only one configuration */ + { + { + 0, /* config index */ + { + 0, /* interrupt ep index */ + NOT_SUPPORTED, /* ts1 index */ + 1, /* TS2 index */ + 2, /* AUDIO */ + 3, /* VIDEO */ + 4, /* VANC */ + 5, /* HANC */ + NOT_SUPPORTED /* ir_index */ + } + } + , + {NOT_SUPPORTED, {NOT_SUPPORTED, NOT_SUPPORTED, NOT_SUPPORTED, + NOT_SUPPORTED, NOT_SUPPORTED, NOT_SUPPORTED, + NOT_SUPPORTED} + } + , + {NOT_SUPPORTED, {NOT_SUPPORTED, NOT_SUPPORTED, NOT_SUPPORTED, + NOT_SUPPORTED, NOT_SUPPORTED, NOT_SUPPORTED, + NOT_SUPPORTED} + } + } + , + /* full-speed */ + { + { + 0, /* config index */ + { + 0, /* interrupt ep index */ + NOT_SUPPORTED, /* ts1 index */ + 1, /* TS2 index */ + 2, /* AUDIO */ + 3, /* VIDEO */ + NOT_SUPPORTED, /* VANC */ + NOT_SUPPORTED, /* HANC */ + NOT_SUPPORTED /* ir_index */ + } + } + , + {NOT_SUPPORTED, {NOT_SUPPORTED, NOT_SUPPORTED, NOT_SUPPORTED, + NOT_SUPPORTED, NOT_SUPPORTED, NOT_SUPPORTED, + NOT_SUPPORTED} + } + , + {NOT_SUPPORTED, {NOT_SUPPORTED, NOT_SUPPORTED, NOT_SUPPORTED, + NOT_SUPPORTED, NOT_SUPPORTED, NOT_SUPPORTED, + NOT_SUPPORTED} + } + } + } + , + + { + INDEX_BUSPOWER_DIGITAL_ONLY, /* index */ + USB_BUS_POWER, /* power_type */ + 0, /* speed , not decide yet */ + MOD_DIGITAL, /* mode ,analog tv AND DIGITAL path */ + SOURCE_TS_BDA, /* ts1_source, disable */ + NOT_SUPPORTED, /* ts2_source */ + NOT_SUPPORTED, /* analog source */ + + 0, /* digital_index */ + 0, /* analog index */ + 0, /* dif_index */ + 0, /* external_index */ + + 1, /* only one configuration */ + { + { + 0, /* config index */ + { + 0, /* interrupt ep index = 2 */ + 1, /* ts1 index */ + NOT_SUPPORTED, /* TS2 index */ + NOT_SUPPORTED, /* AUDIO */ + NOT_SUPPORTED, /* VIDEO */ + NOT_SUPPORTED, /* VANC */ + NOT_SUPPORTED, /* HANC */ + NOT_SUPPORTED /* ir_index */ + } + } + , + {NOT_SUPPORTED, {NOT_SUPPORTED, NOT_SUPPORTED, NOT_SUPPORTED, + NOT_SUPPORTED, NOT_SUPPORTED, NOT_SUPPORTED, + NOT_SUPPORTED} + } + , + {NOT_SUPPORTED, {NOT_SUPPORTED, NOT_SUPPORTED, NOT_SUPPORTED, + NOT_SUPPORTED, NOT_SUPPORTED, NOT_SUPPORTED, + NOT_SUPPORTED} + } + } + , + /* full-speed */ + { + { + 0, /* config index */ + { + 0, /* interrupt ep index = 2 */ + 1, /* ts1 index */ + NOT_SUPPORTED, /* TS2 index */ + NOT_SUPPORTED, /* AUDIO */ + NOT_SUPPORTED, /* VIDEO */ + NOT_SUPPORTED, /* VANC */ + NOT_SUPPORTED, /* HANC */ + NOT_SUPPORTED /* ir_index */ + } + } + , + {NOT_SUPPORTED, {NOT_SUPPORTED, NOT_SUPPORTED, NOT_SUPPORTED, + NOT_SUPPORTED, NOT_SUPPORTED, NOT_SUPPORTED, + NOT_SUPPORTED} + } + , + {NOT_SUPPORTED, {NOT_SUPPORTED, NOT_SUPPORTED, NOT_SUPPORTED, + NOT_SUPPORTED, NOT_SUPPORTED, NOT_SUPPORTED, + NOT_SUPPORTED} + } + } + } + , + { + INDEX_BUSPOWER_ANALOG_ONLY, /* index */ + USB_BUS_POWER, /* power_type */ + 0, /* speed , not decide yet */ + MOD_ANALOG, /* mode ,analog tv AND DIGITAL path */ + NOT_SUPPORTED, /* ts1_source, disable */ + NOT_SUPPORTED, /* ts2_source */ + SOURCE_ANALOG, /* analog source--analog */ + 0, /* digital_index */ + 0, /* analog index */ + 0, /* dif_index */ + 0, /* external_index */ + 1, /* only one configuration */ + { + { + 0, /* config index */ + { + 0, /* interrupt ep index */ + NOT_SUPPORTED, /* ts1 index */ + NOT_SUPPORTED, /* TS2 index */ + 1, /* AUDIO */ + 2, /* VIDEO */ + 3, /* VANC */ + 4, /* HANC */ + NOT_SUPPORTED /* ir_index */ + } + } + , + {NOT_SUPPORTED, {NOT_SUPPORTED, NOT_SUPPORTED, NOT_SUPPORTED, + NOT_SUPPORTED, NOT_SUPPORTED, NOT_SUPPORTED, + NOT_SUPPORTED} + } + , + {NOT_SUPPORTED, {NOT_SUPPORTED, NOT_SUPPORTED, NOT_SUPPORTED, + NOT_SUPPORTED, NOT_SUPPORTED, NOT_SUPPORTED, + NOT_SUPPORTED} + } + } + , + { /* full-speed */ + { + 0, /* config index */ + { + 0, /* interrupt ep index */ + NOT_SUPPORTED, /* ts1 index */ + NOT_SUPPORTED, /* TS2 index */ + 1, /* AUDIO */ + 2, /* VIDEO */ + NOT_SUPPORTED, /* VANC */ + NOT_SUPPORTED, /* HANC */ + NOT_SUPPORTED /* ir_index */ + } + } + , + {NOT_SUPPORTED, {NOT_SUPPORTED, NOT_SUPPORTED, NOT_SUPPORTED, + NOT_SUPPORTED, NOT_SUPPORTED, NOT_SUPPORTED, + NOT_SUPPORTED} + } + , + {NOT_SUPPORTED, {NOT_SUPPORTED, NOT_SUPPORTED, NOT_SUPPORTED, + NOT_SUPPORTED, NOT_SUPPORTED, NOT_SUPPORTED, + NOT_SUPPORTED} + } + } + } + , + { + INDEX_BUSPOWER_DIF_ONLY, /* index */ + USB_BUS_POWER, /* power_type */ + 0, /* speed , not decide yet */ + /* mode ,analog tv AND DIGITAL path */ + MOD_DIF | MOD_ANALOG | MOD_DIGITAL | MOD_EXTERNAL, + SOURCE_TS_BDA, /* ts1_source, disable */ + NOT_SUPPORTED, /* ts2_source */ + SOURCE_DIF | SOURCE_ANALOG | SOURCE_EXTERNAL, /* analog source, dif */ + 0, /* digital_index */ + 0, /* analog index */ + 0, /* dif_index */ + 0, /* external_index */ + 1, /* only one configuration */ + { + { + 0, /* config index */ + { + 0, /* interrupt ep index */ + 1, /* ts1 index */ + NOT_SUPPORTED, /* TS2 index */ + 2, /* AUDIO */ + 3, /* VIDEO */ + 4, /* VANC */ + 5, /* HANC */ + NOT_SUPPORTED /* ir_index */ + } + } + , + {NOT_SUPPORTED, {NOT_SUPPORTED, NOT_SUPPORTED, NOT_SUPPORTED, + NOT_SUPPORTED, NOT_SUPPORTED, NOT_SUPPORTED, + NOT_SUPPORTED} + } + , + {NOT_SUPPORTED, {NOT_SUPPORTED, NOT_SUPPORTED, NOT_SUPPORTED, + NOT_SUPPORTED, NOT_SUPPORTED, NOT_SUPPORTED, + NOT_SUPPORTED} + } + } + , + { /* full speed */ + { + 0, /* config index */ + { + 0, /* interrupt ep index */ + 1, /* ts1 index */ + NOT_SUPPORTED, /* TS2 index */ + 2, /* AUDIO */ + 3, /* VIDEO */ + NOT_SUPPORTED, /* VANC */ + NOT_SUPPORTED, /* HANC */ + NOT_SUPPORTED /* ir_index */ + } + } + , + {NOT_SUPPORTED, {NOT_SUPPORTED, NOT_SUPPORTED, NOT_SUPPORTED, + NOT_SUPPORTED, NOT_SUPPORTED, NOT_SUPPORTED, + NOT_SUPPORTED} + } + , + {NOT_SUPPORTED, {NOT_SUPPORTED, NOT_SUPPORTED, NOT_SUPPORTED, + NOT_SUPPORTED, NOT_SUPPORTED, NOT_SUPPORTED, + NOT_SUPPORTED} + } + } + } + , + +}; + +/*****************************************************************/ + +u32 initialize_cx231xx(struct cx231xx *dev) +{ + u32 config_info = 0; + struct pcb_config *p_pcb_info; + u8 usb_speed = 1; /* from register,1--HS, 0--FS */ + u8 data[4] = { 0, 0, 0, 0 }; + 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; + + /* read board config register to find out which + pcb config it is related to */ + 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 */ + if (config_info & BUS_POWER) { /* bus-power */ + switch (config_info & BUSPOWER_MASK) { + case TS1_PORT | BUS_POWER: + cx231xx_Scenario[INDEX_BUSPOWER_DIGITAL_ONLY].speed = + usb_speed; + p_pcb_info = + &cx231xx_Scenario[INDEX_BUSPOWER_DIGITAL_ONLY]; + _current_scenario_idx = INDEX_BUSPOWER_DIGITAL_ONLY; + break; + case AVDEC_ENABLE | BUS_POWER: + cx231xx_Scenario[INDEX_BUSPOWER_ANALOG_ONLY].speed = + usb_speed; + p_pcb_info = + &cx231xx_Scenario[INDEX_BUSPOWER_ANALOG_ONLY]; + _current_scenario_idx = INDEX_BUSPOWER_ANALOG_ONLY; + break; + case AVDEC_ENABLE | BUS_POWER | TS1_PORT: + cx231xx_Scenario[INDEX_BUSPOWER_DIF_ONLY].speed = + usb_speed; + p_pcb_info = &cx231xx_Scenario[INDEX_BUSPOWER_DIF_ONLY]; + _current_scenario_idx = INDEX_BUSPOWER_DIF_ONLY; + break; + default: + cx231xx_info("bad config in buspower!!!!\n"); + cx231xx_info("config_info=%x\n", + (config_info & BUSPOWER_MASK)); + return 1; + } + } else { /* self-power */ + + switch (config_info & SELFPOWER_MASK) { + case TS1_PORT | SELF_POWER: + cx231xx_Scenario[INDEX_SELFPOWER_DIGITAL_ONLY].speed = + usb_speed; + p_pcb_info = + &cx231xx_Scenario[INDEX_SELFPOWER_DIGITAL_ONLY]; + _current_scenario_idx = INDEX_SELFPOWER_DIGITAL_ONLY; + break; + case TS1_TS2_PORT | SELF_POWER: + cx231xx_Scenario[INDEX_SELFPOWER_DUAL_DIGITAL].speed = + usb_speed; + cx231xx_Scenario[INDEX_SELFPOWER_DUAL_DIGITAL]. + ts2_source = ts2_source; + p_pcb_info = + &cx231xx_Scenario[INDEX_SELFPOWER_DUAL_DIGITAL]; + _current_scenario_idx = INDEX_SELFPOWER_DUAL_DIGITAL; + break; + case AVDEC_ENABLE | SELF_POWER: + cx231xx_Scenario[INDEX_SELFPOWER_ANALOG_ONLY].speed = + usb_speed; + cx231xx_Scenario[INDEX_SELFPOWER_ANALOG_ONLY]. + analog_source = analog_source; + p_pcb_info = + &cx231xx_Scenario[INDEX_SELFPOWER_ANALOG_ONLY]; + _current_scenario_idx = INDEX_SELFPOWER_ANALOG_ONLY; + break; + case AVDEC_ENABLE | TS1_PORT | SELF_POWER: + cx231xx_Scenario[INDEX_SELFPOWER_DUAL].speed = + usb_speed; + cx231xx_Scenario[INDEX_SELFPOWER_DUAL].ts1_source = + ts1_source; + cx231xx_Scenario[INDEX_SELFPOWER_DUAL].analog_source = + analog_source; + p_pcb_info = &cx231xx_Scenario[INDEX_SELFPOWER_DUAL]; + _current_scenario_idx = INDEX_SELFPOWER_DUAL; + break; + case AVDEC_ENABLE | TS1_TS2_PORT | SELF_POWER: + cx231xx_Scenario[INDEX_SELFPOWER_TRIPLE].speed = + usb_speed; + cx231xx_Scenario[INDEX_SELFPOWER_TRIPLE].ts1_source = + ts1_source; + cx231xx_Scenario[INDEX_SELFPOWER_TRIPLE].ts2_source = + ts2_source; + cx231xx_Scenario[INDEX_SELFPOWER_TRIPLE].analog_source = + analog_source; + p_pcb_info = &cx231xx_Scenario[INDEX_SELFPOWER_TRIPLE]; + _current_scenario_idx = INDEX_SELFPOWER_TRIPLE; + break; + case AVDEC_ENABLE | TS1VIP_TS2_PORT | SELF_POWER: + cx231xx_Scenario[INDEX_SELFPOWER_COMPRESSOR].speed = + usb_speed; + cx231xx_Scenario[INDEX_SELFPOWER_COMPRESSOR]. + analog_source = analog_source; + p_pcb_info = + &cx231xx_Scenario[INDEX_SELFPOWER_COMPRESSOR]; + _current_scenario_idx = INDEX_SELFPOWER_COMPRESSOR; + break; + default: + cx231xx_info("bad senario!!!!!\n"); + cx231xx_info("config_info=%x\n", + (config_info & SELFPOWER_MASK)); + return 1; + } + } + + dev->current_scenario_idx = _current_scenario_idx; + + 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); + /*******************************************************************/ + + return 0; +} diff --git a/linux/drivers/media/video/cx231xx/cx231xx-pcb-cfg.h b/linux/drivers/media/video/cx231xx/cx231xx-pcb-cfg.h new file mode 100644 index 000000000..86fec113f --- /dev/null +++ b/linux/drivers/media/video/cx231xx/cx231xx-pcb-cfg.h @@ -0,0 +1,235 @@ +/* + cx231xx-pcb-cfg.h - driver for Conexant + Cx23100/101/102 USB video capture devices + + Copyright (C) 2008 <srinivasa.deevi at conexant dot 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, 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 _PCB_CONFIG_H_ +#define _PCB_CONFIG_H_ + +#include <linux/init.h> +#include <linux/module.h> + +/*************************************************************************** + * Class Information * +***************************************************************************/ +#define CLASS_DEFAULT 0xFF + +enum VENDOR_REQUEST_TYPE { + /* Set/Get I2C */ + VRT_SET_I2C0 = 0x0, + VRT_SET_I2C1 = 0x1, + VRT_SET_I2C2 = 0x2, + VRT_GET_I2C0 = 0x4, + VRT_GET_I2C1 = 0x5, + VRT_GET_I2C2 = 0x6, + + /* Set/Get GPIO */ + VRT_SET_GPIO = 0x8, + VRT_GET_GPIO = 0x9, + + /* Set/Get GPIE */ + VRT_SET_GPIE = 0xA, + VRT_GET_GPIE = 0xB, + + /* Set/Get Register Control/Status */ + VRT_SET_REGISTER = 0xC, + VRT_GET_REGISTER = 0xD, + + /* Get Extended Compat ID Descriptor */ + VRT_GET_EXTCID_DESC = 0xFF, +}; + +enum BYTE_ENABLE_MASK { + ENABLE_ONE_BYTE = 0x1, + ENABLE_TWE_BYTE = 0x3, + ENABLE_THREE_BYTE = 0x7, + ENABLE_FOUR_BYTE = 0xF, +}; + +#define SPEED_MASK 0x1 +enum USB_SPEED{ + FULL_SPEED = 0x0, /* 0: full speed */ + HIGH_SPEED = 0x1 /* 1: high speed */ +}; + +enum _true_false{ + FALSE = 0, + TRUE = 1 +}; + +#define TS_MASK 0x6 +enum TS_PORT{ + NO_TS_PORT = 0x0, /* 2'b00: Neither port used. PCB not a Hybrid, + only offers Analog TV or Video */ + TS1_PORT = 0x4, /* 2'b10: TS1 Input (Hybrid mode : + Digital or External Analog/Compressed source) */ + TS1_TS2_PORT = 0x6, /* 2'b11: TS1 & TS2 Inputs + (Dual inputs from Digital and/or + External Analog/Compressed sources) */ + TS1_EXT_CLOCK = 0x6, /* 2'b11: TS1 & TS2 as selector + to external clock */ + TS1VIP_TS2_PORT = 0x2 /* 2'b01: TS1 used as 656/VIP Output, + TS2 Input (from Compressor) */ +}; + +#define EAVP_MASK 0x8 +enum EAV_PRESENT{ + NO_EXTERNAL_AV = 0x0, /* 0: No External A/V inputs + (no need for Flatiron), + Analog Tuner must be present */ + EXTERNAL_AV = 0x8 /* 1: External A/V inputs + present (requires Flatiron) */ +}; + +#define ATM_MASK 0x30 +enum AT_MODE{ + DIF_TUNER = 0x30, /* 2'b11: IF Tuner (requires use of DIF) */ + BASEBAND_SOUND = 0x20, /* 2'b10: Baseband Composite & + Sound-IF Signals present */ + NO_TUNER = 0x10 /* 2'b0x: No Analog Tuner present */ +}; + +#define PWR_SEL_MASK 0x40 +enum POWE_TYPE{ + SELF_POWER = 0x0, /* 0: self power */ + BUS_POWER = 0x40 /* 1: bus power */ +}; + +enum USB_POWE_TYPE{ + USB_SELF_POWER = 0, + USB_BUS_POWER +}; + +#define BO_0_MASK 0x80 +enum AVDEC_STATUS{ + AVDEC_DISABLE = 0x0, /* 0: A/V Decoder Disabled */ + AVDEC_ENABLE = 0x80 /* 1: A/V Decoder Enabled */ +}; + +#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 + +/***************************************************************************/ +#define NOT_DECIDE_YET 0xFE +#define NOT_SUPPORTED 0xFF + +/*************************************************************************** + * for mod field use * +***************************************************************************/ +#define MOD_DIGITAL 0x1 +#define MOD_ANALOG 0x2 +#define MOD_DIF 0x4 +#define MOD_EXTERNAL 0x8 +#define CAP_ALL_MOD 0x0f + +/*************************************************************************** + * source define * +***************************************************************************/ +#define SOURCE_DIGITAL 0x1 +#define SOURCE_ANALOG 0x2 +#define SOURCE_DIF 0x4 +#define SOURCE_EXTERNAL 0x8 +#define SOURCE_TS_BDA 0x10 +#define SOURCE_TS_ENCODE 0x20 +#define SOURCE_TS_EXTERNAL 0x40 + +/*************************************************************************** + * interface information define * +***************************************************************************/ +struct INTERFACE_INFO { + u8 interrupt_index; + u8 ts1_index; + u8 ts2_index; + u8 audio_index; + u8 video_index; + u8 vanc_index; /* VBI */ + u8 hanc_index; /* Sliced CC */ + u8 ir_index; +}; + +enum INDEX_INTERFACE_INFO{ + INDEX_INTERRUPT = 0x0, + INDEX_TS1, + INDEX_TS2, + INDEX_AUDIO, + INDEX_VIDEO, + INDEX_VANC, + INDEX_HANC, + INDEX_IR, +}; + +/*************************************************************************** + * configuration information define * +***************************************************************************/ +struct CONFIG_INFO { + u8 config_index; + struct INTERFACE_INFO interface_info; +}; + +struct pcb_config { + u8 index; + u8 type; /* bus power or self power, + self power--0, bus_power--1 */ + u8 speed; /* usb speed, 2.0--1, 1.1--0 */ + u8 mode; /* digital , anlog, dif or external A/V */ + u32 ts1_source; /* three source -- BDA,External,encode */ + u32 ts2_source; + u32 analog_source; + u8 digital_index; /* bus-power used */ + u8 analog_index; /* bus-power used */ + u8 dif_index; /* bus-power used */ + u8 external_index; /* bus-power used */ + u8 config_num; /* current config num, 0,1,2, + for self-power, always 0 */ + struct CONFIG_INFO hs_config_info[3]; + struct CONFIG_INFO fs_config_info[3]; +}; + +enum INDEX_PCB_CONFIG{ + INDEX_SELFPOWER_DIGITAL_ONLY = 0x0, + INDEX_SELFPOWER_DUAL_DIGITAL, + INDEX_SELFPOWER_ANALOG_ONLY, + INDEX_SELFPOWER_DUAL, + INDEX_SELFPOWER_TRIPLE, + INDEX_SELFPOWER_COMPRESSOR, + INDEX_BUSPOWER_DIGITAL_ONLY, + INDEX_BUSPOWER_ANALOG_ONLY, + INDEX_BUSPOWER_DIF_ONLY, + INDEX_BUSPOWER_EXTERNAL_ONLY, + INDEX_BUSPOWER_EXTERNAL_ANALOG, + INDEX_BUSPOWER_EXTERNAL_DIF, + INDEX_BUSPOWER_EXTERNAL_DIGITAL, + INDEX_BUSPOWER_DIGITAL_ANALOG, + INDEX_BUSPOWER_DIGITAL_DIF, + INDEX_BUSPOWER_DIGITAL_ANALOG_EXTERNAL, + INDEX_BUSPOWER_DIGITAL_DIF_EXTERNAL, +}; + +/***************************************************************************/ +struct cx231xx; + +u32 initialize_cx231xx(struct cx231xx *p_dev); + +#endif diff --git a/linux/drivers/media/video/cx231xx/cx231xx-reg.h b/linux/drivers/media/video/cx231xx/cx231xx-reg.h new file mode 100644 index 000000000..750c5d37d --- /dev/null +++ b/linux/drivers/media/video/cx231xx/cx231xx-reg.h @@ -0,0 +1,1564 @@ +/* + cx231xx-reg.h - driver for Conexant Cx23100/101/102 + USB video capture devices + + Copyright (C) 2008 <srinivasa.deevi at conexant dot 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, 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 _CX231XX_REG_H +#define _CX231XX_REG_H + +/***************************************************************************** + * VBI codes * +*****************************************************************************/ + +#define SAV_ACTIVE_VIDEO_FIELD1 0x80 +#define EAV_ACTIVE_VIDEO_FIELD1 0x90 + +#define SAV_ACTIVE_VIDEO_FIELD2 0xc0 +#define EAV_ACTIVE_VIDEO_FIELD2 0xd0 + +#define SAV_VBLANK_FIELD1 0xa0 +#define EAV_VBLANK_FIELD1 0xb0 + +#define SAV_VBLANK_FIELD2 0xe0 +#define EAV_VBLANK_FIELD2 0xf0 + +#define SAV_VBI_FIELD1 0x20 +#define EAV_VBI_FIELD1 0x30 + +#define SAV_VBI_FIELD2 0x60 +#define EAV_VBI_FIELD2 0x70 + +/*****************************************************************************/ +/* Audio ADC Registers */ +#define CH_PWR_CTRL1 0x0000000e +#define CH_PWR_CTRL2 0x0000000f +/*****************************************************************************/ + +#define HOST_REG1 0x000 +#define FLD_FORCE_CHIP_SEL 0x80 +#define FLD_AUTO_INC_DIS 0x20 +#define FLD_PREFETCH_EN 0x10 +/* Reserved [2:3] */ +#define FLD_DIGITAL_PWR_DN 0x02 +#define FLD_SLEEP 0x01 + +/*****************************************************************************/ +#define HOST_REG2 0x001 + +/*****************************************************************************/ +#define HOST_REG3 0x002 + +/*****************************************************************************/ +/* added for polaris */ +#define GPIO_PIN_CTL0 0x3 +#define GPIO_PIN_CTL1 0x4 +#define GPIO_PIN_CTL2 0x5 +#define GPIO_PIN_CTL3 0x6 +#define TS1_PIN_CTL0 0x7 +#define TS1_PIN_CTL1 0x8 +/*****************************************************************************/ + +#define FLD_CLK_IN_EN 0x80 +#define FLD_XTAL_CTRL 0x70 +#define FLD_BB_CLK_MODE 0x0C +#define FLD_REF_DIV_PLL 0x02 +#define FLD_REF_SEL_PLL1 0x01 + +/*****************************************************************************/ +#define CHIP_CTRL 0x100 +/* Reserved [27] */ +/* Reserved [31:21] */ +#define FLD_CHIP_ACFG_DIS 0x00100000 +/* Reserved [19] */ +#define FLD_DUAL_MODE_ADC2 0x00040000 +#define FLD_SIF_EN 0x00020000 +#define FLD_SOFT_RST 0x00010000 +#define FLD_DEVICE_ID 0x0000ffff + +/*****************************************************************************/ +#define AFE_CTRL 0x104 +#define AFE_CTRL_C2HH_SRC_CTRL 0x104 +#define FLD_DIF_OUT_SEL 0xc0000000 +#define FLD_AUX_PLL_CLK_ALT_SEL 0x3c000000 +#define FLD_UV_ORDER_MODE 0x02000000 +#define FLD_FUNC_MODE 0x01800000 +#define FLD_ROT1_PHASE_CTL 0x007f8000 +#define FLD_AUD_IN_SEL 0x00004000 +#define FLD_LUMA_IN_SEL 0x00002000 +#define FLD_CHROMA_IN_SEL 0x00001000 +/* reserve [11:10] */ +#define FLD_INV_SPEC_DIS 0x00000200 +#define FLD_VGA_SEL_CH3 0x00000100 +#define FLD_VGA_SEL_CH2 0x00000080 +#define FLD_VGA_SEL_CH1 0x00000040 +#define FLD_DCR_BYP_CH1 0x00000020 +#define FLD_DCR_BYP_CH2 0x00000010 +#define FLD_DCR_BYP_CH3 0x00000008 +#define FLD_EN_12DB_CH3 0x00000004 +#define FLD_EN_12DB_CH2 0x00000002 +#define FLD_EN_12DB_CH1 0x00000001 + +/* redefine in Cx231xx */ +/*****************************************************************************/ +#define DC_CTRL1 0x108 +/* reserve [31:30] */ +#define FLD_CLAMP_LVL_CH1 0x3fff8000 +#define FLD_CLAMP_LVL_CH2 0x00007fff +/*****************************************************************************/ + +/*****************************************************************************/ +#define DC_CTRL2 0x10c +/* reserve [31:28] */ +#define FLD_CLAMP_LVL_CH3 0x00fffe00 +#define FLD_CLAMP_WIND_LENTH 0x000001e0 +#define FLD_C2HH_SAT_MIN 0x0000001e +#define FLD_FLT_BYP_SEL 0x00000001 +/*****************************************************************************/ + +/*****************************************************************************/ +#define DC_CTRL3 0x110 +/* reserve [31:16] */ +#define FLD_ERR_GAIN_CTL 0x00070000 +#define FLD_LPF_MIN 0x0000ffff +/*****************************************************************************/ + +/*****************************************************************************/ +#define DC_CTRL4 0x114 +/* reserve [31:31] */ +#define FLD_INTG_CH1 0x7fffffff +/*****************************************************************************/ + +/*****************************************************************************/ +#define DC_CTRL5 0x118 +/* reserve [31:31] */ +#define FLD_INTG_CH2 0x7fffffff +/*****************************************************************************/ + +/*****************************************************************************/ +#define DC_CTRL6 0x11c +/* reserve [31:31] */ +#define FLD_INTG_CH3 0x7fffffff +/*****************************************************************************/ + +/*****************************************************************************/ +#define PIN_CTRL 0x120 +#define FLD_OEF_AGC_RF 0x00000001 +#define FLD_OEF_AGC_IFVGA 0x00000002 +#define FLD_OEF_AGC_IF 0x00000004 +#define FLD_REG_BO_PUD 0x80000000 +#define FLD_IR_IRQ_STAT 0x40000000 +#define FLD_AUD_IRQ_STAT 0x20000000 +#define FLD_VID_IRQ_STAT 0x10000000 +/* Reserved [27:26] */ +#define FLD_IRQ_N_OUT_EN 0x02000000 +#define FLD_IRQ_N_POLAR 0x01000000 +/* Reserved [23:6] */ +#define FLD_OE_AUX_PLL_CLK 0x00000020 +#define FLD_OE_I2S_BCLK 0x00000010 +#define FLD_OE_I2S_WCLK 0x00000008 +#define FLD_OE_AGC_IF 0x00000004 +#define FLD_OE_AGC_IFVGA 0x00000002 +#define FLD_OE_AGC_RF 0x00000001 + +/*****************************************************************************/ +#define AUD_IO_CTRL 0x124 +/* Reserved [31:8] */ +#define FLD_I2S_PORT_DIR 0x00000080 +#define FLD_I2S_OUT_SRC 0x00000040 +#define FLD_AUD_CHAN3_SRC 0x00000030 +#define FLD_AUD_CHAN2_SRC 0x0000000c +#define FLD_AUD_CHAN1_SRC 0x00000003 + +/*****************************************************************************/ +#define AUD_LOCK1 0x128 +#define FLD_AUD_LOCK_KI_SHIFT 0xc0000000 +#define FLD_AUD_LOCK_KD_SHIFT 0x30000000 +/* Reserved [27:25] */ +#define FLD_EN_AV_LOCK 0x01000000 +#define FLD_VID_COUNT 0x00ffffff + +/*****************************************************************************/ +#define AUD_LOCK2 0x12c +#define FLD_AUD_LOCK_KI_MULT 0xf0000000 +#define FLD_AUD_LOCK_KD_MULT 0x0F000000 +/* Reserved [23:22] */ +#define FLD_AUD_LOCK_FREQ_SHIFT 0x00300000 +#define FLD_AUD_COUNT 0x000fffff + +/*****************************************************************************/ +#define AFE_DIAG_CTRL1 0x134 +/* Reserved [31:16] */ +#define FLD_CUV_DLY_LENGTH 0x0000ff00 +#define FLD_YC_DLY_LENGTH 0x000000ff + +/*****************************************************************************/ +/* Poalris redefine */ +#define AFE_DIAG_CTRL3 0x138 +/* Reserved [31:26] */ +#define FLD_AUD_DUAL_FLAG_POL 0x02000000 +#define FLD_VID_DUAL_FLAG_POL 0x01000000 +/* Reserved [23:23] */ +#define FLD_COL_CLAMP_DIS_CH1 0x00400000 +#define FLD_COL_CLAMP_DIS_CH2 0x00200000 +#define FLD_COL_CLAMP_DIS_CH3 0x00100000 + +#define TEST_CTRL1 0x144 +/* Reserved [31:29] */ +#define FLD_LBIST_EN 0x10000000 +/* Reserved [27:10] */ +#define FLD_FI_BIST_INTR_R 0x0000200 +#define FLD_FI_BIST_INTR_L 0x0000100 +#define FLD_BIST_FAIL_AUD_PLL 0x0000080 +#define FLD_BIST_INTR_AUD_PLL 0x0000040 +#define FLD_BIST_FAIL_VID_PLL 0x0000020 +#define FLD_BIST_INTR_VID_PLL 0x0000010 +/* Reserved [3:1] */ +#define FLD_CIR_TEST_DIS 0x00000001 + +/*****************************************************************************/ +#define TEST_CTRL2 0x148 +#define FLD_TSXCLK_POL_CTL 0x80000000 +#define FLD_ISO_CTL_SEL 0x40000000 +#define FLD_ISO_CTL_EN 0x20000000 +#define FLD_BIST_DEBUGZ 0x10000000 +#define FLD_AUD_BIST_TEST_H 0x0f000000 +/* Reserved [23:22] */ +#define FLD_FLTRN_BIST_TEST_H 0x00020000 +#define FLD_VID_BIST_TEST_H 0x00010000 +/* Reserved [19:17] */ +#define FLD_BIST_TEST_H 0x00010000 +/* Reserved [15:13] */ +#define FLD_TAB_EN 0x00001000 +/* Reserved [11:0] */ + +/*****************************************************************************/ +#define BIST_STAT 0x14c +#define FLD_AUD_BIST_FAIL_H 0xfff00000 +#define FLD_FLTRN_BIST_FAIL_H 0x00180000 +#define FLD_VID_BIST_FAIL_H 0x00070000 +#define FLD_AUD_BIST_TST_DONE 0x0000fff0 +#define FLD_FLTRN_BIST_TST_DONE 0x00000008 +#define FLD_VID_BIST_TST_DONE 0x00000007 + +/*****************************************************************************/ +/* DirectIF registers definition have been moved to DIF_reg.h */ +/*****************************************************************************/ +#define MODE_CTRL 0x400 +#define FLD_AFD_PAL60_DIS 0x20000000 +#define FLD_AFD_FORCE_SECAM 0x10000000 +#define FLD_AFD_FORCE_PALNC 0x08000000 +#define FLD_AFD_FORCE_PAL 0x04000000 +#define FLD_AFD_PALM_SEL 0x03000000 +#define FLD_CKILL_MODE 0x00300000 +#define FLD_COMB_NOTCH_MODE 0x00c00000 /* bit[19:18] */ +#define FLD_CLR_LOCK_STAT 0x00020000 +#define FLD_FAST_LOCK_MD 0x00010000 +#define FLD_WCEN 0x00008000 +#define FLD_CAGCEN 0x00004000 +#define FLD_CKILLEN 0x00002000 +#define FLD_AUTO_SC_LOCK 0x00001000 +#define FLD_MAN_SC_FAST_LOCK 0x00000800 +#define FLD_INPUT_MODE 0x00000600 +#define FLD_AFD_ACQUIRE 0x00000100 +#define FLD_AFD_NTSC_SEL 0x00000080 +#define FLD_AFD_PAL_SEL 0x00000040 +#define FLD_ACFG_DIS 0x00000020 +#define FLD_SQ_PIXEL 0x00000010 +#define FLD_VID_FMT_SEL 0x0000000f + +/*****************************************************************************/ +#define OUT_CTRL1 0x404 +#define FLD_POLAR 0x7f000000 +/* Reserved [23] */ +#define FLD_RND_MODE 0x00600000 +#define FLD_VIPCLAMP_EN 0x00100000 +#define FLD_VIPBLANK_EN 0x00080000 +#define FLD_VIP_OPT_AL 0x00040000 +#define FLD_IDID0_SOURCE 0x00020000 +#define FLD_DCMODE 0x00010000 +#define FLD_CLK_GATING 0x0000c000 +#define FLD_CLK_INVERT 0x00002000 +#define FLD_HSFMT 0x00001000 +#define FLD_VALIDFMT 0x00000800 +#define FLD_ACTFMT 0x00000400 +#define FLD_SWAPRAW 0x00000200 +#define FLD_CLAMPRAW_EN 0x00000100 +#define FLD_BLUE_FIELD_EN 0x00000080 +#define FLD_BLUE_FIELD_ACT 0x00000040 +#define FLD_TASKBIT_VAL 0x00000020 +#define FLD_ANC_DATA_EN 0x00000010 +#define FLD_VBIHACTRAW_EN 0x00000008 +#define FLD_MODE10B 0x00000004 +#define FLD_OUT_MODE 0x00000003 + +/*****************************************************************************/ +#define OUT_CTRL2 0x408 +#define FLD_AUD_GRP 0xc0000000 +#define FLD_SAMPLE_RATE 0x30000000 +#define FLD_AUD_ANC_EN 0x08000000 +#define FLD_EN_C 0x04000000 +#define FLD_EN_B 0x02000000 +#define FLD_EN_A 0x01000000 +/* Reserved [23:20] */ +#define FLD_IDID1_LSB 0x000c0000 +#define FLD_IDID0_LSB 0x00030000 +#define FLD_IDID1_MSB 0x0000ff00 +#define FLD_IDID0_MSB 0x000000ff + +/*****************************************************************************/ +#define GEN_STAT 0x40c +#define FLD_VCR_DETECT 0x00800000 +#define FLD_SPECIAL_PLAY_N 0x00400000 +#define FLD_VPRES 0x00200000 +#define FLD_AGC_LOCK 0x00100000 +#define FLD_CSC_LOCK 0x00080000 +#define FLD_VLOCK 0x00040000 +#define FLD_SRC_LOCK 0x00020000 +#define FLD_HLOCK 0x00010000 +#define FLD_VSYNC_N 0x00008000 +#define FLD_SRC_FIFO_UFLOW 0x00004000 +#define FLD_SRC_FIFO_OFLOW 0x00002000 +#define FLD_FIELD 0x00001000 +#define FLD_AFD_FMT_STAT 0x00000f00 +#define FLD_MV_TYPE2_PAIR 0x00000080 +#define FLD_MV_T3CS 0x00000040 +#define FLD_MV_CS 0x00000020 +#define FLD_MV_PSP 0x00000010 +/* Reserved [3] */ +#define FLD_MV_CDAT 0x00000003 + +/*****************************************************************************/ +#define INT_STAT_MASK 0x410 +#define FLD_COMB_3D_FIFO_MSK 0x80000000 +#define FLD_WSS_DAT_AVAIL_MSK 0x40000000 +#define FLD_GS2_DAT_AVAIL_MSK 0x20000000 +#define FLD_GS1_DAT_AVAIL_MSK 0x10000000 +#define FLD_CC_DAT_AVAIL_MSK 0x08000000 +#define FLD_VPRES_CHANGE_MSK 0x04000000 +#define FLD_MV_CHANGE_MSK 0x02000000 +#define FLD_END_VBI_EVEN_MSK 0x01000000 +#define FLD_END_VBI_ODD_MSK 0x00800000 +#define FLD_FMT_CHANGE_MSK 0x00400000 +#define FLD_VSYNC_TRAIL_MSK 0x00200000 +#define FLD_HLOCK_CHANGE_MSK 0x00100000 +#define FLD_VLOCK_CHANGE_MSK 0x00080000 +#define FLD_CSC_LOCK_CHANGE_MSK 0x00040000 +#define FLD_SRC_FIFO_UFLOW_MSK 0x00020000 +#define FLD_SRC_FIFO_OFLOW_MSK 0x00010000 +#define FLD_COMB_3D_FIFO_STAT 0x00008000 +#define FLD_WSS_DAT_AVAIL_STAT 0x00004000 +#define FLD_GS2_DAT_AVAIL_STAT 0x00002000 +#define FLD_GS1_DAT_AVAIL_STAT 0x00001000 +#define FLD_CC_DAT_AVAIL_STAT 0x00000800 +#define FLD_VPRES_CHANGE_STAT 0x00000400 +#define FLD_MV_CHANGE_STAT 0x00000200 +#define FLD_END_VBI_EVEN_STAT 0x00000100 +#define FLD_END_VBI_ODD_STAT 0x00000080 +#define FLD_FMT_CHANGE_STAT 0x00000040 +#define FLD_VSYNC_TRAIL_STAT 0x00000020 +#define FLD_HLOCK_CHANGE_STAT 0x00000010 +#define FLD_VLOCK_CHANGE_STAT 0x00000008 +#define FLD_CSC_LOCK_CHANGE_STAT 0x00000004 +#define FLD_SRC_FIFO_UFLOW_STAT 0x00000002 +#define FLD_SRC_FIFO_OFLOW_STAT 0x00000001 + +/*****************************************************************************/ +#define LUMA_CTRL 0x414 +#define BRIGHTNESS_CTRL_BYTE 0x414 +#define CONTRAST_CTRL_BYTE 0x415 +#define LUMA_CTRL_BYTE_3 0x416 +#define FLD_LUMA_CORE_SEL 0x00c00000 +#define FLD_RANGE 0x00300000 +/* Reserved [19] */ +#define FLD_PEAK_EN 0x00040000 +#define FLD_PEAK_SEL 0x00030000 +#define FLD_CNTRST 0x0000ff00 +#define FLD_BRITE 0x000000ff + +/*****************************************************************************/ +#define HSCALE_CTRL 0x418 +#define FLD_HFILT 0x03000000 +#define FLD_HSCALE 0x00ffffff + +/*****************************************************************************/ +#define VSCALE_CTRL 0x41c +#define FLD_LINE_AVG_DIS 0x01000000 +/* Reserved [23:20] */ +#define FLD_VS_INTRLACE 0x00080000 +#define FLD_VFILT 0x00070000 +/* Reserved [15:13] */ +#define FLD_VSCALE 0x00001fff + +/*****************************************************************************/ +#define CHROMA_CTRL 0x420 +#define USAT_CTRL_BYTE 0x420 +#define VSAT_CTRL_BYTE 0x421 +#define HUE_CTRL_BYTE 0x422 +#define FLD_C_LPF_EN 0x20000000 +#define FLD_CHR_DELAY 0x1c000000 +#define FLD_C_CORE_SEL 0x03000000 +#define FLD_HUE 0x00ff0000 +#define FLD_VSAT 0x0000ff00 +#define FLD_USAT 0x000000ff + +/*****************************************************************************/ +#define VBI_LINE_CTRL1 0x424 +#define FLD_VBI_MD_LINE4 0xff000000 +#define FLD_VBI_MD_LINE3 0x00ff0000 +#define FLD_VBI_MD_LINE2 0x0000ff00 +#define FLD_VBI_MD_LINE1 0x000000ff + +/*****************************************************************************/ +#define VBI_LINE_CTRL2 0x428 +#define FLD_VBI_MD_LINE8 0xff000000 +#define FLD_VBI_MD_LINE7 0x00ff0000 +#define FLD_VBI_MD_LINE6 0x0000ff00 +#define FLD_VBI_MD_LINE5 0x000000ff + +/*****************************************************************************/ +#define VBI_LINE_CTRL3 0x42c +#define FLD_VBI_MD_LINE12 0xff000000 +#define FLD_VBI_MD_LINE11 0x00ff0000 +#define FLD_VBI_MD_LINE10 0x0000ff00 +#define FLD_VBI_MD_LINE9 0x000000ff + +/*****************************************************************************/ +#define VBI_LINE_CTRL4 0x430 +#define FLD_VBI_MD_LINE16 0xff000000 +#define FLD_VBI_MD_LINE15 0x00ff0000 +#define FLD_VBI_MD_LINE14 0x0000ff00 +#define FLD_VBI_MD_LINE13 0x000000ff + +/*****************************************************************************/ +#define VBI_LINE_CTRL5 0x434 +#define FLD_VBI_MD_LINE17 0x000000ff + +/*****************************************************************************/ +#define VBI_FC_CFG 0x438 +#define FLD_FC_ALT2 0xff000000 +#define FLD_FC_ALT1 0x00ff0000 +#define FLD_FC_ALT2_TYPE 0x0000f000 +#define FLD_FC_ALT1_TYPE 0x00000f00 +/* Reserved [7:1] */ +#define FLD_FC_SEARCH_MODE 0x00000001 + +/*****************************************************************************/ +#define VBI_MISC_CFG1 0x43c +#define FLD_TTX_PKTADRU 0xfff00000 +#define FLD_TTX_PKTADRL 0x000fff00 +/* Reserved [7:6] */ +#define FLD_MOJI_PACK_DIS 0x00000020 +#define FLD_VPS_DEC_DIS 0x00000010 +#define FLD_CRI_MARG_SCALE 0x0000000c +#define FLD_EDGE_RESYNC_EN 0x00000002 +#define FLD_ADAPT_SLICE_DIS 0x00000001 + +/*****************************************************************************/ +#define VBI_MISC_CFG2 0x440 +#define FLD_HAMMING_TYPE 0x0f000000 +/* Reserved [23:20] */ +#define FLD_WSS_FIFO_RST 0x00080000 +#define FLD_GS2_FIFO_RST 0x00040000 +#define FLD_GS1_FIFO_RST 0x00020000 +#define FLD_CC_FIFO_RST 0x00010000 +/* Reserved [15:12] */ +#define FLD_VBI3_SDID 0x00000f00 +#define FLD_VBI2_SDID 0x000000f0 +#define FLD_VBI1_SDID 0x0000000f + +/*****************************************************************************/ +#define VBI_PAY1 0x444 +#define FLD_GS1_FIFO_DAT 0xFF000000 +#define FLD_GS1_STAT 0x00FF0000 +#define FLD_CC_FIFO_DAT 0x0000FF00 +#define FLD_CC_STAT 0x000000FF + +/*****************************************************************************/ +#define VBI_PAY2 0x448 +#define FLD_WSS_FIFO_DAT 0xff000000 +#define FLD_WSS_STAT 0x00ff0000 +#define FLD_GS2_FIFO_DAT 0x0000ff00 +#define FLD_GS2_STAT 0x000000ff + +/*****************************************************************************/ +#define VBI_CUST1_CFG1 0x44c +/* Reserved [31] */ +#define FLD_VBI1_CRIWIN 0x7f000000 +#define FLD_VBI1_SLICE_DIST 0x00f00000 +#define FLD_VBI1_BITINC 0x000fff00 +#define FLD_VBI1_HDELAY 0x000000ff + +/*****************************************************************************/ +#define VBI_CUST1_CFG2 0x450 +#define FLD_VBI1_FC_LENGTH 0x1f000000 +#define FLD_VBI1_FRAME_CODE 0x00ffffff + +/*****************************************************************************/ +#define VBI_CUST1_CFG3 0x454 +#define FLD_VBI1_HAM_EN 0x80000000 +#define FLD_VBI1_FIFO_MODE 0x70000000 +#define FLD_VBI1_FORMAT_TYPE 0x0f000000 +#define FLD_VBI1_PAYLD_LENGTH 0x00ff0000 +#define FLD_VBI1_CRI_LENGTH 0x0000f000 +#define FLD_VBI1_CRI_MARGIN 0x00000f00 +#define FLD_VBI1_CRI_TIME 0x000000ff + +/*****************************************************************************/ +#define VBI_CUST2_CFG1 0x458 +/* Reserved [31] */ +#define FLD_VBI2_CRIWIN 0x7f000000 +#define FLD_VBI2_SLICE_DIST 0x00f00000 +#define FLD_VBI2_BITINC 0x000fff00 +#define FLD_VBI2_HDELAY 0x000000ff + +/*****************************************************************************/ +#define VBI_CUST2_CFG2 0x45c +#define FLD_VBI2_FC_LENGTH 0x1f000000 +#define FLD_VBI2_FRAME_CODE 0x00ffffff + +/*****************************************************************************/ +#define VBI_CUST2_CFG3 0x460 +#define FLD_VBI2_HAM_EN 0x80000000 +#define FLD_VBI2_FIFO_MODE 0x70000000 +#define FLD_VBI2_FORMAT_TYPE 0x0f000000 +#define FLD_VBI2_PAYLD_LENGTH 0x00ff0000 +#define FLD_VBI2_CRI_LENGTH 0x0000f000 +#define FLD_VBI2_CRI_MARGIN 0x00000f00 +#define FLD_VBI2_CRI_TIME 0x000000ff + +/*****************************************************************************/ +#define VBI_CUST3_CFG1 0x464 +/* Reserved [31] */ +#define FLD_VBI3_CRIWIN 0x7f000000 +#define FLD_VBI3_SLICE_DIST 0x00f00000 +#define FLD_VBI3_BITINC 0x000fff00 +#define FLD_VBI3_HDELAY 0x000000ff + +/*****************************************************************************/ +#define VBI_CUST3_CFG2 0x468 +#define FLD_VBI3_FC_LENGTH 0x1f000000 +#define FLD_VBI3_FRAME_CODE 0x00ffffff + +/*****************************************************************************/ +#define VBI_CUST3_CFG3 0x46c +#define FLD_VBI3_HAM_EN 0x80000000 +#define FLD_VBI3_FIFO_MODE 0x70000000 +#define FLD_VBI3_FORMAT_TYPE 0x0f000000 +#define FLD_VBI3_PAYLD_LENGTH 0x00ff0000 +#define FLD_VBI3_CRI_LENGTH 0x0000f000 +#define FLD_VBI3_CRI_MARGIN 0x00000f00 +#define FLD_VBI3_CRI_TIME 0x000000ff + +/*****************************************************************************/ +#define HORIZ_TIM_CTRL 0x470 +#define FLD_BGDEL_CNT 0xff000000 +/* Reserved [23:22] */ +#define FLD_HACTIVE_CNT 0x003ff000 +/* Reserved [11:10] */ +#define FLD_HBLANK_CNT 0x000003ff + +/*****************************************************************************/ +#define VERT_TIM_CTRL 0x474 +#define FLD_V656BLANK_CNT 0xff000000 +/* Reserved [23:22] */ +#define FLD_VACTIVE_CNT 0x003ff000 +/* Reserved [11:10] */ +#define FLD_VBLANK_CNT 0x000003ff + +/*****************************************************************************/ +#define SRC_COMB_CFG 0x478 +#define FLD_CCOMB_2LN_CHECK 0x80000000 +#define FLD_CCOMB_3LN_EN 0x40000000 +#define FLD_CCOMB_2LN_EN 0x20000000 +#define FLD_CCOMB_3D_EN 0x10000000 +/* Reserved [27] */ +#define FLD_LCOMB_3LN_EN 0x04000000 +#define FLD_LCOMB_2LN_EN 0x02000000 +#define FLD_LCOMB_3D_EN 0x01000000 +#define FLD_LUMA_LPF_SEL 0x00c00000 +#define FLD_UV_LPF_SEL 0x00300000 +#define FLD_BLEND_SLOPE 0x000f0000 +#define FLD_CCOMB_REDUCE_EN 0x00008000 +/* Reserved [14:10] */ +#define FLD_SRC_DECIM_RATIO 0x000003ff + +/*****************************************************************************/ +#define CHROMA_VBIOFF_CFG 0x47c +#define FLD_VBI_VOFFSET 0x1f000000 +/* Reserved [23:20] */ +#define FLD_SC_STEP 0x000fffff + +/*****************************************************************************/ +#define FIELD_COUNT 0x480 +#define FLD_FIELD_COUNT_FLD 0x000003ff + +/*****************************************************************************/ +#define MISC_TIM_CTRL 0x484 +#define FLD_DEBOUNCE_COUNT 0xc0000000 +#define FLD_VT_LINE_CNT_HYST 0x30000000 +/* Reserved [27] */ +#define FLD_AFD_STAT 0x07ff0000 +#define FLD_VPRES_VERT_EN 0x00008000 +/* Reserved [14:12] */ +#define FLD_HR32 0x00000800 +#define FLD_TDALGN 0x00000400 +#define FLD_TDFIELD 0x00000200 +/* Reserved [8:6] */ +#define FLD_TEMPDEC 0x0000003f + +/*****************************************************************************/ +#define DFE_CTRL1 0x488 +#define FLD_CLAMP_AUTO_EN 0x80000000 +#define FLD_AGC_AUTO_EN 0x40000000 +#define FLD_VGA_CRUSH_EN 0x20000000 +#define FLD_VGA_AUTO_EN 0x10000000 +#define FLD_VBI_GATE_EN 0x08000000 +#define FLD_CLAMP_LEVEL 0x07000000 +/* Reserved [23:22] */ +#define FLD_CLAMP_SKIP_CNT 0x00300000 +#define FLD_AGC_GAIN 0x000fff00 +/* Reserved [7:6] */ +#define FLD_VGA_GAIN 0x0000003f + +/*****************************************************************************/ +#define DFE_CTRL2 0x48c +#define FLD_VGA_ACQUIRE_RANGE 0x00ff0000 +#define FLD_VGA_TRACK_RANGE 0x0000ff00 +#define FLD_VGA_SYNC 0x000000ff + +/*****************************************************************************/ +#define DFE_CTRL3 0x490 +#define FLD_BP_PERCENT 0xff000000 +#define FLD_DFT_THRESHOLD 0x00ff0000 +/* Reserved [15:12] */ +#define FLD_SYNC_WIDTH_SEL 0x00000600 +#define FLD_BP_LOOP_GAIN 0x00000300 +#define FLD_SYNC_LOOP_GAIN 0x000000c0 +/* Reserved [5:4] */ +#define FLD_AGC_LOOP_GAIN 0x0000000c +#define FLD_DCC_LOOP_GAIN 0x00000003 + +/*****************************************************************************/ +#define PLL_CTRL 0x494 +#define FLD_PLL_KD 0xff000000 +#define FLD_PLL_KI 0x00ff0000 +#define FLD_PLL_MAX_OFFSET 0x0000ffff + +/*****************************************************************************/ +#define HTL_CTRL 0x498 +/* Reserved [31:24] */ +#define FLD_AUTO_LOCK_SPD 0x00080000 +#define FLD_MAN_FAST_LOCK 0x00040000 +#define FLD_HTL_15K_EN 0x00020000 +#define FLD_HTL_500K_EN 0x00010000 +#define FLD_HTL_KD 0x0000ff00 +#define FLD_HTL_KI 0x000000ff + +/*****************************************************************************/ +#define COMB_CTRL 0x49c +#define FLD_COMB_PHASE_LIMIT 0xff000000 +#define FLD_CCOMB_ERR_LIMIT 0x00ff0000 +#define FLD_LUMA_THRESHOLD 0x0000ff00 +#define FLD_LCOMB_ERR_LIMIT 0x000000ff + +/*****************************************************************************/ +#define CRUSH_CTRL 0x4a0 +#define FLD_WTW_EN 0x00400000 +#define FLD_CRUSH_FREQ 0x00200000 +#define FLD_MAJ_SEL_EN 0x00100000 +#define FLD_MAJ_SEL 0x000c0000 +/* Reserved [17:15] */ +#define FLD_SYNC_TIP_REDUCE 0x00007e00 +/* Reserved [8:6] */ +#define FLD_SYNC_TIP_INC 0x0000003f + +/*****************************************************************************/ +#define SOFT_RST_CTRL 0x4a4 +#define FLD_VD_SOFT_RST 0x00008000 +/* Reserved [14:12] */ +#define FLD_REG_RST_MSK 0x00000800 +#define FLD_VOF_RST_MSK 0x00000400 +#define FLD_MVDET_RST_MSK 0x00000200 +#define FLD_VBI_RST_MSK 0x00000100 +#define FLD_SCALE_RST_MSK 0x00000080 +#define FLD_CHROMA_RST_MSK 0x00000040 +#define FLD_LUMA_RST_MSK 0x00000020 +#define FLD_VTG_RST_MSK 0x00000010 +#define FLD_YCSEP_RST_MSK 0x00000008 +#define FLD_SRC_RST_MSK 0x00000004 +#define FLD_DFE_RST_MSK 0x00000002 +/* Reserved [0] */ + +/*****************************************************************************/ +#define MV_DT_CTRL1 0x4a8 +/* Reserved [31:29] */ +#define FLD_PSP_STOP_LINE 0x1f000000 +/* Reserved [23:21] */ +#define FLD_PSP_STRT_LINE 0x001f0000 +/* Reserved [15] */ +#define FLD_PSP_LLIMW 0x00007f00 +/* Reserved [7] */ +#define FLD_PSP_ULIMW 0x0000007f + +/*****************************************************************************/ +#define MV_DT_CTRL2 0x4aC +#define FLD_CS_STOPWIN 0xff000000 +#define FLD_CS_STRTWIN 0x00ff0000 +#define FLD_CS_WIDTH 0x0000ff00 +#define FLD_PSP_SPEC_VAL 0x000000ff + +/*****************************************************************************/ +#define MV_DT_CTRL3 0x4B0 +#define FLD_AUTO_RATE_DIS 0x80000000 +#define FLD_HLOCK_DIS 0x40000000 +#define FLD_SEL_FIELD_CNT 0x20000000 +#define FLD_CS_TYPE2_SEL 0x10000000 +#define FLD_CS_LINE_THRSH_SEL 0x08000000 +#define FLD_CS_ATHRESH_SEL 0x04000000 +#define FLD_PSP_SPEC_SEL 0x02000000 +#define FLD_PSP_LINES_SEL 0x01000000 +#define FLD_FIELD_CNT 0x00f00000 +#define FLD_CS_TYPE2_CNT 0x000fc000 +#define FLD_CS_LINE_CNT 0x00003f00 +#define FLD_CS_ATHRESH_LEV 0x000000ff + +/*****************************************************************************/ +#define CHIP_VERSION 0x4b4 +/* Cx231xx redefine */ +#define VERSION 0x4b4 +#define FLD_REV_ID 0x000000ff + +/*****************************************************************************/ +#define MISC_DIAG_CTRL 0x4b8 +/* Reserved [31:24] */ +#define FLD_SC_CONVERGE_THRESH 0x00ff0000 +#define FLD_CCOMB_ERR_LIMIT_3D 0x0000ff00 +#define FLD_LCOMB_ERR_LIMIT_3D 0x000000ff + +/*****************************************************************************/ +#define VBI_PASS_CTRL 0x4bc +#define FLD_VBI_PASS_MD 0x00200000 +#define FLD_VBI_SETUP_DIS 0x00100000 +#define FLD_PASS_LINE_CTRL 0x000fffff + +/*****************************************************************************/ +/* Cx231xx redefine */ +#define VCR_DET_CTRL 0x4c0 +#define FLD_EN_FIELD_PHASE_DET 0x80000000 +#define FLD_EN_HEAD_SW_DET 0x40000000 +#define FLD_FIELD_PHASE_LENGTH 0x01ff0000 +/* Reserved [29:25] */ +#define FLD_FIELD_PHASE_DELAY 0x0000ff00 +#define FLD_FIELD_PHASE_LIMIT 0x000000f0 +#define FLD_HEAD_SW_DET_LIMIT 0x0000000f + +/*****************************************************************************/ +#define DL_CTL 0x800 +#define DL_CTL_ADDRESS_LOW 0x800 /* Byte 1 in DL_CTL */ +#define DL_CTL_ADDRESS_HIGH 0x801 /* Byte 2 in DL_CTL */ +#define DL_CTL_DATA 0x802 /* Byte 3 in DL_CTL */ +#define DL_CTL_CONTROL 0x803 /* Byte 4 in DL_CTL */ +/* Reserved [31:5] */ +#define FLD_START_8051 0x10000000 +#define FLD_DL_ENABLE 0x08000000 +#define FLD_DL_AUTO_INC 0x04000000 +#define FLD_DL_MAP 0x03000000 + +/*****************************************************************************/ +#define STD_DET_STATUS 0x804 +#define FLD_SPARE_STATUS1 0xff000000 +#define FLD_SPARE_STATUS0 0x00ff0000 +#define FLD_MOD_DET_STATUS1 0x0000ff00 +#define FLD_MOD_DET_STATUS0 0x000000ff + +/*****************************************************************************/ +#define AUD_BUILD_NUM 0x806 +#define AUD_VER_NUM 0x807 +#define STD_DET_CTL 0x808 +#define STD_DET_CTL_AUD_CTL 0x808 /* Byte 1 in STD_DET_CTL */ +#define STD_DET_CTL_PREF_MODE 0x809 /* Byte 2 in STD_DET_CTL */ +#define FLD_SPARE_CTL0 0xff000000 +#define FLD_DIS_DBX 0x00800000 +#define FLD_DIS_BTSC 0x00400000 +#define FLD_DIS_NICAM_A2 0x00200000 +#define FLD_VIDEO_PRESENT 0x00100000 +#define FLD_DW8051_VIDEO_FORMAT 0x000f0000 +#define FLD_PREF_DEC_MODE 0x0000ff00 +#define FLD_AUD_CONFIG 0x000000ff + +/*****************************************************************************/ +#define DW8051_INT 0x80c +#define FLD_VIDEO_PRESENT_CHANGE 0x80000000 +#define FLD_VIDEO_CHANGE 0x40000000 +#define FLD_RDS_READY 0x20000000 +#define FLD_AC97_INT 0x10000000 +#define FLD_NICAM_BIT_ERROR_TOO_HIGH 0x08000000 +#define FLD_NICAM_LOCK 0x04000000 +#define FLD_NICAM_UNLOCK 0x02000000 +#define FLD_DFT4_TH_CMP 0x01000000 +/* Reserved [23:22] */ +#define FLD_LOCK_IND_INT 0x00200000 +#define FLD_DFT3_TH_CMP 0x00100000 +#define FLD_DFT2_TH_CMP 0x00080000 +#define FLD_DFT1_TH_CMP 0x00040000 +#define FLD_FM2_DFT_TH_CMP 0x00020000 +#define FLD_FM1_DFT_TH_CMP 0x00010000 +#define FLD_VIDEO_PRESENT_EN 0x00008000 +#define FLD_VIDEO_CHANGE_EN 0x00004000 +#define FLD_RDS_READY_EN 0x00002000 +#define FLD_AC97_INT_EN 0x00001000 +#define FLD_NICAM_BIT_ERROR_TOO_HIGH_EN 0x00000800 +#define FLD_NICAM_LOCK_EN 0x00000400 +#define FLD_NICAM_UNLOCK_EN 0x00000200 +#define FLD_DFT4_TH_CMP_EN 0x00000100 +/* Reserved [7] */ +#define FLD_DW8051_INT6_CTL1 0x00000040 +#define FLD_DW8051_INT5_CTL1 0x00000020 +#define FLD_DW8051_INT4_CTL1 0x00000010 +#define FLD_DW8051_INT3_CTL1 0x00000008 +#define FLD_DW8051_INT2_CTL1 0x00000004 +#define FLD_DW8051_INT1_CTL1 0x00000002 +#define FLD_DW8051_INT0_CTL1 0x00000001 + +/*****************************************************************************/ +#define GENERAL_CTL 0x810 +#define FLD_RDS_INT 0x80000000 +#define FLD_NBER_INT 0x40000000 +#define FLD_NLL_INT 0x20000000 +#define FLD_IFL_INT 0x10000000 +#define FLD_FDL_INT 0x08000000 +#define FLD_AFC_INT 0x04000000 +#define FLD_AMC_INT 0x02000000 +#define FLD_AC97_INT_CTL 0x01000000 +#define FLD_RDS_INT_DIS 0x00800000 +#define FLD_NBER_INT_DIS 0x00400000 +#define FLD_NLL_INT_DIS 0x00200000 +#define FLD_IFL_INT_DIS 0x00100000 +#define FLD_FDL_INT_DIS 0x00080000 +#define FLD_FC_INT_DIS 0x00040000 +#define FLD_AMC_INT_DIS 0x00020000 +#define FLD_AC97_INT_DIS 0x00010000 +#define FLD_REV_NUM 0x0000ff00 +/* Reserved [7:5] */ +#define FLD_DBX_SOFT_RESET_REG 0x00000010 +#define FLD_AD_SOFT_RESET_REG 0x00000008 +#define FLD_SRC_SOFT_RESET_REG 0x00000004 +#define FLD_CDMOD_SOFT_RESET 0x00000002 +#define FLD_8051_SOFT_RESET 0x00000001 + +/*****************************************************************************/ +#define AAGC_CTL 0x814 +#define FLD_AFE_12DB_EN 0x80000000 +#define FLD_AAGC_DEFAULT_EN 0x40000000 +#define FLD_AAGC_DEFAULT 0x3f000000 +/* Reserved [23] */ +#define FLD_AAGC_GAIN 0x00600000 +#define FLD_AAGC_TH 0x001f0000 +/* Reserved [15:14] */ +#define FLD_AAGC_HYST2 0x00003f00 +/* Reserved [7:6] */ +#define FLD_AAGC_HYST1 0x0000003f + +/*****************************************************************************/ +#define IF_SRC_CTL 0x818 +#define FLD_DBX_BYPASS 0x80000000 +/* Reserved [30:25] */ +#define FLD_IF_SRC_MODE 0x01000000 +/* Reserved [23:18] */ +#define FLD_IF_SRC_PHASE_INC 0x0001ffff + +/*****************************************************************************/ +#define ANALOG_DEMOD_CTL 0x81c +#define FLD_ROT1_PHACC_PROG 0xffff0000 +/* Reserved [15] */ +#define FLD_FM1_DELAY_FIX 0x00007000 +#define FLD_PDF4_SHIFT 0x00000c00 +#define FLD_PDF3_SHIFT 0x00000300 +#define FLD_PDF2_SHIFT 0x000000c0 +#define FLD_PDF1_SHIFT 0x00000030 +#define FLD_FMBYPASS_MODE2 0x00000008 +#define FLD_FMBYPASS_MODE1 0x00000004 +#define FLD_NICAM_MODE 0x00000002 +#define FLD_BTSC_FMRADIO_MODE 0x00000001 + +/*****************************************************************************/ +#define ROT_FREQ_CTL 0x820 +#define FLD_ROT3_PHACC_PROG 0xffff0000 +#define FLD_ROT2_PHACC_PROG 0x0000ffff + +/*****************************************************************************/ +#define FM_CTL 0x824 +#define FLD_FM2_DC_FB_SHIFT 0xf0000000 +#define FLD_FM2_DC_INT_SHIFT 0x0f000000 +#define FLD_FM2_AFC_RESET 0x00800000 +#define FLD_FM2_DC_PASS_IN 0x00400000 +#define FLD_FM2_DAGC_SHIFT 0x00380000 +#define FLD_FM2_CORDIC_SHIFT 0x00070000 +#define FLD_FM1_DC_FB_SHIFT 0x0000f000 +#define FLD_FM1_DC_INT_SHIFT 0x00000f00 +#define FLD_FM1_AFC_RESET 0x00000080 +#define FLD_FM1_DC_PASS_IN 0x00000040 +#define FLD_FM1_DAGC_SHIFT 0x00000038 +#define FLD_FM1_CORDIC_SHIFT 0x00000007 + +/*****************************************************************************/ +#define LPF_PDF_CTL 0x828 +/* Reserved [31:30] */ +#define FLD_LPF32_SHIFT1 0x30000000 +#define FLD_LPF32_SHIFT2 0x0c000000 +#define FLD_LPF160_SHIFTA 0x03000000 +#define FLD_LPF160_SHIFTB 0x00c00000 +#define FLD_LPF160_SHIFTC 0x00300000 +#define FLD_LPF32_COEF_SEL2 0x000c0000 +#define FLD_LPF32_COEF_SEL1 0x00030000 +#define FLD_LPF160_COEF_SELC 0x0000c000 +#define FLD_LPF160_COEF_SELB 0x00003000 +#define FLD_LPF160_COEF_SELA 0x00000c00 +#define FLD_LPF160_IN_EN_REG 0x00000300 +#define FLD_PDF4_PDF_SEL 0x000000c0 +#define FLD_PDF3_PDF_SEL 0x00000030 +#define FLD_PDF2_PDF_SEL 0x0000000c +#define FLD_PDF1_PDF_SEL 0x00000003 + +/*****************************************************************************/ +#define DFT1_CTL1 0x82c +#define FLD_DFT1_DWELL 0xffff0000 +#define FLD_DFT1_FREQ 0x0000ffff + +/*****************************************************************************/ +#define DFT1_CTL2 0x830 +#define FLD_DFT1_THRESHOLD 0xffffff00 +#define FLD_DFT1_CMP_CTL 0x00000080 +#define FLD_DFT1_AVG 0x00000070 +/* Reserved [3:1] */ +#define FLD_DFT1_START 0x00000001 + +/*****************************************************************************/ +#define DFT1_STATUS 0x834 +#define FLD_DFT1_DONE 0x80000000 +#define FLD_DFT1_TH_CMP_STAT 0x40000000 +#define FLD_DFT1_RESULT 0x3fffffff + +/*****************************************************************************/ +#define DFT2_CTL1 0x838 +#define FLD_DFT2_DWELL 0xffff0000 +#define FLD_DFT2_FREQ 0x0000ffff + +/*****************************************************************************/ +#define DFT2_CTL2 0x83C +#define FLD_DFT2_THRESHOLD 0xffffff00 +#define FLD_DFT2_CMP_CTL 0x00000080 +#define FLD_DFT2_AVG 0x00000070 +/* Reserved [3:1] */ +#define FLD_DFT2_START 0x00000001 + +/*****************************************************************************/ +#define DFT2_STATUS 0x840 +#define FLD_DFT2_DONE 0x80000000 +#define FLD_DFT2_TH_CMP_STAT 0x40000000 +#define FLD_DFT2_RESULT 0x3fffffff + +/*****************************************************************************/ +#define DFT3_CTL1 0x844 +#define FLD_DFT3_DWELL 0xffff0000 +#define FLD_DFT3_FREQ 0x0000ffff + +/*****************************************************************************/ +#define DFT3_CTL2 0x848 +#define FLD_DFT3_THRESHOLD 0xffffff00 +#define FLD_DFT3_CMP_CTL 0x00000080 +#define FLD_DFT3_AVG 0x00000070 +/* Reserved [3:1] */ +#define FLD_DFT3_START 0x00000001 + +/*****************************************************************************/ +#define DFT3_STATUS 0x84c +#define FLD_DFT3_DONE 0x80000000 +#define FLD_DFT3_TH_CMP_STAT 0x40000000 +#define FLD_DFT3_RESULT 0x3fffffff + +/*****************************************************************************/ +#define DFT4_CTL1 0x850 +#define FLD_DFT4_DWELL 0xffff0000 +#define FLD_DFT4_FREQ 0x0000ffff + +/*****************************************************************************/ +#define DFT4_CTL2 0x854 +#define FLD_DFT4_THRESHOLD 0xffffff00 +#define FLD_DFT4_CMP_CTL 0x00000080 +#define FLD_DFT4_AVG 0x00000070 +/* Reserved [3:1] */ +#define FLD_DFT4_START 0x00000001 + +/*****************************************************************************/ +#define DFT4_STATUS 0x858 +#define FLD_DFT4_DONE 0x80000000 +#define FLD_DFT4_TH_CMP_STAT 0x40000000 +#define FLD_DFT4_RESULT 0x3fffffff + +/*****************************************************************************/ +#define AM_MTS_DET 0x85c +#define FLD_AM_MTS_MODE 0x80000000 +/* Reserved [30:26] */ +#define FLD_AM_SUB 0x02000000 +#define FLD_AM_GAIN_EN 0x01000000 +/* Reserved [23:16] */ +#define FLD_AMMTS_GAIN_SCALE 0x0000e000 +#define FLD_MTS_PDF_SHIFT 0x00001800 +#define FLD_AM_REG_GAIN 0x00000700 +#define FLD_AGC_REF 0x000000ff + +/*****************************************************************************/ +#define ANALOG_MUX_CTL 0x860 +/* Reserved [31:29] */ +#define FLD_MUX21_SEL 0x10000000 +#define FLD_MUX20_SEL 0x08000000 +#define FLD_MUX19_SEL 0x04000000 +#define FLD_MUX18_SEL 0x02000000 +#define FLD_MUX17_SEL 0x01000000 +#define FLD_MUX16_SEL 0x00800000 +#define FLD_MUX15_SEL 0x00400000 +#define FLD_MUX14_SEL 0x00300000 +#define FLD_MUX13_SEL 0x000C0000 +#define FLD_MUX12_SEL 0x00020000 +#define FLD_MUX11_SEL 0x00018000 +#define FLD_MUX10_SEL 0x00004000 +#define FLD_MUX9_SEL 0x00002000 +#define FLD_MUX8_SEL 0x00001000 +#define FLD_MUX7_SEL 0x00000800 +#define FLD_MUX6_SEL 0x00000600 +#define FLD_MUX5_SEL 0x00000100 +#define FLD_MUX4_SEL 0x000000c0 +#define FLD_MUX3_SEL 0x00000030 +#define FLD_MUX2_SEL 0x0000000c +#define FLD_MUX1_SEL 0x00000003 + +/*****************************************************************************/ +/* Cx231xx redefine */ +#define DPLL_CTRL1 0x864 +#define DIG_PLL_CTL1 0x864 + +#define FLD_PLL_STATUS 0x07000000 +#define FLD_BANDWIDTH_SELECT 0x00030000 +#define FLD_PLL_SHIFT_REG 0x00007000 +#define FLD_PHASE_SHIFT 0x000007ff + +/*****************************************************************************/ +/* Cx231xx redefine */ +#define DPLL_CTRL2 0x868 +#define DIG_PLL_CTL2 0x868 +#define FLD_PLL_UNLOCK_THR 0xff000000 +#define FLD_PLL_LOCK_THR 0x00ff0000 +/* Reserved [15:8] */ +#define FLD_AM_PDF_SEL2 0x000000c0 +#define FLD_AM_PDF_SEL1 0x00000030 +#define FLD_DPLL_FSM_CTRL 0x0000000c +/* Reserved [1] */ +#define FLD_PLL_PILOT_DET 0x00000001 + +/*****************************************************************************/ +/* Cx231xx redefine */ +#define DPLL_CTRL3 0x86c +#define DIG_PLL_CTL3 0x86c +#define FLD_DISABLE_LOOP 0x01000000 +#define FLD_A1_DS1_SEL 0x000c0000 +#define FLD_A1_DS2_SEL 0x00030000 +#define FLD_A1_KI 0x0000ff00 +#define FLD_A1_KD 0x000000ff + +/*****************************************************************************/ +/* Cx231xx redefine */ +#define DPLL_CTRL4 0x870 +#define DIG_PLL_CTL4 0x870 +#define FLD_A2_DS1_SEL 0x000c0000 +#define FLD_A2_DS2_SEL 0x00030000 +#define FLD_A2_KI 0x0000ff00 +#define FLD_A2_KD 0x000000ff + +/*****************************************************************************/ +/* Cx231xx redefine */ +#define DPLL_CTRL5 0x874 +#define DIG_PLL_CTL5 0x874 +#define FLD_TRK_DS1_SEL 0x000c0000 +#define FLD_TRK_DS2_SEL 0x00030000 +#define FLD_TRK_KI 0x0000ff00 +#define FLD_TRK_KD 0x000000ff + +/*****************************************************************************/ +#define DEEMPH_GAIN_CTL 0x878 +#define FLD_DEEMPH2_GAIN 0xFFFF0000 +#define FLD_DEEMPH1_GAIN 0x0000FFFF + +/*****************************************************************************/ +/* Cx231xx redefine */ +#define DEEMPH_COEFF1 0x87c +#define DEEMPH_COEF1 0x87c +#define FLD_DEEMPH_B0 0xffff0000 +#define FLD_DEEMPH_A0 0x0000ffff + +/*****************************************************************************/ +/* Cx231xx redefine */ +#define DEEMPH_COEFF2 0x880 +#define DEEMPH_COEF2 0x880 +#define FLD_DEEMPH_B1 0xFFFF0000 +#define FLD_DEEMPH_A1 0x0000FFFF + +/*****************************************************************************/ +#define DBX1_CTL1 0x884 +#define FLD_DBX1_WBE_GAIN 0xffff0000 +#define FLD_DBX1_IN_GAIN 0x0000ffff + +/*****************************************************************************/ +#define DBX1_CTL2 0x888 +#define FLD_DBX1_SE_BYPASS 0xffff0000 +#define FLD_DBX1_SE_GAIN 0x0000ffff + +/*****************************************************************************/ +#define DBX1_RMS_SE 0x88C +#define FLD_DBX1_RMS_WBE 0xffff0000 +#define FLD_DBX1_RMS_SE_FLD 0x0000ffff + +/*****************************************************************************/ +#define DBX2_CTL1 0x890 +#define FLD_DBX2_WBE_GAIN 0xffff0000 +#define FLD_DBX2_IN_GAIN 0x0000ffff + +/*****************************************************************************/ +#define DBX2_CTL2 0x894 +#define FLD_DBX2_SE_BYPASS 0xffff0000 +#define FLD_DBX2_SE_GAIN 0x0000ffff + +/*****************************************************************************/ +#define DBX2_RMS_SE 0x898 +#define FLD_DBX2_RMS_WBE 0xffff0000 +#define FLD_DBX2_RMS_SE_FLD 0x0000ffff + +/*****************************************************************************/ +#define AM_FM_DIFF 0x89c +/* Reserved [31] */ +#define FLD_FM_DIFF_OUT 0x7fff0000 +/* Reserved [15] */ +#define FLD_AM_DIFF_OUT 0x00007fff + +/*****************************************************************************/ +#define NICAM_FAW 0x8a0 +#define FLD_FAWDETWINEND 0xFc000000 +#define FLD_FAWDETWINSTR 0x03ff0000 +/* Reserved [15:12] */ +#define FLD_FAWDETTHRSHLD3 0x00000f00 +#define FLD_FAWDETTHRSHLD2 0x000000f0 +#define FLD_FAWDETTHRSHLD1 0x0000000f + +/*****************************************************************************/ +/* Cx231xx redefine */ +#define DEEMPH_GAIN 0x8a4 +#define NICAM_DEEMPHGAIN 0x8a4 +/* Reserved [31:18] */ +#define FLD_DEEMPHGAIN 0x0003ffff + +/*****************************************************************************/ +/* Cx231xx redefine */ +#define DEEMPH_NUMER1 0x8a8 +#define NICAM_DEEMPHNUMER1 0x8a8 +/* Reserved [31:18] */ +#define FLD_DEEMPHNUMER1 0x0003ffff + +/*****************************************************************************/ +/* Cx231xx redefine */ +#define DEEMPH_NUMER2 0x8ac +#define NICAM_DEEMPHNUMER2 0x8ac +/* Reserved [31:18] */ +#define FLD_DEEMPHNUMER2 0x0003ffff + +/*****************************************************************************/ +/* Cx231xx redefine */ +#define DEEMPH_DENOM1 0x8b0 +#define NICAM_DEEMPHDENOM1 0x8b0 +/* Reserved [31:18] */ +#define FLD_DEEMPHDENOM1 0x0003ffff + +/*****************************************************************************/ +/* Cx231xx redefine */ +#define DEEMPH_DENOM2 0x8b4 +#define NICAM_DEEMPHDENOM2 0x8b4 +/* Reserved [31:18] */ +#define FLD_DEEMPHDENOM2 0x0003ffff + +/*****************************************************************************/ +#define NICAM_ERRLOG_CTL1 0x8B8 +/* Reserved [31:28] */ +#define FLD_ERRINTRPTTHSHLD1 0x0fff0000 +/* Reserved [15:12] */ +#define FLD_ERRLOGPERIOD 0x00000fff + +/*****************************************************************************/ +#define NICAM_ERRLOG_CTL2 0x8bc +/* Reserved [31:28] */ +#define FLD_ERRINTRPTTHSHLD3 0x0fff0000 +/* Reserved [15:12] */ +#define FLD_ERRINTRPTTHSHLD2 0x00000fff + +/*****************************************************************************/ +#define NICAM_ERRLOG_STS1 0x8c0 +/* Reserved [31:28] */ +#define FLD_ERRLOG2 0x0fff0000 +/* Reserved [15:12] */ +#define FLD_ERRLOG1 0x00000fff + +/*****************************************************************************/ +#define NICAM_ERRLOG_STS2 0x8c4 +/* Reserved [31:12] */ +#define FLD_ERRLOG3 0x00000fff + +/*****************************************************************************/ +#define NICAM_STATUS 0x8c8 +/* Reserved [31:20] */ +#define FLD_NICAM_CIB 0x000c0000 +#define FLD_NICAM_LOCK_STAT 0x00020000 +#define FLD_NICAM_MUTE 0x00010000 +#define FLD_NICAMADDIT_DATA 0x0000ffe0 +#define FLD_NICAMCNTRL 0x0000001f + +/*****************************************************************************/ +#define DEMATRIX_CTL 0x8cc +#define FLD_AC97_IN_SHIFT 0xf0000000 +#define FLD_I2S_IN_SHIFT 0x0f000000 +#define FLD_DEMATRIX_SEL_CTL 0x00ff0000 +/* Reserved [15:11] */ +#define FLD_DMTRX_BYPASS 0x00000400 +#define FLD_DEMATRIX_MODE 0x00000300 +/* Reserved [7:6] */ +#define FLD_PH_DBX_SEL 0x00000020 +#define FLD_PH_CH_SEL 0x00000010 +#define FLD_PHASE_FIX 0x0000000f + +/*****************************************************************************/ +#define PATH1_CTL1 0x8d0 +/* Reserved [31:29] */ +#define FLD_PATH1_MUTE_CTL 0x1f000000 +/* Reserved [23:22] */ +#define FLD_PATH1_AVC_CG 0x00300000 +#define FLD_PATH1_AVC_RT 0x000f0000 +#define FLD_PATH1_AVC_AT 0x0000f000 +#define FLD_PATH1_AVC_STEREO 0x00000800 +#define FLD_PATH1_AVC_CR 0x00000700 +#define FLD_PATH1_AVC_RMS_CON 0x000000f0 +#define FLD_PATH1_SEL_CTL 0x0000000f + +/*****************************************************************************/ +#define PATH1_VOL_CTL 0x8d4 +#define FLD_PATH1_AVC_THRESHOLD 0x7fff0000 +#define FLD_PATH1_BAL_LEFT 0x00008000 +#define FLD_PATH1_BAL_LEVEL 0x00007f00 +#define FLD_PATH1_VOLUME 0x000000ff + +/*****************************************************************************/ +#define PATH1_EQ_CTL 0x8d8 +/* Reserved [31:30] */ +#define FLD_PATH1_EQ_TREBLE_VOL 0x3f000000 +/* Reserved [23:22] */ +#define FLD_PATH1_EQ_MID_VOL 0x003f0000 +/* Reserved [15:14] */ +#define FLD_PATH1_EQ_BASS_VOL 0x00003f00 +/* Reserved [7:1] */ +#define FLD_PATH1_EQ_BAND_SEL 0x00000001 + +/*****************************************************************************/ +#define PATH1_SC_CTL 0x8dc +#define FLD_PATH1_SC_THRESHOLD 0x7fff0000 +#define FLD_PATH1_SC_RT 0x0000f000 +#define FLD_PATH1_SC_AT 0x00000f00 +#define FLD_PATH1_SC_STEREO 0x00000080 +#define FLD_PATH1_SC_CR 0x00000070 +#define FLD_PATH1_SC_RMS_CON 0x0000000f + +/*****************************************************************************/ +#define PATH2_CTL1 0x8e0 +/* Reserved [31:26] */ +#define FLD_PATH2_MUTE_CTL 0x03000000 +/* Reserved [23:22] */ +#define FLD_PATH2_AVC_CG 0x00300000 +#define FLD_PATH2_AVC_RT 0x000f0000 +#define FLD_PATH2_AVC_AT 0x0000f000 +#define FLD_PATH2_AVC_STEREO 0x00000800 +#define FLD_PATH2_AVC_CR 0x00000700 +#define FLD_PATH2_AVC_RMS_CON 0x000000f0 +#define FLD_PATH2_SEL_CTL 0x0000000f + +/*****************************************************************************/ +#define PATH2_VOL_CTL 0x8e4 +#define FLD_PATH2_AVC_THRESHOLD 0xffff0000 +#define FLD_PATH2_BAL_LEFT 0x00008000 +#define FLD_PATH2_BAL_LEVEL 0x00007f00 +#define FLD_PATH2_VOLUME 0x000000ff + +/*****************************************************************************/ +#define PATH2_EQ_CTL 0x8e8 +/* Reserved [31:30] */ +#define FLD_PATH2_EQ_TREBLE_VOL 0x3f000000 +/* Reserved [23:22] */ +#define FLD_PATH2_EQ_MID_VOL 0x003f0000 +/* Reserved [15:14] */ +#define FLD_PATH2_EQ_BASS_VOL 0x00003f00 +/* Reserved [7:1] */ +#define FLD_PATH2_EQ_BAND_SEL 0x00000001 + +/*****************************************************************************/ +#define PATH2_SC_CTL 0x8eC +#define FLD_PATH2_SC_THRESHOLD 0xffff0000 +#define FLD_PATH2_SC_RT 0x0000f000 +#define FLD_PATH2_SC_AT 0x00000f00 +#define FLD_PATH2_SC_STEREO 0x00000080 +#define FLD_PATH2_SC_CR 0x00000070 +#define FLD_PATH2_SC_RMS_CON 0x0000000f + +/*****************************************************************************/ +#define SRC_CTL 0x8f0 +#define FLD_SRC_STATUS 0xffffff00 +#define FLD_FIFO_LF_EN 0x000000fc +#define FLD_BYPASS_LI 0x00000002 +#define FLD_BYPASS_PF 0x00000001 + +/*****************************************************************************/ +#define SRC_LF_COEF 0x8f4 +#define FLD_LOOP_FILTER_COEF2 0xffff0000 +#define FLD_LOOP_FILTER_COEF1 0x0000ffff + +/*****************************************************************************/ +#define SRC1_CTL 0x8f8 +/* Reserved [31:28] */ +#define FLD_SRC1_FIFO_RD_TH 0x0f000000 +/* Reserved [23:18] */ +#define FLD_SRC1_PHASE_INC 0x0003ffff + +/*****************************************************************************/ +#define SRC2_CTL 0x8fc +/* Reserved [31:28] */ +#define FLD_SRC2_FIFO_RD_TH 0x0f000000 +/* Reserved [23:18] */ +#define FLD_SRC2_PHASE_INC 0x0003ffff + +/*****************************************************************************/ +#define SRC3_CTL 0x900 +/* Reserved [31:28] */ +#define FLD_SRC3_FIFO_RD_TH 0x0f000000 +/* Reserved [23:18] */ +#define FLD_SRC3_PHASE_INC 0x0003ffff + +/*****************************************************************************/ +#define SRC4_CTL 0x904 +/* Reserved [31:28] */ +#define FLD_SRC4_FIFO_RD_TH 0x0f000000 +/* Reserved [23:18] */ +#define FLD_SRC4_PHASE_INC 0x0003ffff + +/*****************************************************************************/ +#define SRC5_CTL 0x908 +/* Reserved [31:28] */ +#define FLD_SRC5_FIFO_RD_TH 0x0f000000 +/* Reserved [23:18] */ +#define FLD_SRC5_PHASE_INC 0x0003ffff + +/*****************************************************************************/ +#define SRC6_CTL 0x90c +/* Reserved [31:28] */ +#define FLD_SRC6_FIFO_RD_TH 0x0f000000 +/* Reserved [23:18] */ +#define FLD_SRC6_PHASE_INC 0x0003ffff + +/*****************************************************************************/ +#define BAND_OUT_SEL 0x910 +#define FLD_SRC6_IN_SEL 0xc0000000 +#define FLD_SRC6_CLK_SEL 0x30000000 +#define FLD_SRC5_IN_SEL 0x0c000000 +#define FLD_SRC5_CLK_SEL 0x03000000 +#define FLD_SRC4_IN_SEL 0x00c00000 +#define FLD_SRC4_CLK_SEL 0x00300000 +#define FLD_SRC3_IN_SEL 0x000c0000 +#define FLD_SRC3_CLK_SEL 0x00030000 +#define FLD_BASEBAND_BYPASS_CTL 0x0000ff00 +#define FLD_AC97_SRC_SEL 0x000000c0 +#define FLD_I2S_SRC_SEL 0x00000030 +#define FLD_PARALLEL2_SRC_SEL 0x0000000c +#define FLD_PARALLEL1_SRC_SEL 0x00000003 + +/*****************************************************************************/ +#define I2S_IN_CTL 0x914 +/* Reserved [31:11] */ +#define FLD_I2S_UP2X_BW20K 0x00000400 +#define FLD_I2S_UP2X_BYPASS 0x00000200 +#define FLD_I2S_IN_MASTER_MODE 0x00000100 +#define FLD_I2S_IN_SONY_MODE 0x00000080 +#define FLD_I2S_IN_RIGHT_JUST 0x00000040 +#define FLD_I2S_IN_WS_SEL 0x00000020 +#define FLD_I2S_IN_BCN_DEL 0x0000001f + +/*****************************************************************************/ +#define I2S_OUT_CTL 0x918 +/* Reserved [31:17] */ +#define FLD_I2S_OUT_SOFT_RESET_EN 0x00010000 +/* Reserved [15:9] */ +#define FLD_I2S_OUT_MASTER_MODE 0x00000100 +#define FLD_I2S_OUT_SONY_MODE 0x00000080 +#define FLD_I2S_OUT_RIGHT_JUST 0x00000040 +#define FLD_I2S_OUT_WS_SEL 0x00000020 +#define FLD_I2S_OUT_BCN_DEL 0x0000001f + +/*****************************************************************************/ +#define AC97_CTL 0x91c +/* Reserved [31:26] */ +#define FLD_AC97_UP2X_BW20K 0x02000000 +#define FLD_AC97_UP2X_BYPASS 0x01000000 +/* Reserved [23:17] */ +#define FLD_AC97_RST_ACL 0x00010000 +/* Reserved [15:9] */ +#define FLD_AC97_WAKE_UP_SYNC 0x00000100 +/* Reserved [7:1] */ +#define FLD_AC97_SHUTDOWN 0x00000001 + +/* Cx231xx redefine */ +#define QPSK_IAGC_CTL1 0x94c +#define QPSK_IAGC_CTL2 0x950 +#define QPSK_FEPR_FREQ 0x954 +#define QPSK_BTL_CTL1 0x958 +#define QPSK_BTL_CTL2 0x95c +#define QPSK_CTL_CTL1 0x960 +#define QPSK_CTL_CTL2 0x964 +#define QPSK_MF_FAGC_CTL 0x968 +#define QPSK_EQ_CTL 0x96c +#define QPSK_LOCK_CTL 0x970 + +/*****************************************************************************/ +#define FM1_DFT_CTL 0x9a8 +#define FLD_FM1_DFT_THRESHOLD 0xffff0000 +/* Reserved [15:8] */ +#define FLD_FM1_DFT_CMP_CTL 0x00000080 +#define FLD_FM1_DFT_AVG 0x00000070 +/* Reserved [3:1] */ +#define FLD_FM1_DFT_START 0x00000001 + +/*****************************************************************************/ +#define FM1_DFT_STATUS 0x9ac +#define FLD_FM1_DFT_DONE 0x80000000 +/* Reserved [30:19] */ +#define FLD_FM_DFT_TH_CMP 0x00040000 +#define FLD_FM1_DFT 0x0003ffff + +/*****************************************************************************/ +#define FM2_DFT_CTL 0x9b0 +#define FLD_FM2_DFT_THRESHOLD 0xffff0000 +/* Reserved [15:8] */ +#define FLD_FM2_DFT_CMP_CTL 0x00000080 +#define FLD_FM2_DFT_AVG 0x00000070 +/* Reserved [3:1] */ +#define FLD_FM2_DFT_START 0x00000001 + +/*****************************************************************************/ +#define FM2_DFT_STATUS 0x9b4 +#define FLD_FM2_DFT_DONE 0x80000000 +/* Reserved [30:19] */ +#define FLD_FM2_DFT_TH_CMP_STAT 0x00040000 +#define FLD_FM2_DFT 0x0003ffff + +/*****************************************************************************/ +/* Cx231xx redefine */ +#define AAGC_STATUS_REG 0x9b8 +#define AAGC_STATUS 0x9b8 +/* Reserved [31:27] */ +#define FLD_FM2_DAGC_OUT 0x07000000 +/* Reserved [23:19] */ +#define FLD_FM1_DAGC_OUT 0x00070000 +/* Reserved [15:6] */ +#define FLD_AFE_VGA_OUT 0x0000003f + +/*****************************************************************************/ +#define MTS_GAIN_STATUS 0x9bc +/* Reserved [31:14] */ +#define FLD_MTS_GAIN 0x00003fff + +#define RDS_OUT 0x9c0 +#define FLD_RDS_Q 0xffff0000 +#define FLD_RDS_I 0x0000ffff + +/*****************************************************************************/ +#define AUTOCONFIG_REG 0x9c4 +/* Reserved [31:4] */ +#define FLD_AUTOCONFIG_MODE 0x0000000f + +#define FM_AFC 0x9c8 +#define FLD_FM2_AFC 0xffff0000 +#define FLD_FM1_AFC 0x0000ffff + +/*****************************************************************************/ +/* Cx231xx redefine */ +#define NEW_SPARE 0x9cc +#define NEW_SPARE_REG 0x9cc + +/*****************************************************************************/ +#define DBX_ADJ 0x9d0 +/* Reserved [31:28] */ +#define FLD_DBX2_ADJ 0x0fff0000 +/* Reserved [15:12] */ +#define FLD_DBX1_ADJ 0x00000fff + +#define VID_FMT_AUTO 0 +#define VID_FMT_NTSC_M 1 +#define VID_FMT_NTSC_J 2 +#define VID_FMT_NTSC_443 3 +#define VID_FMT_PAL_BDGHI 4 +#define VID_FMT_PAL_M 5 +#define VID_FMT_PAL_N 6 +#define VID_FMT_PAL_NC 7 +#define VID_FMT_PAL_60 8 +#define VID_FMT_SECAM 12 +#define VID_FMT_SECAM_60 13 + +#define INPUT_MODE_CVBS_0 0 /* INPUT_MODE_VALUE(0) */ +#define INPUT_MODE_YC_1 1 /* INPUT_MODE_VALUE(1) */ +#define INPUT_MODE_YC2_2 2 /* INPUT_MODE_VALUE(2) */ +#define INPUT_MODE_YUV_3 3 /* INPUT_MODE_VALUE(3) */ + +#define LUMA_LPF_LOW_BANDPASS 0 /* 0.6Mhz LPF BW */ +#define LUMA_LPF_MEDIUM_BANDPASS 1 /* 1.0Mhz LPF BW */ +#define LUMA_LPF_HIGH_BANDPASS 2 /* 1.5Mhz LPF BW */ + +#define UV_LPF_LOW_BANDPASS 0 /* 0.6Mhz LPF BW */ +#define UV_LPF_MEDIUM_BANDPASS 1 /* 1.0Mhz LPF BW */ +#define UV_LPF_HIGH_BANDPASS 2 /* 1.5Mhz LPF BW */ + +#define TWO_TAP_FILT 0 +#define THREE_TAP_FILT 1 +#define FOUR_TAP_FILT 2 +#define FIVE_TAP_FILT 3 + +#define AUD_CHAN_SRC_PARALLEL 0 +#define AUD_CHAN_SRC_I2S_INPUT 1 +#define AUD_CHAN_SRC_FLATIRON 2 +#define AUD_CHAN_SRC_PARALLEL3 3 + +#define OUT_MODE_601 0 +#define OUT_MODE_656 1 +#define OUT_MODE_VIP11 2 +#define OUT_MODE_VIP20 3 + +#define PHASE_INC_49MHZ 0x0df22 +#define PHASE_INC_56MHZ 0x0fa5b +#define PHASE_INC_28MHZ 0x010000 + +#endif diff --git a/linux/drivers/media/video/cx231xx/cx231xx-vbi.c b/linux/drivers/media/video/cx231xx/cx231xx-vbi.c new file mode 100644 index 000000000..9080d1755 --- /dev/null +++ b/linux/drivers/media/video/cx231xx/cx231xx-vbi.c @@ -0,0 +1,715 @@ +/* + cx231xx_vbi.c - driver for Conexant Cx23100/101/102 USB video capture devices + + Copyright (C) 2008 <srinivasa.deevi at conexant dot com> + Based on cx88 driver + + 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/init.h> +#include <linux/list.h> +#include <linux/module.h> +#include <linux/kernel.h> +#include <linux/bitmap.h> +#include <linux/usb.h> +#include <linux/i2c.h> +#include <linux/version.h> +#include <linux/mm.h> +#include <linux/mutex.h> + +#include <media/v4l2-common.h> +#include <media/v4l2-ioctl.h> +#include <media/v4l2-chip-ident.h> +#include <media/msp3400.h> +#include <media/tuner.h> + +#include "cx231xx.h" +#include "cx231xx-vbi.h" + +static inline void print_err_status(struct cx231xx *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) { + cx231xx_err(DRIVER_NAME "URB status %d [%s].\n", status, + errmsg); + } else { + cx231xx_err(DRIVER_NAME "URB packet %d, status %d [%s].\n", + packet, status, errmsg); + } +} + +/* + * Controls the isoc copy of each urb packet + */ +static inline int cx231xx_isoc_vbi_copy(struct cx231xx *dev, struct urb *urb) +{ + struct cx231xx_buffer *buf; + struct cx231xx_dmaqueue *dma_q = urb->context; + int rc = 1; + unsigned char *p_buffer; + u32 bytes_parsed = 0, buffer_size = 0; + u8 sav_eav = 0; + + if (!dev) + return 0; + + if ((dev->state & DEV_DISCONNECTED) || (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->vbi_mode.isoc_ctl.buf; + + /* get buffer pointer and length */ + p_buffer = urb->transfer_buffer; + buffer_size = urb->actual_length; + + if (buffer_size > 0) { + bytes_parsed = 0; + + if (dma_q->is_partial_line) { + /* Handle the case where we were working on a partial + line */ + sav_eav = dma_q->last_sav; + } else { + /* Check for a SAV/EAV overlapping the + buffer boundary */ + + sav_eav = cx231xx_find_boundary_SAV_EAV(p_buffer, + dma_q->partial_buf, + &bytes_parsed); + } + + sav_eav &= 0xF0; + /* Get the first line if we have some portion of an SAV/EAV from + the last buffer or a partial line */ + if (sav_eav) { + bytes_parsed += cx231xx_get_vbi_line(dev, dma_q, + sav_eav, /* SAV/EAV */ + p_buffer + bytes_parsed, /* p_buffer */ + buffer_size - bytes_parsed); /* buffer size */ + } + + /* Now parse data that is completely in this buffer */ + dma_q->is_partial_line = 0; + + while (bytes_parsed < buffer_size) { + u32 bytes_used = 0; + + sav_eav = cx231xx_find_next_SAV_EAV( + p_buffer + bytes_parsed, /* p_buffer */ + buffer_size - bytes_parsed, /* buffer size */ + &bytes_used); /* bytes used to get SAV/EAV */ + + bytes_parsed += bytes_used; + + sav_eav &= 0xF0; + if (sav_eav && (bytes_parsed < buffer_size)) { + bytes_parsed += cx231xx_get_vbi_line(dev, + dma_q, sav_eav, /* SAV/EAV */ + p_buffer+bytes_parsed, /* p_buffer */ + buffer_size-bytes_parsed);/*buf size*/ + } + } + + /* Save the last four bytes of the buffer so we can + check the buffer boundary condition next time */ + memcpy(dma_q->partial_buf, p_buffer + buffer_size - 4, 4); + bytes_parsed = 0; + } + + return rc; +} + +/* ------------------------------------------------------------------ + Vbi buf operations + ------------------------------------------------------------------*/ + +static int +vbi_buffer_setup(struct videobuf_queue *vq, unsigned int *count, + unsigned int *size) +{ + struct cx231xx_fh *fh = vq->priv_data; + struct cx231xx *dev = fh->dev; + u32 height = 0; + + height = ((dev->norm & V4L2_STD_625_50) ? + PAL_VBI_LINES : NTSC_VBI_LINES); + + *size = (dev->width * height * 2); + if (0 == *count) + *count = CX231XX_DEF_VBI_BUF; + + 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; +} + +/* This is called *without* dev->slock held; please keep it that way */ +static void free_buffer(struct videobuf_queue *vq, struct cx231xx_buffer *buf) +{ + struct cx231xx_fh *fh = vq->priv_data; + struct cx231xx *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->vbi_mode.slock, flags); + if (dev->vbi_mode.isoc_ctl.buf == buf) + dev->vbi_mode.isoc_ctl.buf = NULL; + spin_unlock_irqrestore(&dev->vbi_mode.slock, flags); + + videobuf_vmalloc_free(&buf->vb); + buf->vb.state = VIDEOBUF_NEEDS_INIT; +} + +static int +vbi_buffer_prepare(struct videobuf_queue *vq, struct videobuf_buffer *vb, + enum v4l2_field field) +{ + struct cx231xx_fh *fh = vq->priv_data; + struct cx231xx_buffer *buf = + container_of(vb, struct cx231xx_buffer, vb); + struct cx231xx *dev = fh->dev; + int rc = 0, urb_init = 0; + u32 height = 0; + + height = ((dev->norm & V4L2_STD_625_50) ? + PAL_VBI_LINES : NTSC_VBI_LINES); + buf->vb.size = ((dev->width << 1) * height); + + if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size) + return -EINVAL; + + buf->vb.width = dev->width; + buf->vb.height = height; + buf->vb.field = field; + buf->vb.field = V4L2_FIELD_SEQ_TB; + + if (VIDEOBUF_NEEDS_INIT == buf->vb.state) { + rc = videobuf_iolock(vq, &buf->vb, NULL); + if (rc < 0) + goto fail; + } + + if (!dev->vbi_mode.isoc_ctl.num_bufs) + urb_init = 1; + + if (urb_init) { + rc = cx231xx_init_vbi_isoc(dev, CX231XX_NUM_VBI_PACKETS, + CX231XX_NUM_VBI_BUFS, + dev->vbi_mode.alt_max_pkt_size[0], + cx231xx_isoc_vbi_copy); + if (rc < 0) + goto fail; + } + + buf->vb.state = VIDEOBUF_PREPARED; + return 0; + +fail: + free_buffer(vq, buf); + return rc; +} + +static void +vbi_buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb) +{ + struct cx231xx_buffer *buf = + container_of(vb, struct cx231xx_buffer, vb); + struct cx231xx_fh *fh = vq->priv_data; + struct cx231xx *dev = fh->dev; + struct cx231xx_dmaqueue *vidq = &dev->vbi_mode.vidq; + + buf->vb.state = VIDEOBUF_QUEUED; + list_add_tail(&buf->vb.queue, &vidq->active); + +} + +static void vbi_buffer_release(struct videobuf_queue *vq, + struct videobuf_buffer *vb) +{ + struct cx231xx_buffer *buf = + container_of(vb, struct cx231xx_buffer, vb); + +#if 0 + struct cx231xx_fh *fh = vq->priv_data; + struct cx231xx *dev = (struct cx231xx *)fh->dev; + + cx231xx_info(DRIVER_NAME "cx231xx: called vbi_buffer_release\n"); +#endif + + free_buffer(vq, buf); +} + +struct videobuf_queue_ops cx231xx_vbi_qops = { + .buf_setup = vbi_buffer_setup, + .buf_prepare = vbi_buffer_prepare, + .buf_queue = vbi_buffer_queue, + .buf_release = vbi_buffer_release, +}; + +/* ------------------------------------------------------------------ + URB control + ------------------------------------------------------------------*/ + +/* + * IRQ callback, called by URB callback + */ +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 19) +static void cx231xx_irq_vbi_callback(struct urb *urb, struct pt_regs *regs) +#else +static void cx231xx_irq_vbi_callback(struct urb *urb) +#endif +{ + struct cx231xx_dmaqueue *dma_q = urb->context; + struct cx231xx_video_mode *vmode = + container_of(dma_q, struct cx231xx_video_mode, vidq); + struct cx231xx *dev = container_of(vmode, struct cx231xx, vbi_mode); + int rc; + + switch (urb->status) { + case 0: /* success */ + case -ETIMEDOUT: /* NAK */ + break; + case -ECONNRESET: /* kill */ + case -ENOENT: + case -ESHUTDOWN: + return; + default: /* error */ + cx231xx_err(DRIVER_NAME "urb completition error %d.\n", + urb->status); + break; + } + + /* Copy data from URB */ + spin_lock(&dev->vbi_mode.slock); + rc = dev->vbi_mode.isoc_ctl.isoc_copy(dev, urb); + spin_unlock(&dev->vbi_mode.slock); + + /* Reset status */ + urb->status = 0; + + urb->status = usb_submit_urb(urb, GFP_ATOMIC); + if (urb->status) { + cx231xx_err(DRIVER_NAME "urb resubmit failed (error=%i)\n", + urb->status); + } +} + +/* + * Stop and Deallocate URBs + */ +void cx231xx_uninit_vbi_isoc(struct cx231xx *dev) +{ + struct urb *urb; + int i; + + cx231xx_info(DRIVER_NAME "cx231xx: called cx231xx_uninit_vbi_isoc\n"); + + dev->vbi_mode.isoc_ctl.nfields = -1; + for (i = 0; i < dev->vbi_mode.isoc_ctl.num_bufs; i++) { + urb = dev->vbi_mode.isoc_ctl.urb[i]; + if (urb) { + if (!irqs_disabled()) + usb_kill_urb(urb); + else + usb_unlink_urb(urb); + + if (dev->vbi_mode.isoc_ctl.transfer_buffer[i]) { + + kfree(dev->vbi_mode.isoc_ctl. + transfer_buffer[i]); + dev->vbi_mode.isoc_ctl.transfer_buffer[i] = + NULL; + } + usb_free_urb(urb); + dev->vbi_mode.isoc_ctl.urb[i] = NULL; + } + dev->vbi_mode.isoc_ctl.transfer_buffer[i] = NULL; + } + + kfree(dev->vbi_mode.isoc_ctl.urb); + kfree(dev->vbi_mode.isoc_ctl.transfer_buffer); + + dev->vbi_mode.isoc_ctl.urb = NULL; + dev->vbi_mode.isoc_ctl.transfer_buffer = NULL; + dev->vbi_mode.isoc_ctl.num_bufs = 0; + + cx231xx_capture_start(dev, 0, Vbi); +} +EXPORT_SYMBOL_GPL(cx231xx_uninit_vbi_isoc); + +/* + * Allocate URBs and start IRQ + */ +int cx231xx_init_vbi_isoc(struct cx231xx *dev, int max_packets, + int num_bufs, int max_pkt_size, + int (*isoc_copy) (struct cx231xx *dev, + struct urb *urb)) +{ + struct cx231xx_dmaqueue *dma_q = &dev->vbi_mode.vidq; + int i; + int sb_size, pipe; + struct urb *urb; + int rc; + + cx231xx_info(DRIVER_NAME "cx231xx: called cx231xx_prepare_isoc\n"); + + /* De-allocates all pending stuff */ + cx231xx_uninit_vbi_isoc(dev); + + /* clear if any halt */ + usb_clear_halt(dev->udev, + usb_rcvbulkpipe(dev->udev, + dev->vbi_mode.end_point_addr)); + + dev->vbi_mode.isoc_ctl.isoc_copy = isoc_copy; + dev->vbi_mode.isoc_ctl.num_bufs = num_bufs; + dma_q->pos = 0; + dma_q->is_partial_line = 0; + dma_q->last_sav = 0; + dma_q->current_field = -1; + dma_q->bytes_left_in_line = dev->width << 1; + dma_q->lines_per_field = ((dev->norm & V4L2_STD_625_50) ? + PAL_VBI_LINES : NTSC_VBI_LINES); + dma_q->lines_completed = 0; + for (i = 0; i < 8; i++) + dma_q->partial_buf[i] = 0; + + dev->vbi_mode.isoc_ctl.urb = kzalloc(sizeof(void *) * num_bufs, + GFP_KERNEL); + if (!dev->vbi_mode.isoc_ctl.urb) { + cx231xx_errdev("cannot alloc memory for usb buffers\n"); + return -ENOMEM; + } + + dev->vbi_mode.isoc_ctl.transfer_buffer = + kzalloc(sizeof(void *) * num_bufs, GFP_KERNEL); + if (!dev->vbi_mode.isoc_ctl.transfer_buffer) { + cx231xx_errdev("cannot allocate memory for usbtransfer\n"); + kfree(dev->vbi_mode.isoc_ctl.urb); + return -ENOMEM; + } + + dev->vbi_mode.isoc_ctl.max_pkt_size = max_pkt_size; + dev->vbi_mode.isoc_ctl.buf = NULL; + + sb_size = max_packets * dev->vbi_mode.isoc_ctl.max_pkt_size; + + /* allocate urbs and transfer buffers */ + for (i = 0; i < dev->vbi_mode.isoc_ctl.num_bufs; i++) { + + urb = usb_alloc_urb(0, GFP_KERNEL); + if (!urb) { + cx231xx_err(DRIVER_NAME + ": cannot alloc isoc_ctl.urb %i\n", i); + cx231xx_uninit_vbi_isoc(dev); + return -ENOMEM; + } + dev->vbi_mode.isoc_ctl.urb[i] = urb; + urb->transfer_flags = 0; + + dev->vbi_mode.isoc_ctl.transfer_buffer[i] = + kzalloc(sb_size, GFP_KERNEL); + if (!dev->vbi_mode.isoc_ctl.transfer_buffer[i]) { + cx231xx_err(DRIVER_NAME + ": unable to allocate %i bytes for transfer" + " buffer %i%s\n", sb_size, i, + in_interrupt() ? " while in int" : ""); + cx231xx_uninit_vbi_isoc(dev); + return -ENOMEM; + } + + pipe = usb_rcvbulkpipe(dev->udev, dev->vbi_mode.end_point_addr); + usb_fill_bulk_urb(urb, dev->udev, pipe, + dev->vbi_mode.isoc_ctl.transfer_buffer[i], + sb_size, cx231xx_irq_vbi_callback, dma_q); + } + + init_waitqueue_head(&dma_q->wq); + + /* submit urbs and enables IRQ */ + for (i = 0; i < dev->vbi_mode.isoc_ctl.num_bufs; i++) { + rc = usb_submit_urb(dev->vbi_mode.isoc_ctl.urb[i], GFP_ATOMIC); + if (rc) { + cx231xx_err(DRIVER_NAME + ": submit of urb %i failed (error=%i)\n", i, + rc); + cx231xx_uninit_vbi_isoc(dev); + return rc; + } + } + + cx231xx_capture_start(dev, 1, Vbi); + + return 0; +} +EXPORT_SYMBOL_GPL(cx231xx_init_vbi_isoc); + +u32 cx231xx_get_vbi_line(struct cx231xx *dev, struct cx231xx_dmaqueue *dma_q, + u8 sav_eav, u8 *p_buffer, u32 buffer_size) +{ + u32 bytes_copied = 0; + int current_field = -1; + + switch (sav_eav) { + + case SAV_VBI_FIELD1: + current_field = 1; + break; + + case SAV_VBI_FIELD2: + current_field = 2; + break; + default: + break; + } + + if (current_field < 0) + return bytes_copied; + + dma_q->last_sav = sav_eav; + + bytes_copied = + cx231xx_copy_vbi_line(dev, dma_q, p_buffer, buffer_size, + current_field); + + return bytes_copied; +} + +/* + * Announces that a buffer were filled and request the next + */ +static inline void vbi_buffer_filled(struct cx231xx *dev, + struct cx231xx_dmaqueue *dma_q, + struct cx231xx_buffer *buf) +{ + /* Advice that buffer was filled */ + /* cx231xx_info(DRIVER_NAME "[%p/%d] wakeup\n", buf, buf->vb.i); */ + + buf->vb.state = VIDEOBUF_DONE; + buf->vb.field_count++; + do_gettimeofday(&buf->vb.ts); + + dev->vbi_mode.isoc_ctl.buf = NULL; + + list_del(&buf->vb.queue); + wake_up(&buf->vb.done); +} + +u32 cx231xx_copy_vbi_line(struct cx231xx *dev, struct cx231xx_dmaqueue *dma_q, + u8 *p_line, u32 length, int field_number) +{ + u32 bytes_to_copy; + struct cx231xx_buffer *buf; + u32 _line_size = dev->width * 2; + + if (dma_q->current_field != field_number) + cx231xx_reset_vbi_buffer(dev, dma_q); + + /* get the buffer pointer */ + buf = dev->vbi_mode.isoc_ctl.buf; + + /* Remember the field number for next time */ + dma_q->current_field = field_number; + + bytes_to_copy = dma_q->bytes_left_in_line; + if (bytes_to_copy > length) + bytes_to_copy = length; + + if (dma_q->lines_completed >= dma_q->lines_per_field) { + dma_q->bytes_left_in_line -= bytes_to_copy; + dma_q->is_partial_line = + (dma_q->bytes_left_in_line == 0) ? 0 : 1; + return 0; + } + + dma_q->is_partial_line = 1; + + /* If we don't have a buffer, just return the number of bytes we would + have copied if we had a buffer. */ + if (!buf) { + dma_q->bytes_left_in_line -= bytes_to_copy; + dma_q->is_partial_line = + (dma_q->bytes_left_in_line == 0) ? 0 : 1; + return bytes_to_copy; + } + + /* copy the data to video buffer */ + cx231xx_do_vbi_copy(dev, dma_q, p_line, bytes_to_copy); + + dma_q->pos += bytes_to_copy; + dma_q->bytes_left_in_line -= bytes_to_copy; + + if (dma_q->bytes_left_in_line == 0) { + + dma_q->bytes_left_in_line = _line_size; + dma_q->lines_completed++; + dma_q->is_partial_line = 0; + + if (cx231xx_is_vbi_buffer_done(dev, dma_q) && buf) { + + vbi_buffer_filled(dev, dma_q, buf); + + dma_q->pos = 0; + buf = NULL; + dma_q->lines_completed = 0; + } + } + + return bytes_to_copy; +} + +/* + * video-buf generic routine to get the next available buffer + */ +static inline void get_next_vbi_buf(struct cx231xx_dmaqueue *dma_q, + struct cx231xx_buffer **buf) +{ + struct cx231xx_video_mode *vmode = + container_of(dma_q, struct cx231xx_video_mode, vidq); + struct cx231xx *dev = container_of(vmode, struct cx231xx, vbi_mode); + char *outp; + + if (list_empty(&dma_q->active)) { + cx231xx_err(DRIVER_NAME ": No active queue to serve\n"); + dev->vbi_mode.isoc_ctl.buf = NULL; + *buf = NULL; + return; + } + + /* Get the next buffer */ + *buf = list_entry(dma_q->active.next, struct cx231xx_buffer, vb.queue); + + /* Cleans up buffer - Usefull for testing for frame/URB loss */ + outp = videobuf_to_vmalloc(&(*buf)->vb); + memset(outp, 0, (*buf)->vb.size); + + dev->vbi_mode.isoc_ctl.buf = *buf; + + return; +} + +void cx231xx_reset_vbi_buffer(struct cx231xx *dev, + struct cx231xx_dmaqueue *dma_q) +{ + struct cx231xx_buffer *buf; + + buf = dev->vbi_mode.isoc_ctl.buf; + + if (buf == NULL) { + /* first try to get the buffer */ + get_next_vbi_buf(dma_q, &buf); + + dma_q->pos = 0; + dma_q->current_field = -1; + } + + dma_q->bytes_left_in_line = dev->width << 1; + dma_q->lines_completed = 0; +} + +int cx231xx_do_vbi_copy(struct cx231xx *dev, struct cx231xx_dmaqueue *dma_q, + u8 *p_buffer, u32 bytes_to_copy) +{ + u8 *p_out_buffer = NULL; + u32 current_line_bytes_copied = 0; + struct cx231xx_buffer *buf; + u32 _line_size = dev->width << 1; + void *startwrite; + int offset, lencopy; + + buf = dev->vbi_mode.isoc_ctl.buf; + + if (buf == NULL) + return -EINVAL; + + p_out_buffer = videobuf_to_vmalloc(&buf->vb); + + if (dma_q->bytes_left_in_line != _line_size) { + current_line_bytes_copied = + _line_size - dma_q->bytes_left_in_line; + } + + offset = (dma_q->lines_completed * _line_size) + + current_line_bytes_copied; + + /* prepare destination address */ + startwrite = p_out_buffer + offset; + + lencopy = dma_q->bytes_left_in_line > bytes_to_copy ? + bytes_to_copy : dma_q->bytes_left_in_line; + + memcpy(startwrite, p_buffer, lencopy); + + return 0; +} + +u8 cx231xx_is_vbi_buffer_done(struct cx231xx *dev, + struct cx231xx_dmaqueue *dma_q) +{ + u32 height = 0; + + height = ((dev->norm & V4L2_STD_625_50) ? + PAL_VBI_LINES : NTSC_VBI_LINES); + return (dma_q->lines_completed == height) ? 1 : 0; +} diff --git a/linux/drivers/media/video/cx231xx/cx231xx-vbi.h b/linux/drivers/media/video/cx231xx/cx231xx-vbi.h new file mode 100644 index 000000000..89c7fe80b --- /dev/null +++ b/linux/drivers/media/video/cx231xx/cx231xx-vbi.h @@ -0,0 +1,65 @@ +/* + cx231xx_vbi.h - driver for Conexant Cx23100/101/102 USB video capture devices + + Copyright (C) 2008 <srinivasa.deevi at conexant dot com> + Based on cx88 driver + + 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 _CX231XX_VBI_H +#define _CX231XX_VBI_H + +extern struct videobuf_queue_ops cx231xx_vbi_qops; + +#define NTSC_VBI_START_LINE 10 /* line 10 - 21 */ +#define NTSC_VBI_END_LINE 21 +#define NTSC_VBI_LINES (NTSC_VBI_END_LINE-NTSC_VBI_START_LINE+1) + +#define PAL_VBI_START_LINE 6 +#define PAL_VBI_END_LINE 23 +#define PAL_VBI_LINES (PAL_VBI_END_LINE-PAL_VBI_START_LINE+1) + +#define VBI_STRIDE 1440 +#define VBI_SAMPLES_PER_LINE 1440 + +#define CX231XX_NUM_VBI_PACKETS 4 +#define CX231XX_NUM_VBI_BUFS 5 + +/* stream functions */ +int cx231xx_init_vbi_isoc(struct cx231xx *dev, int max_packets, + int num_bufs, int max_pkt_size, + int (*isoc_copy) (struct cx231xx *dev, + struct urb *urb)); + +void cx231xx_uninit_vbi_isoc(struct cx231xx *dev); + +/* vbi data copy functions */ +u32 cx231xx_get_vbi_line(struct cx231xx *dev, struct cx231xx_dmaqueue *dma_q, + u8 sav_eav, u8 *p_buffer, u32 buffer_size); + +u32 cx231xx_copy_vbi_line(struct cx231xx *dev, struct cx231xx_dmaqueue *dma_q, + u8 *p_line, u32 length, int field_number); + +void cx231xx_reset_vbi_buffer(struct cx231xx *dev, + struct cx231xx_dmaqueue *dma_q); + +int cx231xx_do_vbi_copy(struct cx231xx *dev, struct cx231xx_dmaqueue *dma_q, + u8 *p_buffer, u32 bytes_to_copy); + +u8 cx231xx_is_vbi_buffer_done(struct cx231xx *dev, + struct cx231xx_dmaqueue *dma_q); + +#endif diff --git a/linux/drivers/media/video/cx231xx/cx231xx-video.c b/linux/drivers/media/video/cx231xx/cx231xx-video.c new file mode 100644 index 000000000..6cb3ae90e --- /dev/null +++ b/linux/drivers/media/video/cx231xx/cx231xx-video.c @@ -0,0 +1,2452 @@ +/* + cx231xx-video.c - driver for Conexant Cx23100/101/102 + USB video capture devices + + Copyright (C) 2008 <srinivasa.deevi at conexant dot com> + Based on em28xx driver + Based on cx23885 driver + Based on cx88 driver + + 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/init.h> +#include <linux/list.h> +#include <linux/module.h> +#include <linux/kernel.h> +#include <linux/bitmap.h> +#include <linux/usb.h> +#include <linux/i2c.h> +#include <linux/version.h> +#include <linux/mm.h> +#include <linux/mutex.h> + +#include <media/v4l2-common.h> +#include <media/v4l2-ioctl.h> +#include <media/v4l2-chip-ident.h> +#include <media/msp3400.h> +#include <media/tuner.h> + +#include "dvb_frontend.h" + +#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" + +#define cx231xx_videodbg(fmt, arg...) do {\ + if (video_debug) \ + printk(KERN_INFO "%s %s :"fmt, \ + dev->name, __func__ , ##arg); } while (0) + +static unsigned int isoc_debug; +module_param(isoc_debug, int, 0644); +MODULE_PARM_DESC(isoc_debug, "enable debug messages [isoc transfers]"); + +#define cx231xx_isocdbg(fmt, arg...) \ +do {\ + if (isoc_debug) { \ + printk(KERN_INFO "%s %s :"fmt, \ + dev->name, __func__ , ##arg); \ + } \ + } while (0) + +MODULE_AUTHOR(DRIVER_AUTHOR); +MODULE_DESCRIPTION(DRIVER_DESC); +MODULE_LICENSE("GPL"); + +static unsigned int card[] = {[0 ... (CX231XX_MAXBOARDS - 1)] = UNSET }; +static unsigned int video_nr[] = {[0 ... (CX231XX_MAXBOARDS - 1)] = UNSET }; +static unsigned int vbi_nr[] = {[0 ... (CX231XX_MAXBOARDS - 1)] = UNSET }; +static unsigned int radio_nr[] = {[0 ... (CX231XX_MAXBOARDS - 1)] = UNSET }; + +module_param_array(card, int, NULL, 0444); +module_param_array(video_nr, int, NULL, 0444); +module_param_array(vbi_nr, int, NULL, 0444); +module_param_array(radio_nr, int, NULL, 0444); + +MODULE_PARM_DESC(card, "card type"); +MODULE_PARM_DESC(video_nr, "video device numbers"); +MODULE_PARM_DESC(vbi_nr, "vbi device numbers"); +MODULE_PARM_DESC(radio_nr, "radio device numbers"); + +static unsigned int video_debug; +module_param(video_debug, int, 0644); +MODULE_PARM_DESC(video_debug, "enable debug messages [video]"); + +/* supported video standards */ +static struct cx231xx_fmt format[] = { + { + .name = "16bpp YUY2, 4:2:2, packed", + .fourcc = V4L2_PIX_FMT_YUYV, + .depth = 16, + .reg = 0, + }, +}; + +/* supported controls */ +/* Common to all boards */ + +/* ------------------------------------------------------------------- */ + +static const struct v4l2_queryctrl no_ctl = { + .name = "42", + .flags = V4L2_CTRL_FLAG_DISABLED, +}; + +static struct cx231xx_ctrl cx231xx_ctls[] = { + /* --- video --- */ + { + .v = { + .id = V4L2_CID_BRIGHTNESS, + .name = "Brightness", + .minimum = 0x00, + .maximum = 0xff, + .step = 1, + .default_value = 0x7f, + .type = V4L2_CTRL_TYPE_INTEGER, + }, + .off = 128, + .reg = LUMA_CTRL, + .mask = 0x00ff, + .shift = 0, + }, { + .v = { + .id = V4L2_CID_CONTRAST, + .name = "Contrast", + .minimum = 0, + .maximum = 0xff, + .step = 1, + .default_value = 0x3f, + .type = V4L2_CTRL_TYPE_INTEGER, + }, + .off = 0, + .reg = LUMA_CTRL, + .mask = 0xff00, + .shift = 8, + }, { + .v = { + .id = V4L2_CID_HUE, + .name = "Hue", + .minimum = 0, + .maximum = 0xff, + .step = 1, + .default_value = 0x7f, + .type = V4L2_CTRL_TYPE_INTEGER, + }, + .off = 128, + .reg = CHROMA_CTRL, + .mask = 0xff0000, + .shift = 16, + }, { + /* strictly, this only describes only U saturation. + * V saturation is handled specially through code. + */ + .v = { + .id = V4L2_CID_SATURATION, + .name = "Saturation", + .minimum = 0, + .maximum = 0xff, + .step = 1, + .default_value = 0x7f, + .type = V4L2_CTRL_TYPE_INTEGER, + }, + .off = 0, + .reg = CHROMA_CTRL, + .mask = 0x00ff, + .shift = 0, + }, { + /* --- audio --- */ + .v = { + .id = V4L2_CID_AUDIO_MUTE, + .name = "Mute", + .minimum = 0, + .maximum = 1, + .default_value = 1, + .type = V4L2_CTRL_TYPE_BOOLEAN, + }, + .reg = PATH1_CTL1, + .mask = (0x1f << 24), + .shift = 24, + }, { + .v = { + .id = V4L2_CID_AUDIO_VOLUME, + .name = "Volume", + .minimum = 0, + .maximum = 0x3f, + .step = 1, + .default_value = 0x3f, + .type = V4L2_CTRL_TYPE_INTEGER, + }, + .reg = PATH1_VOL_CTL, + .mask = 0xff, + .shift = 0, + } +}; +static const int CX231XX_CTLS = ARRAY_SIZE(cx231xx_ctls); + +static const u32 cx231xx_user_ctrls[] = { + V4L2_CID_USER_CLASS, + V4L2_CID_BRIGHTNESS, + V4L2_CID_CONTRAST, + V4L2_CID_SATURATION, + V4L2_CID_HUE, + V4L2_CID_AUDIO_VOLUME, +#if 0 /* Keep */ + V4L2_CID_AUDIO_BALANCE, +#endif + V4L2_CID_AUDIO_MUTE, + 0 +}; + +static const u32 *ctrl_classes[] = { + cx231xx_user_ctrls, + NULL +}; + +/* ------------------------------------------------------------------ + Video buffer and parser functions + ------------------------------------------------------------------*/ + +/* + * Announces that a buffer were filled and request the next + */ +static inline void buffer_filled(struct cx231xx *dev, + struct cx231xx_dmaqueue *dma_q, + struct cx231xx_buffer *buf) +{ + /* Advice that buffer was filled */ + cx231xx_isocdbg("[%p/%d] wakeup\n", buf, buf->vb.i); + buf->vb.state = VIDEOBUF_DONE; + buf->vb.field_count++; + do_gettimeofday(&buf->vb.ts); + + dev->video_mode.isoc_ctl.buf = NULL; + + list_del(&buf->vb.queue); + wake_up(&buf->vb.done); +} + +static inline void print_err_status(struct cx231xx *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) { + cx231xx_isocdbg("URB status %d [%s].\n", status, errmsg); + } else { + cx231xx_isocdbg("URB packet %d, status %d [%s].\n", + packet, status, errmsg); + } +} + +/* + * video-buf generic routine to get the next available buffer + */ +static inline void get_next_buf(struct cx231xx_dmaqueue *dma_q, + struct cx231xx_buffer **buf) +{ + struct cx231xx_video_mode *vmode = + container_of(dma_q, struct cx231xx_video_mode, vidq); + struct cx231xx *dev = container_of(vmode, struct cx231xx, video_mode); + + char *outp; + + if (list_empty(&dma_q->active)) { + cx231xx_isocdbg("No active queue to serve\n"); + dev->video_mode.isoc_ctl.buf = NULL; + *buf = NULL; + return; + } + + /* Get the next buffer */ + *buf = list_entry(dma_q->active.next, struct cx231xx_buffer, vb.queue); + + /* Cleans up buffer - Usefull for testing for frame/URB loss */ + outp = videobuf_to_vmalloc(&(*buf)->vb); + memset(outp, 0, (*buf)->vb.size); + + dev->video_mode.isoc_ctl.buf = *buf; + + return; +} + +/* + * Controls the isoc copy of each urb packet + */ +static inline int cx231xx_isoc_copy(struct cx231xx *dev, struct urb *urb) +{ + struct cx231xx_buffer *buf; + struct cx231xx_dmaqueue *dma_q = urb->context; + unsigned char *outp = NULL; + int i, rc = 1; + unsigned char *p_buffer; + u32 bytes_parsed = 0, buffer_size = 0; + u8 sav_eav = 0; + + if (!dev) + return 0; + + if ((dev->state & DEV_DISCONNECTED) || (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->video_mode.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) { + /* cx231xx_isocdbg("packet %d is empty",i); - spammy */ + continue; + } + if (urb->iso_frame_desc[i].actual_length > + dev->video_mode.max_pkt_size) { + cx231xx_isocdbg("packet bigger than packet size"); + continue; + } + + /* get buffer pointer and length */ + p_buffer = urb->transfer_buffer + urb->iso_frame_desc[i].offset; + buffer_size = urb->iso_frame_desc[i].actual_length; + bytes_parsed = 0; + + if (dma_q->is_partial_line) { + /* Handle the case of a partial line */ + sav_eav = dma_q->last_sav; + } else { + /* Check for a SAV/EAV overlapping + the buffer boundary */ + sav_eav = + cx231xx_find_boundary_SAV_EAV(p_buffer, + dma_q->partial_buf, + &bytes_parsed); + } + + sav_eav &= 0xF0; + /* Get the first line if we have some portion of an SAV/EAV from + the last buffer or a partial line */ + if (sav_eav) { + bytes_parsed += cx231xx_get_video_line(dev, dma_q, + sav_eav, /* SAV/EAV */ + p_buffer + bytes_parsed, /* p_buffer */ + buffer_size - bytes_parsed);/* buf size */ + } + + /* Now parse data that is completely in this buffer */ + /* dma_q->is_partial_line = 0; */ + + while (bytes_parsed < buffer_size) { + u32 bytes_used = 0; + + sav_eav = cx231xx_find_next_SAV_EAV( + p_buffer + bytes_parsed, /* p_buffer */ + buffer_size - bytes_parsed, /* buf size */ + &bytes_used);/* bytes used to get SAV/EAV */ + + bytes_parsed += bytes_used; + + sav_eav &= 0xF0; + if (sav_eav && (bytes_parsed < buffer_size)) { + bytes_parsed += cx231xx_get_video_line(dev, + dma_q, sav_eav, /* SAV/EAV */ + p_buffer + bytes_parsed,/* p_buffer */ + buffer_size - bytes_parsed);/*buf size*/ + } + } + + /* Save the last four bytes of the buffer so we can check the + buffer boundary condition next time */ + memcpy(dma_q->partial_buf, p_buffer + buffer_size - 4, 4); + bytes_parsed = 0; + + } + return rc; +} + +u8 cx231xx_find_boundary_SAV_EAV(u8 *p_buffer, u8 *partial_buf, + u32 *p_bytes_used) +{ + u32 bytes_used; + u8 boundary_bytes[8]; + u8 sav_eav = 0; + + *p_bytes_used = 0; + + /* Create an array of the last 4 bytes of the last buffer and the first + 4 bytes of the current buffer. */ + + memcpy(boundary_bytes, partial_buf, 4); + memcpy(boundary_bytes + 4, p_buffer, 4); + + /* Check for the SAV/EAV in the boundary buffer */ + sav_eav = cx231xx_find_next_SAV_EAV((u8 *)&boundary_bytes, 8, + &bytes_used); + + if (sav_eav) { + /* found a boundary SAV/EAV. Updates the bytes used to reflect + only those used in the new buffer */ + *p_bytes_used = bytes_used - 4; + } + + return sav_eav; +} + +u8 cx231xx_find_next_SAV_EAV(u8 *p_buffer, u32 buffer_size, u32 *p_bytes_used) +{ + u32 i; + u8 sav_eav = 0; + + /* + * Don't search if the buffer size is less than 4. It causes a page + * fault since buffer_size - 4 evaluates to a large number in that + * case. + */ + if (buffer_size < 4) { + *p_bytes_used = buffer_size; + return 0; + } + + for (i = 0; i < (buffer_size - 3); i++) { + + if ((p_buffer[i] == 0xFF) && + (p_buffer[i + 1] == 0x00) && (p_buffer[i + 2] == 0x00)) { + + *p_bytes_used = i + 4; + sav_eav = p_buffer[i + 3]; + return sav_eav; + } + } + + *p_bytes_used = buffer_size; + return 0; +} + +u32 cx231xx_get_video_line(struct cx231xx *dev, + struct cx231xx_dmaqueue *dma_q, u8 sav_eav, + u8 *p_buffer, u32 buffer_size) +{ + u32 bytes_copied = 0; + int current_field = -1; + + switch (sav_eav) { + case SAV_ACTIVE_VIDEO_FIELD1: + /* looking for skipped line which occurred in PAL 720x480 mode. + In this case, there will be no active data contained + between the SAV and EAV */ + if ((buffer_size > 3) && (p_buffer[0] == 0xFF) && + (p_buffer[1] == 0x00) && (p_buffer[2] == 0x00) && + ((p_buffer[3] == EAV_ACTIVE_VIDEO_FIELD1) || + (p_buffer[3] == EAV_ACTIVE_VIDEO_FIELD2) || + (p_buffer[3] == EAV_VBLANK_FIELD1) || + (p_buffer[3] == EAV_VBLANK_FIELD2))) + return bytes_copied; + current_field = 1; + break; + + case SAV_ACTIVE_VIDEO_FIELD2: + /* looking for skipped line which occurred in PAL 720x480 mode. + In this case, there will be no active data contained between + the SAV and EAV */ + if ((buffer_size > 3) && (p_buffer[0] == 0xFF) && + (p_buffer[1] == 0x00) && (p_buffer[2] == 0x00) && + ((p_buffer[3] == EAV_ACTIVE_VIDEO_FIELD1) || + (p_buffer[3] == EAV_ACTIVE_VIDEO_FIELD2) || + (p_buffer[3] == EAV_VBLANK_FIELD1) || + (p_buffer[3] == EAV_VBLANK_FIELD2))) + return bytes_copied; + current_field = 2; + break; + } + + dma_q->last_sav = sav_eav; + + bytes_copied = cx231xx_copy_video_line(dev, dma_q, p_buffer, + buffer_size, current_field); + + return bytes_copied; +} + +u32 cx231xx_copy_video_line(struct cx231xx *dev, + struct cx231xx_dmaqueue *dma_q, u8 *p_line, + u32 length, int field_number) +{ + u32 bytes_to_copy; + struct cx231xx_buffer *buf; + u32 _line_size = dev->width * 2; + + if (dma_q->current_field != field_number) + cx231xx_reset_video_buffer(dev, dma_q); + + /* get the buffer pointer */ + buf = dev->video_mode.isoc_ctl.buf; + + /* Remember the field number for next time */ + dma_q->current_field = field_number; + + bytes_to_copy = dma_q->bytes_left_in_line; + if (bytes_to_copy > length) + bytes_to_copy = length; + + if (dma_q->lines_completed >= dma_q->lines_per_field) { + dma_q->bytes_left_in_line -= bytes_to_copy; + dma_q->is_partial_line = (dma_q->bytes_left_in_line == 0) ? + 0 : 1; + return 0; + } + + dma_q->is_partial_line = 1; + + /* If we don't have a buffer, just return the number of bytes we would + have copied if we had a buffer. */ + if (!buf) { + dma_q->bytes_left_in_line -= bytes_to_copy; + dma_q->is_partial_line = (dma_q->bytes_left_in_line == 0) + ? 0 : 1; + return bytes_to_copy; + } + + /* copy the data to video buffer */ + cx231xx_do_copy(dev, dma_q, p_line, bytes_to_copy); + + dma_q->pos += bytes_to_copy; + dma_q->bytes_left_in_line -= bytes_to_copy; + + if (dma_q->bytes_left_in_line == 0) { + dma_q->bytes_left_in_line = _line_size; + dma_q->lines_completed++; + dma_q->is_partial_line = 0; + + if (cx231xx_is_buffer_done(dev, dma_q) && buf) { + buffer_filled(dev, dma_q, buf); + + dma_q->pos = 0; + buf = NULL; + dma_q->lines_completed = 0; + } + } + + return bytes_to_copy; +} + +void cx231xx_reset_video_buffer(struct cx231xx *dev, + struct cx231xx_dmaqueue *dma_q) +{ + struct cx231xx_buffer *buf; + + /* handle the switch from field 1 to field 2 */ + if (dma_q->current_field == 1) { + if (dma_q->lines_completed >= dma_q->lines_per_field) + dma_q->field1_done = 1; + else + dma_q->field1_done = 0; + } + + buf = dev->video_mode.isoc_ctl.buf; + + if (buf == NULL) { + u8 *outp = NULL; + /* first try to get the buffer */ + get_next_buf(dma_q, &buf); + + if (buf) + outp = videobuf_to_vmalloc(&buf->vb); + + dma_q->pos = 0; + dma_q->field1_done = 0; + dma_q->current_field = -1; + } + + /* reset the counters */ + dma_q->bytes_left_in_line = dev->width << 1; + dma_q->lines_completed = 0; +} + +int cx231xx_do_copy(struct cx231xx *dev, struct cx231xx_dmaqueue *dma_q, + u8 *p_buffer, u32 bytes_to_copy) +{ + u8 *p_out_buffer = NULL; + u32 current_line_bytes_copied = 0; + struct cx231xx_buffer *buf; + u32 _line_size = dev->width << 1; + void *startwrite; + int offset, lencopy; + + buf = dev->video_mode.isoc_ctl.buf; + + if (buf == NULL) + return -1; + + p_out_buffer = videobuf_to_vmalloc(&buf->vb); + + current_line_bytes_copied = _line_size - dma_q->bytes_left_in_line; + + /* Offset field 2 one line from the top of the buffer */ + offset = (dma_q->current_field == 1) ? 0 : _line_size; + + /* Offset for field 2 */ + startwrite = p_out_buffer + offset; + + /* lines already completed in the current field */ + startwrite += (dma_q->lines_completed * _line_size * 2); + + /* bytes already completed in the current line */ + startwrite += current_line_bytes_copied; + + lencopy = dma_q->bytes_left_in_line > bytes_to_copy ? + bytes_to_copy : dma_q->bytes_left_in_line; + + if ((u8 *)(startwrite + lencopy) > (u8 *)(p_out_buffer + buf->vb.size)) + return 0; + + /* The below copies the UYVY data straight into video buffer */ + cx231xx_swab((u16 *) p_buffer, (u16 *) startwrite, (u16) lencopy); + + return 0; +} + +void cx231xx_swab(u16 *from, u16 *to, u16 len) +{ + u16 i; + + if (len <= 0) + return; + + for (i = 0; i < len / 2; i++) + to[i] = (from[i] << 8) | (from[i] >> 8); +} + +u8 cx231xx_is_buffer_done(struct cx231xx *dev, struct cx231xx_dmaqueue *dma_q) +{ + u8 buffer_complete = 0; + + /* Dual field stream */ + buffer_complete = ((dma_q->current_field == 2) && + (dma_q->lines_completed >= dma_q->lines_per_field) && + dma_q->field1_done); + + return buffer_complete; +} + +/* ------------------------------------------------------------------ + Videobuf operations + ------------------------------------------------------------------*/ + +static int +buffer_setup(struct videobuf_queue *vq, unsigned int *count, unsigned int *size) +{ + struct cx231xx_fh *fh = vq->priv_data; + struct cx231xx *dev = fh->dev; + struct v4l2_frequency f; + + *size = (fh->dev->width * fh->dev->height * dev->format->depth + 7)>>3; + if (0 == *count) + *count = CX231XX_DEF_BUF; + + if (*count < CX231XX_MIN_BUF) + *count = CX231XX_MIN_BUF; + + /* Ask tuner to go to analog mode */ + memset(&f, 0, sizeof(f)); + 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); + + return 0; +} + +/* This is called *without* dev->slock held; please keep it that way */ +static void free_buffer(struct videobuf_queue *vq, struct cx231xx_buffer *buf) +{ + struct cx231xx_fh *fh = vq->priv_data; + struct cx231xx *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->video_mode.slock, flags); + if (dev->video_mode.isoc_ctl.buf == buf) + dev->video_mode.isoc_ctl.buf = NULL; + spin_unlock_irqrestore(&dev->video_mode.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 cx231xx_fh *fh = vq->priv_data; + struct cx231xx_buffer *buf = + container_of(vb, struct cx231xx_buffer, vb); + struct cx231xx *dev = fh->dev; + int rc = 0, urb_init = 0; + + /* The only currently supported format is 16 bits/pixel */ + buf->vb.size = (fh->dev->width * fh->dev->height * dev->format->depth + + 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) + goto fail; + } + + if (!dev->video_mode.isoc_ctl.num_bufs) + urb_init = 1; + + if (urb_init) { + rc = cx231xx_init_isoc(dev, CX231XX_NUM_PACKETS, + CX231XX_NUM_BUFS, + dev->video_mode.max_pkt_size, + cx231xx_isoc_copy); + if (rc < 0) + 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 cx231xx_buffer *buf = + container_of(vb, struct cx231xx_buffer, vb); + struct cx231xx_fh *fh = vq->priv_data; + struct cx231xx *dev = fh->dev; + struct cx231xx_dmaqueue *vidq = &dev->video_mode.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 cx231xx_buffer *buf = + container_of(vb, struct cx231xx_buffer, vb); + struct cx231xx_fh *fh = vq->priv_data; + struct cx231xx *dev = (struct cx231xx *)fh->dev; + + cx231xx_isocdbg("cx231xx: called buffer_release\n"); + + free_buffer(vq, buf); +} + +static struct videobuf_queue_ops cx231xx_video_qops = { + .buf_setup = buffer_setup, + .buf_prepare = buffer_prepare, + .buf_queue = buffer_queue, + .buf_release = buffer_release, +}; + +/********************* v4l2 interface **************************************/ + +void video_mux(struct cx231xx *dev, int index) +{ + + struct v4l2_routing route; + + route.input = INPUT(index)->vmux; + route.output = 0; + dev->video_input = index; + dev->ctl_ainput = INPUT(index)->amux; + + cx231xx_set_video_input_mux(dev, index); + + cx231xx_i2c_call_clients(&dev->i2c_bus[0], VIDIOC_INT_S_VIDEO_ROUTING, + &route); + + cx231xx_set_audio_input(dev, dev->ctl_ainput); + + cx231xx_info("video_mux : %d\n", index); + + /* do mode control overrides if required */ + cx231xx_do_mode_ctrl_overrides(dev); +} + +/* Usage lock check functions */ +static int res_get(struct cx231xx_fh *fh) +{ + struct cx231xx *dev = fh->dev; + int rc = 0; + + /* This instance already has stream_on */ + if (fh->stream_on) + return rc; + + if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) { + if (dev->stream_on) + return -EBUSY; + dev->stream_on = 1; + } else if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE) { + if (dev->vbi_stream_on) + return -EBUSY; + dev->vbi_stream_on = 1; + } else + return -EINVAL; + + fh->stream_on = 1; + + return rc; +} + +static int res_check(struct cx231xx_fh *fh) +{ + return fh->stream_on; +} + +static void res_free(struct cx231xx_fh *fh) +{ + struct cx231xx *dev = fh->dev; + + fh->stream_on = 0; + + if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) + dev->stream_on = 0; + if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE) + dev->vbi_stream_on = 0; +} + +static int check_dev(struct cx231xx *dev) +{ + if (dev->state & DEV_DISCONNECTED) { + cx231xx_errdev("v4l2 ioctl: device not present\n"); + return -ENODEV; + } + + if (dev->state & DEV_MISCONFIGURED) { + cx231xx_errdev("v4l2 ioctl: device is misconfigured; " + "close and open it again\n"); + return -EIO; + } + return 0; +} + +void get_scale(struct cx231xx *dev, + unsigned int width, unsigned int height, + unsigned int *hscale, unsigned int *vscale) +{ + unsigned int maxw = norm_maxw(dev); + unsigned int maxh = norm_maxh(dev); + + *hscale = (((unsigned long)maxw) << 12) / width - 4096L; + if (*hscale >= 0x4000) + *hscale = 0x3fff; + + *vscale = (((unsigned long)maxh) << 12) / height - 4096L; + if (*vscale >= 0x4000) + *vscale = 0x3fff; + + dev->hscale = *hscale; + dev->vscale = *vscale; + +} + +/* ------------------------------------------------------------------ + IOCTL vidioc handling + ------------------------------------------------------------------*/ + +static int vidioc_g_fmt_vid_cap(struct file *file, void *priv, + struct v4l2_format *f) +{ + struct cx231xx_fh *fh = priv; + struct cx231xx *dev = fh->dev; + + mutex_lock(&dev->lock); + + f->fmt.pix.width = dev->width; + f->fmt.pix.height = dev->height; + f->fmt.pix.pixelformat = dev->format->fourcc;; + f->fmt.pix.bytesperline = (dev->width * dev->format->depth + 7) >> 3;; + f->fmt.pix.sizeimage = f->fmt.pix.bytesperline * dev->height; + f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; + + f->fmt.pix.field = V4L2_FIELD_INTERLACED; + + mutex_unlock(&dev->lock); + + return 0; +} + +static struct cx231xx_fmt *format_by_fourcc(unsigned int fourcc) +{ + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(format); i++) + if (format[i].fourcc == fourcc) + return &format[i]; + + return NULL; +} + +static int vidioc_try_fmt_vid_cap(struct file *file, void *priv, + struct v4l2_format *f) +{ + struct cx231xx_fh *fh = priv; + struct cx231xx *dev = fh->dev; + int width = f->fmt.pix.width; + int height = f->fmt.pix.height; + unsigned int maxw = norm_maxw(dev); + unsigned int maxh = norm_maxh(dev); + unsigned int hscale, vscale; + struct cx231xx_fmt *fmt; + + fmt = format_by_fourcc(f->fmt.pix.pixelformat); + if (!fmt) { + cx231xx_videodbg("Fourcc format (%08x) invalid.\n", + f->fmt.pix.pixelformat); + return -EINVAL; + } + + /* width must even because of the YUYV format + height must be even because of interlacing */ + height &= 0xfffe; + width &= 0xfffe; + + if (unlikely(height < 32)) + height = 32; + if (unlikely(height > maxh)) + height = maxh; + if (unlikely(width < 48)) + width = 48; + if (unlikely(width > maxw)) + width = maxw; + + get_scale(dev, width, height, &hscale, &vscale); + + width = (((unsigned long)maxw) << 12) / (hscale + 4096L); + height = (((unsigned long)maxh) << 12) / (vscale + 4096L); + + f->fmt.pix.width = width; + f->fmt.pix.height = height; + f->fmt.pix.pixelformat = fmt->fourcc; + f->fmt.pix.bytesperline = (dev->width * fmt->depth + 7) >> 3; + f->fmt.pix.sizeimage = f->fmt.pix.bytesperline * height; + f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; + f->fmt.pix.field = V4L2_FIELD_INTERLACED; + + return 0; +} + +static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, + struct v4l2_format *f) +{ + struct cx231xx_fh *fh = priv; + struct cx231xx *dev = fh->dev; + int rc; + struct cx231xx_fmt *fmt; + + rc = check_dev(dev); + if (rc < 0) + return rc; + + mutex_lock(&dev->lock); + + vidioc_try_fmt_vid_cap(file, priv, f); + + fmt = format_by_fourcc(f->fmt.pix.pixelformat); + if (!fmt) { + rc = -EINVAL; + goto out; + } + + if (videobuf_queue_is_busy(&fh->vb_vidq)) { + cx231xx_errdev("%s queue busy\n", __func__); + rc = -EBUSY; + goto out; + } + + if (dev->stream_on && !fh->stream_on) { + cx231xx_errdev("%s device in use by another fh\n", __func__); + rc = -EBUSY; + goto out; + } + + /* set new image size */ + dev->width = f->fmt.pix.width; + dev->height = f->fmt.pix.height; + 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); + + /* Set the correct alternate setting for this resolution */ + cx231xx_resolution_set(dev); + +out: + mutex_unlock(&dev->lock); + return rc; +} + +static int vidioc_g_std(struct file *file, void *priv, v4l2_std_id * id) +{ + struct cx231xx_fh *fh = priv; + struct cx231xx *dev = fh->dev; + + *id = dev->norm; + return 0; +} + +static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id * norm) +{ + struct cx231xx_fh *fh = priv; + struct cx231xx *dev = fh->dev; + struct v4l2_format f; + int rc; + + rc = check_dev(dev); + if (rc < 0) + return rc; + + cx231xx_info("vidioc_s_std : 0x%x\n", (unsigned int)*norm); + + mutex_lock(&dev->lock); + dev->norm = *norm; + + /* Adjusts width/height, if needed */ + f.fmt.pix.width = dev->width; + f.fmt.pix.height = dev->height; + vidioc_try_fmt_vid_cap(file, priv, &f); + + /* set new image size */ + dev->width = f.fmt.pix.width; + 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); + + mutex_unlock(&dev->lock); + + cx231xx_resolution_set(dev); + + /* do mode control overrides */ + cx231xx_do_mode_ctrl_overrides(dev); + + return 0; +} + +static const char *iname[] = { + [CX231XX_VMUX_COMPOSITE1] = "Composite1", + [CX231XX_VMUX_SVIDEO] = "S-Video", + [CX231XX_VMUX_TELEVISION] = "Television", + [CX231XX_VMUX_CABLE] = "Cable TV", + [CX231XX_VMUX_DVB] = "DVB", + [CX231XX_VMUX_DEBUG] = "for debug only", +}; + +static int vidioc_enum_input(struct file *file, void *priv, + struct v4l2_input *i) +{ + struct cx231xx_fh *fh = priv; + struct cx231xx *dev = fh->dev; + unsigned int n; + + n = i->index; + if (n >= MAX_CX231XX_INPUT) + return -EINVAL; + if (0 == INPUT(n)->type) + return -EINVAL; + + i->index = n; + i->type = V4L2_INPUT_TYPE_CAMERA; + + strcpy(i->name, iname[INPUT(n)->type]); + + if ((CX231XX_VMUX_TELEVISION == INPUT(n)->type) || + (CX231XX_VMUX_CABLE == INPUT(n)->type)) + i->type = V4L2_INPUT_TYPE_TUNER; + + i->std = dev->vdev->tvnorms; + + return 0; +} + +static int vidioc_g_input(struct file *file, void *priv, unsigned int *i) +{ + struct cx231xx_fh *fh = priv; + struct cx231xx *dev = fh->dev; + + *i = dev->video_input; + + return 0; +} + +static int vidioc_s_input(struct file *file, void *priv, unsigned int i) +{ + struct cx231xx_fh *fh = priv; + struct cx231xx *dev = fh->dev; + int rc; + + rc = check_dev(dev); + if (rc < 0) + return rc; + + if (i >= MAX_CX231XX_INPUT) + return -EINVAL; + if (0 == INPUT(i)->type) + return -EINVAL; + + mutex_lock(&dev->lock); + + video_mux(dev, i); + + mutex_unlock(&dev->lock); + return 0; +} + +static int vidioc_g_audio(struct file *file, void *priv, struct v4l2_audio *a) +{ + struct cx231xx_fh *fh = priv; + struct cx231xx *dev = fh->dev; + + switch (a->index) { + case CX231XX_AMUX_VIDEO: + strcpy(a->name, "Television"); + break; + case CX231XX_AMUX_LINE_IN: + strcpy(a->name, "Line In"); + break; + default: + return -EINVAL; + } + + a->index = dev->ctl_ainput; + a->capability = V4L2_AUDCAP_STEREO; + + return 0; +} + +static int vidioc_s_audio(struct file *file, void *priv, struct v4l2_audio *a) +{ + struct cx231xx_fh *fh = priv; + struct cx231xx *dev = fh->dev; + int status = 0; + + /* Doesn't allow manual routing */ + if (a->index != dev->ctl_ainput) + return -EINVAL; + + dev->ctl_ainput = INPUT(a->index)->amux; + status = cx231xx_set_audio_input(dev, dev->ctl_ainput); + + return status; +} + +static int vidioc_queryctrl(struct file *file, void *priv, + struct v4l2_queryctrl *qc) +{ + struct cx231xx_fh *fh = priv; + struct cx231xx *dev = fh->dev; + int id = qc->id; + int i; + int rc; + + rc = check_dev(dev); + if (rc < 0) + return rc; + + qc->id = v4l2_ctrl_next(ctrl_classes, qc->id); + if (unlikely(qc->id == 0)) + return -EINVAL; + + memset(qc, 0, sizeof(*qc)); + + qc->id = id; + + if (qc->id < V4L2_CID_BASE || qc->id >= V4L2_CID_LASTP1) + return -EINVAL; + + for (i = 0; i < CX231XX_CTLS; i++) + if (cx231xx_ctls[i].v.id == qc->id) + break; + + if (i == CX231XX_CTLS) { + *qc = no_ctl; + return 0; + } + *qc = cx231xx_ctls[i].v; + + mutex_lock(&dev->lock); + cx231xx_i2c_call_clients(&dev->i2c_bus[0], VIDIOC_QUERYCTRL, qc); + mutex_unlock(&dev->lock); + + if (qc->type) + return 0; + else + return -EINVAL; +} + +static int vidioc_g_ctrl(struct file *file, void *priv, + struct v4l2_control *ctrl) +{ + struct cx231xx_fh *fh = priv; + struct cx231xx *dev = fh->dev; + int rc; + + rc = check_dev(dev); + if (rc < 0) + return rc; + + mutex_lock(&dev->lock); + + cx231xx_i2c_call_clients(&dev->i2c_bus[0], VIDIOC_G_CTRL, ctrl); + + mutex_unlock(&dev->lock); + return rc; +} + +static int vidioc_s_ctrl(struct file *file, void *priv, + struct v4l2_control *ctrl) +{ + struct cx231xx_fh *fh = priv; + struct cx231xx *dev = fh->dev; + int rc; + + rc = check_dev(dev); + if (rc < 0) + return rc; + + mutex_lock(&dev->lock); + + cx231xx_i2c_call_clients(&dev->i2c_bus[0], VIDIOC_S_CTRL, ctrl); + + mutex_unlock(&dev->lock); + return rc; +} + +static int vidioc_g_tuner(struct file *file, void *priv, struct v4l2_tuner *t) +{ + struct cx231xx_fh *fh = priv; + struct cx231xx *dev = fh->dev; + int rc; + + rc = check_dev(dev); + if (rc < 0) + return rc; + + if (0 != t->index) + return -EINVAL; + + strcpy(t->name, "Tuner"); + + t->type = V4L2_TUNER_ANALOG_TV; + t->capability = V4L2_TUNER_CAP_NORM; + t->rangehigh = 0xffffffffUL; + t->signal = 0xffff; /* LOCKED */ + + return 0; +} + +static int vidioc_s_tuner(struct file *file, void *priv, struct v4l2_tuner *t) +{ + struct cx231xx_fh *fh = priv; + struct cx231xx *dev = fh->dev; + int rc; + + rc = check_dev(dev); + if (rc < 0) + return rc; + + if (0 != t->index) + return -EINVAL; +#if 0 /* Keep */ + mutex_lock(&dev->lock); + + cx231xx_i2c_call_clients(&dev->i2c_bus[1], VIDIOC_S_TUNER, t); + + mutex_unlock(&dev->lock); +#endif + return 0; +} + +static int vidioc_g_frequency(struct file *file, void *priv, + struct v4l2_frequency *f) +{ + struct cx231xx_fh *fh = priv; + struct cx231xx *dev = fh->dev; + + mutex_lock(&dev->lock); + 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); + + mutex_unlock(&dev->lock); + + return 0; +} + +static int vidioc_s_frequency(struct file *file, void *priv, + struct v4l2_frequency *f) +{ + struct cx231xx_fh *fh = priv; + struct cx231xx *dev = fh->dev; + int rc; + + rc = check_dev(dev); + if (rc < 0) + return rc; + + if (0 != f->tuner) + return -EINVAL; + + if (unlikely(0 == fh->radio && f->type != V4L2_TUNER_ANALOG_TV)) + return -EINVAL; + if (unlikely(1 == fh->radio && f->type != V4L2_TUNER_RADIO)) + return -EINVAL; + + /* set pre channel change settings in DIF first */ + rc = cx231xx_tuner_pre_channel_change(dev); + + mutex_lock(&dev->lock); + + dev->ctl_freq = f->frequency; + + 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); + } + + mutex_unlock(&dev->lock); + + /* set post channel change settings in DIF first */ + rc = cx231xx_tuner_post_channel_change(dev); + + cx231xx_info("Set New FREQUENCY to %d\n", f->frequency); + + return rc; +} + +#ifdef CONFIG_VIDEO_ADV_DEBUG + +/* + -R, --list-registers=type=<host/i2cdrv/i2caddr>, + chip=<chip>[,min=<addr>,max=<addr>] + dump registers from <min> to <max> [VIDIOC_DBG_G_REGISTER] + -r, --set-register=type=<host/i2cdrv/i2caddr>, + chip=<chip>,reg=<addr>,val=<val> + set the register [VIDIOC_DBG_S_REGISTER] + + if type == host, then <chip> is the hosts chip ID (default 0) + if type == i2cdrv (default), then <chip> is the I2C driver name or ID + if type == i2caddr, then <chip> is the 7-bit I2C address +*/ + +static int vidioc_g_register(struct file *file, void *priv, + struct v4l2_dbg_register *reg) +{ + struct cx231xx_fh *fh = priv; + struct cx231xx *dev = fh->dev; + int ret = 0; + u8 value[4] = { 0, 0, 0, 0 }; + u32 data = 0; + + switch (reg->match.type) { + case V4L2_CHIP_MATCH_HOST: + switch (reg->match.addr) { + case 0: /* Cx231xx - internal registers */ + ret = cx231xx_read_ctrl_reg(dev, VRT_GET_REGISTER, + (u16)reg->reg, value, 4); + 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, + (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, + (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, + (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, + (u16)reg->reg, 2, &data, 4); + reg->val = le32_to_cpu(data); + break; + case 3: /* flatiron - read byte */ + ret = cx231xx_read_i2c_data(dev, + Flatrion_DEVICE_ADDRESS, + (u16)reg->reg, 1, + &data, 1); + reg->val = le32_to_cpu(data & 0xff); + break; + case 34: /* flatiron - read dword */ + ret = + cx231xx_read_i2c_data(dev, Flatrion_DEVICE_ADDRESS, + (u16)reg->reg, 1, &data, 4); + reg->val = le32_to_cpu(data); + break; + } + return ret < 0 ? ret : 0; + + case V4L2_CHIP_MATCH_I2C_DRIVER: + cx231xx_i2c_call_clients(&dev->i2c_bus[0], + VIDIOC_DBG_G_REGISTER, reg); + return 0; + case V4L2_CHIP_MATCH_I2C_ADDR: + /* Not supported yet */ + return -EINVAL; + default: + if (!v4l2_chip_match_host(®->match)) + return -EINVAL; + } + + mutex_lock(&dev->lock); + cx231xx_i2c_call_clients(&dev->i2c_bus[0], VIDIOC_DBG_G_REGISTER, reg); + mutex_unlock(&dev->lock); + + return ret; +} + +static int vidioc_s_register(struct file *file, void *priv, + struct v4l2_dbg_register *reg) +{ + struct cx231xx_fh *fh = priv; + struct cx231xx *dev = fh->dev; + int ret = 0; + __le64 buf; + u32 value; + u8 data[4] = { 0, 0, 0, 0 }; + + buf = cpu_to_le64(reg->val); + + switch (reg->match.type) { + case V4L2_CHIP_MATCH_HOST: + { + value = (u32) buf & 0xffffffff; + + switch (reg->match.addr) { + case 0: /* cx231xx internal registers */ + data[0] = (u8) value; + data[1] = (u8) (value >> 8); + data[2] = (u8) (value >> 16); + data[3] = (u8) (value >> 24); + ret = cx231xx_write_ctrl_reg(dev, + VRT_SET_REGISTER, + (u16)reg->reg, data, + 4); + break; + case 1: /* Colibri - read byte */ + ret = cx231xx_write_i2c_data(dev, + Colibri_DEVICE_ADDRESS, + (u16)reg->reg, 2, + value, 1); + break; + case 14: /* Colibri - read dword */ + ret = cx231xx_write_i2c_data(dev, + Colibri_DEVICE_ADDRESS, + (u16)reg->reg, 2, + value, 4); + break; + case 2: /* Hammerhead - read byte */ + ret = + cx231xx_write_i2c_data(dev, + HAMMERHEAD_I2C_ADDRESS, + (u16)reg->reg, 2, + value, 1); + break; + case 24: /* Hammerhead - read dword */ + ret = + cx231xx_write_i2c_data(dev, + HAMMERHEAD_I2C_ADDRESS, + (u16)reg->reg, 2, + value, 4); + break; + case 3: /* flatiron - read byte */ + ret = + cx231xx_write_i2c_data(dev, + Flatrion_DEVICE_ADDRESS, + (u16)reg->reg, 1, + value, 1); + break; + case 34: /* flatiron - read dword */ + ret = + cx231xx_write_i2c_data(dev, + Flatrion_DEVICE_ADDRESS, + (u16)reg->reg, 1, + value, 4); + break; + } + } + return ret < 0 ? ret : 0; + + default: + break; + } + + mutex_lock(&dev->lock); + + cx231xx_i2c_call_clients(&dev->i2c_bus[0], VIDIOC_DBG_S_REGISTER, reg); + + mutex_unlock(&dev->lock); + + return ret; +} +#endif + +static int vidioc_cropcap(struct file *file, void *priv, + struct v4l2_cropcap *cc) +{ + struct cx231xx_fh *fh = priv; + struct cx231xx *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; /* 4:3 FIXME: remove magic numbers */ + cc->pixelaspect.denominator = 59; + + return 0; +} + +static int vidioc_streamon(struct file *file, void *priv, + enum v4l2_buf_type type) +{ + struct cx231xx_fh *fh = priv; + struct cx231xx *dev = fh->dev; + int rc; + + rc = check_dev(dev); + if (rc < 0) + return rc; + + 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 cx231xx_fh *fh = priv; + struct cx231xx *dev = fh->dev; + int rc; + + rc = check_dev(dev); + if (rc < 0) + return rc; + + if ((fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) || + (fh->type != V4L2_BUF_TYPE_VBI_CAPTURE)) + return -EINVAL; + if (type != fh->type) + return -EINVAL; + + mutex_lock(&dev->lock); + + videobuf_streamoff(&fh->vb_vidq); + res_free(fh); + + mutex_unlock(&dev->lock); + + return 0; +} + +static int vidioc_querycap(struct file *file, void *priv, + struct v4l2_capability *cap) +{ + struct cx231xx_fh *fh = priv; + struct cx231xx *dev = fh->dev; + + 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)); + + cap->version = CX231XX_VERSION_CODE; + + cap->capabilities = V4L2_CAP_VBI_CAPTURE | +#if 0 /* Keep */ + V4L2_CAP_SLICED_VBI_CAPTURE | +#endif + V4L2_CAP_VIDEO_CAPTURE | + V4L2_CAP_AUDIO | + V4L2_CAP_READWRITE | + V4L2_CAP_STREAMING; + + if (dev->tuner_type != TUNER_ABSENT) + cap->capabilities |= V4L2_CAP_TUNER; + + return 0; +} + +static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv, + struct v4l2_fmtdesc *f) +{ + if (unlikely(f->index >= ARRAY_SIZE(format))) + return -EINVAL; + + strlcpy(f->description, format[f->index].name, sizeof(f->description)); + f->pixelformat = format[f->index].fourcc; + + return 0; +} + +/* Sliced VBI ioctls */ +static int vidioc_g_fmt_sliced_vbi_cap(struct file *file, void *priv, + struct v4l2_format *f) +{ + struct cx231xx_fh *fh = priv; + struct cx231xx *dev = fh->dev; + int rc; + + rc = check_dev(dev); + if (rc < 0) + return rc; + + mutex_lock(&dev->lock); + + f->fmt.sliced.service_set = 0; + + cx231xx_i2c_call_clients(&dev->i2c_bus[0], VIDIOC_G_FMT, f); + + if (f->fmt.sliced.service_set == 0) + rc = -EINVAL; + + mutex_unlock(&dev->lock); + return rc; +} + +static int vidioc_try_set_sliced_vbi_cap(struct file *file, void *priv, + struct v4l2_format *f) +{ + struct cx231xx_fh *fh = priv; + struct cx231xx *dev = fh->dev; + int rc; + + rc = check_dev(dev); + if (rc < 0) + return rc; + + mutex_lock(&dev->lock); + cx231xx_i2c_call_clients(&dev->i2c_bus[0], VIDIOC_G_FMT, f); + mutex_unlock(&dev->lock); + + if (f->fmt.sliced.service_set == 0) + return -EINVAL; + + return 0; +} + +/* RAW VBI ioctls */ + +static int vidioc_g_fmt_vbi_cap(struct file *file, void *priv, + struct v4l2_format *f) +{ + struct cx231xx_fh *fh = priv; + struct cx231xx *dev = fh->dev; + + f->fmt.vbi.sampling_rate = (dev->norm & V4L2_STD_625_50) ? + 35468950 : 28636363; + f->fmt.vbi.samples_per_line = VBI_LINE_LENGTH; + f->fmt.vbi.sample_format = V4L2_PIX_FMT_GREY; + f->fmt.vbi.offset = 64 * 4; + f->fmt.vbi.start[0] = (dev->norm & V4L2_STD_625_50) ? + PAL_VBI_START_LINE : NTSC_VBI_START_LINE; + f->fmt.vbi.count[0] = (dev->norm & V4L2_STD_625_50) ? + PAL_VBI_LINES : NTSC_VBI_LINES; + f->fmt.vbi.start[1] = (dev->norm & V4L2_STD_625_50) ? + PAL_VBI_START_LINE + 312 : NTSC_VBI_START_LINE + 263; + f->fmt.vbi.count[1] = f->fmt.vbi.count[0]; + + return 0; + +} + +static int vidioc_try_fmt_vbi_cap(struct file *file, void *priv, + struct v4l2_format *f) +{ + struct cx231xx_fh *fh = priv; + struct cx231xx *dev = fh->dev; + + if (dev->vbi_stream_on && !fh->stream_on) { + cx231xx_errdev("%s device in use by another fh\n", __func__); + return -EBUSY; + } + + f->type = V4L2_BUF_TYPE_VBI_CAPTURE; + f->fmt.vbi.sampling_rate = (dev->norm & V4L2_STD_625_50) ? + 35468950 : 28636363; + f->fmt.vbi.samples_per_line = VBI_LINE_LENGTH; + f->fmt.vbi.sample_format = V4L2_PIX_FMT_GREY; + f->fmt.vbi.offset = 244; + f->fmt.vbi.flags = 0; + f->fmt.vbi.start[0] = (dev->norm & V4L2_STD_625_50) ? + PAL_VBI_START_LINE : NTSC_VBI_START_LINE; + f->fmt.vbi.count[0] = (dev->norm & V4L2_STD_625_50) ? + PAL_VBI_LINES : NTSC_VBI_LINES; + f->fmt.vbi.start[1] = (dev->norm & V4L2_STD_625_50) ? + PAL_VBI_START_LINE + 312 : NTSC_VBI_START_LINE + 263; + f->fmt.vbi.count[1] = f->fmt.vbi.count[0]; + + return 0; + +} + +static int vidioc_reqbufs(struct file *file, void *priv, + struct v4l2_requestbuffers *rb) +{ + struct cx231xx_fh *fh = priv; + struct cx231xx *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 cx231xx_fh *fh = priv; + struct cx231xx *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 cx231xx_fh *fh = priv; + struct cx231xx *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 cx231xx_fh *fh = priv; + struct cx231xx *dev = fh->dev; + int rc; + + rc = check_dev(dev); + if (rc < 0) + return rc; + + 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 cx231xx_fh *fh = priv; + + return videobuf_cgmbuf(&fh->vb_vidq, mbuf, 8); +} +#endif + +/* ----------------------------------------------------------- */ +/* RADIO ESPECIFIC IOCTLS */ +/* ----------------------------------------------------------- */ + +static int radio_querycap(struct file *file, void *priv, + struct v4l2_capability *cap) +{ + struct cx231xx *dev = ((struct cx231xx_fh *)priv)->dev; + + strlcpy(cap->driver, "cx231xx", sizeof(cap->driver)); + strlcpy(cap->card, cx231xx_boards[dev->model].name, sizeof(cap->card)); + usb_make_path(dev->udev, cap->bus_info, sizeof(cap->bus_info)); + + cap->version = CX231XX_VERSION_CODE; + cap->capabilities = V4L2_CAP_TUNER; + return 0; +} + +static int radio_g_tuner(struct file *file, void *priv, struct v4l2_tuner *t) +{ + struct cx231xx *dev = ((struct cx231xx_fh *)priv)->dev; + + if (unlikely(t->index > 0)) + return -EINVAL; + + strcpy(t->name, "Radio"); + t->type = V4L2_TUNER_RADIO; + + mutex_lock(&dev->lock); + cx231xx_i2c_call_clients(&dev->i2c_bus[1], VIDIOC_G_TUNER, t); + mutex_unlock(&dev->lock); + + return 0; +} + +static int radio_enum_input(struct file *file, void *priv, struct v4l2_input *i) +{ + if (i->index != 0) + return -EINVAL; + strcpy(i->name, "Radio"); + i->type = V4L2_INPUT_TYPE_TUNER; + + return 0; +} + +static int radio_g_audio(struct file *file, void *priv, struct v4l2_audio *a) +{ + if (unlikely(a->index)) + return -EINVAL; + + strcpy(a->name, "Radio"); + return 0; +} + +static int radio_s_tuner(struct file *file, void *priv, struct v4l2_tuner *t) +{ + struct cx231xx *dev = ((struct cx231xx_fh *)priv)->dev; + + if (0 != t->index) + return -EINVAL; + + mutex_lock(&dev->lock); + cx231xx_i2c_call_clients(&dev->i2c_bus[1], VIDIOC_S_TUNER, t); + mutex_unlock(&dev->lock); + + return 0; +} + +static int radio_s_audio(struct file *file, void *fh, struct v4l2_audio *a) +{ + return 0; +} + +static int radio_s_input(struct file *file, void *fh, unsigned int i) +{ + return 0; +} + +static int radio_queryctrl(struct file *file, void *priv, + struct v4l2_queryctrl *c) +{ + int i; + + if (c->id < V4L2_CID_BASE || c->id >= V4L2_CID_LASTP1) + return -EINVAL; + if (c->id == V4L2_CID_AUDIO_MUTE) { + for (i = 0; i < CX231XX_CTLS; i++) + if (cx231xx_ctls[i].v.id == c->id) + break; + *c = cx231xx_ctls[i].v; + } else + *c = no_ctl; + return 0; +} + +/* + * cx231xx_v4l2_open() + * inits the device and starts isoc transfer + */ +static int cx231xx_v4l2_open(struct file *filp) +{ + int minor = video_devdata(filp)->minor; + int errCode = 0, radio = 0; + struct cx231xx *dev = NULL; + struct cx231xx_fh *fh; + enum v4l2_buf_type fh_type = 0; + + dev = cx231xx_get_device(minor, &fh_type, &radio); + if (NULL == dev) + return -ENODEV; + + mutex_lock(&dev->lock); + + cx231xx_videodbg("open minor=%d type=%s users=%d\n", + minor, v4l2_type_names[fh_type], dev->users); + +#if 0 /* Keep */ + errCode = cx231xx_set_mode(dev, CX231XX_ANALOG_MODE); + if (errCode < 0) { + cx231xx_errdev + ("Device locked on digital mode. Can't open analog\n"); + mutex_unlock(&dev->lock); + return -EBUSY; + } +#endif + + fh = kzalloc(sizeof(struct cx231xx_fh), GFP_KERNEL); + if (!fh) { + cx231xx_errdev("cx231xx-video.c: Out of memory?!\n"); + mutex_unlock(&dev->lock); + return -ENOMEM; + } + fh->dev = dev; + fh->radio = radio; + fh->type = fh_type; + filp->private_data = fh; + + if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE && dev->users == 0) { + dev->width = norm_maxw(dev); + dev->height = norm_maxh(dev); + dev->hscale = 0; + dev->vscale = 0; + + /* Power up in Analog TV mode */ + cx231xx_set_power_mode(dev, POLARIS_AVMODE_ANALOGT_TV); + +#if 0 /* Keep */ + cx231xx_set_mode(dev, CX231XX_ANALOG_MODE); +#endif + cx231xx_resolution_set(dev); + + /* set video alternate setting */ + cx231xx_set_video_alternate(dev); + + /* Needed, since GPIO might have disabled power of + some i2c device */ + cx231xx_config_i2c(dev); + + /* device needs to be initialized before isoc transfer */ + dev->video_input = dev->video_input > 2 ? 2 : dev->video_input; + video_mux(dev, dev->video_input); + + } + if (fh->radio) { + cx231xx_videodbg("video_open: setting radio device\n"); + + /* cx231xx_start_radio(dev); */ + + cx231xx_i2c_call_clients(&dev->i2c_bus[1], AUDC_SET_RADIO, + NULL); + } + + dev->users++; + + if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) + videobuf_queue_vmalloc_init(&fh->vb_vidq, &cx231xx_video_qops, + NULL, &dev->video_mode.slock, + fh->type, V4L2_FIELD_INTERLACED, + sizeof(struct cx231xx_buffer), fh); + if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE) { + /* Set the required alternate setting VBI interface works in + Bulk mode only */ + cx231xx_set_alt_setting(dev, INDEX_VANC, 0); + + videobuf_queue_vmalloc_init(&fh->vb_vidq, &cx231xx_vbi_qops, + NULL, &dev->vbi_mode.slock, + fh->type, V4L2_FIELD_SEQ_TB, + sizeof(struct cx231xx_buffer), fh); + } + + mutex_unlock(&dev->lock); + + return errCode; +} + +/* + * cx231xx_realease_resources() + * unregisters the v4l2,i2c and usb devices + * called when the device gets disconected or at module unload +*/ +void cx231xx_release_analog_resources(struct cx231xx *dev) +{ + + /*FIXME: I2C IR should be disconnected */ + + if (dev->radio_dev) { + if (-1 != dev->radio_dev->minor) + video_unregister_device(dev->radio_dev); + else + video_device_release(dev->radio_dev); + dev->radio_dev = NULL; + } + if (dev->vbi_dev) { + cx231xx_info("V4L2 device /dev/vbi%d deregistered\n", + dev->vbi_dev->num); + if (-1 != dev->vbi_dev->minor) + video_unregister_device(dev->vbi_dev); + else + video_device_release(dev->vbi_dev); + dev->vbi_dev = NULL; + } + if (dev->vdev) { + cx231xx_info("V4L2 device /dev/video%d deregistered\n", + dev->vdev->num); + if (-1 != dev->vdev->minor) + video_unregister_device(dev->vdev); + else + video_device_release(dev->vdev); + dev->vdev = NULL; + } +} + +/* + * cx231xx_v4l2_close() + * stops streaming and deallocates all resources allocated by the v4l2 + * calls and ioctls + */ +static int cx231xx_v4l2_close(struct file *filp) +{ + struct cx231xx_fh *fh = filp->private_data; + struct cx231xx *dev = fh->dev; + + cx231xx_videodbg("users=%d\n", dev->users); + + mutex_lock(&dev->lock); + + if (res_check(fh)) + res_free(fh); + + if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE) { + videobuf_stop(&fh->vb_vidq); + videobuf_mmap_free(&fh->vb_vidq); + + /* the device is already disconnect, + free the remaining resources */ + if (dev->state & DEV_DISCONNECTED) { + cx231xx_release_resources(dev); + mutex_unlock(&dev->lock); + kfree(dev); + return 0; + } + + /* do this before setting alternate! */ + cx231xx_uninit_vbi_isoc(dev); + + /* set alternate 0 */ + if (!dev->vbi_or_sliced_cc_mode) + cx231xx_set_alt_setting(dev, INDEX_VANC, 0); + else + cx231xx_set_alt_setting(dev, INDEX_HANC, 0); + + kfree(fh); + dev->users--; + wake_up_interruptible_nr(&dev->open, 1); + mutex_unlock(&dev->lock); + return 0; + } + + if (dev->users == 1) { + videobuf_stop(&fh->vb_vidq); + videobuf_mmap_free(&fh->vb_vidq); + + /* the device is already disconnect, + free the remaining resources */ + if (dev->state & DEV_DISCONNECTED) { + cx231xx_release_resources(dev); + mutex_unlock(&dev->lock); + kfree(dev); + return 0; + } + + /* Save some power by putting tuner to sleep */ + cx231xx_i2c_call_clients(&dev->i2c_bus[1], TUNER_SET_STANDBY, + NULL); + + /* do this before setting alternate! */ + cx231xx_uninit_isoc(dev); + cx231xx_set_mode(dev, CX231XX_SUSPEND); + + /* set alternate 0 */ + cx231xx_set_alt_setting(dev, INDEX_VIDEO, 0); + } + kfree(fh); + dev->users--; + wake_up_interruptible_nr(&dev->open, 1); + mutex_unlock(&dev->lock); + return 0; +} + +/* + * cx231xx_v4l2_read() + * will allocate buffers when called for the first time + */ +static ssize_t +cx231xx_v4l2_read(struct file *filp, char __user *buf, size_t count, + loff_t *pos) +{ + struct cx231xx_fh *fh = filp->private_data; + struct cx231xx *dev = fh->dev; + int rc; + + rc = check_dev(dev); + if (rc < 0) + return rc; + + if ((fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) || + (fh->type == V4L2_BUF_TYPE_VBI_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; +} + +/* + * cx231xx_v4l2_poll() + * will allocate buffers when called for the first time + */ +static unsigned int cx231xx_v4l2_poll(struct file *filp, poll_table * wait) +{ + struct cx231xx_fh *fh = filp->private_data; + struct cx231xx *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) || + (V4L2_BUF_TYPE_VBI_CAPTURE == fh->type)) + return videobuf_poll_stream(filp, &fh->vb_vidq, wait); + else + return POLLERR; +} + +/* + * cx231xx_v4l2_mmap() + */ +static int cx231xx_v4l2_mmap(struct file *filp, struct vm_area_struct *vma) +{ + struct cx231xx_fh *fh = filp->private_data; + struct cx231xx *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); + + cx231xx_videodbg("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 const struct v4l2_file_operations cx231xx_v4l_fops = { + .owner = THIS_MODULE, + .open = cx231xx_v4l2_open, + .release = cx231xx_v4l2_close, + .read = cx231xx_v4l2_read, + .poll = cx231xx_v4l2_poll, + .mmap = cx231xx_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, + .vidioc_g_fmt_vbi_cap = vidioc_g_fmt_vbi_cap, + .vidioc_try_fmt_vbi_cap = vidioc_try_fmt_vbi_cap, + .vidioc_s_fmt_vbi_cap = vidioc_try_fmt_vbi_cap, + .vidioc_g_audio = vidioc_g_audio, + .vidioc_s_audio = vidioc_s_audio, + .vidioc_cropcap = vidioc_cropcap, + .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_reqbufs = vidioc_reqbufs, + .vidioc_querybuf = vidioc_querybuf, + .vidioc_qbuf = vidioc_qbuf, + .vidioc_dqbuf = vidioc_dqbuf, + .vidioc_s_std = vidioc_s_std, + .vidioc_g_std = vidioc_g_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 +#ifdef CONFIG_VIDEO_V4L1_COMPAT + .vidiocgmbuf = vidiocgmbuf, +#endif +}; + +static struct video_device cx231xx_vbi_template; + +static const struct video_device cx231xx_video_template = { + .fops = &cx231xx_v4l_fops, + .release = video_device_release, + .ioctl_ops = &video_ioctl_ops, + .minor = -1, + .tvnorms = V4L2_STD_ALL, + .current_norm = V4L2_STD_PAL, +}; + +static const struct v4l2_file_operations radio_fops = { + .owner = THIS_MODULE, + .open = cx231xx_v4l2_open, + .release = cx231xx_v4l2_close, + .ioctl = video_ioctl2, +}; + +static const struct v4l2_ioctl_ops radio_ioctl_ops = { + .vidioc_querycap = radio_querycap, + .vidioc_g_tuner = radio_g_tuner, + .vidioc_enum_input = radio_enum_input, + .vidioc_g_audio = radio_g_audio, + .vidioc_s_tuner = radio_s_tuner, + .vidioc_s_audio = radio_s_audio, + .vidioc_s_input = radio_s_input, + .vidioc_queryctrl = radio_queryctrl, + .vidioc_g_ctrl = vidioc_g_ctrl, + .vidioc_s_ctrl = vidioc_s_ctrl, + .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 +}; + +static struct video_device cx231xx_radio_template = { + .name = "cx231xx-radio", + .fops = &radio_fops, + .ioctl_ops = &radio_ioctl_ops, + .minor = -1, +}; + +/******************************** usb interface ******************************/ + +static struct video_device *cx231xx_vdev_init(struct cx231xx *dev, + const struct video_device + *template, const char *type_name) +{ + struct video_device *vfd; + + vfd = video_device_alloc(); + if (NULL == vfd) + return NULL; + + *vfd = *template; + vfd->minor = -1; + vfd->parent = &dev->udev->dev; + vfd->release = video_device_release; + vfd->debug = video_debug; + + snprintf(vfd->name, sizeof(vfd->name), "%s %s", dev->name, type_name); + + return vfd; +} + +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, + (CX231XX_VERSION_CODE >> 8) & 0xff, + CX231XX_VERSION_CODE & 0xff); + + /* set default norm */ + /*dev->norm = cx231xx_video_template.current_norm; */ + dev->width = norm_maxw(dev); + dev->height = norm_maxh(dev); + dev->interlaced = 0; + dev->hscale = 0; + dev->vscale = 0; + + /* Analog specific initialization */ + dev->format = &format[0]; + /* video_mux(dev, dev->video_input); */ + + /* Audio defaults */ + dev->mute = 1; + dev->volume = 0x1f; + + /* enable vbi capturing */ + /* write code here... */ + + /* allocate and fill video video_device struct */ + dev->vdev = cx231xx_vdev_init(dev, &cx231xx_video_template, "video"); + if (!dev->vdev) { + cx231xx_errdev("cannot allocate video_device.\n"); + return -ENODEV; + } + + /* register v4l2 video video_device */ + ret = video_register_device(dev->vdev, VFL_TYPE_GRABBER, + video_nr[dev->devno]); + if (ret) { + cx231xx_errdev("unable to register video device (error=%i).\n", + ret); + return ret; + } + + cx231xx_info("%s/0: registered device video%d [v4l2]\n", + dev->name, dev->vdev->num); + + /* Initialize VBI template */ + memcpy(&cx231xx_vbi_template, &cx231xx_video_template, + sizeof(cx231xx_vbi_template)); + strcpy(cx231xx_vbi_template.name, "cx231xx-vbi"); + + /* Allocate and fill vbi video_device struct */ + dev->vbi_dev = cx231xx_vdev_init(dev, &cx231xx_vbi_template, "vbi"); + + /* register v4l2 vbi video_device */ + ret = video_register_device(dev->vbi_dev, VFL_TYPE_VBI, + vbi_nr[dev->devno]); + if (ret < 0) { + cx231xx_errdev("unable to register vbi device\n"); + return ret; + } + + cx231xx_info("%s/0: registered device vbi%d\n", + dev->name, dev->vbi_dev->num); + + if (cx231xx_boards[dev->model].radio.type == CX231XX_RADIO) { + dev->radio_dev = cx231xx_vdev_init(dev, &cx231xx_radio_template, + "radio"); + if (!dev->radio_dev) { + cx231xx_errdev("cannot allocate video_device.\n"); + return -ENODEV; + } + ret = video_register_device(dev->radio_dev, VFL_TYPE_RADIO, + radio_nr[dev->devno]); + if (ret < 0) { + cx231xx_errdev("can't register radio device\n"); + return ret; + } + cx231xx_info("Registered radio device as /dev/radio%d\n", + dev->radio_dev->num); + } + + cx231xx_info("V4L2 device registered as /dev/video%d and /dev/vbi%d\n", + dev->vdev->num, dev->vbi_dev->num); + + return 0; +} diff --git a/linux/drivers/media/video/cx231xx/cx231xx.h b/linux/drivers/media/video/cx231xx/cx231xx.h new file mode 100644 index 000000000..8ab6c615e --- /dev/null +++ b/linux/drivers/media/video/cx231xx/cx231xx.h @@ -0,0 +1,775 @@ +/* + cx231xx.h - driver for Conexant Cx23100/101/102 USB video capture devices + + Copyright (C) 2008 <srinivasa.deevi at conexant dot com> + Based on em28xx driver + + 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 _CX231XX_H +#define _CX231XX_H + +#include "compat.h" +#include <linux/videodev2.h> +#include <media/videobuf-vmalloc.h> + +#include <linux/i2c.h> +#include <linux/i2c-algo-bit.h> +#include <linux/mutex.h> +#include <media/ir-kbd-i2c.h> +#if defined(CONFIG_VIDEO_CX231XX_DVB) || \ + defined(CONFIG_VIDEO_CX231XX_DVB_MODULE) +#include <media/videobuf-dvb.h> +#endif + +#include "cx231xx-reg.h" +#include "cx231xx-pcb-cfg.h" +#include "cx231xx-conf-reg.h" + +#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 DIF_USE_BASEBAND 0xFFFFFFFF + +/* Boards supported by driver */ +#define CX231XX_BOARD_UNKNOWN 0 +#define CX231XX_BOARD_CNXT_RDE_250 1 +#define CX231XX_BOARD_CNXT_RDU_250 2 + +/* Limits minimum and default number of buffers */ +#define CX231XX_MIN_BUF 4 +#define CX231XX_DEF_BUF 12 +#define CX231XX_DEF_VBI_BUF 6 + +#define VBI_LINE_COUNT 17 +#define VBI_LINE_LENGTH 1440 + +/*Limits the max URB message size */ +#define URB_MAX_CTRL_SIZE 80 + +/* Params for validated field */ +#define CX231XX_BOARD_NOT_VALIDATED 1 +#define CX231XX_BOARD_VALIDATED 0 + +/* maximum number of cx231xx boards */ +#define CX231XX_MAXBOARDS 8 + +/* maximum number of frames that can be queued */ +#define CX231XX_NUM_FRAMES 5 + +/* number of buffers for isoc transfers */ +#define CX231XX_NUM_BUFS 8 + +/* number of packets for each buffer + windows requests only 40 packets .. so we better do the same + this is what I found out for all alternate numbers there! + */ +#define CX231XX_NUM_PACKETS 40 + +/* default alternate; 0 means choose the best */ +#define CX231XX_PINOUT 0 + +#define CX231XX_INTERLACED_DEFAULT 1 + +/* time to wait when stopping the isoc transfer */ +#define CX231XX_URB_TIMEOUT \ + msecs_to_jiffies(CX231XX_NUM_BUFS * CX231XX_NUM_PACKETS) + +enum cx231xx_mode { + CX231XX_SUSPEND, + CX231XX_ANALOG_MODE, + CX231XX_DIGITAL_MODE, +}; + +enum cx231xx_std_mode { + CX231XX_TV_AIR = 0, + CX231XX_TV_CABLE +}; + +enum cx231xx_stream_state { + STREAM_OFF, + STREAM_INTERRUPT, + STREAM_ON, +}; + +struct cx231xx; + +struct cx231xx_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 cx231xx_buffer *buf; + + /* Stores the number of received fields */ + int nfields; + + /* isoc urb callback */ + int (*isoc_copy) (struct cx231xx *dev, struct urb *urb); +}; + +struct cx231xx_fmt { + char *name; + u32 fourcc; /* v4l2 format id */ + int depth; + int reg; +}; + +/* buffer for one video frame */ +struct cx231xx_buffer { + /* common v4l buffer stuff -- must be first */ + struct videobuf_buffer vb; + + struct list_head frame; + int top_field; + int receiving; +}; + +struct cx231xx_dmaqueue { + struct list_head active; + struct list_head queued; + + wait_queue_head_t wq; + + /* Counters to control buffer fill */ + int pos; + u8 is_partial_line; + u8 partial_buf[8]; + u8 last_sav; + int current_field; + u32 bytes_left_in_line; + u32 lines_completed; + u8 field1_done; + u32 lines_per_field; +}; + +/* inputs */ + +#define MAX_CX231XX_INPUT 4 + +enum cx231xx_itype { + CX231XX_VMUX_COMPOSITE1 = 1, + CX231XX_VMUX_SVIDEO, + CX231XX_VMUX_TELEVISION, + CX231XX_VMUX_CABLE, + CX231XX_RADIO, + CX231XX_VMUX_DVB, + CX231XX_VMUX_DEBUG +}; + +enum cx231xx_v_input { + CX231XX_VIN_1_1 = 0x1, + CX231XX_VIN_2_1, + CX231XX_VIN_3_1, + CX231XX_VIN_4_1, + CX231XX_VIN_1_2 = 0x01, + CX231XX_VIN_2_2, + CX231XX_VIN_3_2, + CX231XX_VIN_1_3 = 0x1, + CX231XX_VIN_2_3, + CX231XX_VIN_3_3, +}; + +/* cx231xx has two audio inputs: tuner and line in */ +enum cx231xx_amux { + /* This is the only entry for cx231xx tuner input */ + CX231XX_AMUX_VIDEO, /* cx231xx tuner */ + CX231XX_AMUX_LINE_IN, /* Line In */ +}; + +struct cx231xx_reg_seq { + unsigned char bit; + unsigned char val; + int sleep; +}; + +struct cx231xx_input { + enum cx231xx_itype type; + unsigned int vmux; + enum cx231xx_amux amux; + struct cx231xx_reg_seq *gpio; +}; + +#define INPUT(nr) (&cx231xx_boards[dev->model].input[nr]) + +enum cx231xx_decoder { + CX231XX_NODECODER, + CX231XX_AVDECODER +}; + +enum CX231XX_I2C_MASTER_PORT { + I2C_0 = 0, + I2C_1 = 1, + I2C_2 = 2, + I2C_3 = 3 +}; + +struct cx231xx_board { + char *name; + int vchannels; + int tuner_type; + int tuner_addr; + v4l2_std_id norm; /* tv norm */ + + /* demod related */ + int demod_addr; + u8 demod_xfer_mode; /* 0 - Serial; 1 - parallel */ + + /* GPIO Pins */ + struct cx231xx_reg_seq *dvb_gpio; + struct cx231xx_reg_seq *suspend_gpio; + struct cx231xx_reg_seq *tuner_gpio; + u8 tuner_sif_gpio; + u8 tuner_scl_gpio; + u8 tuner_sda_gpio; + + /* PIN ctrl */ + u32 ctl_pin_status_mask; + u8 agc_analog_digital_select_gpio; + u32 gpio_pin_status_mask; + + /* i2c masters */ + u8 tuner_i2c_master; + u8 demod_i2c_master; + + unsigned int max_range_640_480:1; + unsigned int has_dvb:1; + unsigned int valid:1; + + unsigned char xclk, i2c_speed; + + enum cx231xx_decoder decoder; + + struct cx231xx_input input[MAX_CX231XX_INPUT]; + struct cx231xx_input radio; + IR_KEYTAB_TYPE *ir_codes; +}; + +/* device states */ +enum cx231xx_dev_state { + DEV_INITIALIZED = 0x01, + DEV_DISCONNECTED = 0x02, + DEV_MISCONFIGURED = 0x04, +}; + +enum AFE_MODE { + AFE_MODE_LOW_IF, + AFE_MODE_BASEBAND, + AFE_MODE_EU_HI_IF, + AFE_MODE_US_HI_IF, + AFE_MODE_JAPAN_HI_IF +}; + +enum AUDIO_INPUT { + AUDIO_INPUT_MUTE, + AUDIO_INPUT_LINE, + AUDIO_INPUT_TUNER_TV, + AUDIO_INPUT_SPDIF, + AUDIO_INPUT_TUNER_FM +}; + +#define CX231XX_AUDIO_BUFS 5 +#define CX231XX_NUM_AUDIO_PACKETS 64 +#define CX231XX_CAPTURE_STREAM_EN 1 +#define CX231XX_STOP_AUDIO 0 +#define CX231XX_START_AUDIO 1 + +/* cx231xx extensions */ +#define CX231XX_AUDIO 0x10 +#define CX231XX_DVB 0x20 + +struct cx231xx_audio { + char name[50]; + char *transfer_buffer[CX231XX_AUDIO_BUFS]; + struct urb *urb[CX231XX_AUDIO_BUFS]; + struct usb_device *udev; + unsigned int capture_transfer_done; +#if LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 16) + snd_pcm_substream_t *capture_pcm_substream; +#else + struct snd_pcm_substream *capture_pcm_substream; +#endif + + unsigned int hwptr_done_capture; +#if LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 16) + snd_card_t *sndcard; +#else + struct snd_card *sndcard; +#endif + + int users, shutdown; + enum cx231xx_stream_state capture_stream; + spinlock_t slock; + + 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 */ + u16 end_point_addr; +}; + +struct cx231xx; + +struct cx231xx_fh { + struct cx231xx *dev; + unsigned int stream_on:1; /* Locks streams */ + int radio; + + struct videobuf_queue vb_vidq; + + enum v4l2_buf_type type; +}; + +/*****************************************************************/ +/* set/get i2c */ +/* 00--1Mb/s, 01-400kb/s, 10--100kb/s, 11--5Mb/s */ +#define I2C_SPEED_1M 0x0 +#define I2C_SPEED_400K 0x1 +#define I2C_SPEED_100K 0x2 +#define I2C_SPEED_5M 0x3 + +/* 0-- STOP transaction */ +#define I2C_STOP 0x0 +/* 1-- do not transmit STOP at end of transaction */ +#define I2C_NOSTOP 0x1 +/* 1--alllow slave to insert clock wait states */ +#define I2C_SYNC 0x1 + +struct cx231xx_i2c { + struct cx231xx *dev; + + int nr; + + /* i2c i/o */ + struct i2c_adapter i2c_adap; + struct i2c_algo_bit_data i2c_algo; + struct i2c_client i2c_client; + u32 i2c_rc; + + /* different settings for each bus */ + u8 i2c_period; + u8 i2c_nostop; + u8 i2c_reserve; +}; + +struct cx231xx_i2c_xfer_data { + u8 dev_addr; + u8 direction; /* 1 - IN, 0 - OUT */ + u8 saddr_len; /* sub address len */ + u16 saddr_dat; /* sub addr data */ + u8 buf_size; /* buffer size */ + u8 *p_buffer; /* pointer to the buffer */ +}; + +struct VENDOR_REQUEST_IN { + u8 bRequest; + u16 wValue; + u16 wIndex; + u16 wLength; + u8 direction; + u8 bData; + u8 *pBuff; +}; + +struct cx231xx_ctrl { + struct v4l2_queryctrl v; + u32 off; + u32 reg; + u32 mask; + u32 shift; +}; + +enum TRANSFER_TYPE { + Raw_Video = 0, + Audio, + Vbi, /* VANC */ + Sliced_cc, /* HANC */ + TS1_serial_mode, + TS2, + TS1_parallel_mode +} ; + +struct cx231xx_video_mode { + /* Isoc control struct */ + struct cx231xx_dmaqueue vidq; + struct cx231xx_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 */ + u16 end_point_addr; +}; + +/* main device struct */ +struct cx231xx { + /* generic device properties */ + char name[30]; /* name (including minor) of the device */ + int model; /* index in the device_data struct */ + int devno; /* marks the number of this device */ + + struct cx231xx_board board; + + unsigned int stream_on:1; /* Locks streams */ + unsigned int vbi_stream_on:1; /* Locks streams for VBI */ + unsigned int has_audio_class:1; + unsigned int has_alsa_audio:1; + + struct cx231xx_fmt *format; + + struct cx231xx_IR *ir; + + struct list_head devlist; + + int tuner_type; /* type of the tuner */ + int tuner_addr; /* tuner address */ + + /* I2C adapters: Master 1 & 2 (External) & Master 3 (Internal only) */ + struct cx231xx_i2c i2c_bus[3]; + unsigned int xc_fw_load_done:1; + struct mutex gpio_i2c_lock; + + /* video for linux */ + int users; /* user count for exclusive use */ + struct video_device *vdev; /* video for linux device struct */ + v4l2_std_id norm; /* selected tv norm */ + int ctl_freq; /* selected frequency */ + unsigned int ctl_ainput; /* selected audio input */ + int mute; + int volume; + + /* frame properties */ + int width; /* current frame width */ + int height; /* current frame height */ + unsigned hscale; /* horizontal scale factor (see datasheet) */ + unsigned vscale; /* vertical scale factor (see datasheet) */ + int interlaced; /* 1=interlace fileds, 0=just top fileds */ + + struct cx231xx_audio adev; + + /* states */ + enum cx231xx_dev_state state; + + struct work_struct request_module_wk; + + /* locks */ + struct mutex lock; + struct mutex ctrl_urb_lock; /* protects urb_buf */ + struct list_head inqueue, outqueue; + wait_queue_head_t open, wait_frame, wait_stream; + struct video_device *vbi_dev; + struct video_device *radio_dev; + + unsigned char eedata[256]; + + struct cx231xx_video_mode video_mode; + struct cx231xx_video_mode vbi_mode; + struct cx231xx_video_mode sliced_cc_mode; + struct cx231xx_video_mode ts1_mode; + + struct usb_device *udev; /* the usb device */ + char urb_buf[URB_MAX_CTRL_SIZE]; /* urb control msg buffer */ + + /* helper funcs that call usb_control_msg */ + int (*cx231xx_read_ctrl_reg) (struct cx231xx *dev, u8 req, u16 reg, + char *buf, int len); + int (*cx231xx_write_ctrl_reg) (struct cx231xx *dev, u8 req, u16 reg, + char *buf, int len); + int (*cx231xx_send_usb_command) (struct cx231xx_i2c *i2c_bus, + struct cx231xx_i2c_xfer_data *req_data); + int (*cx231xx_gpio_i2c_read) (struct cx231xx *dev, u8 dev_addr, + u8 *buf, u8 len); + int (*cx231xx_gpio_i2c_write) (struct cx231xx *dev, u8 dev_addr, + u8 *buf, u8 len); + + int (*cx231xx_set_analog_freq) (struct cx231xx *dev, u32 freq); + int (*cx231xx_reset_analog_tuner) (struct cx231xx *dev); + + enum cx231xx_mode mode; + + struct cx231xx_dvb *dvb; + + /* Cx231xx supported PCB config's */ + struct pcb_config current_pcb_config; + u8 current_scenario_idx; + u8 interface_count; + u8 max_iad_interface_count; + + /* GPIO related register direction and values */ + u32 gpio_dir; + u32 gpio_val; + + /* Power Modes */ + int power_mode; + + /* colibri parameters */ + enum AFE_MODE colibri_mode; + u32 colibri_ref_count; + + /* video related parameters */ + u32 video_input; + u32 active_mode; + u8 vbi_or_sliced_cc_mode; /* 0 - vbi ; 1 - sliced cc mode */ + enum cx231xx_std_mode std_mode; /* 0 - Air; 1 - cable */ + +}; + +struct cx231xx_ops { + struct list_head next; + char *name; + int id; + int (*init) (struct cx231xx *); + int (*fini) (struct cx231xx *); +}; + +/* call back functions in dvb module */ +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); + +/* Internal block control functions */ +int cx231xx_read_i2c_data(struct cx231xx *dev, u8 dev_addr, + u16 saddr, u8 saddr_len, u32 *data, u8 data_len); +int cx231xx_write_i2c_data(struct cx231xx *dev, u8 dev_addr, + u16 saddr, u8 saddr_len, u32 data, u8 data_len); +int cx231xx_reg_mask_write(struct cx231xx *dev, u8 dev_addr, u8 size, + u16 register_address, u8 bit_start, u8 bit_end, + u32 value); +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, + enum AV_MODE avmode); +int cx231xx_colibri_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, + enum AV_MODE avmode); +int cx231xx_flatiron_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, + u32 function_mode, u32 standard); +int cx231xx_dif_set_standard(struct cx231xx *dev, u32 standard); +int cx231xx_tuner_pre_channel_change(struct cx231xx *dev); +int cx231xx_tuner_post_channel_change(struct cx231xx *dev); + +/* video parser functions */ +u8 cx231xx_find_next_SAV_EAV(u8 *p_buffer, u32 buffer_size, + u32 *p_bytes_used); +u8 cx231xx_find_boundary_SAV_EAV(u8 *p_buffer, u8 *partial_buf, + u32 *p_bytes_used); +int cx231xx_do_copy(struct cx231xx *dev, struct cx231xx_dmaqueue *dma_q, + u8 *p_buffer, u32 bytes_to_copy); +void cx231xx_reset_video_buffer(struct cx231xx *dev, + struct cx231xx_dmaqueue *dma_q); +u8 cx231xx_is_buffer_done(struct cx231xx *dev, struct cx231xx_dmaqueue *dma_q); +u32 cx231xx_copy_video_line(struct cx231xx *dev, struct cx231xx_dmaqueue *dma_q, + u8 *p_line, u32 length, int field_number); +u32 cx231xx_get_video_line(struct cx231xx *dev, struct cx231xx_dmaqueue *dma_q, + u8 sav_eav, u8 *p_buffer, u32 buffer_size); +void cx231xx_swab(u16 *from, u16 *to, u16 len); + +/* Provided by cx231xx-core.c */ + +u32 cx231xx_request_buffers(struct cx231xx *dev, u32 count); +void cx231xx_queue_unusedframes(struct cx231xx *dev); +void cx231xx_release_buffers(struct cx231xx *dev); + +/* read from control pipe */ +int cx231xx_read_ctrl_reg(struct cx231xx *dev, u8 req, u16 reg, + char *buf, int len); + +/* write to control pipe */ +int cx231xx_write_ctrl_reg(struct cx231xx *dev, u8 req, u16 reg, + char *buf, int len); +int cx231xx_mode_register(struct cx231xx *dev, u16 address, u32 mode); + +int cx231xx_send_vendor_cmd(struct cx231xx *dev, + struct VENDOR_REQUEST_IN *ven_req); +int cx231xx_send_usb_command(struct cx231xx_i2c *i2c_bus, + struct cx231xx_i2c_xfer_data *req_data); + +/* Gpio related functions */ +int cx231xx_send_gpio_cmd(struct cx231xx *dev, u32 gpio_bit, u8 *gpio_val, + u8 len, u8 request, u8 direction); +int cx231xx_set_gpio_bit(struct cx231xx *dev, u32 gpio_bit, u8 *gpio_val); +int cx231xx_get_gpio_bit(struct cx231xx *dev, u32 gpio_bit, u8 *gpio_val); +int cx231xx_set_gpio_value(struct cx231xx *dev, int pin_number, int pin_value); +int cx231xx_set_gpio_direction(struct cx231xx *dev, int pin_number, + int pin_value); + +int cx231xx_gpio_i2c_start(struct cx231xx *dev); +int cx231xx_gpio_i2c_end(struct cx231xx *dev); +int cx231xx_gpio_i2c_write_byte(struct cx231xx *dev, u8 data); +int cx231xx_gpio_i2c_read_byte(struct cx231xx *dev, u8 *buf); +int cx231xx_gpio_i2c_read_ack(struct cx231xx *dev); +int cx231xx_gpio_i2c_write_ack(struct cx231xx *dev); +int cx231xx_gpio_i2c_write_nak(struct cx231xx *dev); + +int cx231xx_gpio_i2c_read(struct cx231xx *dev, u8 dev_addr, u8 *buf, u8 len); +int cx231xx_gpio_i2c_write(struct cx231xx *dev, u8 dev_addr, u8 *buf, u8 len); + +/* audio related functions */ +int cx231xx_set_audio_decoder_input(struct cx231xx *dev, + enum AUDIO_INPUT audio_input); + +int cx231xx_capture_start(struct cx231xx *dev, int start, u8 media_type); +int cx231xx_resolution_set(struct cx231xx *dev); +int cx231xx_set_video_alternate(struct cx231xx *dev); +int cx231xx_set_alt_setting(struct cx231xx *dev, u8 index, u8 alt); +int cx231xx_init_isoc(struct cx231xx *dev, int max_packets, + int num_bufs, int max_pkt_size, + int (*isoc_copy) (struct cx231xx *dev, + struct urb *urb)); +void cx231xx_uninit_isoc(struct cx231xx *dev); +int cx231xx_set_mode(struct cx231xx *dev, enum cx231xx_mode set_mode); +int cx231xx_gpio_set(struct cx231xx *dev, struct cx231xx_reg_seq *gpio); + +/* Device list functions */ +void cx231xx_release_resources(struct cx231xx *dev); +void cx231xx_release_analog_resources(struct cx231xx *dev); +int cx231xx_register_analog_devices(struct cx231xx *dev); +void cx231xx_remove_from_devlist(struct cx231xx *dev); +void cx231xx_add_into_devlist(struct cx231xx *dev); +struct cx231xx *cx231xx_get_device(int minor, + enum v4l2_buf_type *fh_type, int *has_radio); +void cx231xx_init_extension(struct cx231xx *dev); +void cx231xx_close_extension(struct cx231xx *dev); + +/* hardware init functions */ +int cx231xx_dev_init(struct cx231xx *dev); +void cx231xx_dev_uninit(struct cx231xx *dev); +void cx231xx_config_i2c(struct cx231xx *dev); +int cx231xx_config(struct cx231xx *dev); + +/* Stream control functions */ +int cx231xx_start_stream(struct cx231xx *dev, u32 ep_mask); +int cx231xx_stop_stream(struct cx231xx *dev, u32 ep_mask); + +int cx231xx_initialize_stream_xfer(struct cx231xx *dev, u32 media_type); + +/* Power control functions */ +int cx231xx_set_power_mode(struct cx231xx *dev, enum AV_MODE mode); +int cx231xx_power_suspend(struct cx231xx *dev); + +/* chip specific control functions */ +int cx231xx_init_ctrl_pin_status(struct cx231xx *dev); +int cx231xx_set_agc_analog_digital_mux_select(struct cx231xx *dev, + u8 analog_or_digital); +int cx231xx_enable_i2c_for_tuner(struct cx231xx *dev, u8 I2CIndex); + +/* video audio decoder related functions */ +void video_mux(struct cx231xx *dev, int index); +int cx231xx_set_video_input_mux(struct cx231xx *dev, u8 input); +int cx231xx_set_decoder_video_input(struct cx231xx *dev, u8 pin_type, u8 input); +int cx231xx_do_mode_ctrl_overrides(struct cx231xx *dev); +int cx231xx_set_audio_input(struct cx231xx *dev, u8 input); +void get_scale(struct cx231xx *dev, + unsigned int width, unsigned int height, + unsigned int *hscale, unsigned int *vscale); + +/* Provided by cx231xx-video.c */ +int cx231xx_register_extension(struct cx231xx_ops *dev); +void cx231xx_unregister_extension(struct cx231xx_ops *dev); +void cx231xx_init_extension(struct cx231xx *dev); +void cx231xx_close_extension(struct cx231xx *dev); + +/* Provided by cx231xx-cards.c */ +extern void cx231xx_pre_card_setup(struct cx231xx *dev); +extern void cx231xx_card_setup(struct cx231xx *dev); +extern struct cx231xx_board cx231xx_boards[]; +extern struct usb_device_id cx231xx_id_table[]; +extern const unsigned int cx231xx_bcount; +void cx231xx_set_ir(struct cx231xx *dev, struct IR_i2c *ir); +int cx231xx_tuner_callback(void *ptr, int component, int command, int arg); + +/* Provided by cx231xx-input.c */ +int cx231xx_ir_init(struct cx231xx *dev); +int cx231xx_ir_fini(struct cx231xx *dev); + +/* printk macros */ + +#define cx231xx_err(fmt, arg...) do {\ + printk(KERN_ERR fmt , ##arg); } while (0) + +#define cx231xx_errdev(fmt, arg...) do {\ + printk(KERN_ERR "%s: "fmt,\ + dev->name , ##arg); } while (0) + +#define cx231xx_info(fmt, arg...) do {\ + printk(KERN_INFO "%s: "fmt,\ + dev->name , ##arg); } while (0) +#define cx231xx_warn(fmt, arg...) do {\ + printk(KERN_WARNING "%s: "fmt,\ + dev->name , ##arg); } while (0) + +static inline unsigned int norm_maxw(struct cx231xx *dev) +{ + if (dev->board.max_range_640_480) + return 640; + else + return 720; +} + +static inline unsigned int norm_maxh(struct cx231xx *dev) +{ + if (dev->board.max_range_640_480) + return 480; + else + return (dev->norm & V4L2_STD_625_50) ? 576 : 480; +} +#endif 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-audio.c b/linux/drivers/media/video/cx25840/cx25840-audio.c index 3ee7d7a7d..9dcdef03e 100644 --- a/linux/drivers/media/video/cx25840/cx25840-audio.c +++ b/linux/drivers/media/video/cx25840/cx25840-audio.c @@ -33,7 +33,7 @@ static int set_audclk_freq(struct i2c_client *client, u32 freq) /* common for all inputs and rates */ /* SA_MCLK_SEL=1, SA_MCLK_DIV=0x10 */ - if (!state->is_cx23885) + if (!state->is_cx23885 && !state->is_cx231xx) cx25840_write(client, 0x127, 0x50); if (state->aud_input != CX25840_AUDIO_SERIAL) { @@ -44,11 +44,14 @@ static int set_audclk_freq(struct i2c_client *client, u32 freq) * so avoid destroying registers. */ break; } - /* VID_PLL and AUX_PLL */ - cx25840_write4(client, 0x108, 0x1006040f); - /* AUX_PLL_FRAC */ - cx25840_write4(client, 0x110, 0x01bb39ee); + if (!state->is_cx231xx) { + /* VID_PLL and AUX_PLL */ + cx25840_write4(client, 0x108, 0x1006040f); + + /* AUX_PLL_FRAC */ + cx25840_write4(client, 0x110, 0x01bb39ee); + } if (state->is_cx25836) break; @@ -65,11 +68,14 @@ static int set_audclk_freq(struct i2c_client *client, u32 freq) * so avoid destroying registers. */ break; } - /* VID_PLL and AUX_PLL */ - cx25840_write4(client, 0x108, 0x1009040f); - /* AUX_PLL_FRAC */ - cx25840_write4(client, 0x110, 0x00ec6bd6); + if (!state->is_cx231xx) { + /* VID_PLL and AUX_PLL */ + cx25840_write4(client, 0x108, 0x1009040f); + + /* AUX_PLL_FRAC */ + cx25840_write4(client, 0x110, 0x00ec6bd6); + } if (state->is_cx25836) break; @@ -86,11 +92,14 @@ static int set_audclk_freq(struct i2c_client *client, u32 freq) * so avoid destroying registers. */ break; } - /* VID_PLL and AUX_PLL */ - cx25840_write4(client, 0x108, 0x100a040f); - /* AUX_PLL_FRAC */ - cx25840_write4(client, 0x110, 0x0098d6e5); + if (!state->is_cx231xx) { + /* VID_PLL and AUX_PLL */ + cx25840_write4(client, 0x108, 0x100a040f); + + /* AUX_PLL_FRAC */ + cx25840_write4(client, 0x110, 0x0098d6e5); + } if (state->is_cx25836) break; @@ -109,11 +118,14 @@ static int set_audclk_freq(struct i2c_client *client, u32 freq) * so avoid destroying registers. */ break; } - /* VID_PLL and AUX_PLL */ - cx25840_write4(client, 0x108, 0x1e08040f); - /* AUX_PLL_FRAC */ - cx25840_write4(client, 0x110, 0x012a0869); + if (!state->is_cx231xx) { + /* VID_PLL and AUX_PLL */ + cx25840_write4(client, 0x108, 0x1e08040f); + + /* AUX_PLL_FRAC */ + cx25840_write4(client, 0x110, 0x012a0869); + } if (state->is_cx25836) break; @@ -137,11 +149,14 @@ static int set_audclk_freq(struct i2c_client *client, u32 freq) break; } - /* VID_PLL and AUX_PLL */ - cx25840_write4(client, 0x108, 0x1809040f); - /* AUX_PLL_FRAC */ - cx25840_write4(client, 0x110, 0x00ec6bd6); + if (!state->is_cx231xx) { + /* VID_PLL and AUX_PLL */ + cx25840_write4(client, 0x108, 0x1809040f); + + /* AUX_PLL_FRAC */ + cx25840_write4(client, 0x110, 0x00ec6bd6); + } if (state->is_cx25836) break; @@ -156,7 +171,7 @@ static int set_audclk_freq(struct i2c_client *client, u32 freq) break; case 48000: - if (!state->is_cx23885) { + if (!state->is_cx23885 && !state->is_cx231xx) { /* VID_PLL and AUX_PLL */ cx25840_write4(client, 0x108, 0x180a040f); @@ -167,7 +182,7 @@ static int set_audclk_freq(struct i2c_client *client, u32 freq) if (state->is_cx25836) break; - if (!state->is_cx23885) { + if (!state->is_cx23885 && !state->is_cx231xx) { /* src1_ctl */ cx25840_write4(client, 0x8f8, 0x08018000); @@ -228,10 +243,9 @@ void cx25840_audio_set_path(struct i2c_client *client) /* deassert soft reset */ cx25840_and_or(client, 0x810, ~0x1, 0x00); - if (state->is_cx23885) { - /* Ensure the controller is running when we exit */ + /* Ensure the controller is running when we exit */ + if (state->is_cx23885 || state->is_cx231xx) cx25840_and_or(client, 0x803, ~0x10, 0x10); - } } static int get_volume(struct i2c_client *client) diff --git a/linux/drivers/media/video/cx25840/cx25840-core.c b/linux/drivers/media/video/cx25840/cx25840-core.c index 921cc96fc..5387a846f 100644 --- a/linux/drivers/media/video/cx25840/cx25840-core.c +++ b/linux/drivers/media/video/cx25840/cx25840-core.c @@ -367,6 +367,85 @@ static void cx23885_initialize(struct i2c_client *client) /* ----------------------------------------------------------------------- */ +static void cx231xx_initialize(struct i2c_client *client) +{ + DEFINE_WAIT(wait); + struct cx25840_state *state = to_state(i2c_get_clientdata(client)); + struct workqueue_struct *q; + + /* Internal Reset */ + cx25840_and_or(client, 0x102, ~0x01, 0x01); + cx25840_and_or(client, 0x102, ~0x01, 0x00); + + /* Stop microcontroller */ + cx25840_and_or(client, 0x803, ~0x10, 0x00); + + /* DIF in reset? */ + cx25840_write(client, 0x398, 0); + + /* Trust the default xtal, no division */ + /* This changes for the cx23888 products */ + cx25840_write(client, 0x2, 0x76); + + /* Bring down the regulator for AUX clk */ + cx25840_write(client, 0x1, 0x40); + + /* Disable DIF bypass */ + cx25840_write4(client, 0x33c, 0x00000001); + + /* DIF Src phase inc */ + cx25840_write4(client, 0x340, 0x0df7df83); + + /* Luma */ + cx25840_write4(client, 0x414, 0x00107d12); + + /* Chroma */ + cx25840_write4(client, 0x420, 0x3d008282); + + /* ADC2 input select */ + cx25840_write(client, 0x102, 0x10); + + /* VIN1 & VIN5 */ + cx25840_write(client, 0x103, 0x11); + + /* Enable format auto detect */ + cx25840_write(client, 0x400, 0); +#if 0 + /* Force to NTSC-M and Disable autoconf regs */ + cx25840_write(client, 0x400, 0x21); +#endif + /* Fast subchroma lock */ + /* White crush, Chroma AGC & Chroma Killer enabled */ + cx25840_write(client, 0x401, 0xe8); + + /* Do the firmware load in a work handler to prevent. + Otherwise the kernel is blocked waiting for the + bit-banging i2c interface to finish uploading the + firmware. */ +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 20) + INIT_WORK(&state->fw_work, cx25840_work_handler); +#else + INIT_WORK(&state->fw_work, cx25840_work_handler, state); +#endif + init_waitqueue_head(&state->fw_wait); + q = create_singlethread_workqueue("cx25840_fw"); + prepare_to_wait(&state->fw_wait, &wait, TASK_UNINTERRUPTIBLE); + queue_work(q, &state->fw_work); + schedule(); + finish_wait(&state->fw_wait, &wait); + destroy_workqueue(q); + + cx25840_std_setup(client); + + /* (re)set input */ + set_input(client, state->vid_input, state->aud_input); + + /* start microcontroller */ + cx25840_and_or(client, 0x803, ~0x10, 0x10); +} + +/* ----------------------------------------------------------------------- */ + void cx25840_std_setup(struct i2c_client *client) { struct cx25840_state *state = to_state(i2c_get_clientdata(client)); @@ -436,39 +515,41 @@ void cx25840_std_setup(struct i2c_client *client) } /* DEBUG: Displays configured PLL frequency */ - pll_int = cx25840_read(client, 0x108); - pll_frac = cx25840_read4(client, 0x10c) & 0x1ffffff; - pll_post = cx25840_read(client, 0x109); - v4l_dbg(1, cx25840_debug, client, - "PLL regs = int: %u, frac: %u, post: %u\n", - pll_int, pll_frac, pll_post); - - if (pll_post) { - int fin, fsc; - int pll = (28636363L * ((((u64)pll_int) << 25L) + pll_frac)) >> 25L; - - pll /= pll_post; - v4l_dbg(1, cx25840_debug, client, "PLL = %d.%06d MHz\n", - pll / 1000000, pll % 1000000); - v4l_dbg(1, cx25840_debug, client, "PLL/8 = %d.%06d MHz\n", - pll / 8000000, (pll / 8) % 1000000); - - fin = ((u64)src_decimation * pll) >> 12; - v4l_dbg(1, cx25840_debug, client, - "ADC Sampling freq = %d.%06d MHz\n", - fin / 1000000, fin % 1000000); - - fsc = (((u64)sc) * pll) >> 24L; + if (!state->is_cx231xx) { + pll_int = cx25840_read(client, 0x108); + pll_frac = cx25840_read4(client, 0x10c) & 0x1ffffff; + pll_post = cx25840_read(client, 0x109); v4l_dbg(1, cx25840_debug, client, - "Chroma sub-carrier freq = %d.%06d MHz\n", - fsc / 1000000, fsc % 1000000); - - v4l_dbg(1, cx25840_debug, client, "hblank %i, hactive %i, " - "vblank %i, vactive %i, vblank656 %i, src_dec %i, " - "burst 0x%02x, luma_lpf %i, uv_lpf %i, comb 0x%02x, " - "sc 0x%06x\n", - hblank, hactive, vblank, vactive, vblank656, - src_decimation, burst, luma_lpf, uv_lpf, comb, sc); + "PLL regs = int: %u, frac: %u, post: %u\n", + pll_int, pll_frac, pll_post); + + if (pll_post) { + int fin, fsc; + int pll = (28636363L * ((((u64)pll_int) << 25L) + pll_frac)) >> 25L; + + pll /= pll_post; + v4l_dbg(1, cx25840_debug, client, "PLL = %d.%06d MHz\n", + pll / 1000000, pll % 1000000); + v4l_dbg(1, cx25840_debug, client, "PLL/8 = %d.%06d MHz\n", + pll / 8000000, (pll / 8) % 1000000); + + fin = ((u64)src_decimation * pll) >> 12; + v4l_dbg(1, cx25840_debug, client, + "ADC Sampling freq = %d.%06d MHz\n", + fin / 1000000, fin % 1000000); + + fsc = (((u64)sc) * pll) >> 24L; + v4l_dbg(1, cx25840_debug, client, + "Chroma sub-carrier freq = %d.%06d MHz\n", + fsc / 1000000, fsc % 1000000); + + v4l_dbg(1, cx25840_debug, client, "hblank %i, hactive %i, " + "vblank %i, vactive %i, vblank656 %i, src_dec %i, " + "burst 0x%02x, luma_lpf %i, uv_lpf %i, comb 0x%02x, " + "sc 0x%06x\n", + hblank, hactive, vblank, vactive, vblank656, + src_decimation, burst, luma_lpf, uv_lpf, comb, sc); + } } /* Sets horizontal blanking delay and active lines */ @@ -618,7 +699,7 @@ static int set_input(struct i2c_client *client, enum cx25840_video_input vid_inp * configuration in reg (for the cx23885) so we have no * need to attempt to flip bits for earlier av decoders. */ - if (!state->is_cx23885) { + if (!state->is_cx23885 && !state->is_cx231xx) { switch (aud_input) { case CX25840_AUDIO_SERIAL: /* do nothing, use serial audio input */ @@ -641,7 +722,7 @@ static int set_input(struct i2c_client *client, enum cx25840_video_input vid_inp /* Set INPUT_MODE to Composite (0) or S-Video (1) */ cx25840_and_or(client, 0x401, ~0x6, is_composite ? 0 : 0x02); - if (!state->is_cx23885) { + if (!state->is_cx23885 && !state->is_cx231xx) { /* Set CH_SEL_ADC2 to 1 if input comes from CH3 */ cx25840_and_or(client, 0x102, ~0x2, (reg & 0x80) == 0 ? 2 : 0); /* Set DUAL_MODE_ADC2 to 1 if input comes from both CH2&CH3 */ @@ -681,6 +762,19 @@ static int set_input(struct i2c_client *client, enum cx25840_video_input vid_inp */ cx25840_write(client, 0x918, 0xa0); cx25840_write(client, 0x919, 0x01); + } else if (state->is_cx231xx) { + /* Audio channel 1 src : Parallel 1 */ + cx25840_write(client, 0x124, 0x03); + + /* I2S_IN_CTL: I2S_IN_SONY_MODE, LEFT SAMPLE on WS=1 */ + cx25840_write(client, 0x914, 0xa0); + + /* I2S_OUT_CTL: + * I2S_IN_SONY_MODE, LEFT SAMPLE on WS=1 + * I2S_OUT_MASTER_MODE = Master + */ + cx25840_write(client, 0x918, 0xa0); + cx25840_write(client, 0x919, 0x01); } return 0; @@ -1142,6 +1236,8 @@ static int cx25840_init(struct v4l2_subdev *sd, u32 val) cx25836_initialize(client); else if (state->is_cx23885) cx23885_initialize(client); + else if (state->is_cx231xx) + cx231xx_initialize(client); else cx25840_initialize(client); } @@ -1197,7 +1293,7 @@ static int cx25840_s_stream(struct v4l2_subdev *sd, int enable) v4l_dbg(1, cx25840_debug, client, "%s output\n", enable ? "enable" : "disable"); if (enable) { - if (state->is_cx23885) { + if (state->is_cx23885 || state->is_cx231xx) { u8 v = (cx25840_read(client, 0x421) | 0x0b); cx25840_write(client, 0x421, v); } else { @@ -1207,7 +1303,7 @@ static int cx25840_s_stream(struct v4l2_subdev *sd, int enable) state->is_cx25836 ? 0x04 : 0x07); } } else { - if (state->is_cx23885) { + if (state->is_cx23885 || state->is_cx231xx) { u8 v = cx25840_read(client, 0x421) & ~(0x0b); cx25840_write(client, 0x421, v); } else { @@ -1388,6 +1484,8 @@ static int cx25840_reset(struct v4l2_subdev *sd, u32 val) cx25836_initialize(client); else if (state->is_cx23885) cx23885_initialize(client); + else if (state->is_cx231xx) + cx231xx_initialize(client); else cx25840_initialize(client); return 0; @@ -1500,6 +1598,8 @@ static int cx25840_probe(struct i2c_client *client, id = V4L2_IDENT_CX25836 + ((device_id >> 4) & 0xf) - 6; } 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); } else { v4l_dbg(1, cx25840_debug, client, "cx25840 not found\n"); @@ -1522,6 +1622,7 @@ static int cx25840_probe(struct i2c_client *client, state->c = client; state->is_cx25836 = ((device_id & 0xff00) == 0x8300); state->is_cx23885 = (device_id == 0x0000) || (device_id == 0x1313); + state->is_cx231xx = (device_id == 0x5a3e); state->vid_input = CX25840_COMPOSITE7; state->aud_input = CX25840_AUDIO8; state->audclk_freq = 48000; diff --git a/linux/drivers/media/video/cx25840/cx25840-core.h b/linux/drivers/media/video/cx25840/cx25840-core.h index 0a99c19df..422c63752 100644 --- a/linux/drivers/media/video/cx25840/cx25840-core.h +++ b/linux/drivers/media/video/cx25840/cx25840-core.h @@ -51,6 +51,7 @@ struct cx25840_state { u32 rev; int is_cx25836; int is_cx23885; + int is_cx231xx; int is_initialized; wait_queue_head_t fw_wait; /* wake up when the fw load is finished */ struct work_struct fw_work; /* work entry for fw load */ diff --git a/linux/drivers/media/video/cx25840/cx25840-firmware.c b/linux/drivers/media/video/cx25840/cx25840-firmware.c index 01fbe174e..f01456ec4 100644 --- a/linux/drivers/media/video/cx25840/cx25840-firmware.c +++ b/linux/drivers/media/video/cx25840/cx25840-firmware.c @@ -26,6 +26,7 @@ #define FWFILE "v4l-cx25840.fw" #define FWFILE_CX23885 "v4l-cx23885-avcore-01.fw" +#define FWFILE_CX231XX "v4l-cx231xx-avcore-01.fw" /* * Mike Isely <isely@pobox.com> - The FWSEND parameter controls the @@ -97,9 +98,17 @@ int cx25840_loadfw(struct i2c_client *client) u8 buffer[FWSEND]; const u8 *ptr; int size, retval; + int MAX_BUF_SIZE = FWSEND; if (state->is_cx23885) firmware = FWFILE_CX23885; + else if (state->is_cx231xx) + firmware = FWFILE_CX231XX; + + if ((state->is_cx231xx) && MAX_BUF_SIZE > 16) { + v4l_err(client, " Firmware download size changed to 16 bytes max length\n"); + MAX_BUF_SIZE = 16; /* cx231xx cannot accept more than 16 bytes at a time */ + } if (request_firmware(&fw, firmware, FWDEV(client)) != 0) { v4l_err(client, "unable to open firmware %s\n", firmware); @@ -114,7 +123,7 @@ int cx25840_loadfw(struct i2c_client *client) size = fw->size; ptr = fw->data; while (size > 0) { - int len = min(FWSEND - 2, size); + int len = min(MAX_BUF_SIZE - 2, size); memcpy(buffer + 2, ptr, len); diff --git a/linux/drivers/media/video/cx88/cx88-cards.c b/linux/drivers/media/video/cx88/cx88-cards.c index f9b5a9c09..719315d02 100644 --- a/linux/drivers/media/video/cx88/cx88-cards.c +++ b/linux/drivers/media/video/cx88/cx88-cards.c @@ -1967,6 +1967,39 @@ static const struct cx88_board cx88_boards[] = { } }, .mpeg = CX88_MPEG_DVB, }, + [CX88_BOARD_TERRATEC_CINERGY_HT_PCI_MKII] = { + .name = "Terratec Cinergy HT PCI MKII", + .tuner_type = TUNER_XC2028, + .tuner_addr = 0x61, + .radio_type = TUNER_XC2028, + .radio_addr = 0x61, + .input = { { + .type = CX88_VMUX_TELEVISION, + .vmux = 0, + .gpio0 = 0x004ff, + .gpio1 = 0x010ff, + .gpio2 = 0x00001, + }, { + .type = CX88_VMUX_COMPOSITE1, + .vmux = 1, + .gpio0 = 0x004fb, + .gpio1 = 0x010ef, + .audioroute = 1, + }, { + .type = CX88_VMUX_SVIDEO, + .vmux = 2, + .gpio0 = 0x004fb, + .gpio1 = 0x010ef, + .audioroute = 1, + } }, + .radio = { + .type = CX88_RADIO, + .gpio0 = 0x004ff, + .gpio1 = 0x010ff, + .gpio2 = 0x0ff, + }, + .mpeg = CX88_MPEG_DVB, + }, }; /* ------------------------------------------------------------------ */ @@ -2376,6 +2409,10 @@ static const struct cx88_subid cx88_subids[] = { .subvendor = 0xb200, .subdevice = 0x4200, .card = CX88_BOARD_SATTRADE_ST4200, + }, { + .subvendor = 0x153b, + .subdevice = 0x1177, + .card = CX88_BOARD_TERRATEC_CINERGY_HT_PCI_MKII, }, }; @@ -2852,6 +2889,7 @@ void cx88_setup_xc3028(struct cx88_core *core, struct xc2028_ctrl *ctl) */ break; case CX88_BOARD_PINNACLE_HYBRID_PCTV: + case CX88_BOARD_TERRATEC_CINERGY_HT_PCI_MKII: ctl->demod = XC3028_FE_ZARLINK456; ctl->mts = 1; break; @@ -3133,7 +3171,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; } 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-dvb.c b/linux/drivers/media/video/cx88/cx88-dvb.c index 488126ad6..10cf470ce 100644 --- a/linux/drivers/media/video/cx88/cx88-dvb.c +++ b/linux/drivers/media/video/cx88/cx88-dvb.c @@ -242,6 +242,12 @@ static struct mt352_config dvico_fusionhdtv_dual = { .demod_init = dvico_dual_demod_init, }; +static struct zl10353_config cx88_terratec_cinergy_ht_pci_mkii_config = { + .demod_address = (0x1e >> 1), + .no_tuner = 1, + .if2 = 45600, +}; + #if defined(CONFIG_VIDEO_CX88_VP3054) || (defined(CONFIG_VIDEO_CX88_VP3054_MODULE) && defined(MODULE)) static int dntv_live_dvbt_pro_demod_init(struct dvb_frontend* fe) { @@ -1138,6 +1144,16 @@ static int dvb_register(struct cx8802_dev *dev) if (fe0->dvb.frontend != NULL) fe0->dvb.frontend->ops.set_voltage = tevii_dvbs_set_voltage; break; + case CX88_BOARD_TERRATEC_CINERGY_HT_PCI_MKII: + fe0->dvb.frontend = dvb_attach(zl10353_attach, + &cx88_terratec_cinergy_ht_pci_mkii_config, + &core->i2c_adap); + if (fe0->dvb.frontend) { + fe0->dvb.frontend->ops.i2c_gate_ctrl = NULL; + if (attach_xc3028(0x61, dev) < 0) + goto frontend_detach; + } + break; default: printk(KERN_ERR "%s/2: The frontend of your DVB/ATSC card isn't supported yet\n", core->name); 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-input.c b/linux/drivers/media/video/cx88/cx88-input.c index dbb6ee2d9..8a2e631b7 100644 --- a/linux/drivers/media/video/cx88/cx88-input.c +++ b/linux/drivers/media/video/cx88/cx88-input.c @@ -49,8 +49,7 @@ struct cx88_IR { /* poll external decoder */ int polling; - struct work_struct work; - struct timer_list timer; + struct delayed_work work; u32 gpio_addr; u32 last_gpio; u32 mask_keycode; @@ -144,13 +143,6 @@ static void cx88_ir_handle_key(struct cx88_IR *ir) } } -static void ir_timer(unsigned long data) -{ - struct cx88_IR *ir = (struct cx88_IR *)data; - - schedule_work(&ir->work); -} - #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20) static void cx88_ir_work(void *data) #else @@ -160,23 +152,22 @@ static void cx88_ir_work(struct work_struct *work) #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20) struct cx88_IR *ir = data; #else - struct cx88_IR *ir = container_of(work, struct cx88_IR, work); + struct cx88_IR *ir = container_of(work, struct cx88_IR, work.work); #endif cx88_ir_handle_key(ir); - mod_timer(&ir->timer, jiffies + msecs_to_jiffies(ir->polling)); + schedule_delayed_work(&ir->work, msecs_to_jiffies(ir->polling)); } void cx88_ir_start(struct cx88_core *core, struct cx88_IR *ir) { if (ir->polling) { - setup_timer(&ir->timer, ir_timer, (unsigned long)ir); #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20) - INIT_WORK(&ir->work, cx88_ir_work, ir); + INIT_DELAYED_WORK(&ir->work, cx88_ir_work, ir); #else - INIT_WORK(&ir->work, cx88_ir_work); + INIT_DELAYED_WORK(&ir->work, cx88_ir_work); #endif - schedule_work(&ir->work); + schedule_delayed_work(&ir->work, 0); } if (ir->sampling) { core->pci_irqmask |= PCI_INT_IR_SMPINT; @@ -192,10 +183,8 @@ void cx88_ir_stop(struct cx88_core *core, struct cx88_IR *ir) core->pci_irqmask &= ~PCI_INT_IR_SMPINT; } - if (ir->polling) { - del_timer_sync(&ir->timer); - flush_scheduled_work(); - } + if (ir->polling) + cancel_delayed_work_sync(&ir->work); } /* ---------------------------------------------------------------------- */ diff --git a/linux/drivers/media/video/cx88/cx88.h b/linux/drivers/media/video/cx88/cx88.h index 2227d93c7..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> @@ -232,6 +232,7 @@ extern struct sram_channel cx88_sram_channels[]; #define CX88_BOARD_SATTRADE_ST4200 76 #define CX88_BOARD_TBS_8910 77 #define CX88_BOARD_PROF_6200 78 +#define CX88_BOARD_TERRATEC_CINERGY_HT_PCI_MKII 79 enum cx88_itype { CX88_VMUX_COMPOSITE1 = 1, @@ -330,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; @@ -368,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/em28xx/em28xx-input.c b/linux/drivers/media/video/em28xx/em28xx-input.c index b97a1bc85..5382a6064 100644 --- a/linux/drivers/media/video/em28xx/em28xx-input.c +++ b/linux/drivers/media/video/em28xx/em28xx-input.c @@ -69,8 +69,7 @@ struct em28xx_IR { /* poll external decoder */ int polling; - struct work_struct work; - struct timer_list timer; + struct delayed_work work; unsigned int last_toggle:1; unsigned int last_readcount; unsigned int repeat_interval; @@ -298,13 +297,6 @@ static void em28xx_ir_handle_key(struct em28xx_IR *ir) return; } -static void ir_timer(unsigned long data) -{ - struct em28xx_IR *ir = (struct em28xx_IR *)data; - - schedule_work(&ir->work); -} - #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 20) static void em28xx_ir_work(void *data) #else @@ -314,28 +306,26 @@ static void em28xx_ir_work(struct work_struct *work) #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 20) struct em28xx_IR *ir = data; #else - struct em28xx_IR *ir = container_of(work, struct em28xx_IR, work); + struct em28xx_IR *ir = container_of(work, struct em28xx_IR, work.work); #endif em28xx_ir_handle_key(ir); - mod_timer(&ir->timer, jiffies + msecs_to_jiffies(ir->polling)); + schedule_delayed_work(&ir->work, msecs_to_jiffies(ir->polling)); } static void em28xx_ir_start(struct em28xx_IR *ir) { - setup_timer(&ir->timer, ir_timer, (unsigned long)ir); #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 20) - INIT_WORK(&ir->work, em28xx_ir_work, ir); + INIT_DELAYED_WORK(&ir->work, em28xx_ir_work, ir); #else - INIT_WORK(&ir->work, em28xx_ir_work); + INIT_DELAYED_WORK(&ir->work, em28xx_ir_work); #endif - schedule_work(&ir->work); + schedule_delayed_work(&ir->work, 0); } static void em28xx_ir_stop(struct em28xx_IR *ir) { - del_timer_sync(&ir->timer); - flush_scheduled_work(); + cancel_delayed_work_sync(&ir->work); } int em28xx_ir_init(struct em28xx *dev) 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/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/sonixj.c b/linux/drivers/media/video/gspca/sonixj.c index 36d6f50be..a7fcc169d 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 -- */ 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/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/zc3xx.c b/linux/drivers/media/video/gspca/zc3xx.c index ad385b9a0..e2ab9c2eb 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[] = { diff --git a/linux/drivers/media/video/ir-kbd-i2c.c b/linux/drivers/media/video/ir-kbd-i2c.c index a99aea49a..7bae57ad3 100644 --- a/linux/drivers/media/video/ir-kbd-i2c.c +++ b/linux/drivers/media/video/ir-kbd-i2c.c @@ -47,9 +47,9 @@ #include <linux/i2c-id.h> #include <linux/workqueue.h> +#include "compat.h" #include <media/ir-common.h> #include <media/ir-kbd-i2c.h> -#include "compat.h" /* ----------------------------------------------------------------------- */ /* insmod parameters */ @@ -280,12 +280,6 @@ static void ir_key_poll(struct IR_i2c *ir) } } -static void ir_timer(unsigned long data) -{ - struct IR_i2c *ir = (struct IR_i2c*)data; - schedule_work(&ir->work); -} - #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20) static void ir_work(void *data) #else @@ -295,7 +289,7 @@ static void ir_work(struct work_struct *work) #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20) struct IR_i2c *ir = data; #else - struct IR_i2c *ir = container_of(work, struct IR_i2c, work); + struct IR_i2c *ir = container_of(work, struct IR_i2c, work.work); #endif int polling_interval = 100; @@ -305,7 +299,7 @@ static void ir_work(struct work_struct *work) polling_interval = 50; ir_key_poll(ir); - mod_timer(&ir->timer, jiffies + msecs_to_jiffies(polling_interval)); + schedule_delayed_work(&ir->work, msecs_to_jiffies(polling_interval)); } /* ----------------------------------------------------------------------- */ @@ -462,14 +456,11 @@ static int ir_attach(struct i2c_adapter *adap, int addr, /* start polling via eventd */ #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20) - INIT_WORK(&ir->work, ir_work, ir); + INIT_DELAYED_WORK(&ir->work, ir_work, ir); #else - INIT_WORK(&ir->work, ir_work); + INIT_DELAYED_WORK(&ir->work, ir_work); #endif - init_timer(&ir->timer); - ir->timer.function = ir_timer; - ir->timer.data = (unsigned long)ir; - schedule_work(&ir->work); + schedule_delayed_work(&ir->work, 0); return 0; @@ -486,8 +477,7 @@ static int ir_detach(struct i2c_client *client) struct IR_i2c *ir = i2c_get_clientdata(client); /* kill outstanding polls */ - del_timer_sync(&ir->timer); - flush_scheduled_work(); + cancel_delayed_work_sync(&ir->work); /* unregister devices */ input_unregister_device(ir->input); diff --git a/linux/drivers/media/video/ivtv/ivtv-version.h b/linux/drivers/media/video/ivtv/ivtv-version.h index 8cd753d30..b530dec39 100644 --- a/linux/drivers/media/video/ivtv/ivtv-version.h +++ b/linux/drivers/media/video/ivtv/ivtv-version.h @@ -23,7 +23,7 @@ #define IVTV_DRIVER_NAME "ivtv" #define IVTV_DRIVER_VERSION_MAJOR 1 #define IVTV_DRIVER_VERSION_MINOR 4 -#define IVTV_DRIVER_VERSION_PATCHLEVEL 0 +#define IVTV_DRIVER_VERSION_PATCHLEVEL 1 #define IVTV_VERSION __stringify(IVTV_DRIVER_VERSION_MAJOR) "." __stringify(IVTV_DRIVER_VERSION_MINOR) "." __stringify(IVTV_DRIVER_VERSION_PATCHLEVEL) #define IVTV_DRIVER_VERSION KERNEL_VERSION(IVTV_DRIVER_VERSION_MAJOR,IVTV_DRIVER_VERSION_MINOR,IVTV_DRIVER_VERSION_PATCHLEVEL) 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..bec6859b3 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; @@ -812,14 +782,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 +790,6 @@ static int mt9v022_probe(struct i2c_client *client, return 0; eisdr: - bus_switch_release(mt9v022); -eswinit: kfree(mt9v022); return ret; } @@ -839,7 +799,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/omap24xxcam.c b/linux/drivers/media/video/omap24xxcam.c index 73eb656ac..61f3c83db 100644 --- a/linux/drivers/media/video/omap24xxcam.c +++ b/linux/drivers/media/video/omap24xxcam.c @@ -1665,7 +1665,6 @@ static int omap24xxcam_device_register(struct v4l2_int_device *s) vfd->parent = cam->dev; strlcpy(vfd->name, CAM_NAME, sizeof(vfd->name)); - vfd->vfl_type = VID_TYPE_CAPTURE | VID_TYPE_CHROMAKEY; vfd->fops = &omap24xxcam_fops; vfd->minor = -1; vfd->ioctl_ops = &omap24xxcam_ioctl_fops; 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/pwc/pwc-if.c b/linux/drivers/media/video/pwc/pwc-if.c index 49a918636..b3765e280 100644 --- a/linux/drivers/media/video/pwc/pwc-if.c +++ b/linux/drivers/media/video/pwc/pwc-if.c @@ -1133,6 +1133,7 @@ static int pwc_video_open(struct file *file) } mutex_lock(&pdev->modlock); + pwc_construct(pdev); /* set min/max sizes correct */ if (!pdev->usb_init) { PWC_DEBUG_OPEN("Doing first time initialization.\n"); pdev->usb_init = 1; @@ -1157,7 +1158,6 @@ static int pwc_video_open(struct file *file) if (pwc_set_leds(pdev, led_on, led_off) < 0) PWC_DEBUG_OPEN("Failed to set LED on/off time.\n"); - pwc_construct(pdev); /* set min/max sizes correct */ /* So far, so good. Allocate memory. */ i = pwc_allocate_buffers(pdev); 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/saa6588.c b/linux/drivers/media/video/saa6588.c index ae96de5fd..d89d70892 100644 --- a/linux/drivers/media/video/saa6588.c +++ b/linux/drivers/media/video/saa6588.c @@ -77,8 +77,7 @@ MODULE_LICENSE("GPL"); struct saa6588 { struct v4l2_subdev sd; - struct work_struct work; - struct timer_list timer; + struct delayed_work work; spinlock_t lock; unsigned char *buffer; unsigned int buf_size; @@ -323,13 +322,6 @@ static void saa6588_i2c_poll(struct saa6588 *s) wake_up_interruptible(&s->read_queue); } -static void saa6588_timer(unsigned long data) -{ - struct saa6588 *s = (struct saa6588 *)data; - - schedule_work(&s->work); -} - #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20) static void saa6588_work(void *data) #else @@ -339,11 +331,11 @@ static void saa6588_work(struct work_struct *work) #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20) struct saa6588 *s = (struct saa6588 *)data; #else - struct saa6588 *s = container_of(work, struct saa6588, work); + struct saa6588 *s = container_of(work, struct saa6588, work.work); #endif saa6588_i2c_poll(s); - mod_timer(&s->timer, jiffies + msecs_to_jiffies(20)); + schedule_delayed_work(&s->work, msecs_to_jiffies(20)); } static int saa6588_configure(struct saa6588 *s) @@ -500,14 +492,11 @@ static int saa6588_probe(struct i2c_client *client, /* start polling via eventd */ #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 20) - INIT_WORK(&s->work, saa6588_work, s); + INIT_DELAYED_WORK(&s->work, saa6588_work, s); #else - INIT_WORK(&s->work, saa6588_work); + INIT_DELAYED_WORK(&s->work, saa6588_work); #endif - init_timer(&s->timer); - s->timer.function = saa6588_timer; - s->timer.data = (unsigned long)s; - schedule_work(&s->work); + schedule_delayed_work(&s->work, 0); return 0; } @@ -518,8 +507,7 @@ static int saa6588_remove(struct i2c_client *client) v4l2_device_unregister_subdev(sd); - del_timer_sync(&s->timer); - flush_scheduled_work(); + cancel_delayed_work_sync(&s->work); kfree(s->buffer); kfree(s); diff --git a/linux/drivers/media/video/saa7134/Kconfig b/linux/drivers/media/video/saa7134/Kconfig index 51f17c82b..e62b29967 100644 --- a/linux/drivers/media/video/saa7134/Kconfig +++ b/linux/drivers/media/video/saa7134/Kconfig @@ -42,6 +42,9 @@ config VIDEO_SAA7134_DVB 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 ---help--- This adds support for DVB cards based on the Philips saa7134 chip. diff --git a/linux/drivers/media/video/saa7134/saa7134-cards.c b/linux/drivers/media/video/saa7134/saa7134-cards.c index 725c05f9e..e8efc883c 100644 --- a/linux/drivers/media/video/saa7134/saa7134-cards.c +++ b/linux/drivers/media/video/saa7134/saa7134-cards.c @@ -3331,14 +3331,16 @@ struct saa7134_board saa7134_boards[] = { .gpio = 0x0200100, }, }, - [SAA7134_BOARD_HAUPPAUGE_HVR1150] = { - .name = "Hauppauge WinTV-HVR1150", + [SAA7134_BOARD_HAUPPAUGE_HVR1120] = { + .name = "Hauppauge WinTV-HVR1120 ATSC/QAM-Hybrid", .audio_clock = 0x00187de7, .tuner_type = TUNER_PHILIPS_TDA8290, .radio_type = UNSET, .tuner_addr = ADDR_UNSET, .radio_addr = ADDR_UNSET, .tuner_config = 3, + .mpeg = SAA7134_MPEG_DVB, + .ts_type = SAA7134_MPEG_TS_SERIAL, .gpiomask = 0x0800100, /* GPIO 21 is an INPUT */ .inputs = {{ .name = name_tv, @@ -5505,7 +5507,7 @@ struct pci_device_id saa7134_pci_tbl[] = { .device = PCI_DEVICE_ID_PHILIPS_SAA7133, .subvendor = 0x0070, .subdevice = 0x6706, - .driver_data = SAA7134_BOARD_HAUPPAUGE_HVR1150, + .driver_data = SAA7134_BOARD_HAUPPAUGE_HVR1120, },{ .vendor = PCI_VENDOR_ID_PHILIPS, .device = PCI_DEVICE_ID_PHILIPS_SAA7133, @@ -5517,7 +5519,7 @@ struct pci_device_id saa7134_pci_tbl[] = { .device = PCI_DEVICE_ID_PHILIPS_SAA7133, .subvendor = 0x0070, .subdevice = 0x6708, - .driver_data = SAA7134_BOARD_HAUPPAUGE_HVR1150, + .driver_data = SAA7134_BOARD_HAUPPAUGE_HVR1120, },{ .vendor = PCI_VENDOR_ID_PHILIPS, .device = PCI_DEVICE_ID_PHILIPS_SAA7133, @@ -6057,7 +6059,7 @@ static int saa7134_tda8290_18271_callback(struct saa7134_dev *dev, switch (command) { case TDA18271_CALLBACK_CMD_AGC_ENABLE: /* 0 */ switch (dev->board) { - case SAA7134_BOARD_HAUPPAUGE_HVR1150: + case SAA7134_BOARD_HAUPPAUGE_HVR1120: case SAA7134_BOARD_HAUPPAUGE_HVR1110R3: ret = saa7134_tda18271_hvr11x0_toggle_agc(dev, arg); break; @@ -6078,7 +6080,7 @@ static int saa7134_tda8290_callback(struct saa7134_dev *dev, int ret; switch (dev->board) { - case SAA7134_BOARD_HAUPPAUGE_HVR1150: + case SAA7134_BOARD_HAUPPAUGE_HVR1120: case SAA7134_BOARD_HAUPPAUGE_HVR1110R3: /* tda8290 + tda18271 */ ret = saa7134_tda8290_18271_callback(dev, command, arg); @@ -6125,7 +6127,7 @@ static void hauppauge_eeprom(struct saa7134_dev *dev, u8 *eeprom_data) switch (tv.model) { case 67019: /* WinTV-HVR1110 (Retail, IR Blaster, hybrid, FM, SVid/Comp, 3.5mm audio in) */ case 67109: /* WinTV-HVR1000 (Retail, IR Receive, analog, no FM, SVid/Comp, 3.5mm audio in) */ - case 67201: /* WinTV-HVR1150 (Retail, IR Receive, hybrid, FM, SVid/Comp, 3.5mm audio in) */ + case 67201: /* WinTV-HVR1120 (Retail, IR Receive, hybrid, FM, SVid/Comp, 3.5mm audio in) */ case 67301: /* WinTV-HVR1000 (Retail, IR Receive, analog, no FM, SVid/Comp, 3.5mm audio in) */ case 67209: /* WinTV-HVR1110 (Retail, IR Receive, hybrid, FM, SVid/Comp, 3.5mm audio in) */ case 67559: /* WinTV-HVR1110 (OEM, no IR, hybrid, FM, SVid/Comp, RCA aud) */ @@ -6133,7 +6135,7 @@ static void hauppauge_eeprom(struct saa7134_dev *dev, u8 *eeprom_data) case 67579: /* WinTV-HVR1110 (OEM, no IR, hybrid, no FM) */ case 67589: /* WinTV-HVR1110 (OEM, no IR, hybrid, no FM, SVid/Comp, RCA aud) */ case 67599: /* WinTV-HVR1110 (OEM, no IR, hybrid, no FM, SVid/Comp, RCA aud) */ - case 67651: /* WinTV-HVR1150 (OEM, no IR, hybrid, FM, SVid/Comp, RCA aud) */ + case 67651: /* WinTV-HVR1120 (OEM, no IR, hybrid, FM, SVid/Comp, RCA aud) */ case 67659: /* WinTV-HVR1110 (OEM, no IR, hybrid, FM, SVid/Comp, RCA aud) */ break; default: @@ -6315,7 +6317,7 @@ int saa7134_board_init1(struct saa7134_dev *dev) saa_writeb (SAA7134_PRODUCTION_TEST_MODE, 0x00); break; - case SAA7134_BOARD_HAUPPAUGE_HVR1150: + case SAA7134_BOARD_HAUPPAUGE_HVR1120: case SAA7134_BOARD_HAUPPAUGE_HVR1110R3: /* GPIO 26 high for digital, low for analog */ saa7134_set_gpio(dev, 26, 0); @@ -6577,7 +6579,7 @@ int saa7134_board_init2(struct saa7134_dev *dev) dev->name, saa7134_boards[dev->board].name); } break; - case SAA7134_BOARD_HAUPPAUGE_HVR1150: + case SAA7134_BOARD_HAUPPAUGE_HVR1120: case SAA7134_BOARD_HAUPPAUGE_HVR1110R3: hauppauge_eeprom(dev, dev->eedata+0x80); break; 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/saa7134/saa7134-dvb.c b/linux/drivers/media/video/saa7134/saa7134-dvb.c index 7745cad95..2e1344ecf 100644 --- a/linux/drivers/media/video/saa7134/saa7134-dvb.c +++ b/linux/drivers/media/video/saa7134/saa7134-dvb.c @@ -48,6 +48,9 @@ #include "isl6405.h" #include "lnbp21.h" #include "tuner-simple.h" +#include "tda18271.h" +#include "lgdt3305.h" +#include "tda8290.h" #include "zl10353.h" @@ -863,6 +866,7 @@ static struct zl10353_config behold_h6_config = { .demod_address = 0x1e>>1, .no_tuner = 1, .parallel_ts = 1, + .disable_i2c_gate_ctrl = 1, }; /* ================================================================== @@ -963,6 +967,34 @@ static struct zl10036_config avertv_a700_tuner = { .tuner_address = 0x60, }; +static struct lgdt3305_config hcw_lgdt3305_config = { + .i2c_addr = 0x0e, + .mpeg_mode = LGDT3305_MPEG_SERIAL, + .tpclk_edge = LGDT3305_TPCLK_RISING_EDGE, + .tpvalid_polarity = LGDT3305_TP_VALID_HIGH, + .deny_i2c_rptr = 1, + .spectral_inversion = 1, + .qam_if_khz = 4000, + .vsb_if_khz = 3250, +}; + +static struct tda18271_std_map hauppauge_tda18271_std_map = { + .atsc_6 = { .if_freq = 3250, .agc_mode = 3, .std = 4, + .if_lvl = 1, .rfagc_top = 0x58, }, + .qam_6 = { .if_freq = 4000, .agc_mode = 3, .std = 5, + .if_lvl = 1, .rfagc_top = 0x58, }, +}; + +static struct tda18271_config hcw_tda18271_config = { + .std_map = &hauppauge_tda18271_std_map, + .gate = TDA18271_GATE_ANALOG, + .config = 3, +}; + +static struct tda829x_config tda829x_no_probe = { + .probe_tuner = TDA829X_DONT_PROBE, +}; + /* ================================================================== * Core code */ @@ -1089,6 +1121,19 @@ static int dvb_init(struct saa7134_dev *dev) &tda827x_cfg_1) < 0) goto dettach_frontend; break; + case SAA7134_BOARD_HAUPPAUGE_HVR1120: + fe0->dvb.frontend = dvb_attach(lgdt3305_attach, + &hcw_lgdt3305_config, + &dev->i2c_adap); + if (fe0->dvb.frontend) { + dvb_attach(tda829x_attach, fe0->dvb.frontend, + &dev->i2c_adap, 0x4b, + &tda829x_no_probe); + dvb_attach(tda18271_attach, fe0->dvb.frontend, + 0x60, &dev->i2c_adap, + &hcw_tda18271_config); + } + break; case SAA7134_BOARD_ASUSTeK_P7131_DUAL: if (configure_tda827x_fe(dev, &asus_p7131_dual_config, &tda827x_cfg_0) < 0) diff --git a/linux/drivers/media/video/saa7134/saa7134-ts.c b/linux/drivers/media/video/saa7134/saa7134-ts.c index ef55a59f0..cc8b923af 100644 --- a/linux/drivers/media/video/saa7134/saa7134-ts.c +++ b/linux/drivers/media/video/saa7134/saa7134-ts.c @@ -79,8 +79,19 @@ static int buffer_activate(struct saa7134_dev *dev, saa_writeb(SAA7134_TS_SERIAL1, 0x00); /* Start TS stream */ - saa_writeb(SAA7134_TS_SERIAL0, 0x40); - saa_writeb(SAA7134_TS_PARALLEL, 0xEC); + switch (saa7134_boards[dev->board].ts_type) { + case SAA7134_MPEG_TS_PARALLEL: + saa_writeb(SAA7134_TS_SERIAL0, 0x40); + saa_writeb(SAA7134_TS_PARALLEL, 0xec); + break; + case SAA7134_MPEG_TS_SERIAL: + saa_writeb(SAA7134_TS_SERIAL0, 0xd8); + saa_writeb(SAA7134_TS_PARALLEL, 0x6c); + saa_writeb(SAA7134_TS_PARALLEL_SERIAL, 0xbc); + saa_writeb(SAA7134_TS_SERIAL1, 0x02); + break; + } + dev->ts_state = SAA7134_TS_STARTED; } diff --git a/linux/drivers/media/video/saa7134/saa7134.h b/linux/drivers/media/video/saa7134/saa7134.h index 0e45c0931..d2b29ed9e 100644 --- a/linux/drivers/media/video/saa7134/saa7134.h +++ b/linux/drivers/media/video/saa7134/saa7134.h @@ -279,7 +279,7 @@ struct saa7134_format { #define SAA7134_BOARD_ASUSTeK_TIGER 152 #define SAA7134_BOARD_KWORLD_PLUS_TV_ANALOG 153 #define SAA7134_BOARD_AVERMEDIA_GO_007_FM_PLUS 154 -#define SAA7134_BOARD_HAUPPAUGE_HVR1150 155 +#define SAA7134_BOARD_HAUPPAUGE_HVR1120 155 #define SAA7134_BOARD_HAUPPAUGE_HVR1110R3 156 #define SAA7134_MAXBOARDS 32 @@ -313,6 +313,11 @@ enum saa7134_mpeg_type { SAA7134_MPEG_DVB, }; +enum saa7134_mpeg_ts_type { + SAA7134_MPEG_TS_PARALLEL = 0, + SAA7134_MPEG_TS_SERIAL, +}; + struct saa7134_board { char *name; unsigned int audio_clock; @@ -335,6 +340,7 @@ struct saa7134_board { /* peripheral I/O */ enum saa7134_video_out video_out; enum saa7134_mpeg_type mpeg; + enum saa7134_mpeg_ts_type ts_type; unsigned int vid_port_opts; }; 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/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/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/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 a5ce43102..32d0246d5 100644 --- a/linux/drivers/media/video/v4l2-common.c +++ b/linux/drivers/media/video/v4l2-common.c @@ -856,11 +856,11 @@ struct v4l2_subdev *v4l2_i2c_new_subdev(struct i2c_adapter *adapter, We need better support from the kernel so that we can easily wait for the load to finish. */ if (client == NULL || client->driver == NULL) - return NULL; + goto error; /* Lock the module so we can safely get the v4l2_subdev pointer */ if (!try_module_get(client->driver->driver.owner)) - return NULL; + goto error; sd = i2c_get_clientdata(client); /* Register with the v4l2_device which increases the module's @@ -869,8 +869,15 @@ struct v4l2_subdev *v4l2_i2c_new_subdev(struct i2c_adapter *adapter, sd = NULL; /* Decrease the module use count to match the first try_module_get. */ module_put(client->driver->driver.owner); - return sd; +error: +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 22) + /* If we have a client but no subdev, then something went wrong and + we must unregister the client. */ + if (client && sd == NULL) + i2c_unregister_device(client); +#endif + return sd; } EXPORT_SYMBOL_GPL(v4l2_i2c_new_subdev); @@ -918,11 +925,11 @@ struct v4l2_subdev *v4l2_i2c_new_probed_subdev(struct i2c_adapter *adapter, We need better support from the kernel so that we can easily wait for the load to finish. */ if (client == NULL || client->driver == NULL) - return NULL; + goto error; /* Lock the module so we can safely get the v4l2_subdev pointer */ if (!try_module_get(client->driver->driver.owner)) - return NULL; + goto error; sd = i2c_get_clientdata(client); /* Register with the v4l2_device which increases the module's @@ -931,6 +938,14 @@ struct v4l2_subdev *v4l2_i2c_new_probed_subdev(struct i2c_adapter *adapter, sd = NULL; /* Decrease the module use count to match the first try_module_get. */ module_put(client->driver->driver.owner); + +error: +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 22) + /* If we have a client but no subdev, then something went wrong and + we must unregister the client. */ + if (client && sd == NULL) + i2c_unregister_device(client); +#endif return sd; } EXPORT_SYMBOL_GPL(v4l2_i2c_new_probed_subdev); diff --git a/linux/drivers/media/video/v4l2-dev.c b/linux/drivers/media/video/v4l2-dev.c index 861e3194f..5e9b46c21 100644 --- a/linux/drivers/media/video/v4l2-dev.c +++ b/linux/drivers/media/video/v4l2-dev.c @@ -433,7 +433,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. */ @@ -654,6 +654,7 @@ module_exit(videodev_exit) MODULE_AUTHOR("Alan Cox, Mauro Carvalho Chehab <mchehab@infradead.org>"); MODULE_DESCRIPTION("Device registrar for Video4Linux drivers v2"); MODULE_LICENSE("GPL"); +MODULE_ALIAS_CHARDEV_MAJOR(VIDEO_MAJOR); /* 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/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.h b/linux/drivers/media/video/zoran/zoran.h index 8beada961..afecf32f1 100644 --- a/linux/drivers/media/video/zoran/zoran.h +++ b/linux/drivers/media/video/zoran/zoran.h @@ -172,6 +172,8 @@ Private IOCTL to set up for displaying MJPEG #endif #define V4L_MASK_FRAME (V4L_MAX_FRAME - 1) +#define MAX_FRAME (BUZ_MAX_FRAME > VIDEO_MAX_FRAME ? BUZ_MAX_FRAME : VIDEO_MAX_FRAME) + #include "zr36057.h" enum card_type { @@ -280,21 +282,21 @@ struct zoran_mapping { int count; }; -struct zoran_jpg_buffer { - struct zoran_mapping *map; - __le32 *frag_tab; /* addresses of frag table */ - u32 frag_tab_bus; /* same value cached to save time in ISR */ - enum zoran_buffer_state state; /* non-zero if corresponding buffer is in use in grab queue */ - struct zoran_sync bs; /* DONE: info to return to application */ -}; - -struct zoran_v4l_buffer { +struct zoran_buffer { struct zoran_mapping *map; - char *fbuffer; /* virtual address of frame buffer */ - unsigned long fbuffer_phys; /* physical address of frame buffer */ - unsigned long fbuffer_bus; /* bus address of frame buffer */ - enum zoran_buffer_state state; /* state: unused/pending/done */ - struct zoran_sync bs; /* DONE: info to return to application */ + enum zoran_buffer_state state; /* state: unused/pending/dma/done */ + struct zoran_sync bs; /* DONE: info to return to application */ + union { + struct { + __le32 *frag_tab; /* addresses of frag table */ + u32 frag_tab_bus; /* same value cached to save time in ISR */ + } jpg; + struct { + char *fbuffer; /* virtual address of frame buffer */ + unsigned long fbuffer_phys;/* physical address of frame buffer */ + unsigned long fbuffer_bus;/* bus address of frame buffer */ + } v4l; + }; }; enum zoran_lock_activity { @@ -304,19 +306,13 @@ enum zoran_lock_activity { }; /* buffer collections */ -struct zoran_jpg_struct { +struct zoran_buffer_col { enum zoran_lock_activity active; /* feature currently in use? */ - struct zoran_jpg_buffer buffer[BUZ_MAX_FRAME]; /* buffers */ - int num_buffers, buffer_size; + unsigned int num_buffers, buffer_size; + struct zoran_buffer buffer[MAX_FRAME]; /* buffers */ u8 allocated; /* Flag if buffers are allocated */ u8 need_contiguous; /* Flag if contiguous buffers are needed */ -}; - -struct zoran_v4l_struct { - enum zoran_lock_activity active; /* feature currently in use? */ - struct zoran_v4l_buffer buffer[VIDEO_MAX_FRAME]; /* buffers */ - int num_buffers, buffer_size; - u8 allocated; /* Flag if buffers are allocated */ + /* only applies to jpg buffers, raw buffers are always contiguous */ }; struct zoran; @@ -325,17 +321,16 @@ struct zoran; struct zoran_fh { struct zoran *zr; - enum zoran_map_mode map_mode; /* Flag which bufferset will map by next mmap() */ + enum zoran_map_mode map_mode; /* Flag which bufferset will map by next mmap() */ struct zoran_overlay_settings overlay_settings; - u32 *overlay_mask; /* overlay mask */ - enum zoran_lock_activity overlay_active; /* feature currently in use? */ + u32 *overlay_mask; /* overlay mask */ + enum zoran_lock_activity overlay_active;/* feature currently in use? */ - struct zoran_v4l_settings v4l_settings; /* structure with a lot of things to play with */ - struct zoran_v4l_struct v4l_buffers; /* V4L buffers' info */ + struct zoran_buffer_col buffers; /* buffers' info */ + struct zoran_v4l_settings v4l_settings; /* structure with a lot of things to play with */ struct zoran_jpg_settings jpg_settings; /* structure with a lot of things to play with */ - struct zoran_jpg_struct jpg_buffers; /* MJPEG buffers' info */ }; struct card_info { @@ -434,7 +429,7 @@ struct zoran { unsigned long v4l_pend_tail; unsigned long v4l_sync_tail; int v4l_pend[V4L_MAX_FRAME]; - struct zoran_v4l_struct v4l_buffers; /* V4L buffers' info */ + struct zoran_buffer_col v4l_buffers; /* V4L buffers' info */ /* Buz MJPEG parameters */ enum zoran_codec_mode codec_mode; /* status of codec */ @@ -461,7 +456,7 @@ struct zoran { int jpg_pend[BUZ_MAX_FRAME]; /* array indexed by frame number */ - struct zoran_jpg_struct jpg_buffers; /* MJPEG buffers' info */ + struct zoran_buffer_col jpg_buffers; /* MJPEG buffers' info */ /* Additional stuff for testing */ #ifdef CONFIG_PROC_FS diff --git a/linux/drivers/media/video/zoran/zoran_card.c b/linux/drivers/media/video/zoran/zoran_card.c index 57cc62d82..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" @@ -255,7 +255,7 @@ zr36016_write (struct videocodec *codec, static void dc10_init (struct zoran *zr) { - dprintk(3, KERN_DEBUG "%s: dc10_init()\n", ZR_DEVNAME(zr)); + dprintk(3, KERN_DEBUG "%s: %s\n", ZR_DEVNAME(zr), __func__); /* Pixel clock selection */ GPIO(zr, 4, 0); @@ -267,13 +267,13 @@ dc10_init (struct zoran *zr) static void dc10plus_init (struct zoran *zr) { - dprintk(3, KERN_DEBUG "%s: dc10plus_init()\n", ZR_DEVNAME(zr)); + dprintk(3, KERN_DEBUG "%s: %s\n", ZR_DEVNAME(zr), __func__); } static void buz_init (struct zoran *zr) { - dprintk(3, KERN_DEBUG "%s: buz_init()\n", ZR_DEVNAME(zr)); + dprintk(3, KERN_DEBUG "%s: %s\n", ZR_DEVNAME(zr), __func__); /* some stuff from Iomega */ pci_write_config_dword(zr->pci_dev, 0xfc, 0x90680f15); @@ -284,7 +284,7 @@ buz_init (struct zoran *zr) static void lml33_init (struct zoran *zr) { - dprintk(3, KERN_DEBUG "%s: lml33_init()\n", ZR_DEVNAME(zr)); + dprintk(3, KERN_DEBUG "%s: %s\n", ZR_DEVNAME(zr), __func__); GPIO(zr, 2, 1); // Set Composite input/output } @@ -759,13 +759,13 @@ zoran_check_jpg_settings (struct zoran *zr, dprintk(4, KERN_DEBUG - "%s: check_jpg_settings() - dec: %d, Hdcm: %d, Vdcm: %d, Tdcm: %d\n", - ZR_DEVNAME(zr), settings->decimation, settings->HorDcm, + "%s: %s - dec: %d, Hdcm: %d, Vdcm: %d, Tdcm: %d\n", + ZR_DEVNAME(zr), __func__, settings->decimation, settings->HorDcm, settings->VerDcm, settings->TmpDcm); dprintk(4, KERN_DEBUG - "%s: check_jpg_settings() - x: %d, y: %d, w: %d, y: %d\n", - ZR_DEVNAME(zr), settings->img_x, settings->img_y, + "%s: %s - x: %d, y: %d, w: %d, y: %d\n", + ZR_DEVNAME(zr), __func__, settings->img_x, settings->img_y, settings->img_width, settings->img_height); /* Check decimation, set default values for decimation = 1, 2, 4 */ switch (settings->decimation) { @@ -797,8 +797,8 @@ zoran_check_jpg_settings (struct zoran *zr, if (zr->card.type == DC10_new) { dprintk(1, KERN_DEBUG - "%s: check_jpg_settings() - HDec by 4 is not supported on the DC10\n", - ZR_DEVNAME(zr)); + "%s: %s - HDec by 4 is not supported on the DC10\n", + ZR_DEVNAME(zr), __func__); err0++; break; } @@ -875,16 +875,16 @@ zoran_check_jpg_settings (struct zoran *zr, if (!try && err0) { dprintk(1, KERN_ERR - "%s: check_jpg_settings() - error in params for decimation = 0\n", - ZR_DEVNAME(zr)); + "%s: %s - error in params for decimation = 0\n", + ZR_DEVNAME(zr), __func__); err++; } break; default: dprintk(1, KERN_ERR - "%s: check_jpg_settings() - decimation = %d, must be 0, 1, 2 or 4\n", - ZR_DEVNAME(zr), settings->decimation); + "%s: %s - decimation = %d, must be 0, 1, 2 or 4\n", + ZR_DEVNAME(zr), __func__, settings->decimation); err++; break; } @@ -964,10 +964,8 @@ zoran_open_init_params (struct zoran *zr) JPEG_MARKER_DHT | JPEG_MARKER_DQT; i = zoran_check_jpg_settings(zr, &zr->jpg_settings, 0); if (i) - dprintk(1, - KERN_ERR - "%s: zoran_open_init_params() internal error\n", - ZR_DEVNAME(zr)); + dprintk(1, KERN_ERR "%s: %s internal error\n", + ZR_DEVNAME(zr), __func__); clear_interrupt_counters(zr); zr->testing = 0; @@ -1006,8 +1004,8 @@ zr36057_init (struct zoran *zr) dprintk(1, KERN_INFO - "%s: zr36057_init() - initializing card[%d], zr=%p\n", - ZR_DEVNAME(zr), zr->id, zr); + "%s: %s - initializing card[%d], zr=%p\n", + ZR_DEVNAME(zr), __func__, zr->id, zr); /* default setup of all parameters which will persist between opens */ zr->user = 0; @@ -1040,8 +1038,8 @@ zr36057_init (struct zoran *zr) if (zr->timing == NULL) { dprintk(1, KERN_WARNING - "%s: zr36057_init() - default TV standard not supported by hardware. PAL will be used.\n", - ZR_DEVNAME(zr)); + "%s: %s - default TV standard not supported by hardware. PAL will be used.\n", + ZR_DEVNAME(zr), __func__); zr->norm = V4L2_STD_PAL; zr->timing = zr->card.tvn[0]; } @@ -1065,8 +1063,8 @@ zr36057_init (struct zoran *zr) if (!zr->stat_com || !zr->video_dev) { dprintk(1, KERN_ERR - "%s: zr36057_init() - kmalloc (STAT_COM) failed\n", - ZR_DEVNAME(zr)); + "%s: %s - kmalloc (STAT_COM) failed\n", + ZR_DEVNAME(zr), __func__); err = -ENOMEM; goto exit_free; } @@ -1160,10 +1158,8 @@ zoran_setup_videocodec (struct zoran *zr, m = kmalloc(sizeof(struct videocodec_master), GFP_KERNEL); if (!m) { - dprintk(1, - KERN_ERR - "%s: zoran_setup_videocodec() - no memory\n", - ZR_DEVNAME(zr)); + dprintk(1, KERN_ERR "%s: %s - no memory\n", + ZR_DEVNAME(zr), __func__); return m; } @@ -1201,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 @@ -1220,21 +1228,18 @@ static int __devinit zoran_probe(struct pci_dev *pdev, nr = zoran_num++; if (nr >= BUZ_MAX) { - dprintk(1, - KERN_ERR - "%s: driver limited to %d card(s) maximum\n", + dprintk(1, KERN_ERR "%s: driver limited to %d card(s) maximum\n", ZORAN_NAME, BUZ_MAX); return -ENOENT; } zr = kzalloc(sizeof(struct zoran), GFP_KERNEL); if (!zr) { - dprintk(1, - KERN_ERR - "%s: find_zr36057() - kzalloc failed\n", - ZORAN_NAME); + dprintk(1, KERN_ERR "%s: %s - kzalloc failed\n", + 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; @@ -1307,9 +1312,7 @@ static int __devinit zoran_probe(struct pci_dev *pdev, zr->zr36057_mem = pci_ioremap_bar(zr->pci_dev, 0); if (!zr->zr36057_mem) { - dprintk(1, - KERN_ERR - "%s: %s() - ioremap failed\n", + dprintk(1, KERN_ERR "%s: %s() - ioremap failed\n", ZR_DEVNAME(zr), __func__); goto zr_unreg; } @@ -1320,18 +1323,18 @@ static int __devinit zoran_probe(struct pci_dev *pdev, if (result == -EINVAL) { dprintk(1, KERN_ERR - "%s: find_zr36057() - bad irq number or handler\n", - ZR_DEVNAME(zr)); + "%s: %s - bad irq number or handler\n", + ZR_DEVNAME(zr), __func__); } else if (result == -EBUSY) { dprintk(1, KERN_ERR - "%s: find_zr36057() - IRQ %d busy, change your PnP config in BIOS\n", - ZR_DEVNAME(zr), zr->pci_dev->irq); + "%s: %s - IRQ %d busy, change your PnP config in BIOS\n", + ZR_DEVNAME(zr), __func__, zr->pci_dev->irq); } else { dprintk(1, KERN_ERR - "%s: find_zr36057() - can't assign irq, error code %d\n", - ZR_DEVNAME(zr), result); + "%s: %s - can't assign irq, error code %d\n", + ZR_DEVNAME(zr), __func__, result); } goto zr_unmap; } @@ -1341,9 +1344,7 @@ static int __devinit zoran_probe(struct pci_dev *pdev, &latency); need_latency = zr->revision > 1 ? 32 : 48; if (latency != need_latency) { - dprintk(2, - KERN_INFO - "%s: Changing PCI latency from %d to %d\n", + dprintk(2, KERN_INFO "%s: Changing PCI latency from %d to %d\n", ZR_DEVNAME(zr), latency, need_latency); pci_write_config_byte(zr->pci_dev, PCI_LATENCY_TIMER, need_latency); @@ -1355,10 +1356,8 @@ static int __devinit zoran_probe(struct pci_dev *pdev, ZR_DEVNAME(zr)); if (zoran_register_i2c(zr) < 0) { - dprintk(1, - KERN_ERR - "%s: find_zr36057() - can't initialize i2c bus\n", - ZR_DEVNAME(zr)); + dprintk(1, KERN_ERR "%s: %s - can't initialize i2c bus\n", + ZR_DEVNAME(zr), __func__); goto zr_free_irq; } @@ -1410,17 +1409,13 @@ static int __devinit zoran_probe(struct pci_dev *pdev, goto zr_unreg_i2c; zr->codec = videocodec_attach(master_codec); if (!zr->codec) { - dprintk(1, - KERN_ERR - "%s: find_zr36057() - no codec found\n", - ZR_DEVNAME(zr)); + dprintk(1, KERN_ERR "%s: %s - no codec found\n", + ZR_DEVNAME(zr), __func__); goto zr_free_codec; } if (zr->codec->type != zr->card.video_codec) { - dprintk(1, - KERN_ERR - "%s: find_zr36057() - wrong codec\n", - ZR_DEVNAME(zr)); + dprintk(1, KERN_ERR "%s: %s - wrong codec\n", + ZR_DEVNAME(zr), __func__); goto zr_detach_codec; } } @@ -1430,17 +1425,13 @@ static int __devinit zoran_probe(struct pci_dev *pdev, goto zr_detach_codec; zr->vfe = videocodec_attach(master_vfe); if (!zr->vfe) { - dprintk(1, - KERN_ERR - "%s: find_zr36057() - no VFE found\n", - ZR_DEVNAME(zr)); + dprintk(1, KERN_ERR "%s: %s - no VFE found\n", + ZR_DEVNAME(zr), __func__); goto zr_free_vfe; } if (zr->vfe->type != zr->card.video_vfe) { - dprintk(1, - KERN_ERR - "%s: find_zr36057() = wrong VFE\n", - ZR_DEVNAME(zr)); + dprintk(1, KERN_ERR "%s: %s = wrong VFE\n", + ZR_DEVNAME(zr), __func__); goto zr_detach_vfe; } } @@ -1448,8 +1439,7 @@ static int __devinit zoran_probe(struct pci_dev *pdev, /* take care of Natoma chipset and a revision 1 zr36057 */ if ((pci_pci_problems & PCIPCI_NATOMA) && zr->revision <= 1) { zr->jpg_buffers.need_contiguous = 1; - dprintk(1, - KERN_INFO + dprintk(1, KERN_INFO "%s: ZR36057/Natoma bug, max. buffer size is 128K\n", ZR_DEVNAME(zr)); } diff --git a/linux/drivers/media/video/zoran/zoran_device.c b/linux/drivers/media/video/zoran/zoran_device.c index c2dfd4b67..54a04ea5c 100644 --- a/linux/drivers/media/video/zoran/zoran_device.c +++ b/linux/drivers/media/video/zoran/zoran_device.c @@ -536,12 +536,8 @@ zr36057_overlay (struct zoran *zr, * and the maximum window size is BUZ_MAX_WIDTH * BUZ_MAX_HEIGHT pixels. */ -void -write_overlay_mask (struct file *file, - struct v4l2_clip *vp, - int count) +void write_overlay_mask(struct zoran_fh *fh, struct v4l2_clip *vp, int count) { - struct zoran_fh *fh = file->private_data; struct zoran *zr = fh->zr; unsigned mask_line_size = (BUZ_MAX_WIDTH + 31) / 32; u32 *mask; @@ -1126,7 +1122,7 @@ zoran_feed_stat_com (struct zoran *zr) if (!(zr->stat_com[i] & cpu_to_le32(1))) break; zr->stat_com[i] = - cpu_to_le32(zr->jpg_buffers.buffer[frame].frag_tab_bus); + cpu_to_le32(zr->jpg_buffers.buffer[frame].jpg.frag_tab_bus); } else { /* fill 2 stat_com entries */ i = ((zr->jpg_dma_head - @@ -1134,9 +1130,9 @@ zoran_feed_stat_com (struct zoran *zr) if (!(zr->stat_com[i] & cpu_to_le32(1))) break; zr->stat_com[i] = - cpu_to_le32(zr->jpg_buffers.buffer[frame].frag_tab_bus); + cpu_to_le32(zr->jpg_buffers.buffer[frame].jpg.frag_tab_bus); zr->stat_com[i + 1] = - cpu_to_le32(zr->jpg_buffers.buffer[frame].frag_tab_bus); + cpu_to_le32(zr->jpg_buffers.buffer[frame].jpg.frag_tab_bus); } zr->jpg_buffers.buffer[frame].state = BUZ_STATE_DMA; zr->jpg_dma_head++; @@ -1156,7 +1152,7 @@ zoran_reap_stat_com (struct zoran *zr) u32 stat_com; unsigned int seq; unsigned int dif; - struct zoran_jpg_buffer *buffer; + struct zoran_buffer *buffer; int frame; /* In motion decompress we don't have a hardware frame counter, @@ -1299,7 +1295,7 @@ error_handler (struct zoran *zr, printk(KERN_INFO "stat_com frames:"); for (j = 0; j < BUZ_NUM_STAT_COM; j++) { for (i = 0; i < zr->jpg_buffers.num_buffers; i++) { - if (le32_to_cpu(zr->stat_com[j]) == zr->jpg_buffers.buffer[i].frag_tab_bus) + if (le32_to_cpu(zr->stat_com[j]) == zr->jpg_buffers.buffer[i].jpg.frag_tab_bus) printk(KERN_CONT "% d->%d", j, i); } } @@ -1443,7 +1439,7 @@ zoran_irq (int irq, /* Buffer address */ - reg = zr->v4l_buffers.buffer[frame].fbuffer_bus; + reg = zr->v4l_buffers.buffer[frame].v4l.fbuffer_bus; btwrite(reg, ZR36057_VDTR); if (zr->v4l_settings.height > BUZ_MAX_HEIGHT / 2) reg += zr->v4l_settings.bytesperline; @@ -1594,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); @@ -1660,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 2eb645904..bf8c94d03 100644 --- a/linux/drivers/media/video/zoran/zoran_device.h +++ b/linux/drivers/media/video/zoran/zoran_device.h @@ -54,7 +54,7 @@ extern int jpeg_codec_reset(struct zoran *zr); /* zr360x7 access to raw capture */ extern void zr36057_overlay(struct zoran *zr, int on); -extern void write_overlay_mask(struct file *file, +extern void write_overlay_mask(struct zoran_fh *fh, struct v4l2_clip *vp, int count); extern void zr36057_set_memgrab(struct zoran *zr, @@ -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 4afd14308..7ef3c015d 100644 --- a/linux/drivers/media/video/zoran/zoran_driver.c +++ b/linux/drivers/media/video/zoran/zoran_driver.c @@ -163,10 +163,6 @@ const struct zoran_format zoran_formats[] = { }; #define NUM_FORMATS ARRAY_SIZE(zoran_formats) -static int lock_norm; /* 0 = default 1 = Don't change TV standard (norm) */ -module_param(lock_norm, int, 0644); -MODULE_PARM_DESC(lock_norm, "Prevent norm changes (1 = ignore, >1 = fail)"); - /* small helper function for calculating buffersizes for v4l2 * we calculate the nearest higher power-of-two, which * will be the recommended buffersize */ @@ -191,8 +187,26 @@ zoran_v4l2_calc_bufsize (struct zoran_jpg_settings *settings) } /* forward references */ -static void v4l_fbuffer_free(struct file *file); -static void jpg_fbuffer_free(struct file *file); +static void v4l_fbuffer_free(struct zoran_fh *fh); +static void jpg_fbuffer_free(struct zoran_fh *fh); + +/* Set mapping mode */ +static void map_mode_raw(struct zoran_fh *fh) +{ + fh->map_mode = ZORAN_MAP_MODE_RAW; + fh->buffers.buffer_size = v4l_bufsize; + fh->buffers.num_buffers = v4l_nbufs; +} +static void map_mode_jpg(struct zoran_fh *fh, int play) +{ + fh->map_mode = play ? ZORAN_MAP_MODE_JPG_PLAY : ZORAN_MAP_MODE_JPG_REC; + fh->buffers.buffer_size = jpg_bufsize; + fh->buffers.num_buffers = jpg_nbufs; +} +static inline const char *mode_name(enum zoran_map_mode mode) +{ + return mode == ZORAN_MAP_MODE_RAW ? "V4L" : "JPG"; +} /* * Allocate the V4L grab buffers @@ -200,75 +214,70 @@ static void jpg_fbuffer_free(struct file *file); * These have to be pysically contiguous. */ -static int -v4l_fbuffer_alloc (struct file *file) +static int v4l_fbuffer_alloc(struct zoran_fh *fh) { - struct zoran_fh *fh = file->private_data; struct zoran *zr = fh->zr; int i, off; unsigned char *mem; - for (i = 0; i < fh->v4l_buffers.num_buffers; i++) { - if (fh->v4l_buffers.buffer[i].fbuffer) + for (i = 0; i < fh->buffers.num_buffers; i++) { + if (fh->buffers.buffer[i].v4l.fbuffer) dprintk(2, KERN_WARNING - "%s: v4l_fbuffer_alloc() - buffer %d already allocated!?\n", - ZR_DEVNAME(zr), i); + "%s: %s - buffer %d already allocated!?\n", + ZR_DEVNAME(zr), __func__, i); //udelay(20); - mem = kmalloc(fh->v4l_buffers.buffer_size, GFP_KERNEL); + mem = kmalloc(fh->buffers.buffer_size, + GFP_KERNEL | __GFP_NOWARN); if (!mem) { dprintk(1, KERN_ERR - "%s: v4l_fbuffer_alloc() - kmalloc for V4L buf %d failed\n", - ZR_DEVNAME(zr), i); - v4l_fbuffer_free(file); + "%s: %s - kmalloc for V4L buf %d failed\n", + ZR_DEVNAME(zr), __func__, i); + v4l_fbuffer_free(fh); return -ENOBUFS; } - fh->v4l_buffers.buffer[i].fbuffer = mem; - fh->v4l_buffers.buffer[i].fbuffer_phys = - virt_to_phys(mem); - fh->v4l_buffers.buffer[i].fbuffer_bus = - virt_to_bus(mem); - for (off = 0; off < fh->v4l_buffers.buffer_size; + fh->buffers.buffer[i].v4l.fbuffer = mem; + fh->buffers.buffer[i].v4l.fbuffer_phys = virt_to_phys(mem); + fh->buffers.buffer[i].v4l.fbuffer_bus = virt_to_bus(mem); + for (off = 0; off < fh->buffers.buffer_size; off += PAGE_SIZE) SetPageReserved(virt_to_page(mem + off)); dprintk(4, KERN_INFO - "%s: v4l_fbuffer_alloc() - V4L frame %d mem 0x%lx (bus: 0x%lx)\n", - ZR_DEVNAME(zr), i, (unsigned long) mem, + "%s: %s - V4L frame %d mem 0x%lx (bus: 0x%lx)\n", + ZR_DEVNAME(zr), __func__, i, (unsigned long) mem, virt_to_bus(mem)); } - fh->v4l_buffers.allocated = 1; + fh->buffers.allocated = 1; return 0; } /* free the V4L grab buffers */ -static void -v4l_fbuffer_free (struct file *file) +static void v4l_fbuffer_free(struct zoran_fh *fh) { - struct zoran_fh *fh = file->private_data; struct zoran *zr = fh->zr; int i, off; unsigned char *mem; - dprintk(4, KERN_INFO "%s: v4l_fbuffer_free()\n", ZR_DEVNAME(zr)); + dprintk(4, KERN_INFO "%s: %s\n", ZR_DEVNAME(zr), __func__); - for (i = 0; i < fh->v4l_buffers.num_buffers; i++) { - if (!fh->v4l_buffers.buffer[i].fbuffer) + for (i = 0; i < fh->buffers.num_buffers; i++) { + if (!fh->buffers.buffer[i].v4l.fbuffer) continue; - mem = fh->v4l_buffers.buffer[i].fbuffer; - for (off = 0; off < fh->v4l_buffers.buffer_size; + mem = fh->buffers.buffer[i].v4l.fbuffer; + for (off = 0; off < fh->buffers.buffer_size; off += PAGE_SIZE) ClearPageReserved(virt_to_page(mem + off)); - kfree((void *) fh->v4l_buffers.buffer[i].fbuffer); - fh->v4l_buffers.buffer[i].fbuffer = NULL; + kfree(fh->buffers.buffer[i].v4l.fbuffer); + fh->buffers.buffer[i].v4l.fbuffer = NULL; } - fh->v4l_buffers.allocated = 0; + fh->buffers.allocated = 0; } /* @@ -299,140 +308,128 @@ v4l_fbuffer_free (struct file *file) * and fragment buffers are not little-endian. */ -static int -jpg_fbuffer_alloc (struct file *file) +static int jpg_fbuffer_alloc(struct zoran_fh *fh) { - struct zoran_fh *fh = file->private_data; struct zoran *zr = fh->zr; int i, j, off; - unsigned long mem; + u8 *mem; - for (i = 0; i < fh->jpg_buffers.num_buffers; i++) { - if (fh->jpg_buffers.buffer[i].frag_tab) + for (i = 0; i < fh->buffers.num_buffers; i++) { + if (fh->buffers.buffer[i].jpg.frag_tab) dprintk(2, KERN_WARNING - "%s: jpg_fbuffer_alloc() - buffer %d already allocated!?\n", - ZR_DEVNAME(zr), i); + "%s: %s - buffer %d already allocated!?\n", + ZR_DEVNAME(zr), __func__, i); /* Allocate fragment table for this buffer */ - mem = get_zeroed_page(GFP_KERNEL); + mem = (void *)get_zeroed_page(GFP_KERNEL); if (mem == 0) { dprintk(1, KERN_ERR - "%s: jpg_fbuffer_alloc() - get_zeroed_page (frag_tab) failed for buffer %d\n", - ZR_DEVNAME(zr), i); - jpg_fbuffer_free(file); + "%s: %s - get_zeroed_page (frag_tab) failed for buffer %d\n", + ZR_DEVNAME(zr), __func__, i); + jpg_fbuffer_free(fh); return -ENOBUFS; } - fh->jpg_buffers.buffer[i].frag_tab = (__le32 *) mem; - fh->jpg_buffers.buffer[i].frag_tab_bus = - virt_to_bus((void *) mem); - - //if (alloc_contig) { - if (fh->jpg_buffers.need_contiguous) { - mem = - (unsigned long) kmalloc(fh->jpg_buffers. - buffer_size, - GFP_KERNEL); - if (mem == 0) { + fh->buffers.buffer[i].jpg.frag_tab = (__le32 *)mem; + fh->buffers.buffer[i].jpg.frag_tab_bus = virt_to_bus(mem); + + if (fh->buffers.need_contiguous) { + mem = kmalloc(fh->buffers.buffer_size, GFP_KERNEL); + if (mem == NULL) { dprintk(1, KERN_ERR - "%s: jpg_fbuffer_alloc() - kmalloc failed for buffer %d\n", - ZR_DEVNAME(zr), i); - jpg_fbuffer_free(file); + "%s: %s - kmalloc failed for buffer %d\n", + ZR_DEVNAME(zr), __func__, i); + jpg_fbuffer_free(fh); return -ENOBUFS; } - fh->jpg_buffers.buffer[i].frag_tab[0] = - cpu_to_le32(virt_to_bus((void *) mem)); - fh->jpg_buffers.buffer[i].frag_tab[1] = - cpu_to_le32(((fh->jpg_buffers.buffer_size / 4) << 1) | 1); - for (off = 0; off < fh->jpg_buffers.buffer_size; - off += PAGE_SIZE) + fh->buffers.buffer[i].jpg.frag_tab[0] = + cpu_to_le32(virt_to_bus(mem)); + fh->buffers.buffer[i].jpg.frag_tab[1] = + cpu_to_le32((fh->buffers.buffer_size >> 1) | 1); + for (off = 0; off < fh->buffers.buffer_size; off += PAGE_SIZE) SetPageReserved(virt_to_page(mem + off)); } else { /* jpg_bufsize is already page aligned */ - for (j = 0; - j < fh->jpg_buffers.buffer_size / PAGE_SIZE; - j++) { - mem = get_zeroed_page(GFP_KERNEL); - if (mem == 0) { + for (j = 0; j < fh->buffers.buffer_size / PAGE_SIZE; j++) { + mem = (void *)get_zeroed_page(GFP_KERNEL); + if (mem == NULL) { dprintk(1, KERN_ERR - "%s: jpg_fbuffer_alloc() - get_zeroed_page failed for buffer %d\n", - ZR_DEVNAME(zr), i); - jpg_fbuffer_free(file); + "%s: %s - get_zeroed_page failed for buffer %d\n", + ZR_DEVNAME(zr), __func__, i); + jpg_fbuffer_free(fh); return -ENOBUFS; } - fh->jpg_buffers.buffer[i].frag_tab[2 * j] = - cpu_to_le32(virt_to_bus((void *) mem)); - fh->jpg_buffers.buffer[i].frag_tab[2 * j + - 1] = - cpu_to_le32((PAGE_SIZE / 4) << 1); + fh->buffers.buffer[i].jpg.frag_tab[2 * j] = + cpu_to_le32(virt_to_bus(mem)); + fh->buffers.buffer[i].jpg.frag_tab[2 * j + 1] = + cpu_to_le32((PAGE_SIZE >> 2) << 1); SetPageReserved(virt_to_page(mem)); } - fh->jpg_buffers.buffer[i].frag_tab[2 * j - 1] |= cpu_to_le32(1); + fh->buffers.buffer[i].jpg.frag_tab[2 * j - 1] |= cpu_to_le32(1); } } dprintk(4, - KERN_DEBUG "%s: jpg_fbuffer_alloc() - %d KB allocated\n", - ZR_DEVNAME(zr), - (fh->jpg_buffers.num_buffers * - fh->jpg_buffers.buffer_size) >> 10); + KERN_DEBUG "%s: %s - %d KB allocated\n", + ZR_DEVNAME(zr), __func__, + (fh->buffers.num_buffers * fh->buffers.buffer_size) >> 10); - fh->jpg_buffers.allocated = 1; + fh->buffers.allocated = 1; return 0; } /* free the MJPEG grab buffers */ -static void -jpg_fbuffer_free (struct file *file) +static void jpg_fbuffer_free(struct zoran_fh *fh) { - struct zoran_fh *fh = file->private_data; struct zoran *zr = fh->zr; int i, j, off; unsigned char *mem; __le32 frag_tab; + struct zoran_buffer *buffer; - dprintk(4, KERN_DEBUG "%s: jpg_fbuffer_free()\n", ZR_DEVNAME(zr)); + dprintk(4, KERN_DEBUG "%s: %s\n", ZR_DEVNAME(zr), __func__); - for (i = 0; i < fh->jpg_buffers.num_buffers; i++) { - if (!fh->jpg_buffers.buffer[i].frag_tab) + for (i = 0, buffer = &fh->buffers.buffer[0]; + i < fh->buffers.num_buffers; i++, buffer++) { + if (!buffer->jpg.frag_tab) continue; - if (fh->jpg_buffers.need_contiguous) { - frag_tab = fh->jpg_buffers.buffer[i].frag_tab[0]; + if (fh->buffers.need_contiguous) { + frag_tab = buffer->jpg.frag_tab[0]; if (frag_tab) { - mem = (unsigned char *)bus_to_virt(le32_to_cpu(frag_tab)); - for (off = 0; off < fh->jpg_buffers.buffer_size; off += PAGE_SIZE) + mem = bus_to_virt(le32_to_cpu(frag_tab)); + for (off = 0; off < fh->buffers.buffer_size; off += PAGE_SIZE) ClearPageReserved(virt_to_page(mem + off)); kfree(mem); - fh->jpg_buffers.buffer[i].frag_tab[0] = 0; - fh->jpg_buffers.buffer[i].frag_tab[1] = 0; + buffer->jpg.frag_tab[0] = 0; + buffer->jpg.frag_tab[1] = 0; } } else { - for (j = 0; j < fh->jpg_buffers.buffer_size / PAGE_SIZE; j++) { - frag_tab = fh->jpg_buffers.buffer[i].frag_tab[2 * j]; + for (j = 0; j < fh->buffers.buffer_size / PAGE_SIZE; j++) { + frag_tab = buffer->jpg.frag_tab[2 * j]; if (!frag_tab) break; ClearPageReserved(virt_to_page(bus_to_virt(le32_to_cpu(frag_tab)))); free_page((unsigned long)bus_to_virt(le32_to_cpu(frag_tab))); - fh->jpg_buffers.buffer[i].frag_tab[2 * j] = 0; - fh->jpg_buffers.buffer[i].frag_tab[2 * j + 1] = 0; + buffer->jpg.frag_tab[2 * j] = 0; + buffer->jpg.frag_tab[2 * j + 1] = 0; } } - free_page((unsigned long)fh->jpg_buffers.buffer[i].frag_tab); - fh->jpg_buffers.buffer[i].frag_tab = NULL; + free_page((unsigned long)buffer->jpg.frag_tab); + buffer->jpg.frag_tab = NULL; } - fh->jpg_buffers.allocated = 0; + fh->buffers.allocated = 0; } /* @@ -440,12 +437,11 @@ jpg_fbuffer_free (struct file *file) */ static int -zoran_v4l_set_format (struct file *file, +zoran_v4l_set_format (struct zoran_fh *fh, int width, int height, const struct zoran_format *format) { - struct zoran_fh *fh = file->private_data; struct zoran *zr = fh->zr; int bpp; @@ -455,19 +451,19 @@ zoran_v4l_set_format (struct file *file, height > BUZ_MAX_HEIGHT || width > BUZ_MAX_WIDTH) { dprintk(1, KERN_ERR - "%s: v4l_set_format() - wrong frame size (%dx%d)\n", - ZR_DEVNAME(zr), width, height); + "%s: %s - wrong frame size (%dx%d)\n", + ZR_DEVNAME(zr), __func__, width, height); return -EINVAL; } bpp = (format->depth + 7) / 8; /* Check against available buffer size */ - if (height * width * bpp > fh->v4l_buffers.buffer_size) { + if (height * width * bpp > fh->buffers.buffer_size) { dprintk(1, KERN_ERR - "%s: v4l_set_format() - video buffer size (%d kB) is too small\n", - ZR_DEVNAME(zr), fh->v4l_buffers.buffer_size >> 10); + "%s: %s - video buffer size (%d kB) is too small\n", + ZR_DEVNAME(zr), __func__, fh->buffers.buffer_size >> 10); return -EINVAL; } @@ -476,8 +472,8 @@ zoran_v4l_set_format (struct file *file, if ((bpp == 2 && (width & 1)) || (bpp == 3 && (width & 3))) { dprintk(1, KERN_ERR - "%s: v4l_set_format() - wrong frame alignment\n", - ZR_DEVNAME(zr)); + "%s: %s - wrong frame alignment\n", + ZR_DEVNAME(zr), __func__); return -EINVAL; } @@ -489,43 +485,40 @@ zoran_v4l_set_format (struct file *file, return 0; } -static int -zoran_v4l_queue_frame (struct file *file, - int num) +static int zoran_v4l_queue_frame(struct zoran_fh *fh, int num) { - struct zoran_fh *fh = file->private_data; struct zoran *zr = fh->zr; unsigned long flags; int res = 0; - if (!fh->v4l_buffers.allocated) { + if (!fh->buffers.allocated) { dprintk(1, KERN_ERR - "%s: v4l_queue_frame() - buffers not yet allocated\n", - ZR_DEVNAME(zr)); + "%s: %s - buffers not yet allocated\n", + ZR_DEVNAME(zr), __func__); res = -ENOMEM; } /* No grabbing outside the buffer range! */ - if (num >= fh->v4l_buffers.num_buffers || num < 0) { + if (num >= fh->buffers.num_buffers || num < 0) { dprintk(1, KERN_ERR - "%s: v4l_queue_frame() - buffer %d is out of range\n", - ZR_DEVNAME(zr), num); + "%s: %s - buffer %d is out of range\n", + ZR_DEVNAME(zr), __func__, num); res = -EINVAL; } spin_lock_irqsave(&zr->spinlock, flags); - if (fh->v4l_buffers.active == ZORAN_FREE) { + if (fh->buffers.active == ZORAN_FREE) { if (zr->v4l_buffers.active == ZORAN_FREE) { - zr->v4l_buffers = fh->v4l_buffers; - fh->v4l_buffers.active = ZORAN_ACTIVE; + zr->v4l_buffers = fh->buffers; + fh->buffers.active = ZORAN_ACTIVE; } else { dprintk(1, KERN_ERR - "%s: v4l_queue_frame() - another session is already capturing\n", - ZR_DEVNAME(zr)); + "%s: %s - another session is already capturing\n", + ZR_DEVNAME(zr), __func__); res = -EBUSY; } } @@ -536,7 +529,7 @@ zoran_v4l_queue_frame (struct file *file, default: case BUZ_STATE_PEND: if (zr->v4l_buffers.active == ZORAN_FREE) { - fh->v4l_buffers.active = ZORAN_FREE; + fh->buffers.active = ZORAN_FREE; zr->v4l_buffers.allocated = 0; } res = -EBUSY; /* what are you doing? */ @@ -544,19 +537,17 @@ zoran_v4l_queue_frame (struct file *file, case BUZ_STATE_DONE: dprintk(2, KERN_WARNING - "%s: v4l_queue_frame() - queueing buffer %d in state DONE!?\n", - ZR_DEVNAME(zr), num); + "%s: %s - queueing buffer %d in state DONE!?\n", + ZR_DEVNAME(zr), __func__, num); case BUZ_STATE_USER: /* since there is at least one unused buffer there's room for at least * one more pend[] entry */ - zr->v4l_pend[zr->v4l_pend_head++ & - V4L_MASK_FRAME] = num; + zr->v4l_pend[zr->v4l_pend_head++ & V4L_MASK_FRAME] = num; zr->v4l_buffers.buffer[num].state = BUZ_STATE_PEND; zr->v4l_buffers.buffer[num].bs.length = fh->v4l_settings.bytesperline * zr->v4l_settings.height; - fh->v4l_buffers.buffer[num] = - zr->v4l_buffers.buffer[num]; + fh->buffers.buffer[num] = zr->v4l_buffers.buffer[num]; break; } } @@ -564,7 +555,7 @@ zoran_v4l_queue_frame (struct file *file, spin_unlock_irqrestore(&zr->spinlock, flags); if (!res && zr->v4l_buffers.active == ZORAN_FREE) - zr->v4l_buffers.active = fh->v4l_buffers.active; + zr->v4l_buffers.active = fh->buffers.active; return res; } @@ -573,27 +564,24 @@ zoran_v4l_queue_frame (struct file *file, * Sync on a V4L buffer */ -static int -v4l_sync (struct file *file, - int frame) +static int v4l_sync(struct zoran_fh *fh, int frame) { - struct zoran_fh *fh = file->private_data; struct zoran *zr = fh->zr; unsigned long flags; - if (fh->v4l_buffers.active == ZORAN_FREE) { + if (fh->buffers.active == ZORAN_FREE) { dprintk(1, KERN_ERR - "%s: v4l_sync() - no grab active for this session\n", - ZR_DEVNAME(zr)); + "%s: %s - no grab active for this session\n", + ZR_DEVNAME(zr), __func__); return -EINVAL; } /* check passed-in frame number */ - if (frame >= fh->v4l_buffers.num_buffers || frame < 0) { + if (frame >= fh->buffers.num_buffers || frame < 0) { dprintk(1, - KERN_ERR "%s: v4l_sync() - frame %d is invalid\n", - ZR_DEVNAME(zr), frame); + KERN_ERR "%s: %s - frame %d is invalid\n", + ZR_DEVNAME(zr), __func__, frame); return -EINVAL; } @@ -601,15 +589,14 @@ v4l_sync (struct file *file, if (zr->v4l_buffers.buffer[frame].state == BUZ_STATE_USER) { dprintk(1, KERN_ERR - "%s: v4l_sync() - attempt to sync on a buffer which was not queued?\n", - ZR_DEVNAME(zr)); + "%s: %s - attempt to sync on a buffer which was not queued?\n", + ZR_DEVNAME(zr), __func__); return -EPROTO; } /* wait on this buffer to get ready */ if (!wait_event_interruptible_timeout(zr->v4l_capq, - (zr->v4l_buffers.buffer[frame].state != BUZ_STATE_PEND), - 10*HZ)) + (zr->v4l_buffers.buffer[frame].state != BUZ_STATE_PEND), 10*HZ)) return -ETIME; if (signal_pending(current)) return -ERESTARTSYS; @@ -617,11 +604,11 @@ v4l_sync (struct file *file, /* buffer should now be in BUZ_STATE_DONE */ if (zr->v4l_buffers.buffer[frame].state != BUZ_STATE_DONE) dprintk(2, - KERN_ERR "%s: v4l_sync() - internal state error\n", - ZR_DEVNAME(zr)); + KERN_ERR "%s: %s - internal state error\n", + ZR_DEVNAME(zr), __func__); zr->v4l_buffers.buffer[frame].state = BUZ_STATE_USER; - fh->v4l_buffers.buffer[frame] = zr->v4l_buffers.buffer[frame]; + fh->buffers.buffer[frame] = zr->v4l_buffers.buffer[frame]; spin_lock_irqsave(&zr->spinlock, flags); @@ -629,8 +616,7 @@ v4l_sync (struct file *file, if (zr->v4l_pend_tail == zr->v4l_pend_head) { zr36057_set_memgrab(zr, 0); if (zr->v4l_buffers.active == ZORAN_ACTIVE) { - fh->v4l_buffers.active = zr->v4l_buffers.active = - ZORAN_FREE; + fh->buffers.active = zr->v4l_buffers.active = ZORAN_FREE; zr->v4l_buffers.allocated = 0; } } @@ -644,31 +630,28 @@ v4l_sync (struct file *file, * Queue a MJPEG buffer for capture/playback */ -static int -zoran_jpg_queue_frame (struct file *file, - int num, - enum zoran_codec_mode mode) +static int zoran_jpg_queue_frame(struct zoran_fh *fh, int num, + enum zoran_codec_mode mode) { - struct zoran_fh *fh = file->private_data; struct zoran *zr = fh->zr; unsigned long flags; int res = 0; /* Check if buffers are allocated */ - if (!fh->jpg_buffers.allocated) { + if (!fh->buffers.allocated) { dprintk(1, KERN_ERR - "%s: jpg_queue_frame() - buffers not yet allocated\n", - ZR_DEVNAME(zr)); + "%s: %s - buffers not yet allocated\n", + ZR_DEVNAME(zr), __func__); return -ENOMEM; } /* No grabbing outside the buffer range! */ - if (num >= fh->jpg_buffers.num_buffers || num < 0) { + if (num >= fh->buffers.num_buffers || num < 0) { dprintk(1, KERN_ERR - "%s: jpg_queue_frame() - buffer %d out of range\n", - ZR_DEVNAME(zr), num); + "%s: %s - buffer %d out of range\n", + ZR_DEVNAME(zr), __func__, num); return -EINVAL; } @@ -679,20 +662,20 @@ zoran_jpg_queue_frame (struct file *file, /* wrong codec mode active - invalid */ dprintk(1, KERN_ERR - "%s: jpg_queue_frame() - codec in wrong mode\n", - ZR_DEVNAME(zr)); + "%s: %s - codec in wrong mode\n", + ZR_DEVNAME(zr), __func__); return -EINVAL; } - if (fh->jpg_buffers.active == ZORAN_FREE) { + if (fh->buffers.active == ZORAN_FREE) { if (zr->jpg_buffers.active == ZORAN_FREE) { - zr->jpg_buffers = fh->jpg_buffers; - fh->jpg_buffers.active = ZORAN_ACTIVE; + zr->jpg_buffers = fh->buffers; + fh->buffers.active = ZORAN_ACTIVE; } else { dprintk(1, KERN_ERR - "%s: jpg_queue_frame() - another session is already capturing\n", - ZR_DEVNAME(zr)); + "%s: %s - another session is already capturing\n", + ZR_DEVNAME(zr), __func__); res = -EBUSY; } } @@ -709,23 +692,21 @@ zoran_jpg_queue_frame (struct file *file, case BUZ_STATE_DONE: dprintk(2, KERN_WARNING - "%s: jpg_queue_frame() - queing frame in BUZ_STATE_DONE state!?\n", - ZR_DEVNAME(zr)); + "%s: %s - queing frame in BUZ_STATE_DONE state!?\n", + ZR_DEVNAME(zr), __func__); case BUZ_STATE_USER: /* since there is at least one unused buffer there's room for at *least one more pend[] entry */ - zr->jpg_pend[zr->jpg_que_head++ & BUZ_MASK_FRAME] = - num; + zr->jpg_pend[zr->jpg_que_head++ & BUZ_MASK_FRAME] = num; zr->jpg_buffers.buffer[num].state = BUZ_STATE_PEND; - fh->jpg_buffers.buffer[num] = - zr->jpg_buffers.buffer[num]; + fh->buffers.buffer[num] = zr->jpg_buffers.buffer[num]; zoran_feed_stat_com(zr); break; default: case BUZ_STATE_DMA: case BUZ_STATE_PEND: if (zr->jpg_buffers.active == ZORAN_FREE) { - fh->jpg_buffers.active = ZORAN_FREE; + fh->buffers.active = ZORAN_FREE; zr->jpg_buffers.allocated = 0; } res = -EBUSY; /* what are you doing? */ @@ -735,47 +716,41 @@ zoran_jpg_queue_frame (struct file *file, spin_unlock_irqrestore(&zr->spinlock, flags); - if (!res && zr->jpg_buffers.active == ZORAN_FREE) { - zr->jpg_buffers.active = fh->jpg_buffers.active; - } + if (!res && zr->jpg_buffers.active == ZORAN_FREE) + zr->jpg_buffers.active = fh->buffers.active; return res; } -static int -jpg_qbuf (struct file *file, - int frame, - enum zoran_codec_mode mode) +static int jpg_qbuf(struct zoran_fh *fh, int frame, enum zoran_codec_mode mode) { - struct zoran_fh *fh = file->private_data; struct zoran *zr = fh->zr; int res = 0; /* Does the user want to stop streaming? */ if (frame < 0) { if (zr->codec_mode == mode) { - if (fh->jpg_buffers.active == ZORAN_FREE) { + if (fh->buffers.active == ZORAN_FREE) { dprintk(1, KERN_ERR - "%s: jpg_qbuf(-1) - session not active\n", - ZR_DEVNAME(zr)); + "%s: %s(-1) - session not active\n", + ZR_DEVNAME(zr), __func__); return -EINVAL; } - fh->jpg_buffers.active = zr->jpg_buffers.active = - ZORAN_FREE; + fh->buffers.active = zr->jpg_buffers.active = ZORAN_FREE; zr->jpg_buffers.allocated = 0; zr36057_enable_jpg(zr, BUZ_MODE_IDLE); return 0; } else { dprintk(1, KERN_ERR - "%s: jpg_qbuf() - stop streaming but not in streaming mode\n", - ZR_DEVNAME(zr)); + "%s: %s - stop streaming but not in streaming mode\n", + ZR_DEVNAME(zr), __func__); return -EINVAL; } } - if ((res = zoran_jpg_queue_frame(file, frame, mode))) + if ((res = zoran_jpg_queue_frame(fh, frame, mode))) return res; /* Start the jpeg codec when the first frame is queued */ @@ -789,28 +764,25 @@ jpg_qbuf (struct file *file, * Sync on a MJPEG buffer */ -static int -jpg_sync (struct file *file, - struct zoran_sync *bs) +static int jpg_sync(struct zoran_fh *fh, struct zoran_sync *bs) { - struct zoran_fh *fh = file->private_data; struct zoran *zr = fh->zr; unsigned long flags; int frame; - if (fh->jpg_buffers.active == ZORAN_FREE) { + if (fh->buffers.active == ZORAN_FREE) { dprintk(1, KERN_ERR - "%s: jpg_sync() - capture is not currently active\n", - ZR_DEVNAME(zr)); + "%s: %s - capture is not currently active\n", + ZR_DEVNAME(zr), __func__); return -EINVAL; } if (zr->codec_mode != BUZ_MODE_MOTION_DECOMPRESS && zr->codec_mode != BUZ_MODE_MOTION_COMPRESS) { dprintk(1, KERN_ERR - "%s: jpg_sync() - codec not in streaming mode\n", - ZR_DEVNAME(zr)); + "%s: %s - codec not in streaming mode\n", + ZR_DEVNAME(zr), __func__); return -EINVAL; } if (!wait_event_interruptible_timeout(zr->jpg_capq, @@ -825,8 +797,8 @@ jpg_sync (struct file *file, sizeof(isr), &isr); dprintk(1, KERN_ERR - "%s: jpg_sync() - timeout: codec isr=0x%02x\n", - ZR_DEVNAME(zr), isr); + "%s: %s - timeout: codec isr=0x%02x\n", + ZR_DEVNAME(zr), __func__, isr); return -ETIME; @@ -844,28 +816,26 @@ jpg_sync (struct file *file, /* buffer should now be in BUZ_STATE_DONE */ if (zr->jpg_buffers.buffer[frame].state != BUZ_STATE_DONE) dprintk(2, - KERN_ERR "%s: jpg_sync() - internal state error\n", - ZR_DEVNAME(zr)); + KERN_ERR "%s: %s - internal state error\n", + ZR_DEVNAME(zr), __func__); *bs = zr->jpg_buffers.buffer[frame].bs; bs->frame = frame; zr->jpg_buffers.buffer[frame].state = BUZ_STATE_USER; - fh->jpg_buffers.buffer[frame] = zr->jpg_buffers.buffer[frame]; + fh->buffers.buffer[frame] = zr->jpg_buffers.buffer[frame]; spin_unlock_irqrestore(&zr->spinlock, flags); return 0; } -static void -zoran_open_init_session (struct file *file) +static void zoran_open_init_session(struct zoran_fh *fh) { int i; - struct zoran_fh *fh = file->private_data; struct zoran *zr = fh->zr; /* Per default, map the V4L Buffers */ - fh->map_mode = ZORAN_MAP_MODE_RAW; + map_mode_raw(fh); /* take over the card's current settings */ fh->overlay_settings = zr->overlay_settings; @@ -875,38 +845,21 @@ zoran_open_init_session (struct file *file) /* v4l settings */ fh->v4l_settings = zr->v4l_settings; - - /* v4l_buffers */ - memset(&fh->v4l_buffers, 0, sizeof(struct zoran_v4l_struct)); - for (i = 0; i < VIDEO_MAX_FRAME; i++) { - fh->v4l_buffers.buffer[i].state = BUZ_STATE_USER; /* nothing going on */ - fh->v4l_buffers.buffer[i].bs.frame = i; - } - fh->v4l_buffers.allocated = 0; - fh->v4l_buffers.active = ZORAN_FREE; - fh->v4l_buffers.buffer_size = v4l_bufsize; - fh->v4l_buffers.num_buffers = v4l_nbufs; - /* jpg settings */ fh->jpg_settings = zr->jpg_settings; - /* jpg_buffers */ - memset(&fh->jpg_buffers, 0, sizeof(struct zoran_jpg_struct)); - for (i = 0; i < BUZ_MAX_FRAME; i++) { - fh->jpg_buffers.buffer[i].state = BUZ_STATE_USER; /* nothing going on */ - fh->jpg_buffers.buffer[i].bs.frame = i; + /* buffers */ + memset(&fh->buffers, 0, sizeof(fh->buffers)); + for (i = 0; i < MAX_FRAME; i++) { + fh->buffers.buffer[i].state = BUZ_STATE_USER; /* nothing going on */ + fh->buffers.buffer[i].bs.frame = i; } - fh->jpg_buffers.need_contiguous = zr->jpg_buffers.need_contiguous; - fh->jpg_buffers.allocated = 0; - fh->jpg_buffers.active = ZORAN_FREE; - fh->jpg_buffers.buffer_size = jpg_bufsize; - fh->jpg_buffers.num_buffers = jpg_nbufs; + fh->buffers.allocated = 0; + fh->buffers.active = ZORAN_FREE; } -static void -zoran_close_end_session (struct file *file) +static void zoran_close_end_session(struct zoran_fh *fh) { - struct zoran_fh *fh = file->private_data; struct zoran *zr = fh->zr; /* overlay */ @@ -918,33 +871,33 @@ zoran_close_end_session (struct file *file) zr->overlay_mask = NULL; } - /* v4l capture */ - if (fh->v4l_buffers.active != ZORAN_FREE) { - unsigned long flags; + if (fh->map_mode == ZORAN_MAP_MODE_RAW) { + /* v4l capture */ + if (fh->buffers.active != ZORAN_FREE) { + unsigned long flags; - spin_lock_irqsave(&zr->spinlock, flags); - zr36057_set_memgrab(zr, 0); - zr->v4l_buffers.allocated = 0; - zr->v4l_buffers.active = fh->v4l_buffers.active = - ZORAN_FREE; - spin_unlock_irqrestore(&zr->spinlock, flags); - } + spin_lock_irqsave(&zr->spinlock, flags); + zr36057_set_memgrab(zr, 0); + zr->v4l_buffers.allocated = 0; + zr->v4l_buffers.active = fh->buffers.active = ZORAN_FREE; + spin_unlock_irqrestore(&zr->spinlock, flags); + } - /* v4l buffers */ - if (fh->v4l_buffers.allocated) - v4l_fbuffer_free(file); + /* v4l buffers */ + if (fh->buffers.allocated) + v4l_fbuffer_free(fh); + } else { + /* jpg capture */ + if (fh->buffers.active != ZORAN_FREE) { + zr36057_enable_jpg(zr, BUZ_MODE_IDLE); + zr->jpg_buffers.allocated = 0; + zr->jpg_buffers.active = fh->buffers.active = ZORAN_FREE; + } - /* jpg capture */ - if (fh->jpg_buffers.active != ZORAN_FREE) { - zr36057_enable_jpg(zr, BUZ_MODE_IDLE); - zr->jpg_buffers.allocated = 0; - zr->jpg_buffers.active = fh->jpg_buffers.active = - ZORAN_FREE; + /* jpg buffers */ + if (fh->buffers.allocated) + jpg_fbuffer_free(fh); } - - /* jpg buffers */ - if (fh->jpg_buffers.allocated) - jpg_fbuffer_free(file); } /* @@ -957,8 +910,8 @@ static int zoran_open(struct file *file) struct zoran_fh *fh; int res, first_open = 0; - dprintk(2, KERN_INFO "%s: zoran_open(%s, pid=[%d]), users(-)=%d\n", - ZR_DEVNAME(zr), current->comm, task_pid_nr(current), zr->user + 1); + dprintk(2, KERN_INFO "%s: %s(%s, pid=[%d]), users(-)=%d\n", + ZR_DEVNAME(zr), __func__, current->comm, task_pid_nr(current), zr->user + 1); lock_kernel(); @@ -974,8 +927,8 @@ static int zoran_open(struct file *file) if (!fh) { dprintk(1, KERN_ERR - "%s: zoran_open() - allocation of zoran_fh failed\n", - ZR_DEVNAME(zr)); + "%s: %s - allocation of zoran_fh failed\n", + ZR_DEVNAME(zr), __func__); res = -ENOMEM; goto fail_unlock; } @@ -986,8 +939,8 @@ static int zoran_open(struct file *file) if (!fh->overlay_mask) { dprintk(1, KERN_ERR - "%s: zoran_open() - allocation of overlay_mask failed\n", - ZR_DEVNAME(zr)); + "%s: %s - allocation of overlay_mask failed\n", + ZR_DEVNAME(zr), __func__); res = -ENOMEM; goto fail_fh; } @@ -1009,7 +962,7 @@ static int zoran_open(struct file *file) /* set file_ops stuff */ file->private_data = fh; fh->zr = zr; - zoran_open_init_session(file); + zoran_open_init_session(fh); unlock_kernel(); return 0; @@ -1031,14 +984,14 @@ zoran_close(struct file *file) struct zoran_fh *fh = file->private_data; struct zoran *zr = fh->zr; - dprintk(2, KERN_INFO "%s: zoran_close(%s, pid=[%d]), users(+)=%d\n", - ZR_DEVNAME(zr), current->comm, task_pid_nr(current), zr->user - 1); + dprintk(2, KERN_INFO "%s: %s(%s, pid=[%d]), users(+)=%d\n", + ZR_DEVNAME(zr), __func__, current->comm, task_pid_nr(current), zr->user - 1); /* kernel locks (fs/device.c), so don't do that ourselves * (prevents deadlocks) */ /*mutex_lock(&zr->resource_lock);*/ - zoran_close_end_session(file); + zoran_close_end_session(fh); if (zr->user-- == 1) { /* Last process */ /* Clean up JPEG process */ @@ -1077,7 +1030,7 @@ zoran_close(struct file *file) kfree(fh->overlay_mask); kfree(fh); - dprintk(4, KERN_INFO "%s: zoran_close() done\n", ZR_DEVNAME(zr)); + dprintk(4, KERN_INFO "%s: %s done\n", ZR_DEVNAME(zr), __func__); return 0; } @@ -1105,15 +1058,13 @@ zoran_write (struct file *file, return -EINVAL; } -static int -setup_fbuffer (struct file *file, +static int setup_fbuffer(struct zoran_fh *fh, void *base, const struct zoran_format *fmt, int width, int height, int bytesperline) { - struct zoran_fh *fh = file->private_data; struct zoran *zr = fh->zr; /* (Ronald) v4l/v4l2 guidelines */ @@ -1141,8 +1092,8 @@ setup_fbuffer (struct file *file, * friendly and silently do as if nothing went wrong */ dprintk(3, KERN_ERR - "%s: setup_fbuffer() - forced overlay turnoff because framebuffer changed\n", - ZR_DEVNAME(zr)); + "%s: %s - forced overlay turnoff because framebuffer changed\n", + ZR_DEVNAME(zr), __func__); zr36057_overlay(zr, 0); } #endif @@ -1150,22 +1101,22 @@ setup_fbuffer (struct file *file, if (!(fmt->flags & ZORAN_FORMAT_OVERLAY)) { dprintk(1, KERN_ERR - "%s: setup_fbuffer() - no valid overlay format given\n", - ZR_DEVNAME(zr)); + "%s: %s - no valid overlay format given\n", + ZR_DEVNAME(zr), __func__); return -EINVAL; } if (height <= 0 || width <= 0 || bytesperline <= 0) { dprintk(1, KERN_ERR - "%s: setup_fbuffer() - invalid height/width/bpl value (%d|%d|%d)\n", - ZR_DEVNAME(zr), width, height, bytesperline); + "%s: %s - invalid height/width/bpl value (%d|%d|%d)\n", + ZR_DEVNAME(zr), __func__, width, height, bytesperline); return -EINVAL; } if (bytesperline & 3) { dprintk(1, KERN_ERR - "%s: setup_fbuffer() - bytesperline (%d) must be 4-byte aligned\n", - ZR_DEVNAME(zr), bytesperline); + "%s: %s - bytesperline (%d) must be 4-byte aligned\n", + ZR_DEVNAME(zr), __func__, bytesperline); return -EINVAL; } @@ -1183,17 +1134,9 @@ setup_fbuffer (struct file *file, } -static int -setup_window (struct file *file, - int x, - int y, - int width, - int height, - struct v4l2_clip __user *clips, - int clipcount, - void __user *bitmap) +static int setup_window(struct zoran_fh *fh, int x, int y, int width, int height, + struct v4l2_clip __user *clips, int clipcount, void __user *bitmap) { - struct zoran_fh *fh = file->private_data; struct zoran *zr = fh->zr; struct v4l2_clip *vcp = NULL; int on, end; @@ -1202,16 +1145,16 @@ setup_window (struct file *file, if (!zr->vbuf_base) { dprintk(1, KERN_ERR - "%s: setup_window() - frame buffer has to be set first\n", - ZR_DEVNAME(zr)); + "%s: %s - frame buffer has to be set first\n", + ZR_DEVNAME(zr), __func__); return -EINVAL; } if (!fh->overlay_settings.format) { dprintk(1, KERN_ERR - "%s: setup_window() - no overlay format set\n", - ZR_DEVNAME(zr)); + "%s: %s - no overlay format set\n", + ZR_DEVNAME(zr), __func__); return -EINVAL; } @@ -1241,8 +1184,8 @@ setup_window (struct file *file, width > BUZ_MAX_WIDTH || height > BUZ_MAX_HEIGHT) { dprintk(1, KERN_ERR - "%s: setup_window() - width = %d or height = %d invalid\n", - ZR_DEVNAME(zr), width, height); + "%s: %s - width = %d or height = %d invalid\n", + ZR_DEVNAME(zr), __func__, width, height); return -EINVAL; } @@ -1284,8 +1227,8 @@ setup_window (struct file *file, if (vcp == NULL) { dprintk(1, KERN_ERR - "%s: setup_window() - Alloc of clip mask failed\n", - ZR_DEVNAME(zr)); + "%s: %s - Alloc of clip mask failed\n", + ZR_DEVNAME(zr), __func__); return -ENOMEM; } if (copy_from_user @@ -1293,7 +1236,7 @@ setup_window (struct file *file, vfree(vcp); return -EFAULT; } - write_overlay_mask(file, vcp, clipcount); + write_overlay_mask(fh, vcp, clipcount); vfree(vcp); } @@ -1309,11 +1252,8 @@ setup_window (struct file *file, return wait_grab_pending(zr); } -static int -setup_overlay (struct file *file, - int on) +static int setup_overlay(struct zoran_fh *fh, int on) { - struct zoran_fh *fh = file->private_data; struct zoran *zr = fh->zr; /* If there is nothing to do, return immediatly */ @@ -1326,16 +1266,16 @@ setup_overlay (struct file *file, fh->overlay_active == ZORAN_FREE) { dprintk(1, KERN_ERR - "%s: setup_overlay() - overlay is already active for another session\n", - ZR_DEVNAME(zr)); + "%s: %s - overlay is already active for another session\n", + ZR_DEVNAME(zr), __func__); return -EBUSY; } if (!on && zr->overlay_active != ZORAN_FREE && fh->overlay_active == ZORAN_FREE) { dprintk(1, KERN_ERR - "%s: setup_overlay() - you cannot cancel someone else's session\n", - ZR_DEVNAME(zr)); + "%s: %s - you cannot cancel someone else's session\n", + ZR_DEVNAME(zr), __func__); return -EPERM; } @@ -1351,15 +1291,15 @@ setup_overlay (struct file *file, if (!zr->vbuf_base || !fh->overlay_settings.is_set) { dprintk(1, KERN_ERR - "%s: setup_overlay() - buffer or window not set\n", - ZR_DEVNAME(zr)); + "%s: %s - buffer or window not set\n", + ZR_DEVNAME(zr), __func__); return -EINVAL; } if (!fh->overlay_settings.format) { dprintk(1, KERN_ERR - "%s: setup_overlay() - no overlay format set\n", - ZR_DEVNAME(zr)); + "%s: %s - no overlay format set\n", + ZR_DEVNAME(zr), __func__); return -EINVAL; } zr->overlay_active = fh->overlay_active = ZORAN_LOCKED; @@ -1376,40 +1316,54 @@ setup_overlay (struct file *file, return wait_grab_pending(zr); } - /* get the status of a buffer in the clients buffer queue */ -static int -zoran_v4l2_buffer_status (struct zoran_fh *fh, - struct v4l2_buffer *buf, - int num) +/* get the status of a buffer in the clients buffer queue */ +static int zoran_v4l2_buffer_status(struct zoran_fh *fh, + struct v4l2_buffer *buf, int num) { struct zoran *zr = fh->zr; + unsigned long flags; buf->flags = V4L2_BUF_FLAG_MAPPED; switch (fh->map_mode) { case ZORAN_MAP_MODE_RAW: - /* check range */ - if (num < 0 || num >= fh->v4l_buffers.num_buffers || - !fh->v4l_buffers.allocated) { + if (num < 0 || num >= fh->buffers.num_buffers || + !fh->buffers.allocated) { dprintk(1, KERN_ERR - "%s: v4l2_buffer_status() - wrong number or buffers not allocated\n", - ZR_DEVNAME(zr)); + "%s: %s - wrong number or buffers not allocated\n", + ZR_DEVNAME(zr), __func__); return -EINVAL; } + spin_lock_irqsave(&zr->spinlock, flags); + dprintk(3, + KERN_DEBUG + "%s: %s() - raw active=%c, buffer %d: state=%c, map=%c\n", + ZR_DEVNAME(zr), __func__, + "FAL"[fh->buffers.active], num, + "UPMD"[zr->v4l_buffers.buffer[num].state], + fh->buffers.buffer[num].map ? 'Y' : 'N'); + spin_unlock_irqrestore(&zr->spinlock, flags); +#if 0 + /* Process is the one capturing? */ + if (fh->v4l_buffers.active != ZORAN_FREE && + /* Buffer ready to DQBUF? */ + zr->v4l_buffers.buffer[frame].state == BUZ_STATE_DONE) + res = POLLIN | POLLRDNORM; +#endif + buf->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - buf->length = fh->v4l_buffers.buffer_size; + buf->length = fh->buffers.buffer_size; /* get buffer */ - buf->bytesused = fh->v4l_buffers.buffer[num].bs.length; - if (fh->v4l_buffers.buffer[num].state == BUZ_STATE_DONE || - fh->v4l_buffers.buffer[num].state == BUZ_STATE_USER) { - buf->sequence = fh->v4l_buffers.buffer[num].bs.seq; + buf->bytesused = fh->buffers.buffer[num].bs.length; + if (fh->buffers.buffer[num].state == BUZ_STATE_DONE || + fh->buffers.buffer[num].state == BUZ_STATE_USER) { + buf->sequence = fh->buffers.buffer[num].bs.seq; buf->flags |= V4L2_BUF_FLAG_DONE; - buf->timestamp = - fh->v4l_buffers.buffer[num].bs.timestamp; + buf->timestamp = fh->buffers.buffer[num].bs.timestamp; } else { buf->flags |= V4L2_BUF_FLAG_QUEUED; } @@ -1425,28 +1379,26 @@ zoran_v4l2_buffer_status (struct zoran_fh *fh, case ZORAN_MAP_MODE_JPG_PLAY: /* check range */ - if (num < 0 || num >= fh->jpg_buffers.num_buffers || - !fh->jpg_buffers.allocated) { + if (num < 0 || num >= fh->buffers.num_buffers || + !fh->buffers.allocated) { dprintk(1, KERN_ERR - "%s: v4l2_buffer_status() - wrong number or buffers not allocated\n", - ZR_DEVNAME(zr)); + "%s: %s - wrong number or buffers not allocated\n", + ZR_DEVNAME(zr), __func__); return -EINVAL; } buf->type = (fh->map_mode == ZORAN_MAP_MODE_JPG_REC) ? V4L2_BUF_TYPE_VIDEO_CAPTURE : V4L2_BUF_TYPE_VIDEO_OUTPUT; - buf->length = fh->jpg_buffers.buffer_size; + buf->length = fh->buffers.buffer_size; /* these variables are only written after frame has been captured */ - if (fh->jpg_buffers.buffer[num].state == BUZ_STATE_DONE || - fh->jpg_buffers.buffer[num].state == BUZ_STATE_USER) { - buf->sequence = fh->jpg_buffers.buffer[num].bs.seq; - buf->timestamp = - fh->jpg_buffers.buffer[num].bs.timestamp; - buf->bytesused = - fh->jpg_buffers.buffer[num].bs.length; + if (fh->buffers.buffer[num].state == BUZ_STATE_DONE || + fh->buffers.buffer[num].state == BUZ_STATE_USER) { + buf->sequence = fh->buffers.buffer[num].bs.seq; + buf->timestamp = fh->buffers.buffer[num].bs.timestamp; + buf->bytesused = fh->buffers.buffer[num].bs.length; buf->flags |= V4L2_BUF_FLAG_DONE; } else { buf->flags |= V4L2_BUF_FLAG_QUEUED; @@ -1454,14 +1406,11 @@ zoran_v4l2_buffer_status (struct zoran_fh *fh, /* which fields are these? */ if (fh->jpg_settings.TmpDcm != 1) - buf->field = - fh->jpg_settings. - odd_even ? V4L2_FIELD_TOP : V4L2_FIELD_BOTTOM; + buf->field = fh->jpg_settings.odd_even ? + V4L2_FIELD_TOP : V4L2_FIELD_BOTTOM; else - buf->field = - fh->jpg_settings. - odd_even ? V4L2_FIELD_SEQ_TB : - V4L2_FIELD_SEQ_BT; + buf->field = fh->jpg_settings.odd_even ? + V4L2_FIELD_SEQ_TB : V4L2_FIELD_SEQ_BT; break; @@ -1469,8 +1418,8 @@ zoran_v4l2_buffer_status (struct zoran_fh *fh, dprintk(5, KERN_ERR - "%s: v4l2_buffer_status() - invalid buffer type|map_mode (%d|%d)\n", - ZR_DEVNAME(zr), buf->type, fh->map_mode); + "%s: %s - invalid buffer type|map_mode (%d|%d)\n", + ZR_DEVNAME(zr), __func__, buf->type, fh->map_mode); return -EINVAL; } @@ -1491,31 +1440,15 @@ zoran_set_norm (struct zoran *zr, zr->jpg_buffers.active != ZORAN_FREE) { dprintk(1, KERN_WARNING - "%s: set_norm() called while in playback/capture mode\n", - ZR_DEVNAME(zr)); + "%s: %s called while in playback/capture mode\n", + ZR_DEVNAME(zr), __func__); return -EBUSY; } - if (lock_norm && norm != zr->norm) { - if (lock_norm > 1) { - dprintk(1, - KERN_WARNING - "%s: set_norm() - TV standard is locked, can not switch norm\n", - ZR_DEVNAME(zr)); - return -EPERM; - } else { - dprintk(1, - KERN_WARNING - "%s: set_norm() - TV standard is locked, norm was not changed\n", - ZR_DEVNAME(zr)); - norm = zr->norm; - } - } - if (!(norm & zr->card.norms)) { dprintk(1, - KERN_ERR "%s: set_norm() - unsupported norm %llx\n", - ZR_DEVNAME(zr), norm); + KERN_ERR "%s: %s - unsupported norm %llx\n", + ZR_DEVNAME(zr), __func__, norm); return -EINVAL; } @@ -1524,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); @@ -1533,10 +1466,10 @@ zoran_set_norm (struct zoran *zr, if (status & V4L2_IN_ST_NO_SIGNAL) { dprintk(1, KERN_ERR - "%s: set_norm() - no norm detected\n", - ZR_DEVNAME(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; } @@ -1555,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) @@ -1581,23 +1514,23 @@ zoran_set_input (struct zoran *zr, zr->jpg_buffers.active != ZORAN_FREE) { dprintk(1, KERN_WARNING - "%s: set_input() called while in playback/capture mode\n", - ZR_DEVNAME(zr)); + "%s: %s called while in playback/capture mode\n", + ZR_DEVNAME(zr), __func__); return -EBUSY; } if (input < 0 || input >= zr->card.inputs) { dprintk(1, KERN_ERR - "%s: set_input() - unnsupported input %d\n", - ZR_DEVNAME(zr), input); + "%s: %s - unnsupported input %d\n", + ZR_DEVNAME(zr), __func__, input); return -EINVAL; } route.input = zr->card.input[input].muxsel; zr->input = input; - decoder_s_routing(zr, &route); + decoder_call(zr, video, s_routing, &route); return 0; } @@ -1744,7 +1677,7 @@ sparams_unlock_and_return: mutex_lock(&zr->resource_lock); - if (fh->jpg_buffers.allocated || fh->v4l_buffers.allocated) { + if (fh->buffers.allocated) { dprintk(1, KERN_ERR "%s: BUZIOC_REQBUFS - buffers already allocated\n", @@ -1753,17 +1686,17 @@ sparams_unlock_and_return: goto jpgreqbuf_unlock_and_return; } - fh->jpg_buffers.num_buffers = breq->count; - fh->jpg_buffers.buffer_size = breq->size; + /* The next mmap will map the MJPEG buffers - could + * also be *_PLAY, but it doesn't matter here */ + map_mode_jpg(fh, 0); + fh->buffers.num_buffers = breq->count; + fh->buffers.buffer_size = breq->size; - if (jpg_fbuffer_alloc(file)) { + if (jpg_fbuffer_alloc(fh)) { res = -ENOMEM; goto jpgreqbuf_unlock_and_return; } - /* The next mmap will map the MJPEG buffers - could - * also be *_PLAY, but it doesn't matter here */ - fh->map_mode = ZORAN_MAP_MODE_JPG_REC; jpgreqbuf_unlock_and_return: mutex_unlock(&zr->resource_lock); @@ -1778,7 +1711,7 @@ jpgreqbuf_unlock_and_return: ZR_DEVNAME(zr), *frame); mutex_lock(&zr->resource_lock); - res = jpg_qbuf(file, *frame, BUZ_MODE_MOTION_COMPRESS); + res = jpg_qbuf(fh, *frame, BUZ_MODE_MOTION_COMPRESS); mutex_unlock(&zr->resource_lock); return res; @@ -1792,7 +1725,7 @@ jpgreqbuf_unlock_and_return: ZR_DEVNAME(zr), *frame); mutex_lock(&zr->resource_lock); - res = jpg_qbuf(file, *frame, BUZ_MODE_MOTION_DECOMPRESS); + res = jpg_qbuf(fh, *frame, BUZ_MODE_MOTION_DECOMPRESS); mutex_unlock(&zr->resource_lock); return res; @@ -1806,7 +1739,15 @@ jpgreqbuf_unlock_and_return: dprintk(3, KERN_DEBUG "%s: BUZIOC_SYNC\n", ZR_DEVNAME(zr)); mutex_lock(&zr->resource_lock); - res = jpg_sync(file, bsync); + + if (fh->map_mode == ZORAN_MAP_MODE_RAW) { + dprintk(2, KERN_WARNING + "%s: %s - not in jpg capture mode\n", + ZR_DEVNAME(zr), __func__); + res = -EINVAL; + } else { + res = jpg_sync(fh, bsync); + } mutex_unlock(&zr->resource_lock); return res; @@ -1842,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); @@ -1853,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); @@ -1885,18 +1826,10 @@ static int zoran_vidiocgmbuf(struct file *file, void *__fh, struct video_mbuf *v struct zoran *zr = fh->zr; int i, res = 0; - vmbuf->size = - fh->v4l_buffers.num_buffers * - fh->v4l_buffers.buffer_size; - vmbuf->frames = fh->v4l_buffers.num_buffers; - for (i = 0; i < vmbuf->frames; i++) { - vmbuf->offsets[i] = - i * fh->v4l_buffers.buffer_size; - } mutex_lock(&zr->resource_lock); - if (fh->jpg_buffers.allocated || fh->v4l_buffers.allocated) { + if (fh->buffers.allocated) { dprintk(1, KERN_ERR "%s: VIDIOCGMBUF - buffers already allocated\n", @@ -1905,13 +1838,19 @@ static int zoran_vidiocgmbuf(struct file *file, void *__fh, struct video_mbuf *v goto v4l1reqbuf_unlock_and_return; } - if (v4l_fbuffer_alloc(file)) { + /* The next mmap will map the V4L buffers */ + map_mode_raw(fh); + + if (v4l_fbuffer_alloc(fh)) { res = -ENOMEM; goto v4l1reqbuf_unlock_and_return; } - /* The next mmap will map the V4L buffers */ - fh->map_mode = ZORAN_MAP_MODE_RAW; + vmbuf->size = fh->buffers.num_buffers * fh->buffers.buffer_size; + vmbuf->frames = fh->buffers.num_buffers; + for (i = 0; i < vmbuf->frames; i++) + vmbuf->offsets[i] = i * fh->buffers.buffer_size; + v4l1reqbuf_unlock_and_return: mutex_unlock(&zr->resource_lock); @@ -2194,14 +2133,10 @@ static int zoran_s_fmt_vid_overlay(struct file *file, void *__fh, fmt->fmt.win.clipcount, fmt->fmt.win.bitmap); mutex_lock(&zr->resource_lock); - res = setup_window(file, fmt->fmt.win.w.left, - fmt->fmt.win.w.top, - fmt->fmt.win.w.width, - fmt->fmt.win.w.height, - (struct v4l2_clip __user *) - fmt->fmt.win.clips, - fmt->fmt.win.clipcount, - fmt->fmt.win.bitmap); + res = setup_window(fh, fmt->fmt.win.w.left, fmt->fmt.win.w.top, + fmt->fmt.win.w.width, fmt->fmt.win.w.height, + (struct v4l2_clip __user *)fmt->fmt.win.clips, + fmt->fmt.win.clipcount, fmt->fmt.win.bitmap); mutex_unlock(&zr->resource_lock); return res; } @@ -2224,15 +2159,15 @@ static int zoran_s_fmt_vid_out(struct file *file, void *__fh, mutex_lock(&zr->resource_lock); - settings = fh->jpg_settings; - - if (fh->v4l_buffers.allocated || fh->jpg_buffers.allocated) { + if (fh->buffers.allocated) { dprintk(1, KERN_ERR "%s: VIDIOC_S_FMT - cannot change capture mode\n", - ZR_DEVNAME(zr)); + ZR_DEVNAME(zr)); res = -EBUSY; goto sfmtjpg_unlock_and_return; } + settings = fh->jpg_settings; + /* we actually need to set 'real' parameters now */ if (fmt->fmt.pix.height * 2 > BUZ_MAX_HEIGHT) settings.TmpDcm = 1; @@ -2270,6 +2205,9 @@ static int zoran_s_fmt_vid_out(struct file *file, void *__fh, /* it's ok, so set them */ fh->jpg_settings = settings; + map_mode_jpg(fh, fmt->type == V4L2_BUF_TYPE_VIDEO_OUTPUT); + fh->buffers.buffer_size = zoran_v4l2_calc_bufsize(&fh->jpg_settings); + /* tell the user what we actually did */ fmt->fmt.pix.width = settings.img_width / settings.HorDcm; fmt->fmt.pix.height = settings.img_height * 2 / @@ -2280,15 +2218,10 @@ static int zoran_s_fmt_vid_out(struct file *file, void *__fh, else fmt->fmt.pix.field = (fh->jpg_settings.odd_even ? V4L2_FIELD_TOP : V4L2_FIELD_BOTTOM); - fh->jpg_buffers.buffer_size = zoran_v4l2_calc_bufsize(&fh->jpg_settings); fmt->fmt.pix.bytesperline = 0; - fmt->fmt.pix.sizeimage = fh->jpg_buffers.buffer_size; + fmt->fmt.pix.sizeimage = fh->buffers.buffer_size; fmt->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; - /* we hereby abuse this variable to show that - * we're gonna do mjpeg capture */ - fh->map_mode = (fmt->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) ? - ZORAN_MAP_MODE_JPG_REC : ZORAN_MAP_MODE_JPG_PLAY; sfmtjpg_unlock_and_return: mutex_unlock(&zr->resource_lock); return res; @@ -2313,9 +2246,11 @@ static int zoran_s_fmt_vid_cap(struct file *file, void *__fh, ZR_DEVNAME(zr), fmt->fmt.pix.pixelformat); return -EINVAL; } + mutex_lock(&zr->resource_lock); - if (fh->jpg_buffers.allocated || - (fh->v4l_buffers.allocated && fh->v4l_buffers.active != ZORAN_FREE)) { + + if ((fh->map_mode != ZORAN_MAP_MODE_RAW && fh->buffers.allocated) || + fh->buffers.active != ZORAN_FREE) { dprintk(1, KERN_ERR "%s: VIDIOC_S_FMT - cannot change capture mode\n", ZR_DEVNAME(zr)); res = -EBUSY; @@ -2326,13 +2261,14 @@ static int zoran_s_fmt_vid_cap(struct file *file, void *__fh, if (fmt->fmt.pix.width > BUZ_MAX_WIDTH) fmt->fmt.pix.width = BUZ_MAX_WIDTH; - res = zoran_v4l_set_format(file, fmt->fmt.pix.width, - fmt->fmt.pix.height, &zoran_formats[i]); + map_mode_raw(fh); + + res = zoran_v4l_set_format(fh, fmt->fmt.pix.width, fmt->fmt.pix.height, + &zoran_formats[i]); if (res) goto sfmtv4l_unlock_and_return; - /* tell the user the - * results/missing stuff */ + /* tell the user the results/missing stuff */ fmt->fmt.pix.bytesperline = fh->v4l_settings.bytesperline; fmt->fmt.pix.sizeimage = fh->v4l_settings.height * fh->v4l_settings.bytesperline; fmt->fmt.pix.colorspace = fh->v4l_settings.format->colorspace; @@ -2341,7 +2277,6 @@ static int zoran_s_fmt_vid_cap(struct file *file, void *__fh, else fmt->fmt.pix.field = V4L2_FIELD_TOP; - fh->map_mode = ZORAN_MAP_MODE_RAW; sfmtv4l_unlock_and_return: mutex_unlock(&zr->resource_lock); return res; @@ -2389,9 +2324,8 @@ static int zoran_s_fbuf(struct file *file, void *__fh, } mutex_lock(&zr->resource_lock); - res = setup_fbuffer(file, fb->base, &zoran_formats[i], - fb->fmt.width, fb->fmt.height, - fb->fmt.bytesperline); + res = setup_fbuffer(fh, fb->base, &zoran_formats[i], fb->fmt.width, + fb->fmt.height, fb->fmt.bytesperline); mutex_unlock(&zr->resource_lock); return res; @@ -2404,7 +2338,7 @@ static int zoran_overlay(struct file *file, void *__fh, unsigned int on) int res; mutex_lock(&zr->resource_lock); - res = setup_overlay(file, on); + res = setup_overlay(fh, on); mutex_unlock(&zr->resource_lock); return res; @@ -2430,7 +2364,7 @@ static int zoran_reqbufs(struct file *file, void *__fh, struct v4l2_requestbuffe return zoran_streamoff(file, fh, req->type); mutex_lock(&zr->resource_lock); - if (fh->v4l_buffers.allocated || fh->jpg_buffers.allocated) { + if (fh->buffers.allocated) { dprintk(2, KERN_ERR "%s: VIDIOC_REQBUFS - buffers already allocated\n", @@ -2440,46 +2374,38 @@ static int zoran_reqbufs(struct file *file, void *__fh, struct v4l2_requestbuffe } if (fh->map_mode == ZORAN_MAP_MODE_RAW && - req->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) { - + req->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) { /* control user input */ if (req->count < 2) req->count = 2; if (req->count > v4l_nbufs) req->count = v4l_nbufs; - fh->v4l_buffers.num_buffers = req->count; - if (v4l_fbuffer_alloc(file)) { + /* The next mmap will map the V4L buffers */ + map_mode_raw(fh); + fh->buffers.num_buffers = req->count; + + if (v4l_fbuffer_alloc(fh)) { res = -ENOMEM; goto v4l2reqbuf_unlock_and_return; } - - /* The next mmap will map the V4L buffers */ - fh->map_mode = ZORAN_MAP_MODE_RAW; - } else if (fh->map_mode == ZORAN_MAP_MODE_JPG_REC || - fh->map_mode == ZORAN_MAP_MODE_JPG_PLAY) { - + fh->map_mode == ZORAN_MAP_MODE_JPG_PLAY) { /* we need to calculate size ourselves now */ if (req->count < 4) req->count = 4; if (req->count > jpg_nbufs) req->count = jpg_nbufs; - fh->jpg_buffers.num_buffers = req->count; - fh->jpg_buffers.buffer_size = - zoran_v4l2_calc_bufsize(&fh->jpg_settings); - if (jpg_fbuffer_alloc(file)) { + /* The next mmap will map the MJPEG buffers */ + map_mode_jpg(fh, req->type == V4L2_BUF_TYPE_VIDEO_OUTPUT); + fh->buffers.num_buffers = req->count; + fh->buffers.buffer_size = zoran_v4l2_calc_bufsize(&fh->jpg_settings); + + if (jpg_fbuffer_alloc(fh)) { res = -ENOMEM; goto v4l2reqbuf_unlock_and_return; } - - /* The next mmap will map the MJPEG buffers */ - if (req->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) - fh->map_mode = ZORAN_MAP_MODE_JPG_REC; - else - fh->map_mode = ZORAN_MAP_MODE_JPG_PLAY; - } else { dprintk(1, KERN_ERR @@ -2525,11 +2451,10 @@ static int zoran_qbuf(struct file *file, void *__fh, struct v4l2_buffer *buf) goto qbuf_unlock_and_return; } - res = zoran_v4l_queue_frame(file, buf->index); + res = zoran_v4l_queue_frame(fh, buf->index); if (res) goto qbuf_unlock_and_return; - if (!zr->v4l_memgrab_active && - fh->v4l_buffers.active == ZORAN_LOCKED) + if (!zr->v4l_memgrab_active && fh->buffers.active == ZORAN_LOCKED) zr36057_set_memgrab(zr, 1); break; @@ -2551,14 +2476,13 @@ static int zoran_qbuf(struct file *file, void *__fh, struct v4l2_buffer *buf) goto qbuf_unlock_and_return; } - res = zoran_jpg_queue_frame(file, buf->index, - codec_mode); + res = zoran_jpg_queue_frame(fh, buf->index, codec_mode); if (res != 0) goto qbuf_unlock_and_return; if (zr->codec_mode == BUZ_MODE_IDLE && - fh->jpg_buffers.active == ZORAN_LOCKED) { + fh->buffers.active == ZORAN_LOCKED) zr36057_enable_jpg(zr, codec_mode); - } + break; default: @@ -2598,7 +2522,7 @@ static int zoran_dqbuf(struct file *file, void *__fh, struct v4l2_buffer *buf) res = -EAGAIN; goto dqbuf_unlock_and_return; } - res = v4l_sync(file, num); + res = v4l_sync(fh, num); if (res) goto dqbuf_unlock_and_return; zr->v4l_sync_tail++; @@ -2630,7 +2554,7 @@ static int zoran_dqbuf(struct file *file, void *__fh, struct v4l2_buffer *buf) res = -EAGAIN; goto dqbuf_unlock_and_return; } - res = jpg_sync(file, &bs); + res = jpg_sync(fh, &bs); if (res) goto dqbuf_unlock_and_return; res = zoran_v4l2_buffer_status(fh, buf, bs.frame); @@ -2661,12 +2585,12 @@ static int zoran_streamon(struct file *file, void *__fh, enum v4l2_buf_type type switch (fh->map_mode) { case ZORAN_MAP_MODE_RAW: /* raw capture */ if (zr->v4l_buffers.active != ZORAN_ACTIVE || - fh->v4l_buffers.active != ZORAN_ACTIVE) { + fh->buffers.active != ZORAN_ACTIVE) { res = -EBUSY; goto strmon_unlock_and_return; } - zr->v4l_buffers.active = fh->v4l_buffers.active = ZORAN_LOCKED; + zr->v4l_buffers.active = fh->buffers.active = ZORAN_LOCKED; zr->v4l_settings = fh->v4l_settings; zr->v4l_sync_tail = zr->v4l_pend_tail; @@ -2680,12 +2604,12 @@ static int zoran_streamon(struct file *file, void *__fh, enum v4l2_buf_type type case ZORAN_MAP_MODE_JPG_PLAY: /* what is the codec mode right now? */ if (zr->jpg_buffers.active != ZORAN_ACTIVE || - fh->jpg_buffers.active != ZORAN_ACTIVE) { + fh->buffers.active != ZORAN_ACTIVE) { res = -EBUSY; goto strmon_unlock_and_return; } - zr->jpg_buffers.active = fh->jpg_buffers.active = ZORAN_LOCKED; + zr->jpg_buffers.active = fh->buffers.active = ZORAN_LOCKED; if (zr->jpg_que_head != zr->jpg_que_tail) { /* Start the jpeg codec when the first frame is queued */ @@ -2712,12 +2636,13 @@ static int zoran_streamoff(struct file *file, void *__fh, enum v4l2_buf_type typ struct zoran_fh *fh = __fh; struct zoran *zr = fh->zr; int i, res = 0; + unsigned long flags; mutex_lock(&zr->resource_lock); switch (fh->map_mode) { case ZORAN_MAP_MODE_RAW: /* raw capture */ - if (fh->v4l_buffers.active == ZORAN_FREE && + if (fh->buffers.active == ZORAN_FREE && zr->v4l_buffers.active != ZORAN_FREE) { res = -EPERM; /* stay off other's settings! */ goto strmoff_unlock_and_return; @@ -2725,30 +2650,30 @@ static int zoran_streamoff(struct file *file, void *__fh, enum v4l2_buf_type typ if (zr->v4l_buffers.active == ZORAN_FREE) goto strmoff_unlock_and_return; + spin_lock_irqsave(&zr->spinlock, flags); /* unload capture */ if (zr->v4l_memgrab_active) { - unsigned long flags; - spin_lock_irqsave(&zr->spinlock, flags); zr36057_set_memgrab(zr, 0); - spin_unlock_irqrestore(&zr->spinlock, flags); } - for (i = 0; i < fh->v4l_buffers.num_buffers; i++) + for (i = 0; i < fh->buffers.num_buffers; i++) zr->v4l_buffers.buffer[i].state = BUZ_STATE_USER; - fh->v4l_buffers = zr->v4l_buffers; + fh->buffers = zr->v4l_buffers; - zr->v4l_buffers.active = fh->v4l_buffers.active = ZORAN_FREE; + zr->v4l_buffers.active = fh->buffers.active = ZORAN_FREE; zr->v4l_grab_seq = 0; zr->v4l_pend_head = zr->v4l_pend_tail = 0; zr->v4l_sync_tail = 0; + spin_unlock_irqrestore(&zr->spinlock, flags); + break; case ZORAN_MAP_MODE_JPG_REC: case ZORAN_MAP_MODE_JPG_PLAY: - if (fh->jpg_buffers.active == ZORAN_FREE && + if (fh->buffers.active == ZORAN_FREE && zr->jpg_buffers.active != ZORAN_FREE) { res = -EPERM; /* stay off other's settings! */ goto strmoff_unlock_and_return; @@ -2756,7 +2681,7 @@ static int zoran_streamoff(struct file *file, void *__fh, enum v4l2_buf_type typ if (zr->jpg_buffers.active == ZORAN_FREE) goto strmoff_unlock_and_return; - res = jpg_qbuf(file, -1, + res = jpg_qbuf(fh, -1, (fh->map_mode == ZORAN_MAP_MODE_JPG_REC) ? BUZ_MODE_MOTION_COMPRESS : BUZ_MODE_MOTION_DECOMPRESS); @@ -3017,7 +2942,7 @@ static int zoran_s_crop(struct file *file, void *__fh, struct v4l2_crop *crop) mutex_lock(&zr->resource_lock); - if (fh->jpg_buffers.allocated || fh->v4l_buffers.allocated) { + if (fh->buffers.allocated) { dprintk(1, KERN_ERR "%s: VIDIOC_S_CROP - cannot change settings while active\n", ZR_DEVNAME(zr)); @@ -3095,8 +3020,7 @@ static int zoran_s_jpegcomp(struct file *file, void *__fh, mutex_lock(&zr->resource_lock); - if (fh->v4l_buffers.active != ZORAN_FREE || - fh->jpg_buffers.active != ZORAN_FREE) { + if (fh->buffers.active != ZORAN_FREE) { dprintk(1, KERN_WARNING "%s: VIDIOC_S_JPEGCOMP called while in playback/capture mode\n", ZR_DEVNAME(zr)); @@ -3107,9 +3031,9 @@ static int zoran_s_jpegcomp(struct file *file, void *__fh, res = zoran_check_jpg_settings(zr, &settings, 0); if (res) goto sjpegc_unlock_and_return; - if (!fh->jpg_buffers.allocated) - fh->jpg_buffers.buffer_size = - zoran_v4l2_calc_bufsize(&fh->jpg_settings); + if (!fh->buffers.allocated) + fh->buffers.buffer_size = + zoran_v4l2_calc_bufsize(&fh->jpg_settings); fh->jpg_settings.jpg_comp = *params = settings.jpg_comp; sjpegc_unlock_and_return: mutex_unlock(&zr->resource_lock); @@ -3146,11 +3070,11 @@ zoran_poll (struct file *file, KERN_DEBUG "%s: %s() raw - active=%c, sync_tail=%lu/%c, pend_tail=%lu, pend_head=%lu\n", ZR_DEVNAME(zr), __func__, - "FAL"[fh->v4l_buffers.active], zr->v4l_sync_tail, + "FAL"[fh->buffers.active], zr->v4l_sync_tail, "UPMD"[zr->v4l_buffers.buffer[frame].state], zr->v4l_pend_tail, zr->v4l_pend_head); /* Process is the one capturing? */ - if (fh->v4l_buffers.active != ZORAN_FREE && + if (fh->buffers.active != ZORAN_FREE && /* Buffer ready to DQBUF? */ zr->v4l_buffers.buffer[frame].state == BUZ_STATE_DONE) res = POLLIN | POLLRDNORM; @@ -3168,10 +3092,10 @@ zoran_poll (struct file *file, KERN_DEBUG "%s: %s() jpg - active=%c, que_tail=%lu/%c, que_head=%lu, dma=%lu/%lu\n", ZR_DEVNAME(zr), __func__, - "FAL"[fh->jpg_buffers.active], zr->jpg_que_tail, + "FAL"[fh->buffers.active], zr->jpg_que_tail, "UPMD"[zr->jpg_buffers.buffer[frame].state], zr->jpg_que_head, zr->jpg_dma_tail, zr->jpg_dma_head); - if (fh->jpg_buffers.active != ZORAN_FREE && + if (fh->buffers.active != ZORAN_FREE && zr->jpg_buffers.buffer[frame].state == BUZ_STATE_DONE) { if (fh->map_mode == ZORAN_MAP_MODE_JPG_REC) res = POLLIN | POLLRDNORM; @@ -3185,8 +3109,8 @@ zoran_poll (struct file *file, default: dprintk(1, KERN_ERR - "%s: zoran_poll() - internal error, unknown map_mode=%d\n", - ZR_DEVNAME(zr), fh->map_mode); + "%s: %s - internal error, unknown map_mode=%d\n", + ZR_DEVNAME(zr), __func__, fh->map_mode); res = POLLNVAL; } @@ -3220,92 +3144,53 @@ static void zoran_vm_close (struct vm_area_struct *vma) { struct zoran_mapping *map = vma->vm_private_data; - struct file *file = map->file; - struct zoran_fh *fh = file->private_data; + struct zoran_fh *fh = map->file->private_data; struct zoran *zr = fh->zr; int i; - map->count--; - if (map->count == 0) { - switch (fh->map_mode) { - case ZORAN_MAP_MODE_JPG_REC: - case ZORAN_MAP_MODE_JPG_PLAY: + if (--map->count > 0) + return; - dprintk(3, KERN_INFO "%s: munmap(MJPEG)\n", - ZR_DEVNAME(zr)); + dprintk(3, KERN_INFO "%s: %s - munmap(%s)\n", ZR_DEVNAME(zr), + __func__, mode_name(fh->map_mode)); - for (i = 0; i < fh->jpg_buffers.num_buffers; i++) { - if (fh->jpg_buffers.buffer[i].map == map) { - fh->jpg_buffers.buffer[i].map = - NULL; - } - } - kfree(map); - - for (i = 0; i < fh->jpg_buffers.num_buffers; i++) - if (fh->jpg_buffers.buffer[i].map) - break; - if (i == fh->jpg_buffers.num_buffers) { - mutex_lock(&zr->resource_lock); - - if (fh->jpg_buffers.active != ZORAN_FREE) { - jpg_qbuf(file, -1, zr->codec_mode); - zr->jpg_buffers.allocated = 0; - zr->jpg_buffers.active = - fh->jpg_buffers.active = - ZORAN_FREE; - } - jpg_fbuffer_free(file); - mutex_unlock(&zr->resource_lock); - } - - break; - - case ZORAN_MAP_MODE_RAW: - - dprintk(3, KERN_INFO "%s: munmap(V4L)\n", - ZR_DEVNAME(zr)); + for (i = 0; i < fh->buffers.num_buffers; i++) { + if (fh->buffers.buffer[i].map == map) + fh->buffers.buffer[i].map = NULL; + } + kfree(map); - for (i = 0; i < fh->v4l_buffers.num_buffers; i++) { - if (fh->v4l_buffers.buffer[i].map == map) { - /* unqueue/unmap */ - fh->v4l_buffers.buffer[i].map = - NULL; - } - } - kfree(map); + /* Any buffers still mapped? */ + for (i = 0; i < fh->buffers.num_buffers; i++) + if (fh->buffers.buffer[i].map) + return; - for (i = 0; i < fh->v4l_buffers.num_buffers; i++) - if (fh->v4l_buffers.buffer[i].map) - break; - if (i == fh->v4l_buffers.num_buffers) { - mutex_lock(&zr->resource_lock); - - if (fh->v4l_buffers.active != ZORAN_FREE) { - unsigned long flags; - - spin_lock_irqsave(&zr->spinlock, flags); - zr36057_set_memgrab(zr, 0); - zr->v4l_buffers.allocated = 0; - zr->v4l_buffers.active = - fh->v4l_buffers.active = - ZORAN_FREE; - spin_unlock_irqrestore(&zr->spinlock, flags); - } - v4l_fbuffer_free(file); - mutex_unlock(&zr->resource_lock); - } + dprintk(3, KERN_INFO "%s: %s - free %s buffers\n", ZR_DEVNAME(zr), + __func__, mode_name(fh->map_mode)); - break; + mutex_lock(&zr->resource_lock); - default: - printk(KERN_ERR - "%s: munmap() - internal error - unknown map mode %d\n", - ZR_DEVNAME(zr), fh->map_mode); - break; + if (fh->map_mode == ZORAN_MAP_MODE_RAW) { + if (fh->buffers.active != ZORAN_FREE) { + unsigned long flags; + spin_lock_irqsave(&zr->spinlock, flags); + zr36057_set_memgrab(zr, 0); + zr->v4l_buffers.allocated = 0; + zr->v4l_buffers.active = fh->buffers.active = ZORAN_FREE; + spin_unlock_irqrestore(&zr->spinlock, flags); } + v4l_fbuffer_free(fh); + } else { + if (fh->buffers.active != ZORAN_FREE) { + jpg_qbuf(fh, -1, zr->codec_mode); + zr->jpg_buffers.allocated = 0; + zr->jpg_buffers.active = fh->buffers.active = ZORAN_FREE; + } + jpg_fbuffer_free(fh); } + + mutex_unlock(&zr->resource_lock); } static struct vm_operations_struct zoran_vm_ops = { @@ -3328,90 +3213,106 @@ zoran_mmap (struct file *file, int res = 0; dprintk(3, - KERN_INFO "%s: mmap(%s) of 0x%08lx-0x%08lx (size=%lu)\n", - ZR_DEVNAME(zr), - fh->map_mode == ZORAN_MAP_MODE_RAW ? "V4L" : "MJPEG", - vma->vm_start, vma->vm_end, size); + KERN_INFO "%s: %s(%s) of 0x%08lx-0x%08lx (size=%lu)\n", + ZR_DEVNAME(zr), __func__, + mode_name(fh->map_mode), vma->vm_start, vma->vm_end, size); if (!(vma->vm_flags & VM_SHARED) || !(vma->vm_flags & VM_READ) || !(vma->vm_flags & VM_WRITE)) { dprintk(1, KERN_ERR - "%s: mmap() - no MAP_SHARED/PROT_{READ,WRITE} given\n", - ZR_DEVNAME(zr)); + "%s: %s - no MAP_SHARED/PROT_{READ,WRITE} given\n", + ZR_DEVNAME(zr), __func__); return -EINVAL; } - switch (fh->map_mode) { + mutex_lock(&zr->resource_lock); - case ZORAN_MAP_MODE_JPG_REC: - case ZORAN_MAP_MODE_JPG_PLAY: + if (!fh->buffers.allocated) { + dprintk(1, + KERN_ERR + "%s: %s(%s) - buffers not yet allocated\n", + ZR_DEVNAME(zr), __func__, mode_name(fh->map_mode)); + res = -ENOMEM; + goto mmap_unlock_and_return; + } - /* lock */ - mutex_lock(&zr->resource_lock); + first = offset / fh->buffers.buffer_size; + last = first - 1 + size / fh->buffers.buffer_size; + if (offset % fh->buffers.buffer_size != 0 || + size % fh->buffers.buffer_size != 0 || first < 0 || + last < 0 || first >= fh->buffers.num_buffers || + last >= fh->buffers.buffer_size) { + dprintk(1, + KERN_ERR + "%s: %s(%s) - offset=%lu or size=%lu invalid for bufsize=%d and numbufs=%d\n", + ZR_DEVNAME(zr), __func__, mode_name(fh->map_mode), offset, size, + fh->buffers.buffer_size, + fh->buffers.num_buffers); + res = -EINVAL; + goto mmap_unlock_and_return; + } - /* Map the MJPEG buffers */ - if (!fh->jpg_buffers.allocated) { + /* Check if any buffers are already mapped */ + for (i = first; i <= last; i++) { + if (fh->buffers.buffer[i].map) { dprintk(1, KERN_ERR - "%s: zoran_mmap(MJPEG) - buffers not yet allocated\n", - ZR_DEVNAME(zr)); - res = -ENOMEM; - goto jpg_mmap_unlock_and_return; + "%s: %s(%s) - buffer %d already mapped\n", + ZR_DEVNAME(zr), __func__, mode_name(fh->map_mode), i); + res = -EBUSY; + goto mmap_unlock_and_return; } + } - first = offset / fh->jpg_buffers.buffer_size; - last = first - 1 + size / fh->jpg_buffers.buffer_size; - if (offset % fh->jpg_buffers.buffer_size != 0 || - size % fh->jpg_buffers.buffer_size != 0 || first < 0 || - last < 0 || first >= fh->jpg_buffers.num_buffers || - last >= fh->jpg_buffers.num_buffers) { - dprintk(1, - KERN_ERR - "%s: mmap(MJPEG) - offset=%lu or size=%lu invalid for bufsize=%d and numbufs=%d\n", - ZR_DEVNAME(zr), offset, size, - fh->jpg_buffers.buffer_size, - fh->jpg_buffers.num_buffers); - res = -EINVAL; - goto jpg_mmap_unlock_and_return; - } + /* map these buffers */ + map = kmalloc(sizeof(struct zoran_mapping), GFP_KERNEL); + if (!map) { + res = -ENOMEM; + goto mmap_unlock_and_return; + } + map->file = file; + map->count = 1; + + vma->vm_ops = &zoran_vm_ops; + vma->vm_flags |= VM_DONTEXPAND; + vma->vm_private_data = map; + + if (fh->map_mode == ZORAN_MAP_MODE_RAW) { for (i = first; i <= last; i++) { - if (fh->jpg_buffers.buffer[i].map) { + todo = size; + if (todo > fh->buffers.buffer_size) + todo = fh->buffers.buffer_size; + page = fh->buffers.buffer[i].v4l.fbuffer_phys; + if (remap_pfn_range(vma, start, page >> PAGE_SHIFT, + todo, PAGE_SHARED)) { dprintk(1, KERN_ERR - "%s: mmap(MJPEG) - buffer %d already mapped\n", - ZR_DEVNAME(zr), i); - res = -EBUSY; - goto jpg_mmap_unlock_and_return; + "%s: %s(V4L) - remap_pfn_range failed\n", + ZR_DEVNAME(zr), __func__); + res = -EAGAIN; + goto mmap_unlock_and_return; } + size -= todo; + start += todo; + fh->buffers.buffer[i].map = map; + if (size == 0) + break; } - - /* map these buffers (v4l_buffers[i]) */ - map = kmalloc(sizeof(struct zoran_mapping), GFP_KERNEL); - if (!map) { - res = -ENOMEM; - goto jpg_mmap_unlock_and_return; - } - map->file = file; - map->count = 1; - - vma->vm_ops = &zoran_vm_ops; - vma->vm_flags |= VM_DONTEXPAND; - vma->vm_private_data = map; - + } else { for (i = first; i <= last; i++) { for (j = 0; - j < fh->jpg_buffers.buffer_size / PAGE_SIZE; + j < fh->buffers.buffer_size / PAGE_SIZE; j++) { fraglen = - (le32_to_cpu(fh->jpg_buffers.buffer[i]. + (le32_to_cpu(fh->buffers.buffer[i].jpg. frag_tab[2 * j + 1]) & ~1) << 1; todo = size; if (todo > fraglen) todo = fraglen; pos = - le32_to_cpu(fh->jpg_buffers. - buffer[i].frag_tab[2 * j]); + le32_to_cpu(fh->buffers. + buffer[i].jpg.frag_tab[2 * j]); /* should just be pos on i386 */ page = virt_to_phys(bus_to_virt(pos)) >> PAGE_SHIFT; @@ -3419,115 +3320,29 @@ zoran_mmap (struct file *file, todo, PAGE_SHARED)) { dprintk(1, KERN_ERR - "%s: zoran_mmap(V4L) - remap_pfn_range failed\n", - ZR_DEVNAME(zr)); + "%s: %s(V4L) - remap_pfn_range failed\n", + ZR_DEVNAME(zr), __func__); res = -EAGAIN; - goto jpg_mmap_unlock_and_return; + goto mmap_unlock_and_return; } size -= todo; start += todo; if (size == 0) break; - if (le32_to_cpu(fh->jpg_buffers.buffer[i]. + if (le32_to_cpu(fh->buffers.buffer[i].jpg. frag_tab[2 * j + 1]) & 1) break; /* was last fragment */ } - fh->jpg_buffers.buffer[i].map = map; + fh->buffers.buffer[i].map = map; if (size == 0) break; } - jpg_mmap_unlock_and_return: - mutex_unlock(&zr->resource_lock); - - break; - - case ZORAN_MAP_MODE_RAW: - - mutex_lock(&zr->resource_lock); - - /* Map the V4L buffers */ - if (!fh->v4l_buffers.allocated) { - dprintk(1, - KERN_ERR - "%s: zoran_mmap(V4L) - buffers not yet allocated\n", - ZR_DEVNAME(zr)); - res = -ENOMEM; - goto v4l_mmap_unlock_and_return; - } - - first = offset / fh->v4l_buffers.buffer_size; - last = first - 1 + size / fh->v4l_buffers.buffer_size; - if (offset % fh->v4l_buffers.buffer_size != 0 || - size % fh->v4l_buffers.buffer_size != 0 || first < 0 || - last < 0 || first >= fh->v4l_buffers.num_buffers || - last >= fh->v4l_buffers.buffer_size) { - dprintk(1, - KERN_ERR - "%s: mmap(V4L) - offset=%lu or size=%lu invalid for bufsize=%d and numbufs=%d\n", - ZR_DEVNAME(zr), offset, size, - fh->v4l_buffers.buffer_size, - fh->v4l_buffers.num_buffers); - res = -EINVAL; - goto v4l_mmap_unlock_and_return; - } - for (i = first; i <= last; i++) { - if (fh->v4l_buffers.buffer[i].map) { - dprintk(1, - KERN_ERR - "%s: mmap(V4L) - buffer %d already mapped\n", - ZR_DEVNAME(zr), i); - res = -EBUSY; - goto v4l_mmap_unlock_and_return; - } - } - - /* map these buffers (v4l_buffers[i]) */ - map = kmalloc(sizeof(struct zoran_mapping), GFP_KERNEL); - if (!map) { - res = -ENOMEM; - goto v4l_mmap_unlock_and_return; - } - map->file = file; - map->count = 1; - - vma->vm_ops = &zoran_vm_ops; - vma->vm_flags |= VM_DONTEXPAND; - vma->vm_private_data = map; - - for (i = first; i <= last; i++) { - todo = size; - if (todo > fh->v4l_buffers.buffer_size) - todo = fh->v4l_buffers.buffer_size; - page = fh->v4l_buffers.buffer[i].fbuffer_phys; - if (remap_pfn_range(vma, start, page >> PAGE_SHIFT, - todo, PAGE_SHARED)) { - dprintk(1, - KERN_ERR - "%s: zoran_mmap(V4L)i - remap_pfn_range failed\n", - ZR_DEVNAME(zr)); - res = -EAGAIN; - goto v4l_mmap_unlock_and_return; - } - size -= todo; - start += todo; - fh->v4l_buffers.buffer[i].map = map; - if (size == 0) - break; - } - v4l_mmap_unlock_and_return: - mutex_unlock(&zr->resource_lock); - - break; - - default: - dprintk(1, - KERN_ERR - "%s: zoran_mmap() - internal error - unknown map mode %d\n", - ZR_DEVNAME(zr), fh->map_mode); - break; } +mmap_unlock_and_return: + mutex_unlock(&zr->resource_lock); + return 0; } diff --git a/linux/include/linux/i2c-id.h b/linux/include/linux/i2c-id.h index 17d9af070..87b7534d1 100644 --- a/linux/include/linux/i2c-id.h +++ b/linux/include/linux/i2c-id.h @@ -88,6 +88,7 @@ #define I2C_HW_B_CX2341X 0x010020 /* Conexant CX2341X MPEG encoder cards */ #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 */ /* --- 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/videodev2.h b/linux/include/linux/videodev2.h index 7a8eafd43..2c8393594 100644 --- a/linux/include/linux/videodev2.h +++ b/linux/include/linux/videodev2.h @@ -1348,6 +1348,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/ir-kbd-i2c.h b/linux/include/media/ir-kbd-i2c.h index 00fa57eb9..07963d705 100644 --- a/linux/include/media/ir-kbd-i2c.h +++ b/linux/include/media/ir-kbd-i2c.h @@ -14,8 +14,7 @@ struct IR_i2c { /* Used to avoid fast repeating */ unsigned char old; - struct work_struct work; - struct timer_list timer; + struct delayed_work work; char phys[32]; int (*get_key)(struct IR_i2c*, u32*, u32*); }; 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-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..1b97a2c33 100644 --- a/linux/include/media/v4l2-subdev.h +++ b/linux/include/media/v4l2-subdev.h @@ -191,4 +191,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/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/Kconfig.sound b/v4l/Kconfig.sound index 55be75cce..67430b792 100644 --- a/v4l/Kconfig.sound +++ b/v4l/Kconfig.sound @@ -25,18 +25,9 @@ config SND_BT87X_OVERCLOCK Higher sample rates won't hurt your hardware, but audio quality may suffer. -config SND_FM801 - tristate - depends on SND && SND_OPL3_LIB && SND_MPU401_UART && SND_AC97_CODEC - -config SND_FM801_TEA575X_BOOL - bool - depends on SND_FM801 - config SND_FM801_TEA575X tristate "ForteMedia FM801 TEA5757 tuner" depends on VIDEO_V4L1 && SND_FM801 - select SND_FM801_TEA575X_BOOL help Say Y here to include support for soundcards based on the ForteMedia diff --git a/v4l/scripts/check.pl b/v4l/scripts/check.pl index 4958e281b..975041c4a 100755 --- a/v4l/scripts/check.pl +++ b/v4l/scripts/check.pl @@ -87,6 +87,10 @@ $pwd =~ s|/[^/]+\n$||; sub print_err() { + if ($err =~ m/LINUX_VERSION_CODE/) { + return; + } + if ($err) { printf STDERR "%s/%s: In '%s':\n", $pwd, $file, $errline; printf STDERR "%s/%s:%d: %s\n", $pwd, $file, $ln_numb, $err; 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 369cbb15d..b4869a157 100644 --- a/v4l/versions.txt +++ b/v4l/versions.txt @@ -20,6 +20,10 @@ SOC_CAMERA SOC_CAMERA_MT9V022 SOC_CAMERA_MT9M001 +[2.6.23] +# Needs field intf_assoc in struct usb_host_config +VIDEO_CX231XX + [2.6.22] #This driver requires I2C probe/remove fields VIDEO_TCM825X 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-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, |