em28xx.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * em28xx.h - driver for Empia EM2800/EM2820/2840 USB video capture devices
  4. *
  5. * Copyright (C) 2005 Markus Rechberger <mrechberger@gmail.com>
  6. * Ludovico Cavedon <cavedon@sssup.it>
  7. * Mauro Carvalho Chehab <mchehab@kernel.org>
  8. * Copyright (C) 2012 Frank Schäfer <fschaefer.oss@googlemail.com>
  9. *
  10. * Based on the em2800 driver from Sascha Sommer <saschasommer@freenet.de>
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation; either version 2 of the License, or
  15. * (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. */
  22. #ifndef _EM28XX_H
  23. #define _EM28XX_H
  24. #include <linux/bitfield.h>
  25. #define EM28XX_VERSION "0.2.2"
  26. #define DRIVER_DESC "Empia em28xx device driver"
  27. #include <linux/workqueue.h>
  28. #include <linux/i2c.h>
  29. #include <linux/mutex.h>
  30. #include <linux/kref.h>
  31. #include <linux/videodev2.h>
  32. #include <media/videobuf2-v4l2.h>
  33. #include <media/videobuf2-vmalloc.h>
  34. #include <media/v4l2-device.h>
  35. #include <media/v4l2-ctrls.h>
  36. #include <media/v4l2-fh.h>
  37. #include <media/i2c/ir-kbd-i2c.h>
  38. #include <media/rc-core.h>
  39. #include "tuner-xc2028.h"
  40. #include "xc5000.h"
  41. #include "em28xx-reg.h"
  42. /* Boards supported by driver */
  43. #define EM2800_BOARD_UNKNOWN 0
  44. #define EM2820_BOARD_UNKNOWN 1
  45. #define EM2820_BOARD_TERRATEC_CINERGY_250 2
  46. #define EM2820_BOARD_PINNACLE_USB_2 3
  47. #define EM2820_BOARD_HAUPPAUGE_WINTV_USB_2 4
  48. #define EM2820_BOARD_MSI_VOX_USB_2 5
  49. #define EM2800_BOARD_TERRATEC_CINERGY_200 6
  50. #define EM2800_BOARD_LEADTEK_WINFAST_USBII 7
  51. #define EM2800_BOARD_KWORLD_USB2800 8
  52. #define EM2820_BOARD_PINNACLE_DVC_90 9
  53. #define EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900 10
  54. #define EM2880_BOARD_TERRATEC_HYBRID_XS 11
  55. #define EM2820_BOARD_KWORLD_PVRTV2800RF 12
  56. #define EM2880_BOARD_TERRATEC_PRODIGY_XS 13
  57. #define EM2820_BOARD_PROLINK_PLAYTV_USB2 14
  58. #define EM2800_BOARD_VGEAR_POCKETTV 15
  59. #define EM2883_BOARD_HAUPPAUGE_WINTV_HVR_950 16
  60. #define EM2880_BOARD_PINNACLE_PCTV_HD_PRO 17
  61. #define EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900_R2 18
  62. #define EM2860_BOARD_SAA711X_REFERENCE_DESIGN 19
  63. #define EM2880_BOARD_AMD_ATI_TV_WONDER_HD_600 20
  64. #define EM2800_BOARD_GRABBEEX_USB2800 21
  65. #define EM2750_BOARD_UNKNOWN 22
  66. #define EM2750_BOARD_DLCW_130 23
  67. #define EM2820_BOARD_DLINK_USB_TV 24
  68. #define EM2820_BOARD_GADMEI_UTV310 25
  69. #define EM2820_BOARD_HERCULES_SMART_TV_USB2 26
  70. #define EM2820_BOARD_PINNACLE_USB_2_FM1216ME 27
  71. #define EM2820_BOARD_LEADTEK_WINFAST_USBII_DELUXE 28
  72. #define EM2860_BOARD_TVP5150_REFERENCE_DESIGN 29
  73. #define EM2820_BOARD_VIDEOLOGY_20K14XUSB 30
  74. #define EM2821_BOARD_USBGEAR_VD204 31
  75. #define EM2821_BOARD_SUPERCOMP_USB_2 32
  76. #define EM2860_BOARD_ELGATO_VIDEO_CAPTURE 33
  77. #define EM2860_BOARD_TERRATEC_HYBRID_XS 34
  78. #define EM2860_BOARD_TYPHOON_DVD_MAKER 35
  79. #define EM2860_BOARD_NETGMBH_CAM 36
  80. #define EM2860_BOARD_GADMEI_UTV330 37
  81. #define EM2861_BOARD_YAKUMO_MOVIE_MIXER 38
  82. #define EM2861_BOARD_KWORLD_PVRTV_300U 39
  83. #define EM2861_BOARD_PLEXTOR_PX_TV100U 40
  84. #define EM2870_BOARD_KWORLD_350U 41
  85. #define EM2870_BOARD_KWORLD_355U 42
  86. #define EM2870_BOARD_TERRATEC_XS 43
  87. #define EM2870_BOARD_TERRATEC_XS_MT2060 44
  88. #define EM2870_BOARD_PINNACLE_PCTV_DVB 45
  89. #define EM2870_BOARD_COMPRO_VIDEOMATE 46
  90. #define EM2880_BOARD_KWORLD_DVB_305U 47
  91. #define EM2880_BOARD_KWORLD_DVB_310U 48
  92. #define EM2880_BOARD_MSI_DIGIVOX_AD 49
  93. #define EM2880_BOARD_MSI_DIGIVOX_AD_II 50
  94. #define EM2880_BOARD_TERRATEC_HYBRID_XS_FR 51
  95. #define EM2881_BOARD_DNT_DA2_HYBRID 52
  96. #define EM2881_BOARD_PINNACLE_HYBRID_PRO 53
  97. #define EM2882_BOARD_KWORLD_VS_DVBT 54
  98. #define EM2882_BOARD_TERRATEC_HYBRID_XS 55
  99. #define EM2882_BOARD_PINNACLE_HYBRID_PRO_330E 56
  100. #define EM2883_BOARD_KWORLD_HYBRID_330U 57
  101. #define EM2820_BOARD_COMPRO_VIDEOMATE_FORYOU 58
  102. #define EM2874_BOARD_PCTV_HD_MINI_80E 59
  103. #define EM2883_BOARD_HAUPPAUGE_WINTV_HVR_850 60
  104. #define EM2820_BOARD_PROLINK_PLAYTV_BOX4_USB2 61
  105. #define EM2820_BOARD_GADMEI_TVR200 62
  106. #define EM2860_BOARD_KAIOMY_TVNPC_U2 63
  107. #define EM2860_BOARD_EASYCAP 64
  108. #define EM2820_BOARD_IODATA_GVMVP_SZ 65
  109. #define EM2880_BOARD_EMPIRE_DUAL_TV 66
  110. #define EM2860_BOARD_TERRATEC_GRABBY 67
  111. #define EM2860_BOARD_TERRATEC_AV350 68
  112. #define EM2882_BOARD_KWORLD_ATSC_315U 69
  113. #define EM2882_BOARD_EVGA_INDTUBE 70
  114. #define EM2820_BOARD_SILVERCREST_WEBCAM 71
  115. #define EM2861_BOARD_GADMEI_UTV330PLUS 72
  116. #define EM2870_BOARD_REDDO_DVB_C_USB_BOX 73
  117. #define EM2800_BOARD_VC211A 74
  118. #define EM2882_BOARD_DIKOM_DK300 75
  119. #define EM2870_BOARD_KWORLD_A340 76
  120. #define EM2874_BOARD_LEADERSHIP_ISDBT 77
  121. #define EM28174_BOARD_PCTV_290E 78
  122. #define EM2884_BOARD_TERRATEC_H5 79
  123. #define EM28174_BOARD_PCTV_460E 80
  124. #define EM2884_BOARD_HAUPPAUGE_WINTV_HVR_930C 81
  125. #define EM2884_BOARD_CINERGY_HTC_STICK 82
  126. #define EM2860_BOARD_HT_VIDBOX_NW03 83
  127. #define EM2874_BOARD_MAXMEDIA_UB425_TC 84
  128. #define EM2884_BOARD_PCTV_510E 85
  129. #define EM2884_BOARD_PCTV_520E 86
  130. #define EM2884_BOARD_TERRATEC_HTC_USB_XS 87
  131. #define EM2884_BOARD_C3TECH_DIGITAL_DUO 88
  132. #define EM2874_BOARD_DELOCK_61959 89
  133. #define EM2874_BOARD_KWORLD_UB435Q_V2 90
  134. #define EM2765_BOARD_SPEEDLINK_VAD_LAPLACE 91
  135. #define EM28178_BOARD_PCTV_461E 92
  136. #define EM2874_BOARD_KWORLD_UB435Q_V3 93
  137. #define EM28178_BOARD_PCTV_292E 94
  138. #define EM2861_BOARD_LEADTEK_VC100 95
  139. #define EM28178_BOARD_TERRATEC_T2_STICK_HD 96
  140. #define EM2884_BOARD_ELGATO_EYETV_HYBRID_2008 97
  141. #define EM28178_BOARD_PLEX_PX_BCUD 98
  142. #define EM28174_BOARD_HAUPPAUGE_WINTV_DUALHD_DVB 99
  143. #define EM28174_BOARD_HAUPPAUGE_WINTV_DUALHD_01595 100
  144. #define EM2884_BOARD_TERRATEC_H6 101
  145. #define EM2882_BOARD_ZOLID_HYBRID_TV_STICK 102
  146. /* Limits minimum and default number of buffers */
  147. #define EM28XX_MIN_BUF 4
  148. #define EM28XX_DEF_BUF 8
  149. /*Limits the max URB message size */
  150. #define URB_MAX_CTRL_SIZE 80
  151. /* Params for validated field */
  152. #define EM28XX_BOARD_NOT_VALIDATED 1
  153. #define EM28XX_BOARD_VALIDATED 0
  154. /* Params for em28xx_cmd() audio */
  155. #define EM28XX_START_AUDIO 1
  156. #define EM28XX_STOP_AUDIO 0
  157. /* maximum number of em28xx boards */
  158. #define EM28XX_MAXBOARDS DVB_MAX_ADAPTERS /* All adapters could be em28xx */
  159. /* maximum number of frames that can be queued */
  160. #define EM28XX_NUM_FRAMES 5
  161. /* number of frames that get used for v4l2_read() */
  162. #define EM28XX_NUM_READ_FRAMES 2
  163. /* number of buffers for isoc transfers */
  164. #define EM28XX_NUM_BUFS 5
  165. #define EM28XX_DVB_NUM_BUFS 5
  166. /* max number of I2C buses on em28xx devices */
  167. #define NUM_I2C_BUSES 2
  168. /*
  169. * isoc transfers: number of packets for each buffer
  170. * windows requests only 64 packets .. so we better do the same
  171. * this is what I found out for all alternate numbers there!
  172. */
  173. #define EM28XX_NUM_ISOC_PACKETS 64
  174. #define EM28XX_DVB_NUM_ISOC_PACKETS 64
  175. /*
  176. * bulk transfers: transfer buffer size = packet size * packet multiplier
  177. * USB 2.0 spec says bulk packet size is always 512 bytes
  178. */
  179. #define EM28XX_BULK_PACKET_MULTIPLIER 384
  180. #define EM28XX_DVB_BULK_PACKET_MULTIPLIER 94
  181. #define EM28XX_INTERLACED_DEFAULT 1
  182. /* time in msecs to wait for AC97 xfers to finish */
  183. #define EM28XX_AC97_XFER_TIMEOUT 100
  184. /* max. number of button state polling addresses */
  185. #define EM28XX_NUM_BUTTON_ADDRESSES_MAX 5
  186. #define PRIMARY_TS 0
  187. #define SECONDARY_TS 1
  188. enum em28xx_mode {
  189. EM28XX_SUSPEND,
  190. EM28XX_ANALOG_MODE,
  191. EM28XX_DIGITAL_MODE,
  192. };
  193. struct em28xx;
  194. /**
  195. * struct em28xx_usb_bufs - Contains URB-related buffer data
  196. *
  197. * @max_pkt_size: max packet size of isoc transaction
  198. * @num_packets: number of packets in each buffer
  199. * @num_bufs: number of allocated urb
  200. * @urb: urb for isoc/bulk transfers
  201. * @buf: transfer buffers for isoc/bulk transfer
  202. */
  203. struct em28xx_usb_bufs {
  204. int max_pkt_size;
  205. int num_packets;
  206. int num_bufs;
  207. struct urb **urb;
  208. char **buf;
  209. };
  210. /**
  211. * struct em28xx_usb_ctl - Contains URB-related buffer data
  212. *
  213. * @analog_bufs: isoc/bulk transfer buffers for analog mode
  214. * @digital_bufs: isoc/bulk transfer buffers for digital mode
  215. * @vid_buf: Stores already requested video buffers
  216. * @vbi_buf: Stores already requested VBI buffers
  217. * @urb_data_copy: copy data from URB
  218. */
  219. struct em28xx_usb_ctl {
  220. struct em28xx_usb_bufs analog_bufs;
  221. struct em28xx_usb_bufs digital_bufs;
  222. struct em28xx_buffer *vid_buf;
  223. struct em28xx_buffer *vbi_buf;
  224. int (*urb_data_copy)(struct em28xx *dev, struct urb *urb);
  225. };
  226. /**
  227. * struct em28xx_fmt - Struct to enumberate video formats
  228. *
  229. * @name: Name for the video standard
  230. * @fourcc: v4l2 format id
  231. * @depth: mean number of bits to represent a pixel
  232. * @reg: em28xx register value to set it
  233. */
  234. struct em28xx_fmt {
  235. char *name;
  236. u32 fourcc;
  237. int depth;
  238. int reg;
  239. };
  240. /**
  241. * struct em28xx_buffer- buffer for storing one video frame
  242. *
  243. * @vb: common v4l buffer stuff
  244. * @list: List to associate it with the other buffers
  245. * @mem: pointer to the buffer, as returned by vb2_plane_vaddr()
  246. * @length: length of the buffer, as returned by vb2_plane_size()
  247. * @top_field: If non-zero, indicate that the buffer is the top field
  248. * @pos: Indicate the next position of the buffer to be filled.
  249. * @vb_buf: pointer to vmalloc memory address in vb
  250. *
  251. * .. note::
  252. *
  253. * in interlaced mode, @pos is reset to zero at the start of each new
  254. * field (not frame !)
  255. */
  256. struct em28xx_buffer {
  257. struct vb2_v4l2_buffer vb; /* must be first */
  258. struct list_head list;
  259. void *mem;
  260. unsigned int length;
  261. int top_field;
  262. unsigned int pos;
  263. char *vb_buf;
  264. };
  265. struct em28xx_dmaqueue {
  266. struct list_head active;
  267. wait_queue_head_t wq;
  268. };
  269. /* inputs */
  270. #define MAX_EM28XX_INPUT 4
  271. enum enum28xx_itype {
  272. EM28XX_VMUX_COMPOSITE = 1,
  273. EM28XX_VMUX_SVIDEO,
  274. EM28XX_VMUX_TELEVISION,
  275. EM28XX_RADIO,
  276. };
  277. enum em28xx_ac97_mode {
  278. EM28XX_NO_AC97 = 0,
  279. EM28XX_AC97_EM202,
  280. EM28XX_AC97_SIGMATEL,
  281. EM28XX_AC97_OTHER,
  282. };
  283. struct em28xx_audio_mode {
  284. enum em28xx_ac97_mode ac97;
  285. };
  286. enum em28xx_int_audio_type {
  287. EM28XX_INT_AUDIO_NONE = 0,
  288. EM28XX_INT_AUDIO_AC97,
  289. EM28XX_INT_AUDIO_I2S,
  290. };
  291. enum em28xx_usb_audio_type {
  292. EM28XX_USB_AUDIO_NONE = 0,
  293. EM28XX_USB_AUDIO_CLASS,
  294. EM28XX_USB_AUDIO_VENDOR,
  295. };
  296. /**
  297. * em28xx_amux - describes the type of audio input used by em28xx
  298. *
  299. * @EM28XX_AMUX_VIDEO:
  300. * On devices without AC97, this is the only value that it is currently
  301. * allowed.
  302. * On devices with AC97, it corresponds to the AC97 mixer "Video" control.
  303. * @EM28XX_AMUX_LINE_IN:
  304. * Only for devices with AC97. Corresponds to AC97 mixer "Line In".
  305. * @EM28XX_AMUX_VIDEO2:
  306. * Only for devices with AC97. It means that em28xx should use "Line In"
  307. * And AC97 should use the "Video" mixer control.
  308. * @EM28XX_AMUX_PHONE:
  309. * Only for devices with AC97. Corresponds to AC97 mixer "Phone".
  310. * @EM28XX_AMUX_MIC:
  311. * Only for devices with AC97. Corresponds to AC97 mixer "Mic".
  312. * @EM28XX_AMUX_CD:
  313. * Only for devices with AC97. Corresponds to AC97 mixer "CD".
  314. * @EM28XX_AMUX_AUX:
  315. * Only for devices with AC97. Corresponds to AC97 mixer "Aux".
  316. * @EM28XX_AMUX_PCM_OUT:
  317. * Only for devices with AC97. Corresponds to AC97 mixer "PCM out".
  318. *
  319. * The em28xx chip itself has only two audio inputs: tuner and line in.
  320. * On almost all devices, only the tuner input is used.
  321. *
  322. * However, on most devices, an auxiliary AC97 codec device is used,
  323. * usually connected to the em28xx tuner input (except for
  324. * @EM28XX_AMUX_LINE_IN).
  325. *
  326. * The AC97 device typically have several different inputs and outputs.
  327. * The exact number and description depends on their model.
  328. *
  329. * It is possible to AC97 to mixer more than one different entries at the
  330. * same time, via the alsa mux.
  331. */
  332. enum em28xx_amux {
  333. EM28XX_AMUX_VIDEO,
  334. EM28XX_AMUX_LINE_IN,
  335. /* Some less-common mixer setups */
  336. EM28XX_AMUX_VIDEO2,
  337. EM28XX_AMUX_PHONE,
  338. EM28XX_AMUX_MIC,
  339. EM28XX_AMUX_CD,
  340. EM28XX_AMUX_AUX,
  341. EM28XX_AMUX_PCM_OUT,
  342. };
  343. enum em28xx_aout {
  344. /* AC97 outputs */
  345. EM28XX_AOUT_MASTER = BIT(0),
  346. EM28XX_AOUT_LINE = BIT(1),
  347. EM28XX_AOUT_MONO = BIT(2),
  348. EM28XX_AOUT_LFE = BIT(3),
  349. EM28XX_AOUT_SURR = BIT(4),
  350. /* PCM IN Mixer - used by AC97_RECORD_SELECT register */
  351. EM28XX_AOUT_PCM_IN = BIT(7),
  352. /* Bits 10-8 are used to indicate the PCM IN record select */
  353. EM28XX_AOUT_PCM_MIC_PCM = 0 << 8,
  354. EM28XX_AOUT_PCM_CD = 1 << 8,
  355. EM28XX_AOUT_PCM_VIDEO = 2 << 8,
  356. EM28XX_AOUT_PCM_AUX = 3 << 8,
  357. EM28XX_AOUT_PCM_LINE = 4 << 8,
  358. EM28XX_AOUT_PCM_STEREO = 5 << 8,
  359. EM28XX_AOUT_PCM_MONO = 6 << 8,
  360. EM28XX_AOUT_PCM_PHONE = 7 << 8,
  361. };
  362. static inline int ac97_return_record_select(int a_out)
  363. {
  364. return (a_out & 0x700) >> 8;
  365. }
  366. struct em28xx_reg_seq {
  367. int reg;
  368. unsigned char val, mask;
  369. int sleep;
  370. };
  371. struct em28xx_input {
  372. enum enum28xx_itype type;
  373. unsigned int vmux;
  374. enum em28xx_amux amux;
  375. enum em28xx_aout aout;
  376. const struct em28xx_reg_seq *gpio;
  377. };
  378. #define INPUT(nr) (&em28xx_boards[dev->model].input[nr])
  379. enum em28xx_decoder {
  380. EM28XX_NODECODER = 0,
  381. EM28XX_TVP5150,
  382. EM28XX_SAA711X,
  383. };
  384. enum em28xx_sensor {
  385. EM28XX_NOSENSOR = 0,
  386. EM28XX_MT9V011,
  387. EM28XX_MT9M001,
  388. EM28XX_MT9M111,
  389. EM28XX_OV2640,
  390. };
  391. enum em28xx_adecoder {
  392. EM28XX_NOADECODER = 0,
  393. EM28XX_TVAUDIO,
  394. };
  395. enum em28xx_led_role {
  396. EM28XX_LED_ANALOG_CAPTURING = 0,
  397. EM28XX_LED_DIGITAL_CAPTURING,
  398. EM28XX_LED_DIGITAL_CAPTURING_TS2,
  399. EM28XX_LED_ILLUMINATION,
  400. EM28XX_NUM_LED_ROLES, /* must be the last */
  401. };
  402. struct em28xx_led {
  403. enum em28xx_led_role role;
  404. u8 gpio_reg;
  405. u8 gpio_mask;
  406. bool inverted;
  407. };
  408. enum em28xx_button_role {
  409. EM28XX_BUTTON_SNAPSHOT = 0,
  410. EM28XX_BUTTON_ILLUMINATION,
  411. EM28XX_NUM_BUTTON_ROLES, /* must be the last */
  412. };
  413. struct em28xx_button {
  414. enum em28xx_button_role role;
  415. u8 reg_r;
  416. u8 reg_clearing;
  417. u8 mask;
  418. bool inverted;
  419. };
  420. struct em28xx_board {
  421. char *name;
  422. int vchannels;
  423. int tuner_type;
  424. int tuner_addr;
  425. unsigned int def_i2c_bus; /* Default I2C bus */
  426. /* i2c flags */
  427. unsigned int tda9887_conf;
  428. /* GPIO sequences */
  429. const struct em28xx_reg_seq *dvb_gpio;
  430. const struct em28xx_reg_seq *suspend_gpio;
  431. const struct em28xx_reg_seq *tuner_gpio;
  432. const struct em28xx_reg_seq *mute_gpio;
  433. unsigned int is_em2800:1;
  434. unsigned int has_msp34xx:1;
  435. unsigned int mts_firmware:1;
  436. unsigned int max_range_640_480:1;
  437. unsigned int has_dvb:1;
  438. unsigned int has_dual_ts:1;
  439. unsigned int is_webcam:1;
  440. unsigned int valid:1;
  441. unsigned int has_ir_i2c:1;
  442. unsigned char xclk, i2c_speed;
  443. unsigned char radio_addr;
  444. unsigned short tvaudio_addr;
  445. enum em28xx_decoder decoder;
  446. enum em28xx_adecoder adecoder;
  447. struct em28xx_input input[MAX_EM28XX_INPUT];
  448. struct em28xx_input radio;
  449. char *ir_codes;
  450. /* LEDs that need to be controlled explicitly */
  451. struct em28xx_led *leds;
  452. /* Buttons */
  453. const struct em28xx_button *buttons;
  454. };
  455. struct em28xx_eeprom {
  456. u8 id[4]; /* 1a eb 67 95 */
  457. __le16 vendor_ID;
  458. __le16 product_ID;
  459. __le16 chip_conf;
  460. __le16 board_conf;
  461. __le16 string1, string2, string3;
  462. u8 string_idx_table;
  463. };
  464. #define EM28XX_CAPTURE_STREAM_EN 1
  465. /* em28xx extensions */
  466. #define EM28XX_AUDIO 0x10
  467. #define EM28XX_DVB 0x20
  468. #define EM28XX_RC 0x30
  469. #define EM28XX_V4L2 0x40
  470. /* em28xx resource types (used for res_get/res_lock etc */
  471. #define EM28XX_RESOURCE_VIDEO 0x01
  472. #define EM28XX_RESOURCE_VBI 0x02
  473. struct em28xx_v4l2 {
  474. struct kref ref;
  475. struct em28xx *dev;
  476. struct v4l2_device v4l2_dev;
  477. struct v4l2_ctrl_handler ctrl_handler;
  478. struct video_device vdev;
  479. struct video_device vbi_dev;
  480. struct video_device radio_dev;
  481. /* Videobuf2 */
  482. struct vb2_queue vb_vidq;
  483. struct vb2_queue vb_vbiq;
  484. struct mutex vb_queue_lock; /* Protects vb_vidq */
  485. struct mutex vb_vbi_queue_lock; /* Protects vb_vbiq */
  486. u8 vinmode;
  487. u8 vinctl;
  488. /* Camera specific fields */
  489. int sensor_xres;
  490. int sensor_yres;
  491. int sensor_xtal;
  492. int users; /* user count for exclusive use */
  493. int streaming_users; /* number of actively streaming users */
  494. u32 frequency; /* selected tuner frequency */
  495. struct em28xx_fmt *format;
  496. v4l2_std_id norm; /* selected tv norm */
  497. /* Progressive/interlaced mode */
  498. bool progressive;
  499. int interlaced_fieldmode; /* 1=interlaced fields, 0=just top fields */
  500. /* FIXME: everything else than interlaced_fieldmode=1 doesn't work */
  501. /* Frame properties */
  502. int width; /* current frame width */
  503. int height; /* current frame height */
  504. unsigned int hscale; /* horizontal scale factor (see datasheet) */
  505. unsigned int vscale; /* vertical scale factor (see datasheet) */
  506. unsigned int vbi_width;
  507. unsigned int vbi_height; /* lines per field */
  508. /* Capture state tracking */
  509. int capture_type;
  510. bool top_field;
  511. int vbi_read;
  512. unsigned int field_count;
  513. #ifdef CONFIG_MEDIA_CONTROLLER
  514. struct media_pad video_pad, vbi_pad;
  515. struct media_entity *decoder;
  516. #endif
  517. };
  518. struct em28xx_audio {
  519. char name[50];
  520. unsigned int num_urb;
  521. char **transfer_buffer;
  522. struct urb **urb;
  523. struct usb_device *udev;
  524. unsigned int capture_transfer_done;
  525. struct snd_pcm_substream *capture_pcm_substream;
  526. unsigned int hwptr_done_capture;
  527. struct snd_card *sndcard;
  528. size_t period;
  529. int users;
  530. spinlock_t slock; /* Protects struct em28xx_audio */
  531. /* Controls streaming */
  532. struct work_struct wq_trigger; /* trigger to start/stop audio */
  533. atomic_t stream_started; /* stream should be running if true */
  534. };
  535. struct em28xx;
  536. enum em28xx_i2c_algo_type {
  537. EM28XX_I2C_ALGO_EM28XX = 0,
  538. EM28XX_I2C_ALGO_EM2800,
  539. EM28XX_I2C_ALGO_EM25XX_BUS_B,
  540. };
  541. struct em28xx_i2c_bus {
  542. struct em28xx *dev;
  543. unsigned int bus;
  544. enum em28xx_i2c_algo_type algo_type;
  545. };
  546. /* main device struct */
  547. struct em28xx {
  548. struct kref ref;
  549. // Sub-module data
  550. struct em28xx_v4l2 *v4l2;
  551. struct em28xx_dvb *dvb;
  552. struct em28xx_audio adev;
  553. struct em28xx_IR *ir;
  554. // generic device properties
  555. int model; // index in the device_data struct
  556. int devno; // marks the number of this device
  557. enum em28xx_chip_id chip_id;
  558. unsigned int is_em25xx:1; // em25xx/em276x/7x/8x family bridge
  559. unsigned int disconnected:1; // device has been diconnected
  560. unsigned int has_video:1;
  561. unsigned int is_audio_only:1;
  562. unsigned int is_webcam:1;
  563. unsigned int has_msp34xx:1;
  564. unsigned int i2c_speed:2;
  565. enum em28xx_int_audio_type int_audio_type;
  566. enum em28xx_usb_audio_type usb_audio_type;
  567. unsigned char name[32];
  568. struct em28xx_board board;
  569. enum em28xx_sensor em28xx_sensor; // camera specific
  570. // Some older em28xx chips needs a waiting time after writing
  571. unsigned int wait_after_write;
  572. struct list_head devlist;
  573. u32 i2s_speed; // I2S speed for audio digital stream
  574. struct em28xx_audio_mode audio_mode;
  575. int tuner_type; // type of the tuner
  576. // i2c i/o
  577. struct i2c_adapter i2c_adap[NUM_I2C_BUSES];
  578. struct i2c_client i2c_client[NUM_I2C_BUSES];
  579. struct em28xx_i2c_bus i2c_bus[NUM_I2C_BUSES];
  580. unsigned char eeprom_addrwidth_16bit:1;
  581. unsigned int def_i2c_bus; // Default I2C bus
  582. unsigned int cur_i2c_bus; // Current I2C bus
  583. struct rt_mutex i2c_bus_lock;
  584. // video for linux
  585. unsigned int ctl_input; // selected input
  586. unsigned int ctl_ainput;// selected audio input
  587. unsigned int ctl_aoutput;// selected audio output
  588. int mute;
  589. int volume;
  590. unsigned long hash; // eeprom hash - for boards with generic ID
  591. unsigned long i2c_hash; // i2c devicelist hash -
  592. // for boards with generic ID
  593. struct work_struct request_module_wk;
  594. // locks
  595. struct mutex lock; /* protects em28xx struct */
  596. struct mutex ctrl_urb_lock; /* protects urb_buf */
  597. // resources in use
  598. unsigned int resources;
  599. // eeprom content
  600. u8 *eedata;
  601. u16 eedata_len;
  602. // Isoc control struct
  603. struct em28xx_dmaqueue vidq;
  604. struct em28xx_dmaqueue vbiq;
  605. struct em28xx_usb_ctl usb_ctl;
  606. spinlock_t slock; /* Protects em28xx video/vbi/dvb IRQ stream data */
  607. // usb transfer
  608. struct usb_interface *intf; // the usb interface
  609. u8 ifnum; // number of the assigned usb interface
  610. u8 analog_ep_isoc; // address of isoc endpoint for analog
  611. u8 analog_ep_bulk; // address of bulk endpoint for analog
  612. u8 dvb_ep_isoc_ts2; // address of isoc endpoint for DVB TS2
  613. u8 dvb_ep_bulk_ts2; // address of bulk endpoint for DVB TS2
  614. u8 dvb_ep_isoc; // address of isoc endpoint for DVB
  615. u8 dvb_ep_bulk; // address of bulk endpoint for DVB
  616. int alt; // alternate setting
  617. int max_pkt_size; // max packet size of the selected ep at alt
  618. int packet_multiplier; // multiplier for wMaxPacketSize, used for
  619. // URB buffer size definition
  620. int num_alt; // number of alternative settings
  621. unsigned int *alt_max_pkt_size_isoc; // array of isoc wMaxPacketSize
  622. unsigned int analog_xfer_bulk:1; // use bulk instead of isoc
  623. // transfers for analog
  624. int dvb_alt_isoc; // alternate setting for DVB isoc transfers
  625. unsigned int dvb_max_pkt_size_isoc; // isoc max packet size of the
  626. // selected DVB ep at dvb_alt
  627. unsigned int dvb_max_pkt_size_isoc_ts2; // isoc max packet size of the
  628. // selected DVB ep at dvb_alt
  629. unsigned int dvb_xfer_bulk:1; // use bulk instead of isoc
  630. // transfers for DVB
  631. char urb_buf[URB_MAX_CTRL_SIZE]; // urb control msg buffer
  632. // helper funcs that call usb_control_msg
  633. int (*em28xx_write_regs)(struct em28xx *dev, u16 reg,
  634. char *buf, int len);
  635. int (*em28xx_read_reg)(struct em28xx *dev, u16 reg);
  636. int (*em28xx_read_reg_req_len)(struct em28xx *dev, u8 req, u16 reg,
  637. char *buf, int len);
  638. int (*em28xx_write_regs_req)(struct em28xx *dev, u8 req, u16 reg,
  639. char *buf, int len);
  640. int (*em28xx_read_reg_req)(struct em28xx *dev, u8 req, u16 reg);
  641. enum em28xx_mode mode;
  642. // Button state polling
  643. struct delayed_work buttons_query_work;
  644. u8 button_polling_addresses[EM28XX_NUM_BUTTON_ADDRESSES_MAX];
  645. u8 button_polling_last_values[EM28XX_NUM_BUTTON_ADDRESSES_MAX];
  646. u8 num_button_polling_addresses;
  647. u16 button_polling_interval; // [ms]
  648. // Snapshot button input device
  649. char snapshot_button_path[30]; // path of the input dev
  650. struct input_dev *sbutton_input_dev;
  651. #ifdef CONFIG_MEDIA_CONTROLLER
  652. struct media_device *media_dev;
  653. struct media_entity input_ent[MAX_EM28XX_INPUT];
  654. struct media_pad input_pad[MAX_EM28XX_INPUT];
  655. #endif
  656. struct em28xx *dev_next;
  657. int ts;
  658. };
  659. #define kref_to_dev(d) container_of(d, struct em28xx, ref)
  660. struct em28xx_ops {
  661. struct list_head next;
  662. char *name;
  663. int id;
  664. int (*init)(struct em28xx *dev);
  665. int (*fini)(struct em28xx *dev);
  666. int (*suspend)(struct em28xx *dev);
  667. int (*resume)(struct em28xx *dev);
  668. };
  669. /* Provided by em28xx-i2c.c */
  670. void em28xx_do_i2c_scan(struct em28xx *dev, unsigned int bus);
  671. int em28xx_i2c_register(struct em28xx *dev, unsigned int bus,
  672. enum em28xx_i2c_algo_type algo_type);
  673. int em28xx_i2c_unregister(struct em28xx *dev, unsigned int bus);
  674. /* Provided by em28xx-core.c */
  675. int em28xx_read_reg_req_len(struct em28xx *dev, u8 req, u16 reg,
  676. char *buf, int len);
  677. int em28xx_read_reg_req(struct em28xx *dev, u8 req, u16 reg);
  678. int em28xx_read_reg(struct em28xx *dev, u16 reg);
  679. int em28xx_write_regs_req(struct em28xx *dev, u8 req, u16 reg, char *buf,
  680. int len);
  681. int em28xx_write_regs(struct em28xx *dev, u16 reg, char *buf, int len);
  682. int em28xx_write_reg(struct em28xx *dev, u16 reg, u8 val);
  683. int em28xx_write_reg_bits(struct em28xx *dev, u16 reg, u8 val,
  684. u8 bitmask);
  685. int em28xx_toggle_reg_bits(struct em28xx *dev, u16 reg, u8 bitmask);
  686. int em28xx_read_ac97(struct em28xx *dev, u8 reg);
  687. int em28xx_write_ac97(struct em28xx *dev, u8 reg, u16 val);
  688. int em28xx_audio_analog_set(struct em28xx *dev);
  689. int em28xx_audio_setup(struct em28xx *dev);
  690. const struct em28xx_led *em28xx_find_led(struct em28xx *dev,
  691. enum em28xx_led_role role);
  692. int em28xx_capture_start(struct em28xx *dev, int start);
  693. int em28xx_alloc_urbs(struct em28xx *dev, enum em28xx_mode mode, int xfer_bulk,
  694. int num_bufs, int max_pkt_size, int packet_multiplier);
  695. int em28xx_init_usb_xfer(struct em28xx *dev, enum em28xx_mode mode,
  696. int xfer_bulk,
  697. int num_bufs, int max_pkt_size, int packet_multiplier,
  698. int (*urb_data_copy)
  699. (struct em28xx *dev, struct urb *urb));
  700. void em28xx_uninit_usb_xfer(struct em28xx *dev, enum em28xx_mode mode);
  701. void em28xx_stop_urbs(struct em28xx *dev);
  702. int em28xx_set_mode(struct em28xx *dev, enum em28xx_mode set_mode);
  703. int em28xx_gpio_set(struct em28xx *dev, const struct em28xx_reg_seq *gpio);
  704. int em28xx_register_extension(struct em28xx_ops *dev);
  705. void em28xx_unregister_extension(struct em28xx_ops *dev);
  706. void em28xx_init_extension(struct em28xx *dev);
  707. void em28xx_close_extension(struct em28xx *dev);
  708. int em28xx_suspend_extension(struct em28xx *dev);
  709. int em28xx_resume_extension(struct em28xx *dev);
  710. /* Provided by em28xx-cards.c */
  711. extern const struct em28xx_board em28xx_boards[];
  712. extern struct usb_device_id em28xx_id_table[];
  713. int em28xx_tuner_callback(void *ptr, int component, int command, int arg);
  714. void em28xx_setup_xc3028(struct em28xx *dev, struct xc2028_ctrl *ctl);
  715. void em28xx_free_device(struct kref *ref);
  716. /* Provided by em28xx-camera.c */
  717. int em28xx_detect_sensor(struct em28xx *dev);
  718. int em28xx_init_camera(struct em28xx *dev);
  719. #endif