1 /***************************************************************************
2 * V4L2 driver for SN9C10x PC Camera Controllers *
4 * Copyright (C) 2004 by Luca Risolia <luca.risolia@studio.unibo.it> *
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. *
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. *
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 ***************************************************************************/
24 #include <linux/version.h>
25 #include <linux/usb.h>
26 #include <linux/videodev.h>
27 #include <linux/device.h>
28 #include <linux/list.h>
29 #include <linux/spinlock.h>
30 #include <linux/time.h>
31 #include <linux/wait.h>
32 #include <linux/types.h>
33 #include <linux/param.h>
34 #include <linux/rwsem.h>
35 #include <asm/semaphore.h>
37 #include "sn9c102_sensor.h"
39 /*****************************************************************************/
42 #define SN9C102_DEBUG_LEVEL 2
43 #define SN9C102_MAX_DEVICES 64
44 #define SN9C102_PRESERVE_IMGSCALE 0
45 #define SN9C102_MAX_FRAMES 32
46 #define SN9C102_URBS 2
47 #define SN9C102_ISO_PACKETS 7
48 #define SN9C102_ALTERNATE_SETTING 8
49 #define SN9C102_URB_TIMEOUT msecs_to_jiffies(3)
50 #define SN9C102_CTRL_TIMEOUT msecs_to_jiffies(100)
52 /*****************************************************************************/
54 #define SN9C102_MODULE_NAME "V4L2 driver for SN9C10x PC Camera Controllers"
55 #define SN9C102_MODULE_AUTHOR "(C) 2004 Luca Risolia"
56 #define SN9C102_AUTHOR_EMAIL "<luca.risolia@studio.unibo.it>"
57 #define SN9C102_MODULE_LICENSE "GPL"
58 #define SN9C102_MODULE_VERSION "1:1.19"
59 #define SN9C102_MODULE_VERSION_CODE KERNEL_VERSION(1, 0, 19)
62 BRIDGE_SN9C101 = 0x01,
63 BRIDGE_SN9C102 = 0x02,
64 BRIDGE_SN9C103 = 0x04,
70 enum sn9c102_frame_state {
78 struct sn9c102_frame_t {
80 struct v4l2_buffer buf;
81 enum sn9c102_frame_state state;
82 struct list_head frame;
83 unsigned long vma_use_count;
86 enum sn9c102_dev_state {
87 DEV_INITIALIZED = 0x01,
88 DEV_DISCONNECTED = 0x02,
89 DEV_MISCONFIGURED = 0x04,
92 enum sn9c102_io_method {
98 enum sn9c102_stream_state {
104 struct sn9c102_sysfs_attr {
108 static DECLARE_MUTEX(sn9c102_sysfs_lock);
109 static DECLARE_RWSEM(sn9c102_disconnect);
111 struct sn9c102_device {
114 struct video_device* v4ldev;
116 enum sn9c102_bridge bridge;
117 struct sn9c102_sensor* sensor;
119 struct usb_device* usbdev;
120 struct urb* urb[SN9C102_URBS];
121 void* transfer_buffer[SN9C102_URBS];
124 struct sn9c102_frame_t *frame_current, frame[SN9C102_MAX_FRAMES];
125 struct list_head inqueue, outqueue;
126 u32 frame_count, nbuffers, nreadbuffers;
128 enum sn9c102_io_method io;
129 enum sn9c102_stream_state stream;
131 struct v4l2_jpegcompression compression;
133 struct sn9c102_sysfs_attr sysfs;
136 enum sn9c102_dev_state state;
139 struct semaphore dev_sem, fileop_sem;
140 spinlock_t queue_lock;
141 wait_queue_head_t open, wait_frame, wait_stream;
144 /*****************************************************************************/
147 sn9c102_attach_sensor(struct sn9c102_device* cam,
148 struct sn9c102_sensor* sensor)
150 cam->sensor = sensor;
151 cam->sensor->dev = &cam->dev;
152 cam->sensor->usbdev = cam->usbdev;
155 /*****************************************************************************/
160 # define DBG(level, fmt, args...) \
162 if (debug >= (level)) { \
164 dev_err(&cam->dev, fmt "\n", ## args); \
165 else if ((level) == 2) \
166 dev_info(&cam->dev, fmt "\n", ## args); \
167 else if ((level) >= 3) \
168 dev_info(&cam->dev, "[%s:%d] " fmt "\n", \
169 __FUNCTION__, __LINE__ , ## args); \
172 # define KDBG(level, fmt, args...) \
174 if (debug >= (level)) { \
175 if ((level) == 1 || (level) == 2) \
176 pr_info("sn9c102: " fmt "\n", ## args); \
177 else if ((level) == 3) \
178 pr_debug("sn9c102: [%s:%d] " fmt "\n", __FUNCTION__, \
179 __LINE__ , ## args); \
183 # define KDBG(level, fmt, args...) do {;} while(0);
184 # define DBG(level, fmt, args...) do {;} while(0);
188 #define PDBG(fmt, args...) \
189 dev_info(&cam->dev, "[%s:%d] " fmt "\n", __FUNCTION__, __LINE__ , ## args);
192 #define PDBGG(fmt, args...) do {;} while(0); /* placeholder */
194 #endif /* _SN9C102_H_ */