em28xx.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835
  1. /*
  2. em28xx.h - driver for Empia EM2800/EM2820/2840 USB video capture devices
  3. Copyright (C) 2005 Markus Rechberger <mrechberger@gmail.com>
  4. Ludovico Cavedon <cavedon@sssup.it>
  5. Mauro Carvalho Chehab <mchehab@infradead.org>
  6. Copyright (C) 2012 Frank Schäfer <fschaefer.oss@googlemail.com>
  7. Based on the em2800 driver from Sascha Sommer <saschasommer@freenet.de>
  8. This program is free software; you can redistribute it and/or modify
  9. it under the terms of the GNU General Public License as published by
  10. the Free Software Foundation; either version 2 of the License, or
  11. (at your option) any later version.
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. GNU General Public License for more details.
  16. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software
  18. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19. */
  20. #ifndef _EM28XX_H
  21. #define _EM28XX_H
  22. #include <linux/workqueue.h>
  23. #include <linux/i2c.h>
  24. #include <linux/mutex.h>
  25. #include <linux/videodev2.h>
  26. #include <media/videobuf2-vmalloc.h>
  27. #include <media/v4l2-device.h>
  28. #include <media/v4l2-ctrls.h>
  29. #include <media/v4l2-fh.h>
  30. #include <media/ir-kbd-i2c.h>
  31. #include <media/rc-core.h>
  32. #include "tuner-xc2028.h"
  33. #include "xc5000.h"
  34. #include "em28xx-reg.h"
  35. /* Boards supported by driver */
  36. #define EM2800_BOARD_UNKNOWN 0
  37. #define EM2820_BOARD_UNKNOWN 1
  38. #define EM2820_BOARD_TERRATEC_CINERGY_250 2
  39. #define EM2820_BOARD_PINNACLE_USB_2 3
  40. #define EM2820_BOARD_HAUPPAUGE_WINTV_USB_2 4
  41. #define EM2820_BOARD_MSI_VOX_USB_2 5
  42. #define EM2800_BOARD_TERRATEC_CINERGY_200 6
  43. #define EM2800_BOARD_LEADTEK_WINFAST_USBII 7
  44. #define EM2800_BOARD_KWORLD_USB2800 8
  45. #define EM2820_BOARD_PINNACLE_DVC_90 9
  46. #define EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900 10
  47. #define EM2880_BOARD_TERRATEC_HYBRID_XS 11
  48. #define EM2820_BOARD_KWORLD_PVRTV2800RF 12
  49. #define EM2880_BOARD_TERRATEC_PRODIGY_XS 13
  50. #define EM2820_BOARD_PROLINK_PLAYTV_USB2 14
  51. #define EM2800_BOARD_VGEAR_POCKETTV 15
  52. #define EM2883_BOARD_HAUPPAUGE_WINTV_HVR_950 16
  53. #define EM2880_BOARD_PINNACLE_PCTV_HD_PRO 17
  54. #define EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900_R2 18
  55. #define EM2860_BOARD_SAA711X_REFERENCE_DESIGN 19
  56. #define EM2880_BOARD_AMD_ATI_TV_WONDER_HD_600 20
  57. #define EM2800_BOARD_GRABBEEX_USB2800 21
  58. #define EM2750_BOARD_UNKNOWN 22
  59. #define EM2750_BOARD_DLCW_130 23
  60. #define EM2820_BOARD_DLINK_USB_TV 24
  61. #define EM2820_BOARD_GADMEI_UTV310 25
  62. #define EM2820_BOARD_HERCULES_SMART_TV_USB2 26
  63. #define EM2820_BOARD_PINNACLE_USB_2_FM1216ME 27
  64. #define EM2820_BOARD_LEADTEK_WINFAST_USBII_DELUXE 28
  65. #define EM2860_BOARD_TVP5150_REFERENCE_DESIGN 29
  66. #define EM2820_BOARD_VIDEOLOGY_20K14XUSB 30
  67. #define EM2821_BOARD_USBGEAR_VD204 31
  68. #define EM2821_BOARD_SUPERCOMP_USB_2 32
  69. #define EM2860_BOARD_ELGATO_VIDEO_CAPTURE 33
  70. #define EM2860_BOARD_TERRATEC_HYBRID_XS 34
  71. #define EM2860_BOARD_TYPHOON_DVD_MAKER 35
  72. #define EM2860_BOARD_NETGMBH_CAM 36
  73. #define EM2860_BOARD_GADMEI_UTV330 37
  74. #define EM2861_BOARD_YAKUMO_MOVIE_MIXER 38
  75. #define EM2861_BOARD_KWORLD_PVRTV_300U 39
  76. #define EM2861_BOARD_PLEXTOR_PX_TV100U 40
  77. #define EM2870_BOARD_KWORLD_350U 41
  78. #define EM2870_BOARD_KWORLD_355U 42
  79. #define EM2870_BOARD_TERRATEC_XS 43
  80. #define EM2870_BOARD_TERRATEC_XS_MT2060 44
  81. #define EM2870_BOARD_PINNACLE_PCTV_DVB 45
  82. #define EM2870_BOARD_COMPRO_VIDEOMATE 46
  83. #define EM2880_BOARD_KWORLD_DVB_305U 47
  84. #define EM2880_BOARD_KWORLD_DVB_310U 48
  85. #define EM2880_BOARD_MSI_DIGIVOX_AD 49
  86. #define EM2880_BOARD_MSI_DIGIVOX_AD_II 50
  87. #define EM2880_BOARD_TERRATEC_HYBRID_XS_FR 51
  88. #define EM2881_BOARD_DNT_DA2_HYBRID 52
  89. #define EM2881_BOARD_PINNACLE_HYBRID_PRO 53
  90. #define EM2882_BOARD_KWORLD_VS_DVBT 54
  91. #define EM2882_BOARD_TERRATEC_HYBRID_XS 55
  92. #define EM2882_BOARD_PINNACLE_HYBRID_PRO_330E 56
  93. #define EM2883_BOARD_KWORLD_HYBRID_330U 57
  94. #define EM2820_BOARD_COMPRO_VIDEOMATE_FORYOU 58
  95. #define EM2883_BOARD_HAUPPAUGE_WINTV_HVR_850 60
  96. #define EM2820_BOARD_PROLINK_PLAYTV_BOX4_USB2 61
  97. #define EM2820_BOARD_GADMEI_TVR200 62
  98. #define EM2860_BOARD_KAIOMY_TVNPC_U2 63
  99. #define EM2860_BOARD_EASYCAP 64
  100. #define EM2820_BOARD_IODATA_GVMVP_SZ 65
  101. #define EM2880_BOARD_EMPIRE_DUAL_TV 66
  102. #define EM2860_BOARD_TERRATEC_GRABBY 67
  103. #define EM2860_BOARD_TERRATEC_AV350 68
  104. #define EM2882_BOARD_KWORLD_ATSC_315U 69
  105. #define EM2882_BOARD_EVGA_INDTUBE 70
  106. #define EM2820_BOARD_SILVERCREST_WEBCAM 71
  107. #define EM2861_BOARD_GADMEI_UTV330PLUS 72
  108. #define EM2870_BOARD_REDDO_DVB_C_USB_BOX 73
  109. #define EM2800_BOARD_VC211A 74
  110. #define EM2882_BOARD_DIKOM_DK300 75
  111. #define EM2870_BOARD_KWORLD_A340 76
  112. #define EM2874_BOARD_LEADERSHIP_ISDBT 77
  113. #define EM28174_BOARD_PCTV_290E 78
  114. #define EM2884_BOARD_TERRATEC_H5 79
  115. #define EM28174_BOARD_PCTV_460E 80
  116. #define EM2884_BOARD_HAUPPAUGE_WINTV_HVR_930C 81
  117. #define EM2884_BOARD_CINERGY_HTC_STICK 82
  118. #define EM2860_BOARD_HT_VIDBOX_NW03 83
  119. #define EM2874_BOARD_MAXMEDIA_UB425_TC 84
  120. #define EM2884_BOARD_PCTV_510E 85
  121. #define EM2884_BOARD_PCTV_520E 86
  122. #define EM2884_BOARD_TERRATEC_HTC_USB_XS 87
  123. /* Limits minimum and default number of buffers */
  124. #define EM28XX_MIN_BUF 4
  125. #define EM28XX_DEF_BUF 8
  126. /*Limits the max URB message size */
  127. #define URB_MAX_CTRL_SIZE 80
  128. /* Params for validated field */
  129. #define EM28XX_BOARD_NOT_VALIDATED 1
  130. #define EM28XX_BOARD_VALIDATED 0
  131. /* Params for em28xx_cmd() audio */
  132. #define EM28XX_START_AUDIO 1
  133. #define EM28XX_STOP_AUDIO 0
  134. /* maximum number of em28xx boards */
  135. #define EM28XX_MAXBOARDS 4 /*FIXME: should be bigger */
  136. /* maximum number of frames that can be queued */
  137. #define EM28XX_NUM_FRAMES 5
  138. /* number of frames that get used for v4l2_read() */
  139. #define EM28XX_NUM_READ_FRAMES 2
  140. /* number of buffers for isoc transfers */
  141. #define EM28XX_NUM_BUFS 5
  142. #define EM28XX_DVB_NUM_BUFS 5
  143. /* isoc transfers: number of packets for each buffer
  144. windows requests only 64 packets .. so we better do the same
  145. this is what I found out for all alternate numbers there!
  146. */
  147. #define EM28XX_NUM_ISOC_PACKETS 64
  148. #define EM28XX_DVB_NUM_ISOC_PACKETS 64
  149. /* bulk transfers: transfer buffer size = packet size * packet multiplier
  150. USB 2.0 spec says bulk packet size is always 512 bytes
  151. */
  152. #define EM28XX_BULK_PACKET_MULTIPLIER 384
  153. #define EM28XX_DVB_BULK_PACKET_MULTIPLIER 384
  154. #define EM28XX_INTERLACED_DEFAULT 1
  155. /*
  156. #define (use usbview if you want to get the other alternate number infos)
  157. #define
  158. #define alternate number 2
  159. #define Endpoint Address: 82
  160. Direction: in
  161. Attribute: 1
  162. Type: Isoc
  163. Max Packet Size: 1448
  164. Interval: 125us
  165. alternate number 7
  166. Endpoint Address: 82
  167. Direction: in
  168. Attribute: 1
  169. Type: Isoc
  170. Max Packet Size: 3072
  171. Interval: 125us
  172. */
  173. /* time in msecs to wait for i2c writes to finish */
  174. #define EM2800_I2C_XFER_TIMEOUT 20
  175. enum em28xx_mode {
  176. EM28XX_SUSPEND,
  177. EM28XX_ANALOG_MODE,
  178. EM28XX_DIGITAL_MODE,
  179. };
  180. struct em28xx;
  181. struct em28xx_usb_bufs {
  182. /* max packet size of isoc transaction */
  183. int max_pkt_size;
  184. /* number of packets in each buffer */
  185. int num_packets;
  186. /* number of allocated urbs */
  187. int num_bufs;
  188. /* urb for isoc/bulk transfers */
  189. struct urb **urb;
  190. /* transfer buffers for isoc/bulk transfer */
  191. char **transfer_buffer;
  192. };
  193. struct em28xx_usb_ctl {
  194. /* isoc/bulk transfer buffers for analog mode */
  195. struct em28xx_usb_bufs analog_bufs;
  196. /* isoc/bulk transfer buffers for digital mode */
  197. struct em28xx_usb_bufs digital_bufs;
  198. /* Stores already requested buffers */
  199. struct em28xx_buffer *vid_buf;
  200. struct em28xx_buffer *vbi_buf;
  201. /* copy data from URB */
  202. int (*urb_data_copy) (struct em28xx *dev, struct urb *urb);
  203. };
  204. /* Struct to enumberate video formats */
  205. struct em28xx_fmt {
  206. char *name;
  207. u32 fourcc; /* v4l2 format id */
  208. int depth;
  209. int reg;
  210. };
  211. /* buffer for one video frame */
  212. struct em28xx_buffer {
  213. /* common v4l buffer stuff -- must be first */
  214. struct vb2_buffer vb;
  215. struct list_head list;
  216. void *mem;
  217. unsigned int length;
  218. int top_field;
  219. /* counter to control buffer fill */
  220. unsigned int pos;
  221. /* NOTE; in interlaced mode, this value is reset to zero at
  222. * the start of each new field (not frame !) */
  223. /* pointer to vmalloc memory address in vb */
  224. char *vb_buf;
  225. };
  226. struct em28xx_dmaqueue {
  227. struct list_head active;
  228. wait_queue_head_t wq;
  229. };
  230. /* inputs */
  231. #define MAX_EM28XX_INPUT 4
  232. enum enum28xx_itype {
  233. EM28XX_VMUX_COMPOSITE1 = 1,
  234. EM28XX_VMUX_COMPOSITE2,
  235. EM28XX_VMUX_COMPOSITE3,
  236. EM28XX_VMUX_COMPOSITE4,
  237. EM28XX_VMUX_SVIDEO,
  238. EM28XX_VMUX_TELEVISION,
  239. EM28XX_VMUX_CABLE,
  240. EM28XX_VMUX_DVB,
  241. EM28XX_VMUX_DEBUG,
  242. EM28XX_RADIO,
  243. };
  244. enum em28xx_ac97_mode {
  245. EM28XX_NO_AC97 = 0,
  246. EM28XX_AC97_EM202,
  247. EM28XX_AC97_SIGMATEL,
  248. EM28XX_AC97_OTHER,
  249. };
  250. struct em28xx_audio_mode {
  251. enum em28xx_ac97_mode ac97;
  252. u16 ac97_feat;
  253. u32 ac97_vendor_id;
  254. unsigned int has_audio:1;
  255. unsigned int i2s_3rates:1;
  256. unsigned int i2s_5rates:1;
  257. };
  258. /* em28xx has two audio inputs: tuner and line in.
  259. However, on most devices, an auxiliary AC97 codec device is used.
  260. The AC97 device may have several different inputs and outputs,
  261. depending on their model. So, it is possible to use AC97 mixer to
  262. address more than two different entries.
  263. */
  264. enum em28xx_amux {
  265. /* This is the only entry for em28xx tuner input */
  266. EM28XX_AMUX_VIDEO, /* em28xx tuner, AC97 mixer Video */
  267. EM28XX_AMUX_LINE_IN, /* AC97 mixer Line In */
  268. /* Some less-common mixer setups */
  269. EM28XX_AMUX_VIDEO2, /* em28xx Line in, AC97 mixer Video */
  270. EM28XX_AMUX_PHONE,
  271. EM28XX_AMUX_MIC,
  272. EM28XX_AMUX_CD,
  273. EM28XX_AMUX_AUX,
  274. EM28XX_AMUX_PCM_OUT,
  275. };
  276. enum em28xx_aout {
  277. /* AC97 outputs */
  278. EM28XX_AOUT_MASTER = 1 << 0,
  279. EM28XX_AOUT_LINE = 1 << 1,
  280. EM28XX_AOUT_MONO = 1 << 2,
  281. EM28XX_AOUT_LFE = 1 << 3,
  282. EM28XX_AOUT_SURR = 1 << 4,
  283. /* PCM IN Mixer - used by AC97_RECORD_SELECT register */
  284. EM28XX_AOUT_PCM_IN = 1 << 7,
  285. /* Bits 10-8 are used to indicate the PCM IN record select */
  286. EM28XX_AOUT_PCM_MIC_PCM = 0 << 8,
  287. EM28XX_AOUT_PCM_CD = 1 << 8,
  288. EM28XX_AOUT_PCM_VIDEO = 2 << 8,
  289. EM28XX_AOUT_PCM_AUX = 3 << 8,
  290. EM28XX_AOUT_PCM_LINE = 4 << 8,
  291. EM28XX_AOUT_PCM_STEREO = 5 << 8,
  292. EM28XX_AOUT_PCM_MONO = 6 << 8,
  293. EM28XX_AOUT_PCM_PHONE = 7 << 8,
  294. };
  295. static inline int ac97_return_record_select(int a_out)
  296. {
  297. return (a_out & 0x700) >> 8;
  298. }
  299. struct em28xx_reg_seq {
  300. int reg;
  301. unsigned char val, mask;
  302. int sleep;
  303. };
  304. struct em28xx_input {
  305. enum enum28xx_itype type;
  306. unsigned int vmux;
  307. enum em28xx_amux amux;
  308. enum em28xx_aout aout;
  309. struct em28xx_reg_seq *gpio;
  310. };
  311. #define INPUT(nr) (&em28xx_boards[dev->model].input[nr])
  312. enum em28xx_decoder {
  313. EM28XX_NODECODER = 0,
  314. EM28XX_TVP5150,
  315. EM28XX_SAA711X,
  316. };
  317. enum em28xx_sensor {
  318. EM28XX_NOSENSOR = 0,
  319. EM28XX_MT9V011,
  320. EM28XX_MT9M001,
  321. EM28XX_MT9M111,
  322. };
  323. enum em28xx_adecoder {
  324. EM28XX_NOADECODER = 0,
  325. EM28XX_TVAUDIO,
  326. };
  327. struct em28xx_board {
  328. char *name;
  329. int vchannels;
  330. int tuner_type;
  331. int tuner_addr;
  332. /* i2c flags */
  333. unsigned int tda9887_conf;
  334. /* GPIO sequences */
  335. struct em28xx_reg_seq *dvb_gpio;
  336. struct em28xx_reg_seq *suspend_gpio;
  337. struct em28xx_reg_seq *tuner_gpio;
  338. struct em28xx_reg_seq *mute_gpio;
  339. unsigned int is_em2800:1;
  340. unsigned int has_msp34xx:1;
  341. unsigned int mts_firmware:1;
  342. unsigned int max_range_640_480:1;
  343. unsigned int has_dvb:1;
  344. unsigned int has_snapshot_button:1;
  345. unsigned int is_webcam:1;
  346. unsigned int valid:1;
  347. unsigned int has_ir_i2c:1;
  348. unsigned char xclk, i2c_speed;
  349. unsigned char radio_addr;
  350. unsigned short tvaudio_addr;
  351. enum em28xx_decoder decoder;
  352. enum em28xx_adecoder adecoder;
  353. struct em28xx_input input[MAX_EM28XX_INPUT];
  354. struct em28xx_input radio;
  355. char *ir_codes;
  356. };
  357. struct em28xx_eeprom {
  358. u32 id; /* 0x9567eb1a */
  359. u16 vendor_ID;
  360. u16 product_ID;
  361. u16 chip_conf;
  362. u16 board_conf;
  363. u16 string1, string2, string3;
  364. u8 string_idx_table;
  365. };
  366. #define EM28XX_AUDIO_BUFS 5
  367. #define EM28XX_NUM_AUDIO_PACKETS 64
  368. #define EM28XX_AUDIO_MAX_PACKET_SIZE 196 /* static value */
  369. #define EM28XX_CAPTURE_STREAM_EN 1
  370. /* em28xx extensions */
  371. #define EM28XX_AUDIO 0x10
  372. #define EM28XX_DVB 0x20
  373. #define EM28XX_RC 0x30
  374. /* em28xx resource types (used for res_get/res_lock etc */
  375. #define EM28XX_RESOURCE_VIDEO 0x01
  376. #define EM28XX_RESOURCE_VBI 0x02
  377. struct em28xx_audio {
  378. char name[50];
  379. char *transfer_buffer[EM28XX_AUDIO_BUFS];
  380. struct urb *urb[EM28XX_AUDIO_BUFS];
  381. struct usb_device *udev;
  382. unsigned int capture_transfer_done;
  383. struct snd_pcm_substream *capture_pcm_substream;
  384. unsigned int hwptr_done_capture;
  385. struct snd_card *sndcard;
  386. int users;
  387. spinlock_t slock;
  388. };
  389. struct em28xx;
  390. struct em28xx_fh {
  391. struct v4l2_fh fh;
  392. struct em28xx *dev;
  393. enum v4l2_buf_type type;
  394. };
  395. /* main device struct */
  396. struct em28xx {
  397. /* generic device properties */
  398. char name[30]; /* name (including minor) of the device */
  399. int model; /* index in the device_data struct */
  400. int devno; /* marks the number of this device */
  401. enum em28xx_chip_id chip_id;
  402. unsigned char disconnected:1; /* device has been diconnected */
  403. int audio_ifnum;
  404. struct v4l2_device v4l2_dev;
  405. struct v4l2_ctrl_handler ctrl_handler;
  406. /* provides ac97 mute and volume overrides */
  407. struct v4l2_ctrl_handler ac97_ctrl_handler;
  408. struct em28xx_board board;
  409. /* Webcam specific fields */
  410. enum em28xx_sensor em28xx_sensor;
  411. int sensor_xres, sensor_yres;
  412. int sensor_xtal;
  413. /* Progressive (non-interlaced) mode */
  414. int progressive;
  415. /* Vinmode/Vinctl used at the driver */
  416. int vinmode, vinctl;
  417. unsigned int has_audio_class:1;
  418. unsigned int has_alsa_audio:1;
  419. unsigned int is_audio_only:1;
  420. /* Controls audio streaming */
  421. struct work_struct wq_trigger; /* Trigger to start/stop audio for alsa module */
  422. atomic_t stream_started; /* stream should be running if true */
  423. struct em28xx_fmt *format;
  424. struct em28xx_IR *ir;
  425. /* Some older em28xx chips needs a waiting time after writing */
  426. unsigned int wait_after_write;
  427. struct list_head devlist;
  428. u32 i2s_speed; /* I2S speed for audio digital stream */
  429. struct em28xx_audio_mode audio_mode;
  430. int tuner_type; /* type of the tuner */
  431. int tuner_addr; /* tuner address */
  432. int tda9887_conf;
  433. /* i2c i/o */
  434. struct i2c_adapter i2c_adap;
  435. struct i2c_client i2c_client;
  436. /* video for linux */
  437. int users; /* user count for exclusive use */
  438. int streaming_users; /* Number of actively streaming users */
  439. struct video_device *vdev; /* video for linux device struct */
  440. v4l2_std_id norm; /* selected tv norm */
  441. int ctl_freq; /* selected frequency */
  442. unsigned int ctl_input; /* selected input */
  443. unsigned int ctl_ainput;/* selected audio input */
  444. unsigned int ctl_aoutput;/* selected audio output */
  445. int mute;
  446. int volume;
  447. /* frame properties */
  448. int width; /* current frame width */
  449. int height; /* current frame height */
  450. unsigned hscale; /* horizontal scale factor (see datasheet) */
  451. unsigned vscale; /* vertical scale factor (see datasheet) */
  452. int interlaced; /* 1=interlace fileds, 0=just top fileds */
  453. unsigned int video_bytesread; /* Number of bytes read */
  454. unsigned long hash; /* eeprom hash - for boards with generic ID */
  455. unsigned long i2c_hash; /* i2c devicelist hash -
  456. for boards with generic ID */
  457. struct em28xx_audio adev;
  458. /* capture state tracking */
  459. int capture_type;
  460. unsigned char top_field:1;
  461. int vbi_read;
  462. unsigned int vbi_width;
  463. unsigned int vbi_height; /* lines per field */
  464. struct work_struct request_module_wk;
  465. /* locks */
  466. struct mutex lock;
  467. struct mutex ctrl_urb_lock; /* protects urb_buf */
  468. /* spinlock_t queue_lock; */
  469. struct list_head inqueue, outqueue;
  470. struct video_device *vbi_dev;
  471. struct video_device *radio_dev;
  472. /* Videobuf2 */
  473. struct vb2_queue vb_vidq;
  474. struct vb2_queue vb_vbiq;
  475. struct mutex vb_queue_lock;
  476. struct mutex vb_vbi_queue_lock;
  477. /* resources in use */
  478. unsigned int resources;
  479. unsigned char eedata[256];
  480. /* Isoc control struct */
  481. struct em28xx_dmaqueue vidq;
  482. struct em28xx_dmaqueue vbiq;
  483. struct em28xx_usb_ctl usb_ctl;
  484. spinlock_t slock;
  485. unsigned int field_count;
  486. unsigned int vbi_field_count;
  487. /* usb transfer */
  488. struct usb_device *udev; /* the usb device */
  489. u8 analog_ep_isoc; /* address of isoc endpoint for analog */
  490. u8 analog_ep_bulk; /* address of bulk endpoint for analog */
  491. u8 dvb_ep_isoc; /* address of isoc endpoint for DVB */
  492. u8 dvb_ep_bulk; /* address of bulk endpoint for DVC */
  493. int alt; /* alternate setting */
  494. int max_pkt_size; /* max packet size of the selected ep at alt */
  495. int packet_multiplier; /* multiplier for wMaxPacketSize, used for
  496. URB buffer size definition */
  497. int num_alt; /* number of alternative settings */
  498. unsigned int *alt_max_pkt_size_isoc; /* array of isoc wMaxPacketSize */
  499. unsigned int analog_xfer_bulk:1; /* use bulk instead of isoc
  500. transfers for analog */
  501. int dvb_alt_isoc; /* alternate setting for DVB isoc transfers */
  502. unsigned int dvb_max_pkt_size_isoc; /* isoc max packet size of the
  503. selected DVB ep at dvb_alt */
  504. unsigned int dvb_xfer_bulk:1; /* use bulk instead of isoc
  505. transfers for DVB */
  506. char urb_buf[URB_MAX_CTRL_SIZE]; /* urb control msg buffer */
  507. /* helper funcs that call usb_control_msg */
  508. int (*em28xx_write_regs) (struct em28xx *dev, u16 reg,
  509. char *buf, int len);
  510. int (*em28xx_read_reg) (struct em28xx *dev, u16 reg);
  511. int (*em28xx_read_reg_req_len) (struct em28xx *dev, u8 req, u16 reg,
  512. char *buf, int len);
  513. int (*em28xx_write_regs_req) (struct em28xx *dev, u8 req, u16 reg,
  514. char *buf, int len);
  515. int (*em28xx_read_reg_req) (struct em28xx *dev, u8 req, u16 reg);
  516. enum em28xx_mode mode;
  517. /* register numbers for GPO/GPIO registers */
  518. u16 reg_gpo_num, reg_gpio_num;
  519. /* Caches GPO and GPIO registers */
  520. unsigned char reg_gpo, reg_gpio;
  521. /* Snapshot button */
  522. char snapshot_button_path[30]; /* path of the input dev */
  523. struct input_dev *sbutton_input_dev;
  524. struct delayed_work sbutton_query_work;
  525. struct em28xx_dvb *dvb;
  526. };
  527. struct em28xx_ops {
  528. struct list_head next;
  529. char *name;
  530. int id;
  531. int (*init)(struct em28xx *);
  532. int (*fini)(struct em28xx *);
  533. };
  534. /* Provided by em28xx-i2c.c */
  535. void em28xx_do_i2c_scan(struct em28xx *dev);
  536. int em28xx_i2c_register(struct em28xx *dev);
  537. int em28xx_i2c_unregister(struct em28xx *dev);
  538. /* Provided by em28xx-core.c */
  539. u32 em28xx_request_buffers(struct em28xx *dev, u32 count);
  540. void em28xx_queue_unusedframes(struct em28xx *dev);
  541. void em28xx_release_buffers(struct em28xx *dev);
  542. int em28xx_read_reg_req_len(struct em28xx *dev, u8 req, u16 reg,
  543. char *buf, int len);
  544. int em28xx_read_reg_req(struct em28xx *dev, u8 req, u16 reg);
  545. int em28xx_read_reg(struct em28xx *dev, u16 reg);
  546. int em28xx_write_regs_req(struct em28xx *dev, u8 req, u16 reg, char *buf,
  547. int len);
  548. int em28xx_write_regs(struct em28xx *dev, u16 reg, char *buf, int len);
  549. int em28xx_write_reg(struct em28xx *dev, u16 reg, u8 val);
  550. int em28xx_write_reg_bits(struct em28xx *dev, u16 reg, u8 val,
  551. u8 bitmask);
  552. int em28xx_read_ac97(struct em28xx *dev, u8 reg);
  553. int em28xx_write_ac97(struct em28xx *dev, u8 reg, u16 val);
  554. int em28xx_audio_analog_set(struct em28xx *dev);
  555. int em28xx_audio_setup(struct em28xx *dev);
  556. int em28xx_colorlevels_set_default(struct em28xx *dev);
  557. int em28xx_capture_start(struct em28xx *dev, int start);
  558. int em28xx_vbi_supported(struct em28xx *dev);
  559. int em28xx_set_outfmt(struct em28xx *dev);
  560. int em28xx_resolution_set(struct em28xx *dev);
  561. int em28xx_set_alternate(struct em28xx *dev);
  562. int em28xx_alloc_urbs(struct em28xx *dev, enum em28xx_mode mode, int xfer_bulk,
  563. int num_bufs, int max_pkt_size, int packet_multiplier);
  564. int em28xx_init_usb_xfer(struct em28xx *dev, enum em28xx_mode mode,
  565. int xfer_bulk,
  566. int num_bufs, int max_pkt_size, int packet_multiplier,
  567. int (*urb_data_copy)
  568. (struct em28xx *dev, struct urb *urb));
  569. void em28xx_uninit_usb_xfer(struct em28xx *dev, enum em28xx_mode mode);
  570. void em28xx_stop_urbs(struct em28xx *dev);
  571. int em28xx_isoc_dvb_max_packetsize(struct em28xx *dev);
  572. int em28xx_set_mode(struct em28xx *dev, enum em28xx_mode set_mode);
  573. int em28xx_gpio_set(struct em28xx *dev, struct em28xx_reg_seq *gpio);
  574. void em28xx_wake_i2c(struct em28xx *dev);
  575. int em28xx_register_extension(struct em28xx_ops *dev);
  576. void em28xx_unregister_extension(struct em28xx_ops *dev);
  577. void em28xx_init_extension(struct em28xx *dev);
  578. void em28xx_close_extension(struct em28xx *dev);
  579. /* Provided by em28xx-video.c */
  580. int em28xx_vb2_setup(struct em28xx *dev);
  581. int em28xx_register_analog_devices(struct em28xx *dev);
  582. void em28xx_release_analog_resources(struct em28xx *dev);
  583. void em28xx_ctrl_notify(struct v4l2_ctrl *ctrl, void *priv);
  584. int em28xx_start_analog_streaming(struct vb2_queue *vq, unsigned int count);
  585. int em28xx_stop_vbi_streaming(struct vb2_queue *vq);
  586. extern const struct v4l2_ctrl_ops em28xx_ctrl_ops;
  587. /* Provided by em28xx-cards.c */
  588. extern int em2800_variant_detect(struct usb_device *udev, int model);
  589. extern struct em28xx_board em28xx_boards[];
  590. extern struct usb_device_id em28xx_id_table[];
  591. extern const unsigned int em28xx_bcount;
  592. int em28xx_tuner_callback(void *ptr, int component, int command, int arg);
  593. void em28xx_release_resources(struct em28xx *dev);
  594. /* Provided by em28xx-vbi.c */
  595. extern struct vb2_ops em28xx_vbi_qops;
  596. /* printk macros */
  597. #define em28xx_err(fmt, arg...) do {\
  598. printk(KERN_ERR fmt , ##arg); } while (0)
  599. #define em28xx_errdev(fmt, arg...) do {\
  600. printk(KERN_ERR "%s: "fmt,\
  601. dev->name , ##arg); } while (0)
  602. #define em28xx_info(fmt, arg...) do {\
  603. printk(KERN_INFO "%s: "fmt,\
  604. dev->name , ##arg); } while (0)
  605. #define em28xx_warn(fmt, arg...) do {\
  606. printk(KERN_WARNING "%s: "fmt,\
  607. dev->name , ##arg); } while (0)
  608. static inline int em28xx_compression_disable(struct em28xx *dev)
  609. {
  610. /* side effect of disabling scaler and mixer */
  611. return em28xx_write_reg(dev, EM28XX_R26_COMPR, 0x00);
  612. }
  613. static inline int em28xx_contrast_get(struct em28xx *dev)
  614. {
  615. return em28xx_read_reg(dev, EM28XX_R20_YGAIN) & 0x1f;
  616. }
  617. static inline int em28xx_brightness_get(struct em28xx *dev)
  618. {
  619. return em28xx_read_reg(dev, EM28XX_R21_YOFFSET);
  620. }
  621. static inline int em28xx_saturation_get(struct em28xx *dev)
  622. {
  623. return em28xx_read_reg(dev, EM28XX_R22_UVGAIN) & 0x1f;
  624. }
  625. static inline int em28xx_u_balance_get(struct em28xx *dev)
  626. {
  627. return em28xx_read_reg(dev, EM28XX_R23_UOFFSET);
  628. }
  629. static inline int em28xx_v_balance_get(struct em28xx *dev)
  630. {
  631. return em28xx_read_reg(dev, EM28XX_R24_VOFFSET);
  632. }
  633. static inline int em28xx_gamma_get(struct em28xx *dev)
  634. {
  635. return em28xx_read_reg(dev, EM28XX_R14_GAMMA) & 0x3f;
  636. }
  637. static inline int em28xx_contrast_set(struct em28xx *dev, s32 val)
  638. {
  639. u8 tmp = (u8) val;
  640. return em28xx_write_regs(dev, EM28XX_R20_YGAIN, &tmp, 1);
  641. }
  642. static inline int em28xx_brightness_set(struct em28xx *dev, s32 val)
  643. {
  644. u8 tmp = (u8) val;
  645. return em28xx_write_regs(dev, EM28XX_R21_YOFFSET, &tmp, 1);
  646. }
  647. static inline int em28xx_saturation_set(struct em28xx *dev, s32 val)
  648. {
  649. u8 tmp = (u8) val;
  650. return em28xx_write_regs(dev, EM28XX_R22_UVGAIN, &tmp, 1);
  651. }
  652. static inline int em28xx_u_balance_set(struct em28xx *dev, s32 val)
  653. {
  654. u8 tmp = (u8) val;
  655. return em28xx_write_regs(dev, EM28XX_R23_UOFFSET, &tmp, 1);
  656. }
  657. static inline int em28xx_v_balance_set(struct em28xx *dev, s32 val)
  658. {
  659. u8 tmp = (u8) val;
  660. return em28xx_write_regs(dev, EM28XX_R24_VOFFSET, &tmp, 1);
  661. }
  662. static inline int em28xx_gamma_set(struct em28xx *dev, s32 val)
  663. {
  664. u8 tmp = (u8) val;
  665. return em28xx_write_regs(dev, EM28XX_R14_GAMMA, &tmp, 1);
  666. }
  667. /*FIXME: maxw should be dependent of alt mode */
  668. static inline unsigned int norm_maxw(struct em28xx *dev)
  669. {
  670. if (dev->board.is_webcam)
  671. return dev->sensor_xres;
  672. if (dev->board.max_range_640_480)
  673. return 640;
  674. return 720;
  675. }
  676. static inline unsigned int norm_maxh(struct em28xx *dev)
  677. {
  678. if (dev->board.is_webcam)
  679. return dev->sensor_yres;
  680. if (dev->board.max_range_640_480)
  681. return 480;
  682. return (dev->norm & V4L2_STD_625_50) ? 576 : 480;
  683. }
  684. #endif