em28xx.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855
  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_UNUSED:
  300. * Used only on em28xx dev->map field, in order to mark an entry
  301. * as unused.
  302. * @EM28XX_AMUX_VIDEO:
  303. * On devices without AC97, this is the only value that it is currently
  304. * allowed.
  305. * On devices with AC97, it corresponds to the AC97 mixer "Video" control.
  306. * @EM28XX_AMUX_LINE_IN:
  307. * Only for devices with AC97. Corresponds to AC97 mixer "Line In".
  308. * @EM28XX_AMUX_VIDEO2:
  309. * Only for devices with AC97. It means that em28xx should use "Line In"
  310. * And AC97 should use the "Video" mixer control.
  311. * @EM28XX_AMUX_PHONE:
  312. * Only for devices with AC97. Corresponds to AC97 mixer "Phone".
  313. * @EM28XX_AMUX_MIC:
  314. * Only for devices with AC97. Corresponds to AC97 mixer "Mic".
  315. * @EM28XX_AMUX_CD:
  316. * Only for devices with AC97. Corresponds to AC97 mixer "CD".
  317. * @EM28XX_AMUX_AUX:
  318. * Only for devices with AC97. Corresponds to AC97 mixer "Aux".
  319. * @EM28XX_AMUX_PCM_OUT:
  320. * Only for devices with AC97. Corresponds to AC97 mixer "PCM out".
  321. *
  322. * The em28xx chip itself has only two audio inputs: tuner and line in.
  323. * On almost all devices, only the tuner input is used.
  324. *
  325. * However, on most devices, an auxiliary AC97 codec device is used,
  326. * usually connected to the em28xx tuner input (except for
  327. * @EM28XX_AMUX_LINE_IN).
  328. *
  329. * The AC97 device typically have several different inputs and outputs.
  330. * The exact number and description depends on their model.
  331. *
  332. * It is possible to AC97 to mixer more than one different entries at the
  333. * same time, via the alsa mux.
  334. */
  335. enum em28xx_amux {
  336. EM28XX_AMUX_UNUSED = -1,
  337. EM28XX_AMUX_VIDEO = 0,
  338. EM28XX_AMUX_LINE_IN,
  339. /* Some less-common mixer setups */
  340. EM28XX_AMUX_VIDEO2,
  341. EM28XX_AMUX_PHONE,
  342. EM28XX_AMUX_MIC,
  343. EM28XX_AMUX_CD,
  344. EM28XX_AMUX_AUX,
  345. EM28XX_AMUX_PCM_OUT,
  346. };
  347. enum em28xx_aout {
  348. /* AC97 outputs */
  349. EM28XX_AOUT_MASTER = BIT(0),
  350. EM28XX_AOUT_LINE = BIT(1),
  351. EM28XX_AOUT_MONO = BIT(2),
  352. EM28XX_AOUT_LFE = BIT(3),
  353. EM28XX_AOUT_SURR = BIT(4),
  354. /* PCM IN Mixer - used by AC97_RECORD_SELECT register */
  355. EM28XX_AOUT_PCM_IN = BIT(7),
  356. /* Bits 10-8 are used to indicate the PCM IN record select */
  357. EM28XX_AOUT_PCM_MIC_PCM = 0 << 8,
  358. EM28XX_AOUT_PCM_CD = 1 << 8,
  359. EM28XX_AOUT_PCM_VIDEO = 2 << 8,
  360. EM28XX_AOUT_PCM_AUX = 3 << 8,
  361. EM28XX_AOUT_PCM_LINE = 4 << 8,
  362. EM28XX_AOUT_PCM_STEREO = 5 << 8,
  363. EM28XX_AOUT_PCM_MONO = 6 << 8,
  364. EM28XX_AOUT_PCM_PHONE = 7 << 8,
  365. };
  366. static inline int ac97_return_record_select(int a_out)
  367. {
  368. return (a_out & 0x700) >> 8;
  369. }
  370. struct em28xx_reg_seq {
  371. int reg;
  372. unsigned char val, mask;
  373. int sleep;
  374. };
  375. struct em28xx_input {
  376. enum enum28xx_itype type;
  377. unsigned int vmux;
  378. enum em28xx_amux amux;
  379. enum em28xx_aout aout;
  380. const struct em28xx_reg_seq *gpio;
  381. };
  382. #define INPUT(nr) (&em28xx_boards[dev->model].input[nr])
  383. enum em28xx_decoder {
  384. EM28XX_NODECODER = 0,
  385. EM28XX_TVP5150,
  386. EM28XX_SAA711X,
  387. };
  388. enum em28xx_sensor {
  389. EM28XX_NOSENSOR = 0,
  390. EM28XX_MT9V011,
  391. EM28XX_MT9M001,
  392. EM28XX_MT9M111,
  393. EM28XX_OV2640,
  394. };
  395. enum em28xx_adecoder {
  396. EM28XX_NOADECODER = 0,
  397. EM28XX_TVAUDIO,
  398. };
  399. enum em28xx_led_role {
  400. EM28XX_LED_ANALOG_CAPTURING = 0,
  401. EM28XX_LED_DIGITAL_CAPTURING,
  402. EM28XX_LED_DIGITAL_CAPTURING_TS2,
  403. EM28XX_LED_ILLUMINATION,
  404. EM28XX_NUM_LED_ROLES, /* must be the last */
  405. };
  406. struct em28xx_led {
  407. enum em28xx_led_role role;
  408. u8 gpio_reg;
  409. u8 gpio_mask;
  410. bool inverted;
  411. };
  412. enum em28xx_button_role {
  413. EM28XX_BUTTON_SNAPSHOT = 0,
  414. EM28XX_BUTTON_ILLUMINATION,
  415. EM28XX_NUM_BUTTON_ROLES, /* must be the last */
  416. };
  417. struct em28xx_button {
  418. enum em28xx_button_role role;
  419. u8 reg_r;
  420. u8 reg_clearing;
  421. u8 mask;
  422. bool inverted;
  423. };
  424. struct em28xx_board {
  425. char *name;
  426. int vchannels;
  427. int tuner_type;
  428. int tuner_addr;
  429. unsigned int def_i2c_bus; /* Default I2C bus */
  430. /* i2c flags */
  431. unsigned int tda9887_conf;
  432. /* GPIO sequences */
  433. const struct em28xx_reg_seq *dvb_gpio;
  434. const struct em28xx_reg_seq *suspend_gpio;
  435. const struct em28xx_reg_seq *tuner_gpio;
  436. const struct em28xx_reg_seq *mute_gpio;
  437. unsigned int is_em2800:1;
  438. unsigned int has_msp34xx:1;
  439. unsigned int mts_firmware:1;
  440. unsigned int max_range_640_480:1;
  441. unsigned int has_dvb:1;
  442. unsigned int has_dual_ts:1;
  443. unsigned int is_webcam:1;
  444. unsigned int valid:1;
  445. unsigned int has_ir_i2c:1;
  446. unsigned char xclk, i2c_speed;
  447. unsigned char radio_addr;
  448. unsigned short tvaudio_addr;
  449. enum em28xx_decoder decoder;
  450. enum em28xx_adecoder adecoder;
  451. struct em28xx_input input[MAX_EM28XX_INPUT];
  452. struct em28xx_input radio;
  453. char *ir_codes;
  454. /* LEDs that need to be controlled explicitly */
  455. struct em28xx_led *leds;
  456. /* Buttons */
  457. const struct em28xx_button *buttons;
  458. };
  459. struct em28xx_eeprom {
  460. u8 id[4]; /* 1a eb 67 95 */
  461. __le16 vendor_ID;
  462. __le16 product_ID;
  463. __le16 chip_conf;
  464. __le16 board_conf;
  465. __le16 string1, string2, string3;
  466. u8 string_idx_table;
  467. };
  468. #define EM28XX_CAPTURE_STREAM_EN 1
  469. /* em28xx extensions */
  470. #define EM28XX_AUDIO 0x10
  471. #define EM28XX_DVB 0x20
  472. #define EM28XX_RC 0x30
  473. #define EM28XX_V4L2 0x40
  474. /* em28xx resource types (used for res_get/res_lock etc */
  475. #define EM28XX_RESOURCE_VIDEO 0x01
  476. #define EM28XX_RESOURCE_VBI 0x02
  477. struct em28xx_v4l2 {
  478. struct kref ref;
  479. struct em28xx *dev;
  480. struct v4l2_device v4l2_dev;
  481. struct v4l2_ctrl_handler ctrl_handler;
  482. struct video_device vdev;
  483. struct video_device vbi_dev;
  484. struct video_device radio_dev;
  485. /* Videobuf2 */
  486. struct vb2_queue vb_vidq;
  487. struct vb2_queue vb_vbiq;
  488. struct mutex vb_queue_lock; /* Protects vb_vidq */
  489. struct mutex vb_vbi_queue_lock; /* Protects vb_vbiq */
  490. u8 vinmode;
  491. u8 vinctl;
  492. /* Camera specific fields */
  493. int sensor_xres;
  494. int sensor_yres;
  495. int sensor_xtal;
  496. int users; /* user count for exclusive use */
  497. int streaming_users; /* number of actively streaming users */
  498. u32 frequency; /* selected tuner frequency */
  499. struct em28xx_fmt *format;
  500. v4l2_std_id norm; /* selected tv norm */
  501. /* Progressive/interlaced mode */
  502. bool progressive;
  503. int interlaced_fieldmode; /* 1=interlaced fields, 0=just top fields */
  504. /* FIXME: everything else than interlaced_fieldmode=1 doesn't work */
  505. /* Frame properties */
  506. int width; /* current frame width */
  507. int height; /* current frame height */
  508. unsigned int hscale; /* horizontal scale factor (see datasheet) */
  509. unsigned int vscale; /* vertical scale factor (see datasheet) */
  510. unsigned int vbi_width;
  511. unsigned int vbi_height; /* lines per field */
  512. /* Capture state tracking */
  513. int capture_type;
  514. bool top_field;
  515. int vbi_read;
  516. unsigned int field_count;
  517. #ifdef CONFIG_MEDIA_CONTROLLER
  518. struct media_pad video_pad, vbi_pad;
  519. struct media_entity *decoder;
  520. #endif
  521. };
  522. struct em28xx_audio {
  523. char name[50];
  524. unsigned int num_urb;
  525. char **transfer_buffer;
  526. struct urb **urb;
  527. struct usb_device *udev;
  528. unsigned int capture_transfer_done;
  529. struct snd_pcm_substream *capture_pcm_substream;
  530. unsigned int hwptr_done_capture;
  531. struct snd_card *sndcard;
  532. size_t period;
  533. int users;
  534. spinlock_t slock; /* Protects struct em28xx_audio */
  535. /* Controls streaming */
  536. struct work_struct wq_trigger; /* trigger to start/stop audio */
  537. atomic_t stream_started; /* stream should be running if true */
  538. };
  539. struct em28xx;
  540. enum em28xx_i2c_algo_type {
  541. EM28XX_I2C_ALGO_EM28XX = 0,
  542. EM28XX_I2C_ALGO_EM2800,
  543. EM28XX_I2C_ALGO_EM25XX_BUS_B,
  544. };
  545. struct em28xx_i2c_bus {
  546. struct em28xx *dev;
  547. unsigned int bus;
  548. enum em28xx_i2c_algo_type algo_type;
  549. };
  550. /* main device struct */
  551. struct em28xx {
  552. struct kref ref;
  553. // Sub-module data
  554. struct em28xx_v4l2 *v4l2;
  555. struct em28xx_dvb *dvb;
  556. struct em28xx_audio adev;
  557. struct em28xx_IR *ir;
  558. // generic device properties
  559. int model; // index in the device_data struct
  560. int devno; // marks the number of this device
  561. enum em28xx_chip_id chip_id;
  562. unsigned int is_em25xx:1; // em25xx/em276x/7x/8x family bridge
  563. unsigned int disconnected:1; // device has been diconnected
  564. unsigned int has_video:1;
  565. unsigned int is_audio_only:1;
  566. unsigned int is_webcam:1;
  567. unsigned int has_msp34xx:1;
  568. unsigned int i2c_speed:2;
  569. enum em28xx_int_audio_type int_audio_type;
  570. enum em28xx_usb_audio_type usb_audio_type;
  571. unsigned char name[32];
  572. struct em28xx_board board;
  573. enum em28xx_sensor em28xx_sensor; // camera specific
  574. // Some older em28xx chips needs a waiting time after writing
  575. unsigned int wait_after_write;
  576. struct list_head devlist;
  577. u32 i2s_speed; // I2S speed for audio digital stream
  578. struct em28xx_audio_mode audio_mode;
  579. int tuner_type; // type of the tuner
  580. // i2c i/o
  581. struct i2c_adapter i2c_adap[NUM_I2C_BUSES];
  582. struct i2c_client i2c_client[NUM_I2C_BUSES];
  583. struct em28xx_i2c_bus i2c_bus[NUM_I2C_BUSES];
  584. unsigned char eeprom_addrwidth_16bit:1;
  585. unsigned int def_i2c_bus; // Default I2C bus
  586. unsigned int cur_i2c_bus; // Current I2C bus
  587. struct rt_mutex i2c_bus_lock;
  588. // video for linux
  589. unsigned int ctl_input; // selected input
  590. unsigned int ctl_ainput;// selected audio input
  591. unsigned int ctl_aoutput;// selected audio output
  592. enum em28xx_amux amux_map[MAX_EM28XX_INPUT];
  593. int mute;
  594. int volume;
  595. unsigned long hash; // eeprom hash - for boards with generic ID
  596. unsigned long i2c_hash; // i2c devicelist hash -
  597. // for boards with generic ID
  598. struct work_struct request_module_wk;
  599. // locks
  600. struct mutex lock; /* protects em28xx struct */
  601. struct mutex ctrl_urb_lock; /* protects urb_buf */
  602. // resources in use
  603. unsigned int resources;
  604. // eeprom content
  605. u8 *eedata;
  606. u16 eedata_len;
  607. // Isoc control struct
  608. struct em28xx_dmaqueue vidq;
  609. struct em28xx_dmaqueue vbiq;
  610. struct em28xx_usb_ctl usb_ctl;
  611. spinlock_t slock; /* Protects em28xx video/vbi/dvb IRQ stream data */
  612. // usb transfer
  613. struct usb_interface *intf; // the usb interface
  614. u8 ifnum; // number of the assigned usb interface
  615. u8 analog_ep_isoc; // address of isoc endpoint for analog
  616. u8 analog_ep_bulk; // address of bulk endpoint for analog
  617. u8 dvb_ep_isoc_ts2; // address of isoc endpoint for DVB TS2
  618. u8 dvb_ep_bulk_ts2; // address of bulk endpoint for DVB TS2
  619. u8 dvb_ep_isoc; // address of isoc endpoint for DVB
  620. u8 dvb_ep_bulk; // address of bulk endpoint for DVB
  621. int alt; // alternate setting
  622. int max_pkt_size; // max packet size of the selected ep at alt
  623. int packet_multiplier; // multiplier for wMaxPacketSize, used for
  624. // URB buffer size definition
  625. int num_alt; // number of alternative settings
  626. unsigned int *alt_max_pkt_size_isoc; // array of isoc wMaxPacketSize
  627. unsigned int analog_xfer_bulk:1; // use bulk instead of isoc
  628. // transfers for analog
  629. int dvb_alt_isoc; // alternate setting for DVB isoc transfers
  630. unsigned int dvb_max_pkt_size_isoc; // isoc max packet size of the
  631. // selected DVB ep at dvb_alt
  632. unsigned int dvb_max_pkt_size_isoc_ts2; // isoc max packet size of the
  633. // selected DVB ep at dvb_alt
  634. unsigned int dvb_xfer_bulk:1; // use bulk instead of isoc
  635. // transfers for DVB
  636. char urb_buf[URB_MAX_CTRL_SIZE]; // urb control msg buffer
  637. // helper funcs that call usb_control_msg
  638. int (*em28xx_write_regs)(struct em28xx *dev, u16 reg,
  639. char *buf, int len);
  640. int (*em28xx_read_reg)(struct em28xx *dev, u16 reg);
  641. int (*em28xx_read_reg_req_len)(struct em28xx *dev, u8 req, u16 reg,
  642. char *buf, int len);
  643. int (*em28xx_write_regs_req)(struct em28xx *dev, u8 req, u16 reg,
  644. char *buf, int len);
  645. int (*em28xx_read_reg_req)(struct em28xx *dev, u8 req, u16 reg);
  646. enum em28xx_mode mode;
  647. // Button state polling
  648. struct delayed_work buttons_query_work;
  649. u8 button_polling_addresses[EM28XX_NUM_BUTTON_ADDRESSES_MAX];
  650. u8 button_polling_last_values[EM28XX_NUM_BUTTON_ADDRESSES_MAX];
  651. u8 num_button_polling_addresses;
  652. u16 button_polling_interval; // [ms]
  653. // Snapshot button input device
  654. char snapshot_button_path[30]; // path of the input dev
  655. struct input_dev *sbutton_input_dev;
  656. #ifdef CONFIG_MEDIA_CONTROLLER
  657. struct media_device *media_dev;
  658. struct media_entity input_ent[MAX_EM28XX_INPUT];
  659. struct media_pad input_pad[MAX_EM28XX_INPUT];
  660. #endif
  661. struct em28xx *dev_next;
  662. int ts;
  663. };
  664. #define kref_to_dev(d) container_of(d, struct em28xx, ref)
  665. struct em28xx_ops {
  666. struct list_head next;
  667. char *name;
  668. int id;
  669. int (*init)(struct em28xx *dev);
  670. int (*fini)(struct em28xx *dev);
  671. int (*suspend)(struct em28xx *dev);
  672. int (*resume)(struct em28xx *dev);
  673. };
  674. /* Provided by em28xx-i2c.c */
  675. void em28xx_do_i2c_scan(struct em28xx *dev, unsigned int bus);
  676. int em28xx_i2c_register(struct em28xx *dev, unsigned int bus,
  677. enum em28xx_i2c_algo_type algo_type);
  678. int em28xx_i2c_unregister(struct em28xx *dev, unsigned int bus);
  679. /* Provided by em28xx-core.c */
  680. int em28xx_read_reg_req_len(struct em28xx *dev, u8 req, u16 reg,
  681. char *buf, int len);
  682. int em28xx_read_reg_req(struct em28xx *dev, u8 req, u16 reg);
  683. int em28xx_read_reg(struct em28xx *dev, u16 reg);
  684. int em28xx_write_regs_req(struct em28xx *dev, u8 req, u16 reg, char *buf,
  685. int len);
  686. int em28xx_write_regs(struct em28xx *dev, u16 reg, char *buf, int len);
  687. int em28xx_write_reg(struct em28xx *dev, u16 reg, u8 val);
  688. int em28xx_write_reg_bits(struct em28xx *dev, u16 reg, u8 val,
  689. u8 bitmask);
  690. int em28xx_toggle_reg_bits(struct em28xx *dev, u16 reg, u8 bitmask);
  691. int em28xx_read_ac97(struct em28xx *dev, u8 reg);
  692. int em28xx_write_ac97(struct em28xx *dev, u8 reg, u16 val);
  693. int em28xx_audio_analog_set(struct em28xx *dev);
  694. int em28xx_audio_setup(struct em28xx *dev);
  695. const struct em28xx_led *em28xx_find_led(struct em28xx *dev,
  696. enum em28xx_led_role role);
  697. int em28xx_capture_start(struct em28xx *dev, int start);
  698. int em28xx_alloc_urbs(struct em28xx *dev, enum em28xx_mode mode, int xfer_bulk,
  699. int num_bufs, int max_pkt_size, int packet_multiplier);
  700. int em28xx_init_usb_xfer(struct em28xx *dev, enum em28xx_mode mode,
  701. int xfer_bulk,
  702. int num_bufs, int max_pkt_size, int packet_multiplier,
  703. int (*urb_data_copy)
  704. (struct em28xx *dev, struct urb *urb));
  705. void em28xx_uninit_usb_xfer(struct em28xx *dev, enum em28xx_mode mode);
  706. void em28xx_stop_urbs(struct em28xx *dev);
  707. int em28xx_set_mode(struct em28xx *dev, enum em28xx_mode set_mode);
  708. int em28xx_gpio_set(struct em28xx *dev, const struct em28xx_reg_seq *gpio);
  709. int em28xx_register_extension(struct em28xx_ops *dev);
  710. void em28xx_unregister_extension(struct em28xx_ops *dev);
  711. void em28xx_init_extension(struct em28xx *dev);
  712. void em28xx_close_extension(struct em28xx *dev);
  713. int em28xx_suspend_extension(struct em28xx *dev);
  714. int em28xx_resume_extension(struct em28xx *dev);
  715. /* Provided by em28xx-cards.c */
  716. extern const struct em28xx_board em28xx_boards[];
  717. extern struct usb_device_id em28xx_id_table[];
  718. int em28xx_tuner_callback(void *ptr, int component, int command, int arg);
  719. void em28xx_setup_xc3028(struct em28xx *dev, struct xc2028_ctrl *ctl);
  720. void em28xx_free_device(struct kref *ref);
  721. /* Provided by em28xx-camera.c */
  722. int em28xx_detect_sensor(struct em28xx *dev);
  723. int em28xx_init_camera(struct em28xx *dev);
  724. #endif