Path: blob/master/drivers/media/video/em28xx/em28xx.h
17778 views
/*1em28xx.h - driver for Empia EM2800/EM2820/2840 USB video capture devices23Copyright (C) 2005 Markus Rechberger <[email protected]>4Ludovico Cavedon <[email protected]>5Mauro Carvalho Chehab <[email protected]>67Based on the em2800 driver from Sascha Sommer <[email protected]>89This program is free software; you can redistribute it and/or modify10it under the terms of the GNU General Public License as published by11the Free Software Foundation; either version 2 of the License, or12(at your option) any later version.1314This program is distributed in the hope that it will be useful,15but WITHOUT ANY WARRANTY; without even the implied warranty of16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the17GNU General Public License for more details.1819You should have received a copy of the GNU General Public License20along with this program; if not, write to the Free Software21Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.22*/2324#ifndef _EM28XX_H25#define _EM28XX_H2627#include <linux/workqueue.h>28#include <linux/i2c.h>29#include <linux/mutex.h>30#include <linux/videodev2.h>3132#include <media/videobuf-vmalloc.h>33#include <media/v4l2-device.h>34#include <media/ir-kbd-i2c.h>35#include <media/rc-core.h>36#if defined(CONFIG_VIDEO_EM28XX_DVB) || defined(CONFIG_VIDEO_EM28XX_DVB_MODULE)37#include <media/videobuf-dvb.h>38#endif39#include "tuner-xc2028.h"40#include "em28xx-reg.h"4142/* Boards supported by driver */43#define EM2800_BOARD_UNKNOWN 044#define EM2820_BOARD_UNKNOWN 145#define EM2820_BOARD_TERRATEC_CINERGY_250 246#define EM2820_BOARD_PINNACLE_USB_2 347#define EM2820_BOARD_HAUPPAUGE_WINTV_USB_2 448#define EM2820_BOARD_MSI_VOX_USB_2 549#define EM2800_BOARD_TERRATEC_CINERGY_200 650#define EM2800_BOARD_LEADTEK_WINFAST_USBII 751#define EM2800_BOARD_KWORLD_USB2800 852#define EM2820_BOARD_PINNACLE_DVC_90 953#define EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900 1054#define EM2880_BOARD_TERRATEC_HYBRID_XS 1155#define EM2820_BOARD_KWORLD_PVRTV2800RF 1256#define EM2880_BOARD_TERRATEC_PRODIGY_XS 1357#define EM2820_BOARD_PROLINK_PLAYTV_USB2 1458#define EM2800_BOARD_VGEAR_POCKETTV 1559#define EM2883_BOARD_HAUPPAUGE_WINTV_HVR_950 1660#define EM2880_BOARD_PINNACLE_PCTV_HD_PRO 1761#define EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900_R2 1862#define EM2860_BOARD_SAA711X_REFERENCE_DESIGN 1963#define EM2880_BOARD_AMD_ATI_TV_WONDER_HD_600 2064#define EM2800_BOARD_GRABBEEX_USB2800 2165#define EM2750_BOARD_UNKNOWN 2266#define EM2750_BOARD_DLCW_130 2367#define EM2820_BOARD_DLINK_USB_TV 2468#define EM2820_BOARD_GADMEI_UTV310 2569#define EM2820_BOARD_HERCULES_SMART_TV_USB2 2670#define EM2820_BOARD_PINNACLE_USB_2_FM1216ME 2771#define EM2820_BOARD_LEADTEK_WINFAST_USBII_DELUXE 2872#define EM2860_BOARD_TVP5150_REFERENCE_DESIGN 2973#define EM2820_BOARD_VIDEOLOGY_20K14XUSB 3074#define EM2821_BOARD_USBGEAR_VD204 3175#define EM2821_BOARD_SUPERCOMP_USB_2 3276#define EM2860_BOARD_ELGATO_VIDEO_CAPTURE 3377#define EM2860_BOARD_TERRATEC_HYBRID_XS 3478#define EM2860_BOARD_TYPHOON_DVD_MAKER 3579#define EM2860_BOARD_NETGMBH_CAM 3680#define EM2860_BOARD_GADMEI_UTV330 3781#define EM2861_BOARD_YAKUMO_MOVIE_MIXER 3882#define EM2861_BOARD_KWORLD_PVRTV_300U 3983#define EM2861_BOARD_PLEXTOR_PX_TV100U 4084#define EM2870_BOARD_KWORLD_350U 4185#define EM2870_BOARD_KWORLD_355U 4286#define EM2870_BOARD_TERRATEC_XS 4387#define EM2870_BOARD_TERRATEC_XS_MT2060 4488#define EM2870_BOARD_PINNACLE_PCTV_DVB 4589#define EM2870_BOARD_COMPRO_VIDEOMATE 4690#define EM2880_BOARD_KWORLD_DVB_305U 4791#define EM2880_BOARD_KWORLD_DVB_310U 4892#define EM2880_BOARD_MSI_DIGIVOX_AD 4993#define EM2880_BOARD_MSI_DIGIVOX_AD_II 5094#define EM2880_BOARD_TERRATEC_HYBRID_XS_FR 5195#define EM2881_BOARD_DNT_DA2_HYBRID 5296#define EM2881_BOARD_PINNACLE_HYBRID_PRO 5397#define EM2882_BOARD_KWORLD_VS_DVBT 5498#define EM2882_BOARD_TERRATEC_HYBRID_XS 5599#define EM2882_BOARD_PINNACLE_HYBRID_PRO_330E 56100#define EM2883_BOARD_KWORLD_HYBRID_330U 57101#define EM2820_BOARD_COMPRO_VIDEOMATE_FORYOU 58102#define EM2883_BOARD_HAUPPAUGE_WINTV_HVR_850 60103#define EM2820_BOARD_PROLINK_PLAYTV_BOX4_USB2 61104#define EM2820_BOARD_GADMEI_TVR200 62105#define EM2860_BOARD_KAIOMY_TVNPC_U2 63106#define EM2860_BOARD_EASYCAP 64107#define EM2820_BOARD_IODATA_GVMVP_SZ 65108#define EM2880_BOARD_EMPIRE_DUAL_TV 66109#define EM2860_BOARD_TERRATEC_GRABBY 67110#define EM2860_BOARD_TERRATEC_AV350 68111#define EM2882_BOARD_KWORLD_ATSC_315U 69112#define EM2882_BOARD_EVGA_INDTUBE 70113#define EM2820_BOARD_SILVERCREST_WEBCAM 71114#define EM2861_BOARD_GADMEI_UTV330PLUS 72115#define EM2870_BOARD_REDDO_DVB_C_USB_BOX 73116#define EM2800_BOARD_VC211A 74117#define EM2882_BOARD_DIKOM_DK300 75118#define EM2870_BOARD_KWORLD_A340 76119#define EM2874_LEADERSHIP_ISDBT 77120#define EM28174_BOARD_PCTV_290E 78121122123/* Limits minimum and default number of buffers */124#define EM28XX_MIN_BUF 4125#define EM28XX_DEF_BUF 8126127/*Limits the max URB message size */128#define URB_MAX_CTRL_SIZE 80129130/* Params for validated field */131#define EM28XX_BOARD_NOT_VALIDATED 1132#define EM28XX_BOARD_VALIDATED 0133134/* Params for em28xx_cmd() audio */135#define EM28XX_START_AUDIO 1136#define EM28XX_STOP_AUDIO 0137138/* maximum number of em28xx boards */139#define EM28XX_MAXBOARDS 4 /*FIXME: should be bigger */140141/* maximum number of frames that can be queued */142#define EM28XX_NUM_FRAMES 5143/* number of frames that get used for v4l2_read() */144#define EM28XX_NUM_READ_FRAMES 2145146/* number of buffers for isoc transfers */147#define EM28XX_NUM_BUFS 5148149/* number of packets for each buffer150windows requests only 64 packets .. so we better do the same151this is what I found out for all alternate numbers there!152*/153#define EM28XX_NUM_PACKETS 64154155#define EM28XX_INTERLACED_DEFAULT 1156157/*158#define (use usbview if you want to get the other alternate number infos)159#define160#define alternate number 2161#define Endpoint Address: 82162Direction: in163Attribute: 1164Type: Isoc165Max Packet Size: 1448166Interval: 125us167168alternate number 7169170Endpoint Address: 82171Direction: in172Attribute: 1173Type: Isoc174Max Packet Size: 3072175Interval: 125us176*/177178/* time to wait when stopping the isoc transfer */179#define EM28XX_URB_TIMEOUT \180msecs_to_jiffies(EM28XX_NUM_BUFS * EM28XX_NUM_PACKETS)181182/* time in msecs to wait for i2c writes to finish */183#define EM2800_I2C_WRITE_TIMEOUT 20184185enum em28xx_mode {186EM28XX_SUSPEND,187EM28XX_ANALOG_MODE,188EM28XX_DIGITAL_MODE,189};190191192struct em28xx;193194struct em28xx_usb_isoc_ctl {195/* max packet size of isoc transaction */196int max_pkt_size;197198/* number of allocated urbs */199int num_bufs;200201/* urb for isoc transfers */202struct urb **urb;203204/* transfer buffers for isoc transfer */205char **transfer_buffer;206207/* Last buffer command and region */208u8 cmd;209int pos, size, pktsize;210211/* Last field: ODD or EVEN? */212int field;213214/* Stores incomplete commands */215u32 tmp_buf;216int tmp_buf_len;217218/* Stores already requested buffers */219struct em28xx_buffer *vid_buf;220struct em28xx_buffer *vbi_buf;221222/* Stores the number of received fields */223int nfields;224225/* isoc urb callback */226int (*isoc_copy) (struct em28xx *dev, struct urb *urb);227228};229230/* Struct to enumberate video formats */231struct em28xx_fmt {232char *name;233u32 fourcc; /* v4l2 format id */234int depth;235int reg;236};237238/* buffer for one video frame */239struct em28xx_buffer {240/* common v4l buffer stuff -- must be first */241struct videobuf_buffer vb;242243struct list_head frame;244int top_field;245int receiving;246};247248struct em28xx_dmaqueue {249struct list_head active;250struct list_head queued;251252wait_queue_head_t wq;253254/* Counters to control buffer fill */255int pos;256};257258/* io methods */259enum em28xx_io_method {260IO_NONE,261IO_READ,262IO_MMAP,263};264265/* inputs */266267#define MAX_EM28XX_INPUT 4268enum enum28xx_itype {269EM28XX_VMUX_COMPOSITE1 = 1,270EM28XX_VMUX_COMPOSITE2,271EM28XX_VMUX_COMPOSITE3,272EM28XX_VMUX_COMPOSITE4,273EM28XX_VMUX_SVIDEO,274EM28XX_VMUX_TELEVISION,275EM28XX_VMUX_CABLE,276EM28XX_VMUX_DVB,277EM28XX_VMUX_DEBUG,278EM28XX_RADIO,279};280281enum em28xx_ac97_mode {282EM28XX_NO_AC97 = 0,283EM28XX_AC97_EM202,284EM28XX_AC97_SIGMATEL,285EM28XX_AC97_OTHER,286};287288struct em28xx_audio_mode {289enum em28xx_ac97_mode ac97;290291u16 ac97_feat;292u32 ac97_vendor_id;293294unsigned int has_audio:1;295296unsigned int i2s_3rates:1;297unsigned int i2s_5rates:1;298};299300/* em28xx has two audio inputs: tuner and line in.301However, on most devices, an auxiliary AC97 codec device is used.302The AC97 device may have several different inputs and outputs,303depending on their model. So, it is possible to use AC97 mixer to304address more than two different entries.305*/306enum em28xx_amux {307/* This is the only entry for em28xx tuner input */308EM28XX_AMUX_VIDEO, /* em28xx tuner, AC97 mixer Video */309310EM28XX_AMUX_LINE_IN, /* AC97 mixer Line In */311312/* Some less-common mixer setups */313EM28XX_AMUX_VIDEO2, /* em28xx Line in, AC97 mixer Video */314EM28XX_AMUX_PHONE,315EM28XX_AMUX_MIC,316EM28XX_AMUX_CD,317EM28XX_AMUX_AUX,318EM28XX_AMUX_PCM_OUT,319};320321enum em28xx_aout {322/* AC97 outputs */323EM28XX_AOUT_MASTER = 1 << 0,324EM28XX_AOUT_LINE = 1 << 1,325EM28XX_AOUT_MONO = 1 << 2,326EM28XX_AOUT_LFE = 1 << 3,327EM28XX_AOUT_SURR = 1 << 4,328329/* PCM IN Mixer - used by AC97_RECORD_SELECT register */330EM28XX_AOUT_PCM_IN = 1 << 7,331332/* Bits 10-8 are used to indicate the PCM IN record select */333EM28XX_AOUT_PCM_MIC_PCM = 0 << 8,334EM28XX_AOUT_PCM_CD = 1 << 8,335EM28XX_AOUT_PCM_VIDEO = 2 << 8,336EM28XX_AOUT_PCM_AUX = 3 << 8,337EM28XX_AOUT_PCM_LINE = 4 << 8,338EM28XX_AOUT_PCM_STEREO = 5 << 8,339EM28XX_AOUT_PCM_MONO = 6 << 8,340EM28XX_AOUT_PCM_PHONE = 7 << 8,341};342343static inline int ac97_return_record_select(int a_out)344{345return (a_out & 0x700) >> 8;346}347348struct em28xx_reg_seq {349int reg;350unsigned char val, mask;351int sleep;352};353354struct em28xx_input {355enum enum28xx_itype type;356unsigned int vmux;357enum em28xx_amux amux;358enum em28xx_aout aout;359struct em28xx_reg_seq *gpio;360};361362#define INPUT(nr) (&em28xx_boards[dev->model].input[nr])363364enum em28xx_decoder {365EM28XX_NODECODER = 0,366EM28XX_TVP5150,367EM28XX_SAA711X,368};369370enum em28xx_sensor {371EM28XX_NOSENSOR = 0,372EM28XX_MT9V011,373EM28XX_MT9M001,374EM28XX_MT9M111,375};376377enum em28xx_adecoder {378EM28XX_NOADECODER = 0,379EM28XX_TVAUDIO,380};381382struct em28xx_board {383char *name;384int vchannels;385int tuner_type;386int tuner_addr;387388/* i2c flags */389unsigned int tda9887_conf;390391/* GPIO sequences */392struct em28xx_reg_seq *dvb_gpio;393struct em28xx_reg_seq *suspend_gpio;394struct em28xx_reg_seq *tuner_gpio;395struct em28xx_reg_seq *mute_gpio;396397unsigned int is_em2800:1;398unsigned int has_msp34xx:1;399unsigned int mts_firmware:1;400unsigned int max_range_640_480:1;401unsigned int has_dvb:1;402unsigned int has_snapshot_button:1;403unsigned int is_webcam:1;404unsigned int valid:1;405unsigned int has_ir_i2c:1;406407unsigned char xclk, i2c_speed;408unsigned char radio_addr;409unsigned short tvaudio_addr;410411enum em28xx_decoder decoder;412enum em28xx_adecoder adecoder;413414struct em28xx_input input[MAX_EM28XX_INPUT];415struct em28xx_input radio;416char *ir_codes;417};418419struct em28xx_eeprom {420u32 id; /* 0x9567eb1a */421u16 vendor_ID;422u16 product_ID;423424u16 chip_conf;425426u16 board_conf;427428u16 string1, string2, string3;429430u8 string_idx_table;431};432433/* device states */434enum em28xx_dev_state {435DEV_INITIALIZED = 0x01,436DEV_DISCONNECTED = 0x02,437DEV_MISCONFIGURED = 0x04,438};439440#define EM28XX_AUDIO_BUFS 5441#define EM28XX_NUM_AUDIO_PACKETS 64442#define EM28XX_AUDIO_MAX_PACKET_SIZE 196 /* static value */443#define EM28XX_CAPTURE_STREAM_EN 1444445/* em28xx extensions */446#define EM28XX_AUDIO 0x10447#define EM28XX_DVB 0x20448449/* em28xx resource types (used for res_get/res_lock etc */450#define EM28XX_RESOURCE_VIDEO 0x01451#define EM28XX_RESOURCE_VBI 0x02452453struct em28xx_audio {454char name[50];455char *transfer_buffer[EM28XX_AUDIO_BUFS];456struct urb *urb[EM28XX_AUDIO_BUFS];457struct usb_device *udev;458unsigned int capture_transfer_done;459struct snd_pcm_substream *capture_pcm_substream;460461unsigned int hwptr_done_capture;462struct snd_card *sndcard;463464int users;465spinlock_t slock;466};467468struct em28xx;469470struct em28xx_fh {471struct em28xx *dev;472int radio;473unsigned int resources;474475struct videobuf_queue vb_vidq;476struct videobuf_queue vb_vbiq;477478enum v4l2_buf_type type;479};480481/* main device struct */482struct em28xx {483/* generic device properties */484char name[30]; /* name (including minor) of the device */485int model; /* index in the device_data struct */486int devno; /* marks the number of this device */487enum em28xx_chip_id chip_id;488489struct v4l2_device v4l2_dev;490struct em28xx_board board;491492/* Webcam specific fields */493enum em28xx_sensor em28xx_sensor;494int sensor_xres, sensor_yres;495int sensor_xtal;496497/* Allows progressive (e. g. non-interlaced) mode */498int progressive;499500/* Vinmode/Vinctl used at the driver */501int vinmode, vinctl;502503unsigned int has_audio_class:1;504unsigned int has_alsa_audio:1;505506/* Controls audio streaming */507struct work_struct wq_trigger; /* Trigger to start/stop audio for alsa module */508atomic_t stream_started; /* stream should be running if true */509510struct em28xx_fmt *format;511512struct em28xx_IR *ir;513514/* Some older em28xx chips needs a waiting time after writing */515unsigned int wait_after_write;516517struct list_head devlist;518519u32 i2s_speed; /* I2S speed for audio digital stream */520521struct em28xx_audio_mode audio_mode;522523int tuner_type; /* type of the tuner */524int tuner_addr; /* tuner address */525int tda9887_conf;526/* i2c i/o */527struct i2c_adapter i2c_adap;528struct i2c_client i2c_client;529/* video for linux */530int users; /* user count for exclusive use */531struct video_device *vdev; /* video for linux device struct */532v4l2_std_id norm; /* selected tv norm */533int ctl_freq; /* selected frequency */534unsigned int ctl_input; /* selected input */535unsigned int ctl_ainput;/* selected audio input */536unsigned int ctl_aoutput;/* selected audio output */537int mute;538int volume;539/* frame properties */540int width; /* current frame width */541int height; /* current frame height */542unsigned hscale; /* horizontal scale factor (see datasheet) */543unsigned vscale; /* vertical scale factor (see datasheet) */544int interlaced; /* 1=interlace fileds, 0=just top fileds */545unsigned int video_bytesread; /* Number of bytes read */546547unsigned long hash; /* eeprom hash - for boards with generic ID */548unsigned long i2c_hash; /* i2c devicelist hash -549for boards with generic ID */550551struct em28xx_audio adev;552553/* states */554enum em28xx_dev_state state;555enum em28xx_io_method io;556557/* vbi related state tracking */558int capture_type;559int vbi_read;560unsigned char cur_field;561unsigned int vbi_width;562unsigned int vbi_height; /* lines per field */563564struct work_struct request_module_wk;565566/* locks */567struct mutex lock;568struct mutex ctrl_urb_lock; /* protects urb_buf */569/* spinlock_t queue_lock; */570struct list_head inqueue, outqueue;571wait_queue_head_t open, wait_frame, wait_stream;572struct video_device *vbi_dev;573struct video_device *radio_dev;574575/* resources in use */576unsigned int resources;577578unsigned char eedata[256];579580/* Isoc control struct */581struct em28xx_dmaqueue vidq;582struct em28xx_dmaqueue vbiq;583struct em28xx_usb_isoc_ctl isoc_ctl;584spinlock_t slock;585586/* usb transfer */587struct usb_device *udev; /* the usb device */588int alt; /* alternate */589int max_pkt_size; /* max packet size of isoc transaction */590int num_alt; /* Number of alternative settings */591unsigned int *alt_max_pkt_size; /* array of wMaxPacketSize */592struct urb *urb[EM28XX_NUM_BUFS]; /* urb for isoc transfers */593char *transfer_buffer[EM28XX_NUM_BUFS]; /* transfer buffers for isoc594transfer */595char urb_buf[URB_MAX_CTRL_SIZE]; /* urb control msg buffer */596597/* helper funcs that call usb_control_msg */598int (*em28xx_write_regs) (struct em28xx *dev, u16 reg,599char *buf, int len);600int (*em28xx_read_reg) (struct em28xx *dev, u16 reg);601int (*em28xx_read_reg_req_len) (struct em28xx *dev, u8 req, u16 reg,602char *buf, int len);603int (*em28xx_write_regs_req) (struct em28xx *dev, u8 req, u16 reg,604char *buf, int len);605int (*em28xx_read_reg_req) (struct em28xx *dev, u8 req, u16 reg);606607enum em28xx_mode mode;608609/* register numbers for GPO/GPIO registers */610u16 reg_gpo_num, reg_gpio_num;611612/* Caches GPO and GPIO registers */613unsigned char reg_gpo, reg_gpio;614615/* Snapshot button */616char snapshot_button_path[30]; /* path of the input dev */617struct input_dev *sbutton_input_dev;618struct delayed_work sbutton_query_work;619620struct em28xx_dvb *dvb;621622/* I2C keyboard data */623struct IR_i2c_init_data init_data;624};625626struct em28xx_ops {627struct list_head next;628char *name;629int id;630int (*init)(struct em28xx *);631int (*fini)(struct em28xx *);632};633634/* Provided by em28xx-i2c.c */635void em28xx_do_i2c_scan(struct em28xx *dev);636int em28xx_i2c_register(struct em28xx *dev);637int em28xx_i2c_unregister(struct em28xx *dev);638639/* Provided by em28xx-core.c */640641u32 em28xx_request_buffers(struct em28xx *dev, u32 count);642void em28xx_queue_unusedframes(struct em28xx *dev);643void em28xx_release_buffers(struct em28xx *dev);644645int em28xx_read_reg_req_len(struct em28xx *dev, u8 req, u16 reg,646char *buf, int len);647int em28xx_read_reg_req(struct em28xx *dev, u8 req, u16 reg);648int em28xx_read_reg(struct em28xx *dev, u16 reg);649int em28xx_write_regs_req(struct em28xx *dev, u8 req, u16 reg, char *buf,650int len);651int em28xx_write_regs(struct em28xx *dev, u16 reg, char *buf, int len);652int em28xx_write_reg(struct em28xx *dev, u16 reg, u8 val);653int em28xx_write_reg_bits(struct em28xx *dev, u16 reg, u8 val,654u8 bitmask);655656int em28xx_read_ac97(struct em28xx *dev, u8 reg);657int em28xx_write_ac97(struct em28xx *dev, u8 reg, u16 val);658659int em28xx_audio_analog_set(struct em28xx *dev);660int em28xx_audio_setup(struct em28xx *dev);661662int em28xx_colorlevels_set_default(struct em28xx *dev);663int em28xx_capture_start(struct em28xx *dev, int start);664int em28xx_vbi_supported(struct em28xx *dev);665int em28xx_set_outfmt(struct em28xx *dev);666int em28xx_resolution_set(struct em28xx *dev);667int em28xx_set_alternate(struct em28xx *dev);668int em28xx_init_isoc(struct em28xx *dev, int max_packets,669int num_bufs, int max_pkt_size,670int (*isoc_copy) (struct em28xx *dev, struct urb *urb));671void em28xx_uninit_isoc(struct em28xx *dev);672int em28xx_isoc_dvb_max_packetsize(struct em28xx *dev);673int em28xx_set_mode(struct em28xx *dev, enum em28xx_mode set_mode);674int em28xx_gpio_set(struct em28xx *dev, struct em28xx_reg_seq *gpio);675void em28xx_wake_i2c(struct em28xx *dev);676void em28xx_remove_from_devlist(struct em28xx *dev);677void em28xx_add_into_devlist(struct em28xx *dev);678int em28xx_register_extension(struct em28xx_ops *dev);679void em28xx_unregister_extension(struct em28xx_ops *dev);680void em28xx_init_extension(struct em28xx *dev);681void em28xx_close_extension(struct em28xx *dev);682683/* Provided by em28xx-video.c */684int em28xx_register_analog_devices(struct em28xx *dev);685void em28xx_release_analog_resources(struct em28xx *dev);686687/* Provided by em28xx-cards.c */688extern int em2800_variant_detect(struct usb_device *udev, int model);689extern void em28xx_pre_card_setup(struct em28xx *dev);690extern void em28xx_card_setup(struct em28xx *dev);691extern struct em28xx_board em28xx_boards[];692extern struct usb_device_id em28xx_id_table[];693extern const unsigned int em28xx_bcount;694void em28xx_register_i2c_ir(struct em28xx *dev);695int em28xx_tuner_callback(void *ptr, int component, int command, int arg);696void em28xx_release_resources(struct em28xx *dev);697698/* Provided by em28xx-input.c */699int em28xx_get_key_terratec(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw);700int em28xx_get_key_em_haup(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw);701int em28xx_get_key_pinnacle_usb_grey(struct IR_i2c *ir, u32 *ir_key,702u32 *ir_raw);703int em28xx_get_key_winfast_usbii_deluxe(struct IR_i2c *ir, u32 *ir_key,704u32 *ir_raw);705void em28xx_register_snapshot_button(struct em28xx *dev);706void em28xx_deregister_snapshot_button(struct em28xx *dev);707708int em28xx_ir_init(struct em28xx *dev);709int em28xx_ir_fini(struct em28xx *dev);710711/* Provided by em28xx-vbi.c */712extern struct videobuf_queue_ops em28xx_vbi_qops;713714/* printk macros */715716#define em28xx_err(fmt, arg...) do {\717printk(KERN_ERR fmt , ##arg); } while (0)718719#define em28xx_errdev(fmt, arg...) do {\720printk(KERN_ERR "%s: "fmt,\721dev->name , ##arg); } while (0)722723#define em28xx_info(fmt, arg...) do {\724printk(KERN_INFO "%s: "fmt,\725dev->name , ##arg); } while (0)726#define em28xx_warn(fmt, arg...) do {\727printk(KERN_WARNING "%s: "fmt,\728dev->name , ##arg); } while (0)729730static inline int em28xx_compression_disable(struct em28xx *dev)731{732/* side effect of disabling scaler and mixer */733return em28xx_write_reg(dev, EM28XX_R26_COMPR, 0x00);734}735736static inline int em28xx_contrast_get(struct em28xx *dev)737{738return em28xx_read_reg(dev, EM28XX_R20_YGAIN) & 0x1f;739}740741static inline int em28xx_brightness_get(struct em28xx *dev)742{743return em28xx_read_reg(dev, EM28XX_R21_YOFFSET);744}745746static inline int em28xx_saturation_get(struct em28xx *dev)747{748return em28xx_read_reg(dev, EM28XX_R22_UVGAIN) & 0x1f;749}750751static inline int em28xx_u_balance_get(struct em28xx *dev)752{753return em28xx_read_reg(dev, EM28XX_R23_UOFFSET);754}755756static inline int em28xx_v_balance_get(struct em28xx *dev)757{758return em28xx_read_reg(dev, EM28XX_R24_VOFFSET);759}760761static inline int em28xx_gamma_get(struct em28xx *dev)762{763return em28xx_read_reg(dev, EM28XX_R14_GAMMA) & 0x3f;764}765766static inline int em28xx_contrast_set(struct em28xx *dev, s32 val)767{768u8 tmp = (u8) val;769return em28xx_write_regs(dev, EM28XX_R20_YGAIN, &tmp, 1);770}771772static inline int em28xx_brightness_set(struct em28xx *dev, s32 val)773{774u8 tmp = (u8) val;775return em28xx_write_regs(dev, EM28XX_R21_YOFFSET, &tmp, 1);776}777778static inline int em28xx_saturation_set(struct em28xx *dev, s32 val)779{780u8 tmp = (u8) val;781return em28xx_write_regs(dev, EM28XX_R22_UVGAIN, &tmp, 1);782}783784static inline int em28xx_u_balance_set(struct em28xx *dev, s32 val)785{786u8 tmp = (u8) val;787return em28xx_write_regs(dev, EM28XX_R23_UOFFSET, &tmp, 1);788}789790static inline int em28xx_v_balance_set(struct em28xx *dev, s32 val)791{792u8 tmp = (u8) val;793return em28xx_write_regs(dev, EM28XX_R24_VOFFSET, &tmp, 1);794}795796static inline int em28xx_gamma_set(struct em28xx *dev, s32 val)797{798u8 tmp = (u8) val;799return em28xx_write_regs(dev, EM28XX_R14_GAMMA, &tmp, 1);800}801802/*FIXME: maxw should be dependent of alt mode */803static inline unsigned int norm_maxw(struct em28xx *dev)804{805if (dev->board.is_webcam)806return dev->sensor_xres;807808if (dev->board.max_range_640_480 || dev->board.is_em2800)809return 640;810811return 720;812}813814static inline unsigned int norm_maxh(struct em28xx *dev)815{816if (dev->board.is_webcam)817return dev->sensor_yres;818819if (dev->board.max_range_640_480)820return 480;821822return (dev->norm & V4L2_STD_625_50) ? 576 : 480;823}824#endif825826827