1 /***************************************************************************
2 * V4L2 driver for ZC0301 Image Processor and Control Chip *
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/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/mutex.h>
36 #include <linux/rwsem.h>
37 #include <asm/semaphore.h>
39 #include "zc0301_sensor.h"
41 /*****************************************************************************/
44 #define ZC0301_DEBUG_LEVEL 2
45 #define ZC0301_MAX_DEVICES 64
46 #define ZC0301_FORCE_MUNMAP 0
47 #define ZC0301_MAX_FRAMES 32
48 #define ZC0301_COMPRESSION_QUALITY 2
50 #define ZC0301_ISO_PACKETS 7
51 #define ZC0301_ALTERNATE_SETTING 7
52 #define ZC0301_URB_TIMEOUT msecs_to_jiffies(2 * ZC0301_ISO_PACKETS)
53 #define ZC0301_CTRL_TIMEOUT 100
54 #define ZC0301_FRAME_TIMEOUT 2 * 1000 * msecs_to_jiffies(1)
56 /*****************************************************************************/
61 enum zc0301_frame_state
{
69 struct zc0301_frame_t
{
71 struct v4l2_buffer buf
;
72 enum zc0301_frame_state state
;
73 struct list_head frame
;
74 unsigned long vma_use_count
;
77 enum zc0301_dev_state
{
78 DEV_INITIALIZED
= 0x01,
79 DEV_DISCONNECTED
= 0x02,
80 DEV_MISCONFIGURED
= 0x04,
83 enum zc0301_io_method
{
89 enum zc0301_stream_state
{
95 struct zc0301_module_param
{
99 static DECLARE_RWSEM(zc0301_disconnect
);
101 struct zc0301_device
{
102 struct video_device
* v4ldev
;
104 struct zc0301_sensor
* sensor
;
106 struct usb_device
* usbdev
;
107 struct urb
* urb
[ZC0301_URBS
];
108 void* transfer_buffer
[ZC0301_URBS
];
111 struct zc0301_frame_t
*frame_current
, frame
[ZC0301_MAX_FRAMES
];
112 struct list_head inqueue
, outqueue
;
113 u32 frame_count
, nbuffers
, nreadbuffers
;
115 enum zc0301_io_method io
;
116 enum zc0301_stream_state stream
;
118 struct v4l2_jpegcompression compression
;
120 struct zc0301_module_param module_param
;
122 enum zc0301_dev_state state
;
125 struct mutex dev_mutex
, fileop_mutex
;
126 spinlock_t queue_lock
;
127 wait_queue_head_t open
, wait_frame
, wait_stream
;
130 /*****************************************************************************/
133 zc0301_attach_sensor(struct zc0301_device
* cam
, struct zc0301_sensor
* sensor
)
135 cam
->sensor
= sensor
;
136 cam
->sensor
->usbdev
= cam
->usbdev
;
139 /*****************************************************************************/
144 # define DBG(level, fmt, args...) \
146 if (debug >= (level)) { \
148 dev_err(&cam->usbdev->dev, fmt "\n", ## args); \
149 else if ((level) == 2) \
150 dev_info(&cam->usbdev->dev, fmt "\n", ## args); \
151 else if ((level) >= 3) \
152 dev_info(&cam->usbdev->dev, "[%s:%d] " fmt "\n", \
153 __FUNCTION__, __LINE__ , ## args); \
156 # define KDBG(level, fmt, args...) \
158 if (debug >= (level)) { \
159 if ((level) == 1 || (level) == 2) \
160 pr_info("zc0301: " fmt "\n", ## args); \
161 else if ((level) == 3) \
162 pr_debug("zc0301: [%s:%d] " fmt "\n", __FUNCTION__, \
163 __LINE__ , ## args); \
166 # define V4LDBG(level, name, cmd) \
168 if (debug >= (level)) \
169 v4l_print_ioctl(name, cmd); \
172 # define DBG(level, fmt, args...) do {;} while(0)
173 # define KDBG(level, fmt, args...) do {;} while(0)
174 # define V4LDBG(level, name, cmd) do {;} while(0)
178 #define PDBG(fmt, args...) \
179 dev_info(&cam->usbdev->dev, "[%s:%d] " fmt "\n", \
180 __FUNCTION__, __LINE__ , ## args)
183 #define PDBGG(fmt, args...) do {;} while(0) /* placeholder */
185 #endif /* _ZC0301_H_ */