2 * Fushicai USBTV007 Audio-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-v4l2.h>
28 #include <media/videobuf2-vmalloc.h>
31 #define USBTV_VIDEO_ENDP 0x81
32 #define USBTV_AUDIO_ENDP 0x83
33 #define USBTV_BASE 0xc000
34 #define USBTV_REQUEST_REG 12
36 /* Number of concurrent isochronous urbs submitted.
37 * Higher numbers was seen to overly saturate the USB bus. */
38 #define USBTV_ISOC_TRANSFERS 16
39 #define USBTV_ISOC_PACKETS 8
41 #define USBTV_CHUNK_SIZE 256
42 #define USBTV_CHUNK 240
44 #define USBTV_AUDIO_URBSIZE 20480
45 #define USBTV_AUDIO_HDRSIZE 4
46 #define USBTV_AUDIO_BUFFER 65536
49 #define USBTV_MAGIC_OK(chunk) ((be32_to_cpu(chunk[0]) & 0xff000000) \
51 #define USBTV_FRAME_ID(chunk) ((be32_to_cpu(chunk[0]) & 0x00ff0000) >> 16)
52 #define USBTV_ODD(chunk) ((be32_to_cpu(chunk[0]) & 0x0000f000) >> 15)
53 #define USBTV_CHUNK_NO(chunk) (be32_to_cpu(chunk[0]) & 0x00000fff)
55 #define USBTV_TV_STD (V4L2_STD_525_60 | V4L2_STD_PAL)
57 /* parameters for supported TV norms */
58 struct usbtv_norm_params
{
60 int cap_width
, cap_height
;
63 /* A single videobuf2 frame buffer. */
65 struct vb2_v4l2_buffer vb
;
66 struct list_head list
;
69 /* Per-device structure. */
72 struct usb_device
*udev
;
75 struct v4l2_device v4l2_dev
;
76 struct video_device vdev
;
77 struct vb2_queue vb2q
;
78 struct mutex v4l2_lock
;
79 struct mutex vb2q_lock
;
81 /* List of videobuf2 buffers protected by a lock. */
83 struct list_head bufs
;
85 /* Number of currently processed frame, useful find
86 * out when a new one begins. */
91 USBTV_COMPOSITE_INPUT
,
99 unsigned int sequence
;
100 struct urb
*isoc_urbs
[USBTV_ISOC_TRANSFERS
];
103 struct snd_card
*snd
;
104 struct snd_pcm_substream
*snd_substream
;
106 struct work_struct snd_trigger
;
107 struct urb
*snd_bulk_urb
;
108 size_t snd_buffer_pos
;
109 size_t snd_period_pos
;
112 int usbtv_set_regs(struct usbtv
*usbtv
, const u16 regs
[][2], int size
);
114 int usbtv_video_init(struct usbtv
*usbtv
);
115 void usbtv_video_free(struct usbtv
*usbtv
);
117 int usbtv_audio_init(struct usbtv
*usbtv
);
118 void usbtv_audio_free(struct usbtv
*usbtv
);
119 void usbtv_audio_suspend(struct usbtv
*usbtv
);
120 void usbtv_audio_resume(struct usbtv
*usbtv
);