em28xx.h 24 KB

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