• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /netgear-WNDR4500v2-V1.0.0.60_1.0.38/src/linux/linux-2.6/drivers/media/video/sn9c102/
1/***************************************************************************
2 * V4L2 driver for SN9C1xx PC Camera Controllers                           *
3 *                                                                         *
4 * Copyright (C) 2004-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 _SN9C102_H_
22#define _SN9C102_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/rwsem.h>
36#include <linux/mutex.h>
37#include <linux/string.h>
38#include <linux/stddef.h>
39
40#include "sn9c102_config.h"
41#include "sn9c102_sensor.h"
42#include "sn9c102_devtable.h"
43
44
45enum sn9c102_frame_state {
46	F_UNUSED,
47	F_QUEUED,
48	F_GRABBING,
49	F_DONE,
50	F_ERROR,
51};
52
53struct sn9c102_frame_t {
54	void* bufmem;
55	struct v4l2_buffer buf;
56	enum sn9c102_frame_state state;
57	struct list_head frame;
58	unsigned long vma_use_count;
59};
60
61enum sn9c102_dev_state {
62	DEV_INITIALIZED = 0x01,
63	DEV_DISCONNECTED = 0x02,
64	DEV_MISCONFIGURED = 0x04,
65};
66
67enum sn9c102_io_method {
68	IO_NONE,
69	IO_READ,
70	IO_MMAP,
71};
72
73enum sn9c102_stream_state {
74	STREAM_OFF,
75	STREAM_INTERRUPT,
76	STREAM_ON,
77};
78
79typedef char sn9c102_sof_header_t[62];
80
81struct sn9c102_sof_t {
82	sn9c102_sof_header_t header;
83	u16 bytesread;
84};
85
86struct sn9c102_sysfs_attr {
87	u16 reg, i2c_reg;
88	sn9c102_sof_header_t frame_header;
89};
90
91struct sn9c102_module_param {
92	u8 force_munmap;
93	u16 frame_timeout;
94};
95
96static DEFINE_MUTEX(sn9c102_sysfs_lock);
97static DECLARE_RWSEM(sn9c102_disconnect);
98
99struct sn9c102_device {
100	struct video_device* v4ldev;
101
102	enum sn9c102_bridge bridge;
103	struct sn9c102_sensor sensor;
104
105	struct usb_device* usbdev;
106	struct urb* urb[SN9C102_URBS];
107	void* transfer_buffer[SN9C102_URBS];
108	u8* control_buffer;
109
110	struct sn9c102_frame_t *frame_current, frame[SN9C102_MAX_FRAMES];
111	struct list_head inqueue, outqueue;
112	u32 frame_count, nbuffers, nreadbuffers;
113
114	enum sn9c102_io_method io;
115	enum sn9c102_stream_state stream;
116
117	struct v4l2_jpegcompression compression;
118
119	struct sn9c102_sysfs_attr sysfs;
120	struct sn9c102_sof_t sof;
121	u16 reg[384];
122
123	struct sn9c102_module_param module_param;
124
125	enum sn9c102_dev_state state;
126	u8 users;
127
128	struct mutex dev_mutex, fileop_mutex;
129	spinlock_t queue_lock;
130	wait_queue_head_t open, wait_frame, wait_stream;
131};
132
133/*****************************************************************************/
134
135struct sn9c102_device*
136sn9c102_match_id(struct sn9c102_device* cam, const struct usb_device_id *id)
137{
138	return usb_match_id(usb_ifnum_to_if(cam->usbdev, 0), id) ? cam : NULL;
139}
140
141
142void
143sn9c102_attach_sensor(struct sn9c102_device* cam,
144		      const struct sn9c102_sensor* sensor)
145{
146	memcpy(&cam->sensor, sensor, sizeof(struct sn9c102_sensor));
147}
148
149
150enum sn9c102_bridge
151sn9c102_get_bridge(struct sn9c102_device* cam)
152{
153	return cam->bridge;
154}
155
156
157struct sn9c102_sensor* sn9c102_get_sensor(struct sn9c102_device* cam)
158{
159	return &cam->sensor;
160}
161
162/*****************************************************************************/
163
164#undef DBG
165#undef KDBG
166#ifdef SN9C102_DEBUG
167#	define DBG(level, fmt, args...)                                       \
168do {                                                                          \
169	if (debug >= (level)) {                                               \
170		if ((level) == 1)                                             \
171			dev_err(&cam->usbdev->dev, fmt "\n", ## args);        \
172		else if ((level) == 2)                                        \
173			dev_info(&cam->usbdev->dev, fmt "\n", ## args);       \
174		else if ((level) >= 3)                                        \
175			dev_info(&cam->usbdev->dev, "[%s:%d] " fmt "\n",      \
176				 __FUNCTION__, __LINE__ , ## args);           \
177	}                                                                     \
178} while (0)
179#	define V4LDBG(level, name, cmd)                                       \
180do {                                                                          \
181	if (debug >= (level))                                                 \
182		v4l_print_ioctl(name, cmd);                                   \
183} while (0)
184#	define KDBG(level, fmt, args...)                                      \
185do {                                                                          \
186	if (debug >= (level)) {                                               \
187		if ((level) == 1 || (level) == 2)                             \
188			pr_info("sn9c102: " fmt "\n", ## args);               \
189		else if ((level) == 3)                                        \
190			pr_debug("sn9c102: [%s:%d] " fmt "\n",                \
191				 __FUNCTION__, __LINE__ , ## args);           \
192	}                                                                     \
193} while (0)
194#else
195#	define DBG(level, fmt, args...) do {;} while(0)
196#	define V4LDBG(level, name, cmd) do {;} while(0)
197#	define KDBG(level, fmt, args...) do {;} while(0)
198#endif
199
200#undef PDBG
201#define PDBG(fmt, args...)                                                    \
202dev_info(&cam->usbdev->dev, "[%s:%s:%d] " fmt "\n", __FILE__, __FUNCTION__,   \
203	 __LINE__ , ## args)
204
205#undef PDBGG
206#define PDBGG(fmt, args...) do {;} while(0) /* placeholder */
207
208#endif /* _SN9C102_H_ */
209