1 /***************************************************************************
2 * V4L2 driver for SN9C10[12] 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/wait.h>
31 #include <linux/types.h>
32 #include <linux/param.h>
33 #include <linux/rwsem.h>
34 #include <asm/semaphore.h>
36 #include "sn9c102_sensor.h"
38 /*****************************************************************************/
41 #define SN9C102_DEBUG_LEVEL 2
42 #define SN9C102_MAX_DEVICES 64
43 #define SN9C102_PRESERVE_IMGSCALE 0
44 #define SN9C102_MAX_FRAMES 32
45 #define SN9C102_URBS 2
46 #define SN9C102_ISO_PACKETS 7
47 #define SN9C102_ALTERNATE_SETTING 8
48 #define SN9C102_CTRL_TIMEOUT 10*HZ
50 /*****************************************************************************/
52 #define SN9C102_MODULE_NAME "V4L2 driver for SN9C10[12] PC Camera Controllers"
53 #define SN9C102_MODULE_AUTHOR "(C) 2004 Luca Risolia"
54 #define SN9C102_AUTHOR_EMAIL "<luca.risolia@studio.unibo.it>"
55 #define SN9C102_MODULE_LICENSE "GPL"
56 #define SN9C102_MODULE_VERSION "1:1.08"
57 #define SN9C102_MODULE_VERSION_CODE KERNEL_VERSION(1, 0, 8)
62 enum sn9c102_frame_state {
70 struct sn9c102_frame_t {
72 struct v4l2_buffer buf;
73 enum sn9c102_frame_state state;
74 struct list_head frame;
75 unsigned long vma_use_count;
78 enum sn9c102_dev_state {
79 DEV_INITIALIZED = 0x01,
80 DEV_DISCONNECTED = 0x02,
81 DEV_MISCONFIGURED = 0x04,
84 enum sn9c102_io_method {
90 enum sn9c102_stream_state {
96 struct sn9c102_sysfs_attr {
97 u8 reg, val, i2c_reg, i2c_val;
100 static DECLARE_MUTEX(sn9c102_sysfs_lock);
101 static DECLARE_RWSEM(sn9c102_disconnect);
103 struct sn9c102_device {
106 struct video_device* v4ldev;
108 struct sn9c102_sensor* sensor;
110 struct usb_device* usbdev;
111 struct urb* urb[SN9C102_URBS];
112 void* transfer_buffer[SN9C102_URBS];
115 struct sn9c102_frame_t *frame_current, frame[SN9C102_MAX_FRAMES];
116 struct list_head inqueue, outqueue;
117 u32 frame_count, nbuffers;
119 enum sn9c102_io_method io;
120 enum sn9c102_stream_state stream;
122 struct sn9c102_sysfs_attr sysfs;
125 enum sn9c102_dev_state state;
128 struct semaphore dev_sem, fileop_sem;
129 spinlock_t queue_lock;
130 wait_queue_head_t open, wait_frame, wait_stream;
133 /*****************************************************************************/
136 sn9c102_attach_sensor(struct sn9c102_device* cam,
137 struct sn9c102_sensor* sensor)
139 cam->sensor = sensor;
140 cam->sensor->dev = &cam->dev;
141 cam->sensor->usbdev = cam->usbdev;
144 /*****************************************************************************/
149 # define DBG(level, fmt, args...) \
151 if (debug >= (level)) { \
153 dev_err(&cam->dev, fmt "\n", ## args); \
154 else if ((level) == 2) \
155 dev_info(&cam->dev, fmt "\n", ## args); \
156 else if ((level) >= 3) \
157 dev_info(&cam->dev, "[%s:%d] " fmt "\n", \
158 __FUNCTION__, __LINE__ , ## args); \
161 # define KDBG(level, fmt, args...) \
163 if (debug >= (level)) { \
164 if ((level) == 1 || (level) == 2) \
165 pr_info("sn9c102: " fmt "\n", ## args); \
166 else if ((level) == 3) \
167 pr_debug("sn9c102: [%s:%d] " fmt "\n", __FUNCTION__, \
168 __LINE__ , ## args); \
172 # define KDBG(level, fmt, args...) do {;} while(0);
173 # define DBG(level, fmt, args...) do {;} while(0);
177 #define PDBG(fmt, args...) \
178 dev_info(&cam->dev, "[%s:%d] " fmt "\n", __FUNCTION__, __LINE__ , ## args);
181 #define PDBGG(fmt, args...) do {;} while(0); /* placeholder */
183 #endif /* _SN9C102_H_ */