1 /***************************************************************************
2 * V4L2 driver for ET61X[12]51 PC Camera Controllers *
4 * Copyright (C) 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/usb.h>
25 #include <linux/videodev2.h>
26 #include <media/v4l2-common.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 <linux/mutex.h>
36 #include <linux/stddef.h>
37 #include <linux/string.h>
38 #include <linux/kref.h>
40 #include "et61x251_sensor.h"
42 /*****************************************************************************/
44 #define ET61X251_DEBUG
45 #define ET61X251_DEBUG_LEVEL 2
46 #define ET61X251_MAX_DEVICES 64
47 #define ET61X251_PRESERVE_IMGSCALE 0
48 #define ET61X251_FORCE_MUNMAP 0
49 #define ET61X251_MAX_FRAMES 32
50 #define ET61X251_COMPRESSION_QUALITY 0
51 #define ET61X251_URBS 2
52 #define ET61X251_ISO_PACKETS 7
53 #define ET61X251_ALTERNATE_SETTING 13
54 #define ET61X251_URB_TIMEOUT msecs_to_jiffies(2 * ET61X251_ISO_PACKETS)
55 #define ET61X251_CTRL_TIMEOUT 100
56 #define ET61X251_FRAME_TIMEOUT 2
58 /*****************************************************************************/
60 static const struct usb_device_id et61x251_id_table
[] = {
61 { USB_DEVICE(0x102c, 0x6251), },
67 /*****************************************************************************/
69 enum et61x251_frame_state
{
77 struct et61x251_frame_t
{
79 struct v4l2_buffer buf
;
80 enum et61x251_frame_state state
;
81 struct list_head frame
;
82 unsigned long vma_use_count
;
85 enum et61x251_dev_state
{
86 DEV_INITIALIZED
= 0x01,
87 DEV_DISCONNECTED
= 0x02,
88 DEV_MISCONFIGURED
= 0x04,
91 enum et61x251_io_method
{
97 enum et61x251_stream_state
{
103 struct et61x251_sysfs_attr
{
107 struct et61x251_module_param
{
112 static DEFINE_MUTEX(et61x251_sysfs_lock
);
113 static DECLARE_RWSEM(et61x251_dev_lock
);
115 struct et61x251_device
{
116 struct video_device
* v4ldev
;
118 struct et61x251_sensor sensor
;
120 struct usb_device
* usbdev
;
121 struct urb
* urb
[ET61X251_URBS
];
122 void* transfer_buffer
[ET61X251_URBS
];
125 struct et61x251_frame_t
*frame_current
, frame
[ET61X251_MAX_FRAMES
];
126 struct list_head inqueue
, outqueue
;
127 u32 frame_count
, nbuffers
, nreadbuffers
;
129 enum et61x251_io_method io
;
130 enum et61x251_stream_state stream
;
132 struct v4l2_jpegcompression compression
;
134 struct et61x251_sysfs_attr sysfs
;
135 struct et61x251_module_param module_param
;
138 enum et61x251_dev_state state
;
141 struct completion probe
;
142 struct mutex open_mutex
, fileop_mutex
;
143 spinlock_t queue_lock
;
144 wait_queue_head_t wait_open
, wait_frame
, wait_stream
;
147 /*****************************************************************************/
149 struct et61x251_device
*
150 et61x251_match_id(struct et61x251_device
* cam
, const struct usb_device_id
*id
)
152 return usb_match_id(usb_ifnum_to_if(cam
->usbdev
, 0), id
) ? cam
: NULL
;
157 et61x251_attach_sensor(struct et61x251_device
* cam
,
158 const struct et61x251_sensor
* sensor
)
160 memcpy(&cam
->sensor
, sensor
, sizeof(struct et61x251_sensor
));
163 /*****************************************************************************/
167 #ifdef ET61X251_DEBUG
168 #define DBG(level, fmt, ...) \
170 if (debug >= (level)) { \
172 dev_err(&cam->usbdev->dev, fmt "\n", \
174 else if ((level) == 2) \
175 dev_info(&cam->usbdev->dev, fmt "\n", \
177 else if ((level) >= 3) \
178 dev_info(&cam->usbdev->dev, "[%s:%s:%d] " fmt "\n", \
179 __FILE__, __func__, __LINE__, \
183 #define KDBG(level, fmt, ...) \
185 if (debug >= (level)) { \
186 if ((level) == 1 || (level) == 2) \
187 pr_info(fmt "\n", ##__VA_ARGS__); \
188 else if ((level) == 3) \
189 pr_debug("[%s:%s:%d] " fmt "\n", \
190 __FILE__, __func__, __LINE__, \
194 #define V4LDBG(level, name, cmd) \
196 if (debug >= (level)) \
197 v4l_print_ioctl(name, cmd); \
200 #define DBG(level, fmt, ...) do {;} while(0)
201 #define KDBG(level, fmt, ...) do {;} while(0)
202 #define V4LDBG(level, name, cmd) do {;} while(0)
206 #define PDBG(fmt, ...) \
207 dev_info(&cam->usbdev->dev, "[%s:%s:%d] " fmt "\n", \
208 __FILE__, __func__, __LINE__, ##__VA_ARGS__)
211 #define PDBGG(fmt, args...) do {;} while (0) /* placeholder */
213 #endif /* _ET61X251_H_ */