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>
35 #include "sn9c102_sensor.h"
37 /*****************************************************************************/
40 #define SN9C102_DEBUG_LEVEL 2
41 #define SN9C102_MAX_DEVICES 64
42 #define SN9C102_MAX_FRAMES 32
43 #define SN9C102_URBS 2
44 #define SN9C102_ISO_PACKETS 7
45 #define SN9C102_ALTERNATE_SETTING 8
46 #define SN9C102_CTRL_TIMEOUT 10*HZ
48 /*****************************************************************************/
50 #define SN9C102_MODULE_NAME "V4L2 driver for SN9C10[12] PC Camera Controllers"
51 #define SN9C102_MODULE_AUTHOR "(C) 2004 Luca Risolia"
52 #define SN9C102_AUTHOR_EMAIL "<luca.risolia@studio.unibo.it>"
53 #define SN9C102_MODULE_LICENSE "GPL"
54 #define SN9C102_MODULE_VERSION "1:1.01-beta"
55 #define SN9C102_MODULE_VERSION_CODE KERNEL_VERSION(1, 0, 1)
60 enum sn9c102_frame_state {
68 struct sn9c102_frame_t {
70 struct v4l2_buffer buf;
71 enum sn9c102_frame_state state;
72 struct list_head frame;
73 unsigned long vma_use_count;
76 enum sn9c102_dev_state {
77 DEV_INITIALIZED = 0x01,
78 DEV_DISCONNECTED = 0x02,
79 DEV_MISCONFIGURED = 0x04,
82 enum sn9c102_io_method {
88 enum sn9c102_stream_state {
94 struct sn9c102_sysfs_attr {
95 u8 reg, val, i2c_reg, i2c_val;
98 static DECLARE_MUTEX(sn9c102_sysfs_lock);
99 static DECLARE_RWSEM(sn9c102_disconnect);
101 struct sn9c102_device {
104 struct video_device* v4ldev;
106 struct sn9c102_sensor* sensor;
108 struct usb_device* usbdev;
109 struct urb* urb[SN9C102_URBS];
110 void* transfer_buffer[SN9C102_URBS];
113 struct sn9c102_frame_t *frame_current, frame[SN9C102_MAX_FRAMES];
114 struct list_head inqueue, outqueue;
115 u32 frame_count, nbuffers;
117 enum sn9c102_io_method io;
118 enum sn9c102_stream_state stream;
120 struct sn9c102_sysfs_attr sysfs;
123 enum sn9c102_dev_state state;
126 struct semaphore dev_sem, fileop_sem;
127 spinlock_t queue_lock;
128 wait_queue_head_t open, wait_frame, wait_stream;
131 /*****************************************************************************/
134 sn9c102_attach_sensor(struct sn9c102_device* cam,
135 struct sn9c102_sensor* sensor)
137 cam->sensor = sensor;
138 cam->sensor->dev = &cam->dev;
139 cam->sensor->usbdev = cam->usbdev;
142 /*****************************************************************************/
147 # define DBG(level, fmt, args...) \
149 if (debug >= (level)) { \
151 dev_err(&cam->dev, fmt "\n", ## args); \
152 else if ((level) == 2) \
153 dev_info(&cam->dev, fmt "\n", ## args); \
154 else if ((level) >= 3) \
155 dev_info(&cam->dev, "[%s:%d] " fmt "\n", \
156 __FUNCTION__, __LINE__ , ## args); \
159 # define KDBG(level, fmt, args...) \
161 if (debug >= (level)) { \
162 if ((level) == 1 || (level) == 2) \
163 pr_info("sn9c102: " fmt "\n", ## args); \
164 else if ((level) == 3) \
165 pr_debug("sn9c102: [%s:%d] " fmt "\n", __FUNCTION__, \
166 __LINE__ , ## args); \
170 # define KDBG(level, fmt, args...) do {;} while(0);
171 # define DBG(level, fmt, args...) do {;} while(0);
175 #define PDBG(fmt, args...) \
176 dev_info(&cam->dev, "[%s:%d] " fmt "\n", __FUNCTION__, __LINE__ , ## args);
179 #define PDBGG(fmt, args...) do {;} while(0); /* placeholder */
181 #endif /* _SN9C102_H_ */