aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/media/zc0301.h
diff options
context:
space:
mode:
authorLuca Risolia <luca.risolia@studio.unibo.it>2006-02-06 11:29:35 -0500
committerGreg Kroah-Hartman <gregkh@suse.de>2006-03-20 17:49:52 -0500
commit60f780528f3ae603eb169a221628b93b6c6929f9 (patch)
tree535b75e9eafb445c7acd85ee350cdc0efbbcdecb /drivers/usb/media/zc0301.h
parentc4a1745aa09fc110afdefea0e5d025043e348bae (diff)
[PATCH] USB: Add ZC0301 Video4Linux2 driver
This patch adds a Video4Linux2 driver for ZC0301 Image Processor and Control Chip. Signed-off-by: Luca Risolia <luca.risolia@studio.unibo.it> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/usb/media/zc0301.h')
-rw-r--r--drivers/usb/media/zc0301.h185
1 files changed, 185 insertions, 0 deletions
diff --git a/drivers/usb/media/zc0301.h b/drivers/usb/media/zc0301.h
new file mode 100644
index 000000000000..6fa5075f1e3d
--- /dev/null
+++ b/drivers/usb/media/zc0301.h
@@ -0,0 +1,185 @@
1/***************************************************************************
2 * V4L2 driver for ZC0301 Image Processor and Control Chip *
3 * *
4 * Copyright (C) 2006 by Luca Risolia <luca.risolia@studio.unibo.it> *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the Free Software *
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
19 ***************************************************************************/
20
21#ifndef _ZC0301_H_
22#define _ZC0301_H_
23
24#include <linux/version.h>
25#include <linux/usb.h>
26#include <linux/videodev2.h>
27#include <media/v4l2-common.h>
28#include <linux/device.h>
29#include <linux/list.h>
30#include <linux/spinlock.h>
31#include <linux/time.h>
32#include <linux/wait.h>
33#include <linux/types.h>
34#include <linux/param.h>
35#include <linux/mutex.h>
36#include <linux/rwsem.h>
37#include <asm/semaphore.h>
38
39#include "zc0301_sensor.h"
40
41/*****************************************************************************/
42
43#define ZC0301_DEBUG
44#define ZC0301_DEBUG_LEVEL 2
45#define ZC0301_MAX_DEVICES 64
46#define ZC0301_FORCE_MUNMAP 0
47#define ZC0301_MAX_FRAMES 32
48#define ZC0301_COMPRESSION_QUALITY 2
49#define ZC0301_URBS 2
50#define ZC0301_ISO_PACKETS 7
51#define ZC0301_ALTERNATE_SETTING 7
52#define ZC0301_URB_TIMEOUT msecs_to_jiffies(2 * ZC0301_ISO_PACKETS)
53#define ZC0301_CTRL_TIMEOUT 100
54#define ZC0301_FRAME_TIMEOUT 2 * 1000 * msecs_to_jiffies(1)
55
56/*****************************************************************************/
57
58ZC0301_ID_TABLE
59ZC0301_SENSOR_TABLE
60
61enum zc0301_frame_state {
62 F_UNUSED,
63 F_QUEUED,
64 F_GRABBING,
65 F_DONE,
66 F_ERROR,
67};
68
69struct zc0301_frame_t {
70 void* bufmem;
71 struct v4l2_buffer buf;
72 enum zc0301_frame_state state;
73 struct list_head frame;
74 unsigned long vma_use_count;
75};
76
77enum zc0301_dev_state {
78 DEV_INITIALIZED = 0x01,
79 DEV_DISCONNECTED = 0x02,
80 DEV_MISCONFIGURED = 0x04,
81};
82
83enum zc0301_io_method {
84 IO_NONE,
85 IO_READ,
86 IO_MMAP,
87};
88
89enum zc0301_stream_state {
90 STREAM_OFF,
91 STREAM_INTERRUPT,
92 STREAM_ON,
93};
94
95struct zc0301_module_param {
96 u8 force_munmap;
97};
98
99static DECLARE_RWSEM(zc0301_disconnect);
100
101struct zc0301_device {
102 struct video_device* v4ldev;
103
104 struct zc0301_sensor* sensor;
105
106 struct usb_device* usbdev;
107 struct urb* urb[ZC0301_URBS];
108 void* transfer_buffer[ZC0301_URBS];
109 u8* control_buffer;
110
111 struct zc0301_frame_t *frame_current, frame[ZC0301_MAX_FRAMES];
112 struct list_head inqueue, outqueue;
113 u32 frame_count, nbuffers, nreadbuffers;
114
115 enum zc0301_io_method io;
116 enum zc0301_stream_state stream;
117
118 struct v4l2_jpegcompression compression;
119
120 struct zc0301_module_param module_param;
121
122 enum zc0301_dev_state state;
123 u8 users;
124
125 struct mutex dev_mutex, fileop_mutex;
126 spinlock_t queue_lock;
127 wait_queue_head_t open, wait_frame, wait_stream;
128};
129
130/*****************************************************************************/
131
132void
133zc0301_attach_sensor(struct zc0301_device* cam, struct zc0301_sensor* sensor)
134{
135 cam->sensor = sensor;
136 cam->sensor->usbdev = cam->usbdev;
137}
138
139/*****************************************************************************/
140
141#undef DBG
142#undef KDBG
143#ifdef ZC0301_DEBUG
144# define DBG(level, fmt, args...) \
145do { \
146 if (debug >= (level)) { \
147 if ((level) == 1) \
148 dev_err(&cam->usbdev->dev, fmt "\n", ## args); \
149 else if ((level) == 2) \
150 dev_info(&cam->usbdev->dev, fmt "\n", ## args); \
151 else if ((level) >= 3) \
152 dev_info(&cam->usbdev->dev, "[%s:%d] " fmt "\n", \
153 __FUNCTION__, __LINE__ , ## args); \
154 } \
155} while (0)
156# define KDBG(level, fmt, args...) \
157do { \
158 if (debug >= (level)) { \
159 if ((level) == 1 || (level) == 2) \
160 pr_info("zc0301: " fmt "\n", ## args); \
161 else if ((level) == 3) \
162 pr_debug("zc0301: [%s:%d] " fmt "\n", __FUNCTION__, \
163 __LINE__ , ## args); \
164 } \
165} while (0)
166# define V4LDBG(level, name, cmd) \
167do { \
168 if (debug >= (level)) \
169 v4l_print_ioctl(name, cmd); \
170} while (0)
171#else
172# define DBG(level, fmt, args...) do {;} while(0)
173# define KDBG(level, fmt, args...) do {;} while(0)
174# define V4LDBG(level, name, cmd) do {;} while(0)
175#endif
176
177#undef PDBG
178#define PDBG(fmt, args...) \
179dev_info(&cam->usbdev->dev, "[%s:%d] " fmt "\n", \
180 __FUNCTION__, __LINE__ , ## args)
181
182#undef PDBGG
183#define PDBGG(fmt, args...) do {;} while(0) /* placeholder */
184
185#endif /* _ZC0301_H_ */