[PATCH] USB: SN9C10x driver updates
[deliverable/linux.git] / drivers / usb / media / sn9c102.h
CommitLineData
1da177e4
LT
1/***************************************************************************
2 * V4L2 driver for SN9C10x PC Camera Controllers *
3 * *
a966f3e7 4 * Copyright (C) 2004-2006 by Luca Risolia <luca.risolia@studio.unibo.it> *
1da177e4
LT
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 _SN9C102_H_
22#define _SN9C102_H_
23
24#include <linux/version.h>
25#include <linux/usb.h>
cd6fcc55
LR
26#include <linux/videodev2.h>
27#include <media/v4l2-common.h>
1da177e4
LT
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/rwsem.h>
36#include <asm/semaphore.h>
37
38#include "sn9c102_sensor.h"
39
40/*****************************************************************************/
41
42#define SN9C102_DEBUG
43#define SN9C102_DEBUG_LEVEL 2
44#define SN9C102_MAX_DEVICES 64
45#define SN9C102_PRESERVE_IMGSCALE 0
46#define SN9C102_FORCE_MUNMAP 0
47#define SN9C102_MAX_FRAMES 32
48#define SN9C102_URBS 2
49#define SN9C102_ISO_PACKETS 7
50#define SN9C102_ALTERNATE_SETTING 8
51#define SN9C102_URB_TIMEOUT msecs_to_jiffies(2 * SN9C102_ISO_PACKETS)
52#define SN9C102_CTRL_TIMEOUT 300
53
54/*****************************************************************************/
55
1da177e4
LT
56enum sn9c102_bridge {
57 BRIDGE_SN9C101 = 0x01,
58 BRIDGE_SN9C102 = 0x02,
59 BRIDGE_SN9C103 = 0x04,
60};
61
62SN9C102_ID_TABLE
63SN9C102_SENSOR_TABLE
64
65enum sn9c102_frame_state {
66 F_UNUSED,
67 F_QUEUED,
68 F_GRABBING,
69 F_DONE,
70 F_ERROR,
71};
72
73struct sn9c102_frame_t {
74 void* bufmem;
75 struct v4l2_buffer buf;
76 enum sn9c102_frame_state state;
77 struct list_head frame;
78 unsigned long vma_use_count;
79};
80
81enum sn9c102_dev_state {
82 DEV_INITIALIZED = 0x01,
83 DEV_DISCONNECTED = 0x02,
84 DEV_MISCONFIGURED = 0x04,
85};
86
87enum sn9c102_io_method {
88 IO_NONE,
89 IO_READ,
90 IO_MMAP,
91};
92
93enum sn9c102_stream_state {
94 STREAM_OFF,
95 STREAM_INTERRUPT,
96 STREAM_ON,
97};
98
a966f3e7 99typedef char sn9c103_sof_header_t[18];
1da177e4
LT
100typedef char sn9c102_sof_header_t[12];
101typedef char sn9c102_eof_header_t[4];
102
103struct sn9c102_sysfs_attr {
104 u8 reg, i2c_reg;
a966f3e7 105 sn9c103_sof_header_t frame_header;
1da177e4
LT
106};
107
108struct sn9c102_module_param {
109 u8 force_munmap;
110};
111
112static DECLARE_MUTEX(sn9c102_sysfs_lock);
113static DECLARE_RWSEM(sn9c102_disconnect);
114
115struct sn9c102_device {
1da177e4
LT
116 struct video_device* v4ldev;
117
118 enum sn9c102_bridge bridge;
119 struct sn9c102_sensor* sensor;
120
121 struct usb_device* usbdev;
122 struct urb* urb[SN9C102_URBS];
123 void* transfer_buffer[SN9C102_URBS];
124 u8* control_buffer;
125
126 struct sn9c102_frame_t *frame_current, frame[SN9C102_MAX_FRAMES];
127 struct list_head inqueue, outqueue;
128 u32 frame_count, nbuffers, nreadbuffers;
129
130 enum sn9c102_io_method io;
131 enum sn9c102_stream_state stream;
132
133 struct v4l2_jpegcompression compression;
134
135 struct sn9c102_sysfs_attr sysfs;
a966f3e7
LR
136 sn9c103_sof_header_t sof_header;
137 u16 reg[63];
1da177e4
LT
138
139 struct sn9c102_module_param module_param;
140
141 enum sn9c102_dev_state state;
142 u8 users;
143
144 struct semaphore dev_sem, fileop_sem;
145 spinlock_t queue_lock;
146 wait_queue_head_t open, wait_frame, wait_stream;
147};
148
149/*****************************************************************************/
150
151void
152sn9c102_attach_sensor(struct sn9c102_device* cam,
153 struct sn9c102_sensor* sensor)
154{
155 cam->sensor = sensor;
1da177e4
LT
156 cam->sensor->usbdev = cam->usbdev;
157}
158
159/*****************************************************************************/
160
161#undef DBG
162#undef KDBG
163#ifdef SN9C102_DEBUG
164# define DBG(level, fmt, args...) \
a966f3e7 165do { \
1da177e4
LT
166 if (debug >= (level)) { \
167 if ((level) == 1) \
cd6fcc55 168 dev_err(&cam->usbdev->dev, fmt "\n", ## args); \
1da177e4 169 else if ((level) == 2) \
cd6fcc55 170 dev_info(&cam->usbdev->dev, fmt "\n", ## args); \
1da177e4 171 else if ((level) >= 3) \
cd6fcc55 172 dev_info(&cam->usbdev->dev, "[%s:%d] " fmt "\n", \
1da177e4
LT
173 __FUNCTION__, __LINE__ , ## args); \
174 } \
a966f3e7 175} while (0)
cd6fcc55
LR
176# define V4LDBG(level, name, cmd) \
177do { \
178 if (debug >= (level)) \
179 v4l_print_ioctl(name, cmd); \
180} while (0)
1da177e4 181# define KDBG(level, fmt, args...) \
a966f3e7 182do { \
1da177e4
LT
183 if (debug >= (level)) { \
184 if ((level) == 1 || (level) == 2) \
185 pr_info("sn9c102: " fmt "\n", ## args); \
186 else if ((level) == 3) \
187 pr_debug("sn9c102: [%s:%d] " fmt "\n", __FUNCTION__, \
188 __LINE__ , ## args); \
189 } \
a966f3e7 190} while (0)
1da177e4 191#else
a966f3e7 192# define DBG(level, fmt, args...) do {;} while(0)
cd6fcc55
LR
193# define V4LDBG(level, name, cmd) do {;} while(0)
194# define KDBG(level, fmt, args...) do {;} while(0)
1da177e4
LT
195#endif
196
197#undef PDBG
198#define PDBG(fmt, args...) \
a966f3e7 199dev_info(&cam->dev, "[%s:%d] " fmt "\n", __FUNCTION__, __LINE__ , ## args)
1da177e4
LT
200
201#undef PDBGG
a966f3e7 202#define PDBGG(fmt, args...) do {;} while(0) /* placeholder */
1da177e4
LT
203
204#endif /* _SN9C102_H_ */
This page took 0.098193 seconds and 5 git commands to generate.