2 * Fushicai USBTV007 Video Grabber Driver
4 * Copyright (c) 2013 Lubomir Rintel
6 * No physical hardware was harmed running Windows during the
7 * reverse-engineering activity
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions, and the following disclaimer,
14 * without modification.
15 * 2. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
18 * Alternatively, this software may be distributed under the terms of the
19 * GNU General Public License ("GPL").
22 #include <linux/module.h>
23 #include <linux/slab.h>
24 #include <linux/usb.h>
26 #include <media/v4l2-device.h>
27 #include <media/videobuf2-vmalloc.h>
30 #define USBTV_VIDEO_ENDP 0x81
31 #define USBTV_BASE 0xc000
32 #define USBTV_REQUEST_REG 12
34 /* Number of concurrent isochronous urbs submitted.
35 * Higher numbers was seen to overly saturate the USB bus. */
36 #define USBTV_ISOC_TRANSFERS 16
37 #define USBTV_ISOC_PACKETS 8
39 #define USBTV_CHUNK_SIZE 256
40 #define USBTV_CHUNK 240
43 #define USBTV_MAGIC_OK(chunk) ((be32_to_cpu(chunk[0]) & 0xff000000) \
45 #define USBTV_FRAME_ID(chunk) ((be32_to_cpu(chunk[0]) & 0x00ff0000) >> 16)
46 #define USBTV_ODD(chunk) ((be32_to_cpu(chunk[0]) & 0x0000f000) >> 15)
47 #define USBTV_CHUNK_NO(chunk) (be32_to_cpu(chunk[0]) & 0x00000fff)
49 #define USBTV_TV_STD (V4L2_STD_525_60 | V4L2_STD_PAL)
51 /* parameters for supported TV norms */
52 struct usbtv_norm_params
{
54 int cap_width
, cap_height
;
57 /* A single videobuf2 frame buffer. */
60 struct list_head list
;
63 /* Per-device structure. */
66 struct usb_device
*udev
;
69 struct v4l2_device v4l2_dev
;
70 struct video_device vdev
;
71 struct vb2_queue vb2q
;
72 struct mutex v4l2_lock
;
73 struct mutex vb2q_lock
;
75 /* List of videobuf2 buffers protected by a lock. */
77 struct list_head bufs
;
79 /* Number of currently processed frame, useful find
80 * out when a new one begins. */
85 USBTV_COMPOSITE_INPUT
,
92 unsigned int sequence
;
93 struct urb
*isoc_urbs
[USBTV_ISOC_TRANSFERS
];
96 int usbtv_set_regs(struct usbtv
*usbtv
, const u16 regs
[][2], int size
);
98 int usbtv_video_init(struct usbtv
*usbtv
);
99 void usbtv_video_free(struct usbtv
*usbtv
);