blob: 968119581fab3e95adad4771576c3249ff56b0d5 [file] [log] [blame]
Federico Simoncellia3550ea2014-01-07 19:13:21 -03001/*
Federico Simoncelli63ddf682014-08-11 18:42:22 -03002 * Fushicai USBTV007 Audio-Video Grabber Driver
Federico Simoncellia3550ea2014-01-07 19:13:21 -03003 *
4 * Copyright (c) 2013 Lubomir Rintel
5 * All rights reserved.
6 * No physical hardware was harmed running Windows during the
7 * reverse-engineering activity
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
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.
17 *
18 * Alternatively, this software may be distributed under the terms of the
19 * GNU General Public License ("GPL").
20 */
21
Hans Verkuil9fd93302014-02-04 06:00:52 -030022#include <linux/module.h>
Federico Simoncellia3550ea2014-01-07 19:13:21 -030023#include <linux/slab.h>
24#include <linux/usb.h>
25
26#include <media/v4l2-device.h>
27#include <media/videobuf2-vmalloc.h>
28
29/* Hardware. */
30#define USBTV_VIDEO_ENDP 0x81
Federico Simoncelli63ddf682014-08-11 18:42:22 -030031#define USBTV_AUDIO_ENDP 0x83
Federico Simoncellia3550ea2014-01-07 19:13:21 -030032#define USBTV_BASE 0xc000
33#define USBTV_REQUEST_REG 12
34
35/* Number of concurrent isochronous urbs submitted.
36 * Higher numbers was seen to overly saturate the USB bus. */
37#define USBTV_ISOC_TRANSFERS 16
38#define USBTV_ISOC_PACKETS 8
39
40#define USBTV_CHUNK_SIZE 256
41#define USBTV_CHUNK 240
42
Federico Simoncelli63ddf682014-08-11 18:42:22 -030043#define USBTV_AUDIO_URBSIZE 20480
44#define USBTV_AUDIO_HDRSIZE 4
45#define USBTV_AUDIO_BUFFER 65536
46
Federico Simoncellia3550ea2014-01-07 19:13:21 -030047/* Chunk header. */
48#define USBTV_MAGIC_OK(chunk) ((be32_to_cpu(chunk[0]) & 0xff000000) \
49 == 0x88000000)
50#define USBTV_FRAME_ID(chunk) ((be32_to_cpu(chunk[0]) & 0x00ff0000) >> 16)
51#define USBTV_ODD(chunk) ((be32_to_cpu(chunk[0]) & 0x0000f000) >> 15)
52#define USBTV_CHUNK_NO(chunk) (be32_to_cpu(chunk[0]) & 0x00000fff)
53
54#define USBTV_TV_STD (V4L2_STD_525_60 | V4L2_STD_PAL)
55
56/* parameters for supported TV norms */
57struct usbtv_norm_params {
58 v4l2_std_id norm;
59 int cap_width, cap_height;
60};
61
62/* A single videobuf2 frame buffer. */
63struct usbtv_buf {
64 struct vb2_buffer vb;
65 struct list_head list;
66};
67
68/* Per-device structure. */
69struct usbtv {
70 struct device *dev;
71 struct usb_device *udev;
72
73 /* video */
74 struct v4l2_device v4l2_dev;
75 struct video_device vdev;
76 struct vb2_queue vb2q;
77 struct mutex v4l2_lock;
78 struct mutex vb2q_lock;
79
80 /* List of videobuf2 buffers protected by a lock. */
81 spinlock_t buflock;
82 struct list_head bufs;
83
84 /* Number of currently processed frame, useful find
85 * out when a new one begins. */
86 u32 frame_id;
87 int chunks_done;
88
89 enum {
90 USBTV_COMPOSITE_INPUT,
91 USBTV_SVIDEO_INPUT,
92 } input;
93 v4l2_std_id norm;
94 int width, height;
95 int n_chunks;
96 int iso_size;
97 unsigned int sequence;
98 struct urb *isoc_urbs[USBTV_ISOC_TRANSFERS];
Federico Simoncelli63ddf682014-08-11 18:42:22 -030099
100 /* audio */
101 struct snd_card *snd;
102 struct snd_pcm_substream *snd_substream;
103 atomic_t snd_stream;
104 struct work_struct snd_trigger;
105 struct urb *snd_bulk_urb;
106 size_t snd_buffer_pos;
107 size_t snd_period_pos;
Federico Simoncellia3550ea2014-01-07 19:13:21 -0300108};
109
110int usbtv_set_regs(struct usbtv *usbtv, const u16 regs[][2], int size);
111
112int usbtv_video_init(struct usbtv *usbtv);
113void usbtv_video_free(struct usbtv *usbtv);
Federico Simoncelli63ddf682014-08-11 18:42:22 -0300114
115int usbtv_audio_init(struct usbtv *usbtv);
116void usbtv_audio_free(struct usbtv *usbtv);
117void usbtv_audio_suspend(struct usbtv *usbtv);
118void usbtv_audio_resume(struct usbtv *usbtv);