brintos

brintos / linux-shallow public Read only

0
0
Text · 4.1 KiB · b9fa7c0 Raw
139 lines · c
1/*2 * Copyright (c) 2013 Lubomir Rintel3 * All rights reserved.4 *5 * Redistribution and use in source and binary forms, with or without6 * modification, are permitted provided that the following conditions7 * are met:8 * 1. Redistributions of source code must retain the above copyright9 *    notice, this list of conditions, and the following disclaimer,10 *    without modification.11 * 2. The name of the author may not be used to endorse or promote products12 *    derived from this software without specific prior written permission.13 *14 * Alternatively, this software may be distributed under the terms of the15 * GNU General Public License ("GPL").16 *17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR20 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT21 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.28 */29/*30 * Fushicai USBTV007 Audio-Video Grabber Driver31 *32 * No physical hardware was harmed running Windows during the33 * reverse-engineering activity34 */35 36#include <linux/module.h>37#include <linux/slab.h>38#include <linux/usb.h>39 40#include <media/v4l2-device.h>41#include <media/v4l2-ctrls.h>42#include <media/videobuf2-v4l2.h>43#include <media/videobuf2-vmalloc.h>44 45/* Hardware. */46#define USBTV_VIDEO_ENDP	0x8147#define USBTV_AUDIO_ENDP	0x8348#define USBTV_BASE		0xc00049#define USBTV_CONTROL_REG	1150#define USBTV_REQUEST_REG	1251 52/* Number of concurrent isochronous urbs submitted.53 * Higher numbers was seen to overly saturate the USB bus. */54#define USBTV_ISOC_TRANSFERS	1655#define USBTV_ISOC_PACKETS	856 57#define USBTV_CHUNK_SIZE	25658#define USBTV_CHUNK		24059 60#define USBTV_AUDIO_URBSIZE	2048061#define USBTV_AUDIO_HDRSIZE	462#define USBTV_AUDIO_BUFFER	6553663 64/* Chunk header. */65#define USBTV_MAGIC_OK(chunk)	((be32_to_cpu(chunk[0]) & 0xff000000) \66							== 0x88000000)67#define USBTV_FRAME_ID(chunk)	((be32_to_cpu(chunk[0]) & 0x00ff0000) >> 16)68#define USBTV_ODD(chunk)	((be32_to_cpu(chunk[0]) & 0x0000f000) >> 15)69#define USBTV_CHUNK_NO(chunk)	(be32_to_cpu(chunk[0]) & 0x00000fff)70 71#define USBTV_TV_STD		(V4L2_STD_525_60 | V4L2_STD_PAL | \72				 V4L2_STD_PAL_Nc | V4L2_STD_SECAM)73 74/* parameters for supported TV norms */75struct usbtv_norm_params {76	v4l2_std_id norm;77	int cap_width, cap_height;78};79 80/* A single videobuf2 frame buffer. */81struct usbtv_buf {82	struct vb2_v4l2_buffer vb;83	struct list_head list;84};85 86/* Per-device structure. */87struct usbtv {88	struct device *dev;89	struct usb_device *udev;90 91	/* video */92	struct v4l2_device v4l2_dev;93	struct v4l2_ctrl_handler ctrl;94	struct video_device vdev;95	struct vb2_queue vb2q;96	struct mutex v4l2_lock;97	struct mutex vb2q_lock;98 99	/* List of videobuf2 buffers protected by a lock. */100	spinlock_t buflock;101	struct list_head bufs;102 103	/* Number of currently processed frame, useful find104	 * out when a new one begins. */105	u32 frame_id;106	int chunks_done;107 108	enum {109		USBTV_COMPOSITE_INPUT,110		USBTV_SVIDEO_INPUT,111	} input;112	v4l2_std_id norm;113	int width, height;114	int n_chunks;115	int iso_size;116	int last_odd;117	unsigned int sequence;118	struct urb *isoc_urbs[USBTV_ISOC_TRANSFERS];119 120	/* audio */121	struct snd_card *snd;122	struct snd_pcm_substream *snd_substream;123	atomic_t snd_stream;124	struct work_struct snd_trigger;125	struct urb *snd_bulk_urb;126	size_t snd_buffer_pos;127	size_t snd_period_pos;128};129 130int usbtv_set_regs(struct usbtv *usbtv, const u16 regs[][2], int size);131 132int usbtv_video_init(struct usbtv *usbtv);133void usbtv_video_free(struct usbtv *usbtv);134 135int usbtv_audio_init(struct usbtv *usbtv);136void usbtv_audio_free(struct usbtv *usbtv);137void usbtv_audio_suspend(struct usbtv *usbtv);138void usbtv_audio_resume(struct usbtv *usbtv);139