em28xx.h revision 579d315218e8a3f696e375c5f6917da6488bec8a
13aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab/* 23aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab em28xx.h - driver for Empia EM2800/EM2820/2840 USB video capture devices 33aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab 43aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab Copyright (C) 2005 Markus Rechberger <mrechberger@gmail.com> 53aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab Ludovico Cavedon <cavedon@sssup.it> 6bdfbf9520372daf2b4d6941474c92310848ccb27Devin Heitmueller Mauro Carvalho Chehab <mchehab@infradead.org> 7bdfbf9520372daf2b4d6941474c92310848ccb27Devin Heitmueller 8bdfbf9520372daf2b4d6941474c92310848ccb27Devin Heitmueller Based on the em2800 driver from Sascha Sommer <saschasommer@freenet.de> 93aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab 103aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab This program is free software; you can redistribute it and/or modify 113aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab it under the terms of the GNU General Public License as published by 123aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab the Free Software Foundation; either version 2 of the License, or 133aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab (at your option) any later version. 143aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab 153aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab This program is distributed in the hope that it will be useful, 163aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab but WITHOUT ANY WARRANTY; without even the implied warranty of 173aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 183aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab GNU General Public License for more details. 193aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab 203aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab You should have received a copy of the GNU General Public License 213aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab along with this program; if not, write to the Free Software 223aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 233aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab */ 243aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab 253aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab#ifndef _EM28XX_H 263aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab#define _EM28XX_H 273aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab 283aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab#include <linux/videodev2.h> 293aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab#include <media/videobuf-vmalloc.h> 303aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab#include <media/v4l2-device.h> 313aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab 323aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab#include <linux/i2c.h> 333aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab#include <linux/mutex.h> 343aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab#include <media/ir-kbd-i2c.h> 353aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab#if defined(CONFIG_VIDEO_EM28XX_DVB) || defined(CONFIG_VIDEO_EM28XX_DVB_MODULE) 363aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab#include <media/videobuf-dvb.h> 373aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab#endif 383aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab#include "tuner-xc2028.h" 393aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab#include "em28xx-reg.h" 403aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab 413aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab/* Boards supported by driver */ 423aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab#define EM2800_BOARD_UNKNOWN 0 433aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab#define EM2820_BOARD_UNKNOWN 1 443aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab#define EM2820_BOARD_TERRATEC_CINERGY_250 2 453aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab#define EM2820_BOARD_PINNACLE_USB_2 3 463aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab#define EM2820_BOARD_HAUPPAUGE_WINTV_USB_2 4 473aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab#define EM2820_BOARD_MSI_VOX_USB_2 5 4852284c3e47bf502aaff72ab2ede509193b628b1bMauro Carvalho Chehab#define EM2800_BOARD_TERRATEC_CINERGY_200 6 493aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab#define EM2800_BOARD_LEADTEK_WINFAST_USBII 7 503aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab#define EM2800_BOARD_KWORLD_USB2800 8 513aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab#define EM2820_BOARD_PINNACLE_DVC_90 9 523aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab#define EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900 10 533aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab#define EM2880_BOARD_TERRATEC_HYBRID_XS 11 543aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab#define EM2820_BOARD_KWORLD_PVRTV2800RF 12 553aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab#define EM2880_BOARD_TERRATEC_PRODIGY_XS 13 563aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab#define EM2820_BOARD_PROLINK_PLAYTV_USB2 14 573aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab#define EM2800_BOARD_VGEAR_POCKETTV 15 583aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab#define EM2883_BOARD_HAUPPAUGE_WINTV_HVR_950 16 593aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab#define EM2880_BOARD_PINNACLE_PCTV_HD_PRO 17 603aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab#define EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900_R2 18 613aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab#define EM2860_BOARD_SAA711X_REFERENCE_DESIGN 19 623aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab#define EM2880_BOARD_AMD_ATI_TV_WONDER_HD_600 20 63227ad4ab9058ef2624934183e8083886cf64bf56Mauro Carvalho Chehab#define EM2800_BOARD_GRABBEEX_USB2800 21 64227ad4ab9058ef2624934183e8083886cf64bf56Mauro Carvalho Chehab#define EM2750_BOARD_UNKNOWN 22 65227ad4ab9058ef2624934183e8083886cf64bf56Mauro Carvalho Chehab#define EM2750_BOARD_DLCW_130 23 66227ad4ab9058ef2624934183e8083886cf64bf56Mauro Carvalho Chehab#define EM2820_BOARD_DLINK_USB_TV 24 673aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab#define EM2820_BOARD_GADMEI_UTV310 25 683aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab#define EM2820_BOARD_HERCULES_SMART_TV_USB2 26 693aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab#define EM2820_BOARD_PINNACLE_USB_2_FM1216ME 27 703aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab#define EM2820_BOARD_LEADTEK_WINFAST_USBII_DELUXE 28 713aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab#define EM2820_BOARD_VIDEOLOGY_20K14XUSB 30 723aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab#define EM2821_BOARD_USBGEAR_VD204 31 733aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab#define EM2821_BOARD_SUPERCOMP_USB_2 32 743ca9c09379e8f3be0744c47f72769457fa46e9f3Mauro Carvalho Chehab#define EM2860_BOARD_TERRATEC_HYBRID_XS 34 753ca9c09379e8f3be0744c47f72769457fa46e9f3Mauro Carvalho Chehab#define EM2860_BOARD_TYPHOON_DVD_MAKER 35 763ca9c09379e8f3be0744c47f72769457fa46e9f3Mauro Carvalho Chehab#define EM2860_BOARD_NETGMBH_CAM 36 773ca9c09379e8f3be0744c47f72769457fa46e9f3Mauro Carvalho Chehab#define EM2860_BOARD_GADMEI_UTV330 37 783ca9c09379e8f3be0744c47f72769457fa46e9f3Mauro Carvalho Chehab#define EM2861_BOARD_YAKUMO_MOVIE_MIXER 38 793ca9c09379e8f3be0744c47f72769457fa46e9f3Mauro Carvalho Chehab#define EM2861_BOARD_KWORLD_PVRTV_300U 39 803ca9c09379e8f3be0744c47f72769457fa46e9f3Mauro Carvalho Chehab#define EM2861_BOARD_PLEXTOR_PX_TV100U 40 813ca9c09379e8f3be0744c47f72769457fa46e9f3Mauro Carvalho Chehab#define EM2870_BOARD_KWORLD_350U 41 823ca9c09379e8f3be0744c47f72769457fa46e9f3Mauro Carvalho Chehab#define EM2870_BOARD_KWORLD_355U 42 833aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab#define EM2870_BOARD_TERRATEC_XS 43 843aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab#define EM2870_BOARD_TERRATEC_XS_MT2060 44 853aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab#define EM2870_BOARD_PINNACLE_PCTV_DVB 45 863aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab#define EM2870_BOARD_COMPRO_VIDEOMATE 46 873aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab#define EM2880_BOARD_KWORLD_DVB_305U 47 883aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab#define EM2880_BOARD_KWORLD_DVB_310U 48 893aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab#define EM2880_BOARD_MSI_DIGIVOX_AD 49 903aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab#define EM2880_BOARD_MSI_DIGIVOX_AD_II 50 913aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab#define EM2880_BOARD_TERRATEC_HYBRID_XS_FR 51 923aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab#define EM2881_BOARD_DNT_DA2_HYBRID 52 933aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab#define EM2881_BOARD_PINNACLE_HYBRID_PRO 53 943aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab#define EM2882_BOARD_KWORLD_VS_DVBT 54 953aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab#define EM2882_BOARD_TERRATEC_HYBRID_XS 55 963aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab#define EM2882_BOARD_PINNACLE_HYBRID_PRO 56 973aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab#define EM2883_BOARD_KWORLD_HYBRID_330U 57 983aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab#define EM2820_BOARD_COMPRO_VIDEOMATE_FORYOU 58 993aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab#define EM2883_BOARD_HAUPPAUGE_WINTV_HVR_850 60 1003aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab#define EM2820_BOARD_PROLINK_PLAYTV_BOX4_USB2 61 1013aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab#define EM2820_BOARD_GADMEI_TVR200 62 1023aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab#define EM2860_BOARD_KAIOMY_TVNPC_U2 63 1033aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab#define EM2860_BOARD_EASYCAP 64 1043aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab#define EM2820_BOARD_IODATA_GVMVP_SZ 65 1053aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab#define EM2880_BOARD_EMPIRE_DUAL_TV 66 1063aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab#define EM2860_BOARD_TERRATEC_GRABBY 67 1073aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab#define EM2860_BOARD_TERRATEC_AV350 68 1083aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab#define EM2882_BOARD_KWORLD_ATSC_315U 69 1093aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab#define EM2882_BOARD_EVGA_INDTUBE 70 1103aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab#define EM2820_BOARD_SILVERCREST_WEBCAM 71 1113aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab 1123aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab/* Limits minimum and default number of buffers */ 11352284c3e47bf502aaff72ab2ede509193b628b1bMauro Carvalho Chehab#define EM28XX_MIN_BUF 4 11452284c3e47bf502aaff72ab2ede509193b628b1bMauro Carvalho Chehab#define EM28XX_DEF_BUF 8 11552284c3e47bf502aaff72ab2ede509193b628b1bMauro Carvalho Chehab 11652284c3e47bf502aaff72ab2ede509193b628b1bMauro Carvalho Chehab/*Limits the max URB message size */ 11752284c3e47bf502aaff72ab2ede509193b628b1bMauro Carvalho Chehab#define URB_MAX_CTRL_SIZE 80 1183aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab 1193aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab/* Params for validated field */ 1203aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab#define EM28XX_BOARD_NOT_VALIDATED 1 1213aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab#define EM28XX_BOARD_VALIDATED 0 12252284c3e47bf502aaff72ab2ede509193b628b1bMauro Carvalho Chehab 1233aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab/* Params for em28xx_cmd() audio */ 1243aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab#define EM28XX_START_AUDIO 1 1253aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab#define EM28XX_STOP_AUDIO 0 126227ad4ab9058ef2624934183e8083886cf64bf56Mauro Carvalho Chehab 127227ad4ab9058ef2624934183e8083886cf64bf56Mauro Carvalho Chehab/* maximum number of em28xx boards */ 128bdfbf9520372daf2b4d6941474c92310848ccb27Devin Heitmueller#define EM28XX_MAXBOARDS 4 /*FIXME: should be bigger */ 129227ad4ab9058ef2624934183e8083886cf64bf56Mauro Carvalho Chehab 130227ad4ab9058ef2624934183e8083886cf64bf56Mauro Carvalho Chehab/* maximum number of frames that can be queued */ 131227ad4ab9058ef2624934183e8083886cf64bf56Mauro Carvalho Chehab#define EM28XX_NUM_FRAMES 5 132227ad4ab9058ef2624934183e8083886cf64bf56Mauro Carvalho Chehab/* number of frames that get used for v4l2_read() */ 133227ad4ab9058ef2624934183e8083886cf64bf56Mauro Carvalho Chehab#define EM28XX_NUM_READ_FRAMES 2 134227ad4ab9058ef2624934183e8083886cf64bf56Mauro Carvalho Chehab 135227ad4ab9058ef2624934183e8083886cf64bf56Mauro Carvalho Chehab/* number of buffers for isoc transfers */ 136227ad4ab9058ef2624934183e8083886cf64bf56Mauro Carvalho Chehab#define EM28XX_NUM_BUFS 5 1373aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab 1383aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab/* number of packets for each buffer 1393aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab windows requests only 40 packets .. so we better do the same 1403aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab this is what I found out for all alternate numbers there! 1413aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab */ 1423aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab#define EM28XX_NUM_PACKETS 40 1433aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab 1443aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab/* default alternate; 0 means choose the best */ 1453aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab#define EM28XX_PINOUT 0 1463aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab 1473aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab#define EM28XX_INTERLACED_DEFAULT 1 1483aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab 1493aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab/* 1503aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab#define (use usbview if you want to get the other alternate number infos) 1513aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab#define 1523aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab#define alternate number 2 1533aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab#define Endpoint Address: 82 1543aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab Direction: in 1553aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab Attribute: 1 1563aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab Type: Isoc 1573aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab Max Packet Size: 1448 1583aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab Interval: 125us 1593aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab 1603aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab alternate number 7 1613aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab 1623aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab Endpoint Address: 82 1633aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab Direction: in 1643aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab Attribute: 1 1653aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab Type: Isoc 1663aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab Max Packet Size: 3072 1673aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab Interval: 125us 1683aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab*/ 1693aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab 1703aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab/* time to wait when stopping the isoc transfer */ 1713aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab#define EM28XX_URB_TIMEOUT \ 1723aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab msecs_to_jiffies(EM28XX_NUM_BUFS * EM28XX_NUM_PACKETS) 1733aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab 1743aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab/* time in msecs to wait for i2c writes to finish */ 1753aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab#define EM2800_I2C_WRITE_TIMEOUT 20 1763aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab 1773aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehabenum em28xx_mode { 1783aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab EM28XX_SUSPEND, 1793aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab EM28XX_ANALOG_MODE, 1803aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab EM28XX_DIGITAL_MODE, 1813aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab}; 1823aefb79af8d41c85e11da7109d62038849421bb6Mauro Carvalho Chehab 183enum em28xx_stream_state { 184 STREAM_OFF, 185 STREAM_INTERRUPT, 186 STREAM_ON, 187}; 188 189struct em28xx; 190 191struct em28xx_usb_isoc_ctl { 192 /* max packet size of isoc transaction */ 193 int max_pkt_size; 194 195 /* number of allocated urbs */ 196 int num_bufs; 197 198 /* urb for isoc transfers */ 199 struct urb **urb; 200 201 /* transfer buffers for isoc transfer */ 202 char **transfer_buffer; 203 204 /* Last buffer command and region */ 205 u8 cmd; 206 int pos, size, pktsize; 207 208 /* Last field: ODD or EVEN? */ 209 int field; 210 211 /* Stores incomplete commands */ 212 u32 tmp_buf; 213 int tmp_buf_len; 214 215 /* Stores already requested buffers */ 216 struct em28xx_buffer *buf; 217 218 /* Stores the number of received fields */ 219 int nfields; 220 221 /* isoc urb callback */ 222 int (*isoc_copy) (struct em28xx *dev, struct urb *urb); 223 224}; 225 226/* Struct to enumberate video formats */ 227struct em28xx_fmt { 228 char *name; 229 u32 fourcc; /* v4l2 format id */ 230 int depth; 231 int reg; 232}; 233 234/* buffer for one video frame */ 235struct em28xx_buffer { 236 /* common v4l buffer stuff -- must be first */ 237 struct videobuf_buffer vb; 238 239 struct list_head frame; 240 int top_field; 241 int receiving; 242}; 243 244struct em28xx_dmaqueue { 245 struct list_head active; 246 struct list_head queued; 247 248 wait_queue_head_t wq; 249 250 /* Counters to control buffer fill */ 251 int pos; 252}; 253 254/* io methods */ 255enum em28xx_io_method { 256 IO_NONE, 257 IO_READ, 258 IO_MMAP, 259}; 260 261/* inputs */ 262 263#define MAX_EM28XX_INPUT 4 264enum enum28xx_itype { 265 EM28XX_VMUX_COMPOSITE1 = 1, 266 EM28XX_VMUX_COMPOSITE2, 267 EM28XX_VMUX_COMPOSITE3, 268 EM28XX_VMUX_COMPOSITE4, 269 EM28XX_VMUX_SVIDEO, 270 EM28XX_VMUX_TELEVISION, 271 EM28XX_VMUX_CABLE, 272 EM28XX_VMUX_DVB, 273 EM28XX_VMUX_DEBUG, 274 EM28XX_RADIO, 275}; 276 277enum em28xx_ac97_mode { 278 EM28XX_NO_AC97 = 0, 279 EM28XX_AC97_EM202, 280 EM28XX_AC97_SIGMATEL, 281 EM28XX_AC97_OTHER, 282}; 283 284struct em28xx_audio_mode { 285 enum em28xx_ac97_mode ac97; 286 287 u16 ac97_feat; 288 u32 ac97_vendor_id; 289 290 unsigned int has_audio:1; 291 292 unsigned int i2s_3rates:1; 293 unsigned int i2s_5rates:1; 294}; 295 296/* em28xx has two audio inputs: tuner and line in. 297 However, on most devices, an auxiliary AC97 codec device is used. 298 The AC97 device may have several different inputs and outputs, 299 depending on their model. So, it is possible to use AC97 mixer to 300 address more than two different entries. 301 */ 302enum em28xx_amux { 303 /* This is the only entry for em28xx tuner input */ 304 EM28XX_AMUX_VIDEO, /* em28xx tuner, AC97 mixer Video */ 305 306 EM28XX_AMUX_LINE_IN, /* AC97 mixer Line In */ 307 308 /* Some less-common mixer setups */ 309 EM28XX_AMUX_VIDEO2, /* em28xx Line in, AC97 mixer Video */ 310 EM28XX_AMUX_PHONE, 311 EM28XX_AMUX_MIC, 312 EM28XX_AMUX_CD, 313 EM28XX_AMUX_AUX, 314 EM28XX_AMUX_PCM_OUT, 315}; 316 317enum em28xx_aout { 318 /* AC97 outputs */ 319 EM28XX_AOUT_MASTER = 1 << 0, 320 EM28XX_AOUT_LINE = 1 << 1, 321 EM28XX_AOUT_MONO = 1 << 2, 322 EM28XX_AOUT_LFE = 1 << 3, 323 EM28XX_AOUT_SURR = 1 << 4, 324 325 /* PCM IN Mixer - used by AC97_RECORD_SELECT register */ 326 EM28XX_AOUT_PCM_IN = 1 << 7, 327 328 /* Bits 10-8 are used to indicate the PCM IN record select */ 329 EM28XX_AOUT_PCM_MIC_PCM = 0 << 8, 330 EM28XX_AOUT_PCM_CD = 1 << 8, 331 EM28XX_AOUT_PCM_VIDEO = 2 << 8, 332 EM28XX_AOUT_PCM_AUX = 3 << 8, 333 EM28XX_AOUT_PCM_LINE = 4 << 8, 334 EM28XX_AOUT_PCM_STEREO = 5 << 8, 335 EM28XX_AOUT_PCM_MONO = 6 << 8, 336 EM28XX_AOUT_PCM_PHONE = 7 << 8, 337}; 338 339static inline int ac97_return_record_select(int a_out) 340{ 341 return (a_out & 0x700) >> 8; 342} 343 344struct em28xx_reg_seq { 345 int reg; 346 unsigned char val, mask; 347 int sleep; 348}; 349 350struct em28xx_input { 351 enum enum28xx_itype type; 352 unsigned int vmux; 353 enum em28xx_amux amux; 354 enum em28xx_aout aout; 355 struct em28xx_reg_seq *gpio; 356}; 357 358#define INPUT(nr) (&em28xx_boards[dev->model].input[nr]) 359 360enum em28xx_decoder { 361 EM28XX_NODECODER = 0, 362 EM28XX_TVP5150, 363 EM28XX_SAA711X, 364}; 365 366enum em28xx_sensor { 367 EM28XX_NOSENSOR = 0, 368 EM28XX_MT9V011, 369}; 370 371enum em28xx_adecoder { 372 EM28XX_NOADECODER = 0, 373 EM28XX_TVAUDIO, 374}; 375 376struct em28xx_board { 377 char *name; 378 int vchannels; 379 int tuner_type; 380 int tuner_addr; 381 382 /* i2c flags */ 383 unsigned int tda9887_conf; 384 385 /* GPIO sequences */ 386 struct em28xx_reg_seq *dvb_gpio; 387 struct em28xx_reg_seq *suspend_gpio; 388 struct em28xx_reg_seq *tuner_gpio; 389 struct em28xx_reg_seq *mute_gpio; 390 391 unsigned int is_em2800:1; 392 unsigned int has_msp34xx:1; 393 unsigned int mts_firmware:1; 394 unsigned int max_range_640_480:1; 395 unsigned int has_dvb:1; 396 unsigned int has_snapshot_button:1; 397 unsigned int is_webcam:1; 398 unsigned int valid:1; 399 400 unsigned char xclk, i2c_speed; 401 unsigned char radio_addr; 402 unsigned short tvaudio_addr; 403 404 enum em28xx_decoder decoder; 405 enum em28xx_adecoder adecoder; 406 407 struct em28xx_input input[MAX_EM28XX_INPUT]; 408 struct em28xx_input radio; 409 IR_KEYTAB_TYPE *ir_codes; 410}; 411 412struct em28xx_eeprom { 413 u32 id; /* 0x9567eb1a */ 414 u16 vendor_ID; 415 u16 product_ID; 416 417 u16 chip_conf; 418 419 u16 board_conf; 420 421 u16 string1, string2, string3; 422 423 u8 string_idx_table; 424}; 425 426/* device states */ 427enum em28xx_dev_state { 428 DEV_INITIALIZED = 0x01, 429 DEV_DISCONNECTED = 0x02, 430 DEV_MISCONFIGURED = 0x04, 431}; 432 433#define EM28XX_AUDIO_BUFS 5 434#define EM28XX_NUM_AUDIO_PACKETS 64 435#define EM28XX_AUDIO_MAX_PACKET_SIZE 196 /* static value */ 436#define EM28XX_CAPTURE_STREAM_EN 1 437 438/* em28xx extensions */ 439#define EM28XX_AUDIO 0x10 440#define EM28XX_DVB 0x20 441 442struct em28xx_audio { 443 char name[50]; 444 char *transfer_buffer[EM28XX_AUDIO_BUFS]; 445 struct urb *urb[EM28XX_AUDIO_BUFS]; 446 struct usb_device *udev; 447 unsigned int capture_transfer_done; 448 struct snd_pcm_substream *capture_pcm_substream; 449 450 unsigned int hwptr_done_capture; 451 struct snd_card *sndcard; 452 453 int users; 454 enum em28xx_stream_state capture_stream; 455 spinlock_t slock; 456}; 457 458struct em28xx; 459 460struct em28xx_fh { 461 struct em28xx *dev; 462 unsigned int stream_on:1; /* Locks streams */ 463 int radio; 464 465 struct videobuf_queue vb_vidq; 466 467 enum v4l2_buf_type type; 468}; 469 470/* main device struct */ 471struct em28xx { 472 /* generic device properties */ 473 char name[30]; /* name (including minor) of the device */ 474 int model; /* index in the device_data struct */ 475 int devno; /* marks the number of this device */ 476 enum em28xx_chip_id chip_id; 477 478 struct v4l2_device v4l2_dev; 479 struct em28xx_board board; 480 481 /* Webcam specific fields */ 482 enum em28xx_sensor em28xx_sensor; 483 int sensor_xres, sensor_yres; 484 int sensor_xtal; 485 486 /* Vinmode/Vinctl used at the driver */ 487 int vinmode, vinctl; 488 489 unsigned int stream_on:1; /* Locks streams */ 490 unsigned int has_audio_class:1; 491 unsigned int has_alsa_audio:1; 492 493 struct em28xx_fmt *format; 494 495 struct em28xx_IR *ir; 496 497 /* Some older em28xx chips needs a waiting time after writing */ 498 unsigned int wait_after_write; 499 500 struct list_head devlist; 501 502 u32 i2s_speed; /* I2S speed for audio digital stream */ 503 504 struct em28xx_audio_mode audio_mode; 505 506 int tuner_type; /* type of the tuner */ 507 int tuner_addr; /* tuner address */ 508 int tda9887_conf; 509 /* i2c i/o */ 510 struct i2c_adapter i2c_adap; 511 struct i2c_client i2c_client; 512 /* video for linux */ 513 int users; /* user count for exclusive use */ 514 struct video_device *vdev; /* video for linux device struct */ 515 v4l2_std_id norm; /* selected tv norm */ 516 int ctl_freq; /* selected frequency */ 517 unsigned int ctl_input; /* selected input */ 518 unsigned int ctl_ainput;/* selected audio input */ 519 unsigned int ctl_aoutput;/* selected audio output */ 520 int mute; 521 int volume; 522 /* frame properties */ 523 int width; /* current frame width */ 524 int height; /* current frame height */ 525 unsigned hscale; /* horizontal scale factor (see datasheet) */ 526 unsigned vscale; /* vertical scale factor (see datasheet) */ 527 int interlaced; /* 1=interlace fileds, 0=just top fileds */ 528 unsigned int video_bytesread; /* Number of bytes read */ 529 530 unsigned long hash; /* eeprom hash - for boards with generic ID */ 531 unsigned long i2c_hash; /* i2c devicelist hash - 532 for boards with generic ID */ 533 534 struct em28xx_audio adev; 535 536 /* states */ 537 enum em28xx_dev_state state; 538 enum em28xx_io_method io; 539 540 struct work_struct request_module_wk; 541 542 /* locks */ 543 struct mutex lock; 544 struct mutex ctrl_urb_lock; /* protects urb_buf */ 545 /* spinlock_t queue_lock; */ 546 struct list_head inqueue, outqueue; 547 wait_queue_head_t open, wait_frame, wait_stream; 548 struct video_device *vbi_dev; 549 struct video_device *radio_dev; 550 551 unsigned char eedata[256]; 552 553 /* Isoc control struct */ 554 struct em28xx_dmaqueue vidq; 555 struct em28xx_usb_isoc_ctl isoc_ctl; 556 spinlock_t slock; 557 558 /* usb transfer */ 559 struct usb_device *udev; /* the usb device */ 560 int alt; /* alternate */ 561 int max_pkt_size; /* max packet size of isoc transaction */ 562 int num_alt; /* Number of alternative settings */ 563 unsigned int *alt_max_pkt_size; /* array of wMaxPacketSize */ 564 struct urb *urb[EM28XX_NUM_BUFS]; /* urb for isoc transfers */ 565 char *transfer_buffer[EM28XX_NUM_BUFS]; /* transfer buffers for isoc 566 transfer */ 567 char urb_buf[URB_MAX_CTRL_SIZE]; /* urb control msg buffer */ 568 569 /* helper funcs that call usb_control_msg */ 570 int (*em28xx_write_regs) (struct em28xx *dev, u16 reg, 571 char *buf, int len); 572 int (*em28xx_read_reg) (struct em28xx *dev, u16 reg); 573 int (*em28xx_read_reg_req_len) (struct em28xx *dev, u8 req, u16 reg, 574 char *buf, int len); 575 int (*em28xx_write_regs_req) (struct em28xx *dev, u8 req, u16 reg, 576 char *buf, int len); 577 int (*em28xx_read_reg_req) (struct em28xx *dev, u8 req, u16 reg); 578 579 enum em28xx_mode mode; 580 581 /* register numbers for GPO/GPIO registers */ 582 u16 reg_gpo_num, reg_gpio_num; 583 584 /* Caches GPO and GPIO registers */ 585 unsigned char reg_gpo, reg_gpio; 586 587 /* Snapshot button */ 588 char snapshot_button_path[30]; /* path of the input dev */ 589 struct input_dev *sbutton_input_dev; 590 struct delayed_work sbutton_query_work; 591 592 struct em28xx_dvb *dvb; 593}; 594 595struct em28xx_ops { 596 struct list_head next; 597 char *name; 598 int id; 599 int (*init)(struct em28xx *); 600 int (*fini)(struct em28xx *); 601}; 602 603/* Provided by em28xx-i2c.c */ 604void em28xx_do_i2c_scan(struct em28xx *dev); 605int em28xx_i2c_register(struct em28xx *dev); 606int em28xx_i2c_unregister(struct em28xx *dev); 607 608/* Provided by em28xx-core.c */ 609 610u32 em28xx_request_buffers(struct em28xx *dev, u32 count); 611void em28xx_queue_unusedframes(struct em28xx *dev); 612void em28xx_release_buffers(struct em28xx *dev); 613 614int em28xx_read_reg_req_len(struct em28xx *dev, u8 req, u16 reg, 615 char *buf, int len); 616int em28xx_read_reg_req(struct em28xx *dev, u8 req, u16 reg); 617int em28xx_read_reg(struct em28xx *dev, u16 reg); 618int em28xx_write_regs_req(struct em28xx *dev, u8 req, u16 reg, char *buf, 619 int len); 620int em28xx_write_regs(struct em28xx *dev, u16 reg, char *buf, int len); 621int em28xx_write_reg(struct em28xx *dev, u16 reg, u8 val); 622 623int em28xx_read_ac97(struct em28xx *dev, u8 reg); 624int em28xx_write_ac97(struct em28xx *dev, u8 reg, u16 val); 625 626int em28xx_audio_analog_set(struct em28xx *dev); 627int em28xx_audio_setup(struct em28xx *dev); 628 629int em28xx_colorlevels_set_default(struct em28xx *dev); 630int em28xx_capture_start(struct em28xx *dev, int start); 631int em28xx_set_outfmt(struct em28xx *dev); 632int em28xx_resolution_set(struct em28xx *dev); 633int em28xx_set_alternate(struct em28xx *dev); 634int em28xx_init_isoc(struct em28xx *dev, int max_packets, 635 int num_bufs, int max_pkt_size, 636 int (*isoc_copy) (struct em28xx *dev, struct urb *urb)); 637void em28xx_uninit_isoc(struct em28xx *dev); 638int em28xx_isoc_dvb_max_packetsize(struct em28xx *dev); 639int em28xx_set_mode(struct em28xx *dev, enum em28xx_mode set_mode); 640int em28xx_gpio_set(struct em28xx *dev, struct em28xx_reg_seq *gpio); 641void em28xx_wake_i2c(struct em28xx *dev); 642void em28xx_remove_from_devlist(struct em28xx *dev); 643void em28xx_add_into_devlist(struct em28xx *dev); 644struct em28xx *em28xx_get_device(int minor, 645 enum v4l2_buf_type *fh_type, 646 int *has_radio); 647int em28xx_register_extension(struct em28xx_ops *dev); 648void em28xx_unregister_extension(struct em28xx_ops *dev); 649void em28xx_init_extension(struct em28xx *dev); 650void em28xx_close_extension(struct em28xx *dev); 651 652/* Provided by em28xx-video.c */ 653int em28xx_register_analog_devices(struct em28xx *dev); 654void em28xx_release_analog_resources(struct em28xx *dev); 655 656/* Provided by em28xx-cards.c */ 657extern int em2800_variant_detect(struct usb_device *udev, int model); 658extern void em28xx_pre_card_setup(struct em28xx *dev); 659extern void em28xx_card_setup(struct em28xx *dev); 660extern struct em28xx_board em28xx_boards[]; 661extern struct usb_device_id em28xx_id_table[]; 662extern const unsigned int em28xx_bcount; 663void em28xx_register_i2c_ir(struct em28xx *dev); 664int em28xx_tuner_callback(void *ptr, int component, int command, int arg); 665void em28xx_release_resources(struct em28xx *dev); 666 667/* Provided by em28xx-input.c */ 668int em28xx_get_key_terratec(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw); 669int em28xx_get_key_em_haup(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw); 670int em28xx_get_key_pinnacle_usb_grey(struct IR_i2c *ir, u32 *ir_key, 671 u32 *ir_raw); 672void em28xx_register_snapshot_button(struct em28xx *dev); 673void em28xx_deregister_snapshot_button(struct em28xx *dev); 674 675int em28xx_ir_init(struct em28xx *dev); 676int em28xx_ir_fini(struct em28xx *dev); 677 678/* printk macros */ 679 680#define em28xx_err(fmt, arg...) do {\ 681 printk(KERN_ERR fmt , ##arg); } while (0) 682 683#define em28xx_errdev(fmt, arg...) do {\ 684 printk(KERN_ERR "%s: "fmt,\ 685 dev->name , ##arg); } while (0) 686 687#define em28xx_info(fmt, arg...) do {\ 688 printk(KERN_INFO "%s: "fmt,\ 689 dev->name , ##arg); } while (0) 690#define em28xx_warn(fmt, arg...) do {\ 691 printk(KERN_WARNING "%s: "fmt,\ 692 dev->name , ##arg); } while (0) 693 694static inline int em28xx_compression_disable(struct em28xx *dev) 695{ 696 /* side effect of disabling scaler and mixer */ 697 return em28xx_write_reg(dev, EM28XX_R26_COMPR, 0x00); 698} 699 700static inline int em28xx_contrast_get(struct em28xx *dev) 701{ 702 return em28xx_read_reg(dev, EM28XX_R20_YGAIN) & 0x1f; 703} 704 705static inline int em28xx_brightness_get(struct em28xx *dev) 706{ 707 return em28xx_read_reg(dev, EM28XX_R21_YOFFSET); 708} 709 710static inline int em28xx_saturation_get(struct em28xx *dev) 711{ 712 return em28xx_read_reg(dev, EM28XX_R22_UVGAIN) & 0x1f; 713} 714 715static inline int em28xx_u_balance_get(struct em28xx *dev) 716{ 717 return em28xx_read_reg(dev, EM28XX_R23_UOFFSET); 718} 719 720static inline int em28xx_v_balance_get(struct em28xx *dev) 721{ 722 return em28xx_read_reg(dev, EM28XX_R24_VOFFSET); 723} 724 725static inline int em28xx_gamma_get(struct em28xx *dev) 726{ 727 return em28xx_read_reg(dev, EM28XX_R14_GAMMA) & 0x3f; 728} 729 730static inline int em28xx_contrast_set(struct em28xx *dev, s32 val) 731{ 732 u8 tmp = (u8) val; 733 return em28xx_write_regs(dev, EM28XX_R20_YGAIN, &tmp, 1); 734} 735 736static inline int em28xx_brightness_set(struct em28xx *dev, s32 val) 737{ 738 u8 tmp = (u8) val; 739 return em28xx_write_regs(dev, EM28XX_R21_YOFFSET, &tmp, 1); 740} 741 742static inline int em28xx_saturation_set(struct em28xx *dev, s32 val) 743{ 744 u8 tmp = (u8) val; 745 return em28xx_write_regs(dev, EM28XX_R22_UVGAIN, &tmp, 1); 746} 747 748static inline int em28xx_u_balance_set(struct em28xx *dev, s32 val) 749{ 750 u8 tmp = (u8) val; 751 return em28xx_write_regs(dev, EM28XX_R23_UOFFSET, &tmp, 1); 752} 753 754static inline int em28xx_v_balance_set(struct em28xx *dev, s32 val) 755{ 756 u8 tmp = (u8) val; 757 return em28xx_write_regs(dev, EM28XX_R24_VOFFSET, &tmp, 1); 758} 759 760static inline int em28xx_gamma_set(struct em28xx *dev, s32 val) 761{ 762 u8 tmp = (u8) val; 763 return em28xx_write_regs(dev, EM28XX_R14_GAMMA, &tmp, 1); 764} 765 766/*FIXME: maxw should be dependent of alt mode */ 767static inline unsigned int norm_maxw(struct em28xx *dev) 768{ 769 if (dev->board.is_webcam) 770 return dev->sensor_xres; 771 772 if (dev->board.max_range_640_480) 773 return 640; 774 775 return 720; 776} 777 778static inline unsigned int norm_maxh(struct em28xx *dev) 779{ 780 if (dev->board.is_webcam) 781 return dev->sensor_yres; 782 783 if (dev->board.max_range_640_480) 784 return 480; 785 786 return (dev->norm & V4L2_STD_625_50) ? 576 : 480; 787} 788#endif 789