aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/usb/em28xx/em28xx.h
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/media/usb/em28xx/em28xx.h')
-rw-r--r--drivers/media/usb/em28xx/em28xx.h149
1 files changed, 87 insertions, 62 deletions
diff --git a/drivers/media/usb/em28xx/em28xx.h b/drivers/media/usb/em28xx/em28xx.h
index 86e90d86da6d..5f0b2c59e846 100644
--- a/drivers/media/usb/em28xx/em28xx.h
+++ b/drivers/media/usb/em28xx/em28xx.h
@@ -4,6 +4,7 @@
4 Copyright (C) 2005 Markus Rechberger <mrechberger@gmail.com> 4 Copyright (C) 2005 Markus Rechberger <mrechberger@gmail.com>
5 Ludovico Cavedon <cavedon@sssup.it> 5 Ludovico Cavedon <cavedon@sssup.it>
6 Mauro Carvalho Chehab <mchehab@infradead.org> 6 Mauro Carvalho Chehab <mchehab@infradead.org>
7 Copyright (C) 2012 Frank Schäfer <fschaefer.oss@googlemail.com>
7 8
8 Based on the em2800 driver from Sascha Sommer <saschasommer@freenet.de> 9 Based on the em2800 driver from Sascha Sommer <saschasommer@freenet.de>
9 10
@@ -30,13 +31,12 @@
30#include <linux/mutex.h> 31#include <linux/mutex.h>
31#include <linux/videodev2.h> 32#include <linux/videodev2.h>
32 33
33#include <media/videobuf-vmalloc.h> 34#include <media/videobuf2-vmalloc.h>
34#include <media/v4l2-device.h> 35#include <media/v4l2-device.h>
36#include <media/v4l2-ctrls.h>
37#include <media/v4l2-fh.h>
35#include <media/ir-kbd-i2c.h> 38#include <media/ir-kbd-i2c.h>
36#include <media/rc-core.h> 39#include <media/rc-core.h>
37#if defined(CONFIG_VIDEO_EM28XX_DVB) || defined(CONFIG_VIDEO_EM28XX_DVB_MODULE)
38#include <media/videobuf-dvb.h>
39#endif
40#include "tuner-xc2028.h" 40#include "tuner-xc2028.h"
41#include "xc5000.h" 41#include "xc5000.h"
42#include "em28xx-reg.h" 42#include "em28xx-reg.h"
@@ -157,12 +157,18 @@
157#define EM28XX_NUM_BUFS 5 157#define EM28XX_NUM_BUFS 5
158#define EM28XX_DVB_NUM_BUFS 5 158#define EM28XX_DVB_NUM_BUFS 5
159 159
160/* number of packets for each buffer 160/* isoc transfers: number of packets for each buffer
161 windows requests only 64 packets .. so we better do the same 161 windows requests only 64 packets .. so we better do the same
162 this is what I found out for all alternate numbers there! 162 this is what I found out for all alternate numbers there!
163 */ 163 */
164#define EM28XX_NUM_PACKETS 64 164#define EM28XX_NUM_ISOC_PACKETS 64
165#define EM28XX_DVB_MAX_PACKETS 64 165#define EM28XX_DVB_NUM_ISOC_PACKETS 64
166
167/* bulk transfers: transfer buffer size = packet size * packet multiplier
168 USB 2.0 spec says bulk packet size is always 512 bytes
169 */
170#define EM28XX_BULK_PACKET_MULTIPLIER 384
171#define EM28XX_DVB_BULK_PACKET_MULTIPLIER 384
166 172
167#define EM28XX_INTERLACED_DEFAULT 1 173#define EM28XX_INTERLACED_DEFAULT 1
168 174
@@ -187,12 +193,8 @@
187 Interval: 125us 193 Interval: 125us
188*/ 194*/
189 195
190/* time to wait when stopping the isoc transfer */
191#define EM28XX_URB_TIMEOUT \
192 msecs_to_jiffies(EM28XX_NUM_BUFS * EM28XX_NUM_PACKETS)
193
194/* time in msecs to wait for i2c writes to finish */ 196/* time in msecs to wait for i2c writes to finish */
195#define EM2800_I2C_WRITE_TIMEOUT 20 197#define EM2800_I2C_XFER_TIMEOUT 20
196 198
197enum em28xx_mode { 199enum em28xx_mode {
198 EM28XX_SUSPEND, 200 EM28XX_SUSPEND,
@@ -203,7 +205,7 @@ enum em28xx_mode {
203 205
204struct em28xx; 206struct em28xx;
205 207
206struct em28xx_usb_isoc_bufs { 208struct em28xx_usb_bufs {
207 /* max packet size of isoc transaction */ 209 /* max packet size of isoc transaction */
208 int max_pkt_size; 210 int max_pkt_size;
209 211
@@ -213,26 +215,26 @@ struct em28xx_usb_isoc_bufs {
213 /* number of allocated urbs */ 215 /* number of allocated urbs */
214 int num_bufs; 216 int num_bufs;
215 217
216 /* urb for isoc transfers */ 218 /* urb for isoc/bulk transfers */
217 struct urb **urb; 219 struct urb **urb;
218 220
219 /* transfer buffers for isoc transfer */ 221 /* transfer buffers for isoc/bulk transfer */
220 char **transfer_buffer; 222 char **transfer_buffer;
221}; 223};
222 224
223struct em28xx_usb_isoc_ctl { 225struct em28xx_usb_ctl {
224 /* isoc transfer buffers for analog mode */ 226 /* isoc/bulk transfer buffers for analog mode */
225 struct em28xx_usb_isoc_bufs analog_bufs; 227 struct em28xx_usb_bufs analog_bufs;
226 228
227 /* isoc transfer buffers for digital mode */ 229 /* isoc/bulk transfer buffers for digital mode */
228 struct em28xx_usb_isoc_bufs digital_bufs; 230 struct em28xx_usb_bufs digital_bufs;
229 231
230 /* Stores already requested buffers */ 232 /* Stores already requested buffers */
231 struct em28xx_buffer *vid_buf; 233 struct em28xx_buffer *vid_buf;
232 struct em28xx_buffer *vbi_buf; 234 struct em28xx_buffer *vbi_buf;
233 235
234 /* isoc urb callback */ 236 /* copy data from URB */
235 int (*isoc_copy) (struct em28xx *dev, struct urb *urb); 237 int (*urb_data_copy) (struct em28xx *dev, struct urb *urb);
236 238
237}; 239};
238 240
@@ -247,19 +249,26 @@ struct em28xx_fmt {
247/* buffer for one video frame */ 249/* buffer for one video frame */
248struct em28xx_buffer { 250struct em28xx_buffer {
249 /* common v4l buffer stuff -- must be first */ 251 /* common v4l buffer stuff -- must be first */
250 struct videobuf_buffer vb; 252 struct vb2_buffer vb;
253 struct list_head list;
251 254
252 struct list_head frame; 255 void *mem;
256 unsigned int length;
253 int top_field; 257 int top_field;
258
259 /* counter to control buffer fill */
260 unsigned int pos;
261 /* NOTE; in interlaced mode, this value is reset to zero at
262 * the start of each new field (not frame !) */
263
264 /* pointer to vmalloc memory address in vb */
265 char *vb_buf;
254}; 266};
255 267
256struct em28xx_dmaqueue { 268struct em28xx_dmaqueue {
257 struct list_head active; 269 struct list_head active;
258 270
259 wait_queue_head_t wq; 271 wait_queue_head_t wq;
260
261 /* Counters to control buffer fill */
262 int pos;
263}; 272};
264 273
265/* inputs */ 274/* inputs */
@@ -430,13 +439,6 @@ struct em28xx_eeprom {
430 u8 string_idx_table; 439 u8 string_idx_table;
431}; 440};
432 441
433/* device states */
434enum em28xx_dev_state {
435 DEV_INITIALIZED = 0x01,
436 DEV_DISCONNECTED = 0x02,
437 DEV_MISCONFIGURED = 0x04,
438};
439
440#define EM28XX_AUDIO_BUFS 5 442#define EM28XX_AUDIO_BUFS 5
441#define EM28XX_NUM_AUDIO_PACKETS 64 443#define EM28XX_NUM_AUDIO_PACKETS 64
442#define EM28XX_AUDIO_MAX_PACKET_SIZE 196 /* static value */ 444#define EM28XX_AUDIO_MAX_PACKET_SIZE 196 /* static value */
@@ -469,12 +471,8 @@ struct em28xx_audio {
469struct em28xx; 471struct em28xx;
470 472
471struct em28xx_fh { 473struct em28xx_fh {
474 struct v4l2_fh fh;
472 struct em28xx *dev; 475 struct em28xx *dev;
473 int radio;
474 unsigned int resources;
475
476 struct videobuf_queue vb_vidq;
477 struct videobuf_queue vb_vbiq;
478 476
479 enum v4l2_buf_type type; 477 enum v4l2_buf_type type;
480}; 478};
@@ -487,9 +485,14 @@ struct em28xx {
487 int devno; /* marks the number of this device */ 485 int devno; /* marks the number of this device */
488 enum em28xx_chip_id chip_id; 486 enum em28xx_chip_id chip_id;
489 487
488 unsigned char disconnected:1; /* device has been diconnected */
489
490 int audio_ifnum; 490 int audio_ifnum;
491 491
492 struct v4l2_device v4l2_dev; 492 struct v4l2_device v4l2_dev;
493 struct v4l2_ctrl_handler ctrl_handler;
494 /* provides ac97 mute and volume overrides */
495 struct v4l2_ctrl_handler ac97_ctrl_handler;
493 struct em28xx_board board; 496 struct em28xx_board board;
494 497
495 /* Webcam specific fields */ 498 /* Webcam specific fields */
@@ -497,7 +500,7 @@ struct em28xx {
497 int sensor_xres, sensor_yres; 500 int sensor_xres, sensor_yres;
498 int sensor_xtal; 501 int sensor_xtal;
499 502
500 /* Allows progressive (e. g. non-interlaced) mode */ 503 /* Progressive (non-interlaced) mode */
501 int progressive; 504 int progressive;
502 505
503 /* Vinmode/Vinctl used at the driver */ 506 /* Vinmode/Vinctl used at the driver */
@@ -532,6 +535,7 @@ struct em28xx {
532 struct i2c_client i2c_client; 535 struct i2c_client i2c_client;
533 /* video for linux */ 536 /* video for linux */
534 int users; /* user count for exclusive use */ 537 int users; /* user count for exclusive use */
538 int streaming_users; /* Number of actively streaming users */
535 struct video_device *vdev; /* video for linux device struct */ 539 struct video_device *vdev; /* video for linux device struct */
536 v4l2_std_id norm; /* selected tv norm */ 540 v4l2_std_id norm; /* selected tv norm */
537 int ctl_freq; /* selected frequency */ 541 int ctl_freq; /* selected frequency */
@@ -554,13 +558,10 @@ struct em28xx {
554 558
555 struct em28xx_audio adev; 559 struct em28xx_audio adev;
556 560
557 /* states */ 561 /* capture state tracking */
558 enum em28xx_dev_state state;
559
560 /* vbi related state tracking */
561 int capture_type; 562 int capture_type;
563 unsigned char top_field:1;
562 int vbi_read; 564 int vbi_read;
563 unsigned char cur_field;
564 unsigned int vbi_width; 565 unsigned int vbi_width;
565 unsigned int vbi_height; /* lines per field */ 566 unsigned int vbi_height; /* lines per field */
566 567
@@ -574,6 +575,12 @@ struct em28xx {
574 struct video_device *vbi_dev; 575 struct video_device *vbi_dev;
575 struct video_device *radio_dev; 576 struct video_device *radio_dev;
576 577
578 /* Videobuf2 */
579 struct vb2_queue vb_vidq;
580 struct vb2_queue vb_vbiq;
581 struct mutex vb_queue_lock;
582 struct mutex vb_vbi_queue_lock;
583
577 /* resources in use */ 584 /* resources in use */
578 unsigned int resources; 585 unsigned int resources;
579 586
@@ -582,17 +589,31 @@ struct em28xx {
582 /* Isoc control struct */ 589 /* Isoc control struct */
583 struct em28xx_dmaqueue vidq; 590 struct em28xx_dmaqueue vidq;
584 struct em28xx_dmaqueue vbiq; 591 struct em28xx_dmaqueue vbiq;
585 struct em28xx_usb_isoc_ctl isoc_ctl; 592 struct em28xx_usb_ctl usb_ctl;
586 spinlock_t slock; 593 spinlock_t slock;
587 594
595 unsigned int field_count;
596 unsigned int vbi_field_count;
597
588 /* usb transfer */ 598 /* usb transfer */
589 struct usb_device *udev; /* the usb device */ 599 struct usb_device *udev; /* the usb device */
590 int alt; /* alternate */ 600 u8 analog_ep_isoc; /* address of isoc endpoint for analog */
591 int max_pkt_size; /* max packet size of isoc transaction */ 601 u8 analog_ep_bulk; /* address of bulk endpoint for analog */
592 int num_alt; /* Number of alternative settings */ 602 u8 dvb_ep_isoc; /* address of isoc endpoint for DVB */
593 unsigned int *alt_max_pkt_size; /* array of wMaxPacketSize */ 603 u8 dvb_ep_bulk; /* address of bulk endpoint for DVC */
594 int dvb_alt; /* alternate for DVB */ 604 int alt; /* alternate setting */
595 unsigned int dvb_max_pkt_size; /* wMaxPacketSize for DVB */ 605 int max_pkt_size; /* max packet size of the selected ep at alt */
606 int packet_multiplier; /* multiplier for wMaxPacketSize, used for
607 URB buffer size definition */
608 int num_alt; /* number of alternative settings */
609 unsigned int *alt_max_pkt_size_isoc; /* array of isoc wMaxPacketSize */
610 unsigned int analog_xfer_bulk:1; /* use bulk instead of isoc
611 transfers for analog */
612 int dvb_alt_isoc; /* alternate setting for DVB isoc transfers */
613 unsigned int dvb_max_pkt_size_isoc; /* isoc max packet size of the
614 selected DVB ep at dvb_alt */
615 unsigned int dvb_xfer_bulk:1; /* use bulk instead of isoc
616 transfers for DVB */
596 char urb_buf[URB_MAX_CTRL_SIZE]; /* urb control msg buffer */ 617 char urb_buf[URB_MAX_CTRL_SIZE]; /* urb control msg buffer */
597 618
598 /* helper funcs that call usb_control_msg */ 619 /* helper funcs that call usb_control_msg */
@@ -619,9 +640,6 @@ struct em28xx {
619 struct delayed_work sbutton_query_work; 640 struct delayed_work sbutton_query_work;
620 641
621 struct em28xx_dvb *dvb; 642 struct em28xx_dvb *dvb;
622
623 /* I2C keyboard data */
624 struct IR_i2c_init_data init_data;
625}; 643};
626 644
627struct em28xx_ops { 645struct em28xx_ops {
@@ -666,12 +684,14 @@ int em28xx_vbi_supported(struct em28xx *dev);
666int em28xx_set_outfmt(struct em28xx *dev); 684int em28xx_set_outfmt(struct em28xx *dev);
667int em28xx_resolution_set(struct em28xx *dev); 685int em28xx_resolution_set(struct em28xx *dev);
668int em28xx_set_alternate(struct em28xx *dev); 686int em28xx_set_alternate(struct em28xx *dev);
669int em28xx_alloc_isoc(struct em28xx *dev, enum em28xx_mode mode, 687int em28xx_alloc_urbs(struct em28xx *dev, enum em28xx_mode mode, int xfer_bulk,
670 int max_packets, int num_bufs, int max_pkt_size); 688 int num_bufs, int max_pkt_size, int packet_multiplier);
671int em28xx_init_isoc(struct em28xx *dev, enum em28xx_mode mode, 689int em28xx_init_usb_xfer(struct em28xx *dev, enum em28xx_mode mode,
672 int max_packets, int num_bufs, int max_pkt_size, 690 int xfer_bulk,
673 int (*isoc_copy) (struct em28xx *dev, struct urb *urb)); 691 int num_bufs, int max_pkt_size, int packet_multiplier,
674void em28xx_uninit_isoc(struct em28xx *dev, enum em28xx_mode mode); 692 int (*urb_data_copy)
693 (struct em28xx *dev, struct urb *urb));
694void em28xx_uninit_usb_xfer(struct em28xx *dev, enum em28xx_mode mode);
675void em28xx_stop_urbs(struct em28xx *dev); 695void em28xx_stop_urbs(struct em28xx *dev);
676int em28xx_isoc_dvb_max_packetsize(struct em28xx *dev); 696int em28xx_isoc_dvb_max_packetsize(struct em28xx *dev);
677int em28xx_set_mode(struct em28xx *dev, enum em28xx_mode set_mode); 697int em28xx_set_mode(struct em28xx *dev, enum em28xx_mode set_mode);
@@ -683,8 +703,13 @@ void em28xx_init_extension(struct em28xx *dev);
683void em28xx_close_extension(struct em28xx *dev); 703void em28xx_close_extension(struct em28xx *dev);
684 704
685/* Provided by em28xx-video.c */ 705/* Provided by em28xx-video.c */
706int em28xx_vb2_setup(struct em28xx *dev);
686int em28xx_register_analog_devices(struct em28xx *dev); 707int em28xx_register_analog_devices(struct em28xx *dev);
687void em28xx_release_analog_resources(struct em28xx *dev); 708void em28xx_release_analog_resources(struct em28xx *dev);
709void em28xx_ctrl_notify(struct v4l2_ctrl *ctrl, void *priv);
710int em28xx_start_analog_streaming(struct vb2_queue *vq, unsigned int count);
711int em28xx_stop_vbi_streaming(struct vb2_queue *vq);
712extern const struct v4l2_ctrl_ops em28xx_ctrl_ops;
688 713
689/* Provided by em28xx-cards.c */ 714/* Provided by em28xx-cards.c */
690extern int em2800_variant_detect(struct usb_device *udev, int model); 715extern int em2800_variant_detect(struct usb_device *udev, int model);
@@ -695,7 +720,7 @@ int em28xx_tuner_callback(void *ptr, int component, int command, int arg);
695void em28xx_release_resources(struct em28xx *dev); 720void em28xx_release_resources(struct em28xx *dev);
696 721
697/* Provided by em28xx-vbi.c */ 722/* Provided by em28xx-vbi.c */
698extern struct videobuf_queue_ops em28xx_vbi_qops; 723extern struct vb2_ops em28xx_vbi_qops;
699 724
700/* printk macros */ 725/* printk macros */
701 726