Commit | Line | Data |
---|---|---|
60f78052 | 1 | /*************************************************************************** |
7e3a0660 | 2 | * V4L2 driver for ZC0301[P] Image Processor and Control Chip * |
60f78052 | 3 | * * |
7e3a0660 | 4 | * Copyright (C) 2006-2007 by Luca Risolia <luca.risolia@studio.unibo.it> * |
60f78052 LR |
5 | * * |
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. * | |
10 | * * | |
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. * | |
15 | * * | |
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 | ***************************************************************************/ | |
20 | ||
21 | #ifndef _ZC0301_H_ | |
22 | #define _ZC0301_H_ | |
23 | ||
24 | #include <linux/version.h> | |
25 | #include <linux/usb.h> | |
26 | #include <linux/videodev2.h> | |
27 | #include <media/v4l2-common.h> | |
35ea11ff | 28 | #include <media/v4l2-ioctl.h> |
60f78052 LR |
29 | #include <linux/device.h> |
30 | #include <linux/list.h> | |
31 | #include <linux/spinlock.h> | |
32 | #include <linux/time.h> | |
33 | #include <linux/wait.h> | |
34 | #include <linux/types.h> | |
35 | #include <linux/param.h> | |
36 | #include <linux/mutex.h> | |
37 | #include <linux/rwsem.h> | |
a8474239 LR |
38 | #include <linux/stddef.h> |
39 | #include <linux/string.h> | |
4052fcc7 | 40 | #include <linux/kref.h> |
60f78052 LR |
41 | |
42 | #include "zc0301_sensor.h" | |
43 | ||
44 | /*****************************************************************************/ | |
45 | ||
46 | #define ZC0301_DEBUG | |
47 | #define ZC0301_DEBUG_LEVEL 2 | |
48 | #define ZC0301_MAX_DEVICES 64 | |
49 | #define ZC0301_FORCE_MUNMAP 0 | |
50 | #define ZC0301_MAX_FRAMES 32 | |
9e47a52b | 51 | #define ZC0301_COMPRESSION_QUALITY 0 |
60f78052 LR |
52 | #define ZC0301_URBS 2 |
53 | #define ZC0301_ISO_PACKETS 7 | |
54 | #define ZC0301_ALTERNATE_SETTING 7 | |
55 | #define ZC0301_URB_TIMEOUT msecs_to_jiffies(2 * ZC0301_ISO_PACKETS) | |
56 | #define ZC0301_CTRL_TIMEOUT 100 | |
a8474239 | 57 | #define ZC0301_FRAME_TIMEOUT 2 |
60f78052 LR |
58 | |
59 | /*****************************************************************************/ | |
60 | ||
61 | ZC0301_ID_TABLE | |
62 | ZC0301_SENSOR_TABLE | |
63 | ||
64 | enum zc0301_frame_state { | |
65 | F_UNUSED, | |
66 | F_QUEUED, | |
67 | F_GRABBING, | |
68 | F_DONE, | |
69 | F_ERROR, | |
70 | }; | |
71 | ||
72 | struct zc0301_frame_t { | |
73 | void* bufmem; | |
74 | struct v4l2_buffer buf; | |
75 | enum zc0301_frame_state state; | |
76 | struct list_head frame; | |
77 | unsigned long vma_use_count; | |
78 | }; | |
79 | ||
80 | enum zc0301_dev_state { | |
81 | DEV_INITIALIZED = 0x01, | |
82 | DEV_DISCONNECTED = 0x02, | |
83 | DEV_MISCONFIGURED = 0x04, | |
84 | }; | |
85 | ||
86 | enum zc0301_io_method { | |
87 | IO_NONE, | |
88 | IO_READ, | |
89 | IO_MMAP, | |
90 | }; | |
91 | ||
92 | enum zc0301_stream_state { | |
93 | STREAM_OFF, | |
94 | STREAM_INTERRUPT, | |
95 | STREAM_ON, | |
96 | }; | |
97 | ||
98 | struct zc0301_module_param { | |
99 | u8 force_munmap; | |
a8474239 | 100 | u16 frame_timeout; |
60f78052 LR |
101 | }; |
102 | ||
4052fcc7 | 103 | static DECLARE_RWSEM(zc0301_dev_lock); |
60f78052 LR |
104 | |
105 | struct zc0301_device { | |
106 | struct video_device* v4ldev; | |
107 | ||
a8474239 | 108 | struct zc0301_sensor sensor; |
60f78052 LR |
109 | |
110 | struct usb_device* usbdev; | |
111 | struct urb* urb[ZC0301_URBS]; | |
112 | void* transfer_buffer[ZC0301_URBS]; | |
113 | u8* control_buffer; | |
114 | ||
115 | struct zc0301_frame_t *frame_current, frame[ZC0301_MAX_FRAMES]; | |
116 | struct list_head inqueue, outqueue; | |
117 | u32 frame_count, nbuffers, nreadbuffers; | |
118 | ||
119 | enum zc0301_io_method io; | |
120 | enum zc0301_stream_state stream; | |
121 | ||
122 | struct v4l2_jpegcompression compression; | |
123 | ||
124 | struct zc0301_module_param module_param; | |
125 | ||
4052fcc7 | 126 | struct kref kref; |
60f78052 LR |
127 | enum zc0301_dev_state state; |
128 | u8 users; | |
129 | ||
4052fcc7 LR |
130 | struct completion probe; |
131 | struct mutex open_mutex, fileop_mutex; | |
60f78052 | 132 | spinlock_t queue_lock; |
4052fcc7 | 133 | wait_queue_head_t wait_open, wait_frame, wait_stream; |
60f78052 LR |
134 | }; |
135 | ||
136 | /*****************************************************************************/ | |
137 | ||
a8474239 LR |
138 | struct zc0301_device* |
139 | zc0301_match_id(struct zc0301_device* cam, const struct usb_device_id *id) | |
140 | { | |
6e0755a4 | 141 | return usb_match_id(usb_ifnum_to_if(cam->usbdev, 0), id) ? cam : NULL; |
a8474239 LR |
142 | } |
143 | ||
60f78052 LR |
144 | void |
145 | zc0301_attach_sensor(struct zc0301_device* cam, struct zc0301_sensor* sensor) | |
146 | { | |
a8474239 | 147 | memcpy(&cam->sensor, sensor, sizeof(struct zc0301_sensor)); |
60f78052 LR |
148 | } |
149 | ||
150 | /*****************************************************************************/ | |
151 | ||
152 | #undef DBG | |
153 | #undef KDBG | |
154 | #ifdef ZC0301_DEBUG | |
155 | # define DBG(level, fmt, args...) \ | |
156 | do { \ | |
157 | if (debug >= (level)) { \ | |
158 | if ((level) == 1) \ | |
159 | dev_err(&cam->usbdev->dev, fmt "\n", ## args); \ | |
160 | else if ((level) == 2) \ | |
161 | dev_info(&cam->usbdev->dev, fmt "\n", ## args); \ | |
162 | else if ((level) >= 3) \ | |
4052fcc7 | 163 | dev_info(&cam->usbdev->dev, "[%s:%s:%d] " fmt "\n", \ |
d5a50e49 | 164 | __FILE__, __func__, __LINE__ , ## args); \ |
60f78052 LR |
165 | } \ |
166 | } while (0) | |
167 | # define KDBG(level, fmt, args...) \ | |
168 | do { \ | |
169 | if (debug >= (level)) { \ | |
170 | if ((level) == 1 || (level) == 2) \ | |
171 | pr_info("zc0301: " fmt "\n", ## args); \ | |
172 | else if ((level) == 3) \ | |
4052fcc7 | 173 | pr_debug("sn9c102: [%s:%s:%d] " fmt "\n", __FILE__, \ |
d5a50e49 | 174 | __func__, __LINE__ , ## args); \ |
60f78052 LR |
175 | } \ |
176 | } while (0) | |
177 | # define V4LDBG(level, name, cmd) \ | |
178 | do { \ | |
179 | if (debug >= (level)) \ | |
180 | v4l_print_ioctl(name, cmd); \ | |
181 | } while (0) | |
182 | #else | |
183 | # define DBG(level, fmt, args...) do {;} while(0) | |
184 | # define KDBG(level, fmt, args...) do {;} while(0) | |
185 | # define V4LDBG(level, name, cmd) do {;} while(0) | |
186 | #endif | |
187 | ||
188 | #undef PDBG | |
189 | #define PDBG(fmt, args...) \ | |
d5a50e49 | 190 | dev_info(&cam->usbdev->dev, "[%s:%s:%d] " fmt "\n", __FILE__, __func__, \ |
4052fcc7 | 191 | __LINE__ , ## args) |
60f78052 LR |
192 | |
193 | #undef PDBGG | |
194 | #define PDBGG(fmt, args...) do {;} while(0) /* placeholder */ | |
195 | ||
196 | #endif /* _ZC0301_H_ */ |