1 /***************************************************************************
2 * V4L2 driver for SN9C10x PC Camera Controllers *
4 * Copyright (C) 2004-2006 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/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>
40 #include "sn9c102_sensor.h"
42 /*****************************************************************************/
45 #define SN9C102_DEBUG_LEVEL 2
46 #define SN9C102_MAX_DEVICES 64
47 #define SN9C102_PRESERVE_IMGSCALE 0
48 #define SN9C102_FORCE_MUNMAP 0
49 #define SN9C102_MAX_FRAMES 32
50 #define SN9C102_URBS 2
51 #define SN9C102_ISO_PACKETS 7
52 #define SN9C102_ALTERNATE_SETTING 8
53 #define SN9C102_URB_TIMEOUT msecs_to_jiffies(2 * SN9C102_ISO_PACKETS)
54 #define SN9C102_CTRL_TIMEOUT 300
55 #define SN9C102_FRAME_TIMEOUT 2
57 /*****************************************************************************/
60 BRIDGE_SN9C101 = 0x01,
61 BRIDGE_SN9C102 = 0x02,
62 BRIDGE_SN9C103 = 0x04,
68 enum sn9c102_frame_state {
76 struct sn9c102_frame_t {
78 struct v4l2_buffer buf;
79 enum sn9c102_frame_state state;
80 struct list_head frame;
81 unsigned long vma_use_count;
84 enum sn9c102_dev_state {
85 DEV_INITIALIZED = 0x01,
86 DEV_DISCONNECTED = 0x02,
87 DEV_MISCONFIGURED = 0x04,
90 enum sn9c102_io_method {
96 enum sn9c102_stream_state {
102 typedef char sn9c103_sof_header_t[18];
103 typedef char sn9c102_sof_header_t[12];
104 typedef char sn9c102_eof_header_t[4];
106 struct sn9c102_sysfs_attr {
108 sn9c103_sof_header_t frame_header;
111 struct sn9c102_module_param {
116 static DEFINE_MUTEX(sn9c102_sysfs_lock);
117 static DECLARE_RWSEM(sn9c102_disconnect);
119 struct sn9c102_device {
120 struct video_device* v4ldev;
122 enum sn9c102_bridge bridge;
123 struct sn9c102_sensor sensor;
125 struct usb_device* usbdev;
126 struct urb* urb[SN9C102_URBS];
127 void* transfer_buffer[SN9C102_URBS];
130 struct sn9c102_frame_t *frame_current, frame[SN9C102_MAX_FRAMES];
131 struct list_head inqueue, outqueue;
132 u32 frame_count, nbuffers, nreadbuffers;
134 enum sn9c102_io_method io;
135 enum sn9c102_stream_state stream;
137 struct v4l2_jpegcompression compression;
139 struct sn9c102_sysfs_attr sysfs;
140 sn9c103_sof_header_t sof_header;
143 struct sn9c102_module_param module_param;
145 enum sn9c102_dev_state state;
148 struct mutex dev_mutex, fileop_mutex;
149 spinlock_t queue_lock;
150 wait_queue_head_t open, wait_frame, wait_stream;
153 /*****************************************************************************/
155 struct sn9c102_device*
156 sn9c102_match_id(struct sn9c102_device* cam, const struct usb_device_id *id)
158 if (usb_match_id(usb_ifnum_to_if(cam->usbdev, 0), id))
166 sn9c102_attach_sensor(struct sn9c102_device* cam,
167 struct sn9c102_sensor* sensor)
169 memcpy(&cam->sensor, sensor, sizeof(struct sn9c102_sensor));
172 /*****************************************************************************/
177 # define DBG(level, fmt, args...) \
179 if (debug >= (level)) { \
181 dev_err(&cam->usbdev->dev, fmt "\n", ## args); \
182 else if ((level) == 2) \
183 dev_info(&cam->usbdev->dev, fmt "\n", ## args); \
184 else if ((level) >= 3) \
185 dev_info(&cam->usbdev->dev, "[%s:%d] " fmt "\n", \
186 __FUNCTION__, __LINE__ , ## args); \
189 # define V4LDBG(level, name, cmd) \
191 if (debug >= (level)) \
192 v4l_print_ioctl(name, cmd); \
194 # define KDBG(level, fmt, args...) \
196 if (debug >= (level)) { \
197 if ((level) == 1 || (level) == 2) \
198 pr_info("sn9c102: " fmt "\n", ## args); \
199 else if ((level) == 3) \
200 pr_debug("sn9c102: [%s:%d] " fmt "\n", __FUNCTION__, \
201 __LINE__ , ## args); \
205 # define DBG(level, fmt, args...) do {;} while(0)
206 # define V4LDBG(level, name, cmd) do {;} while(0)
207 # define KDBG(level, fmt, args...) do {;} while(0)
211 #define PDBG(fmt, args...) \
212 dev_info(&cam->usbdev->dev, "[%s:%d] " fmt "\n", \
213 __FUNCTION__, __LINE__ , ## args)
216 #define PDBGG(fmt, args...) do {;} while(0) /* placeholder */
218 #endif /* _SN9C102_H_ */