diff options
author | Alan Cox <alan@linux.intel.com> | 2009-06-09 09:02:11 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2009-06-16 18:07:54 -0400 |
commit | aae40fd21906f051ce1ee5f623b8d70a2f32b7fc (patch) | |
tree | 9a13bbc33f97617bc13f616d7b7ed1b4e7f29f66 | |
parent | 226a040e6a95fbedff0c82a10fea4dd42320e79f (diff) |
V4L/DVB (11998): se401: Fix coding style
Having fixed the sprintfs I decided a quick clean wouldn't do any harm so
it was actually easy to read in future.
Signed-off-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
-rw-r--r-- | drivers/media/video/se401.c | 876 | ||||
-rw-r--r-- | drivers/media/video/se401.h | 7 |
2 files changed, 452 insertions, 431 deletions
diff --git a/drivers/media/video/se401.c b/drivers/media/video/se401.c index 08129a830d6e..c8f05297d0f0 100644 --- a/drivers/media/video/se401.c +++ b/drivers/media/video/se401.c | |||
@@ -38,7 +38,7 @@ static const char version[] = "0.24"; | |||
38 | static int flickerless; | 38 | static int flickerless; |
39 | static int video_nr = -1; | 39 | static int video_nr = -1; |
40 | 40 | ||
41 | static struct usb_device_id device_table [] = { | 41 | static struct usb_device_id device_table[] = { |
42 | { USB_DEVICE(0x03e8, 0x0004) },/* Endpoints/Aox SE401 */ | 42 | { USB_DEVICE(0x03e8, 0x0004) },/* Endpoints/Aox SE401 */ |
43 | { USB_DEVICE(0x0471, 0x030b) },/* Philips PCVC665K */ | 43 | { USB_DEVICE(0x0471, 0x030b) },/* Philips PCVC665K */ |
44 | { USB_DEVICE(0x047d, 0x5001) },/* Kensington 67014 */ | 44 | { USB_DEVICE(0x047d, 0x5001) },/* Kensington 67014 */ |
@@ -53,7 +53,8 @@ MODULE_AUTHOR("Jeroen Vreeken <pe1rxq@amsat.org>"); | |||
53 | MODULE_DESCRIPTION("SE401 USB Camera Driver"); | 53 | MODULE_DESCRIPTION("SE401 USB Camera Driver"); |
54 | MODULE_LICENSE("GPL"); | 54 | MODULE_LICENSE("GPL"); |
55 | module_param(flickerless, int, 0); | 55 | module_param(flickerless, int, 0); |
56 | MODULE_PARM_DESC(flickerless, "Net frequency to adjust exposure time to (0/50/60)"); | 56 | MODULE_PARM_DESC(flickerless, |
57 | "Net frequency to adjust exposure time to (0/50/60)"); | ||
57 | module_param(video_nr, int, 0); | 58 | module_param(video_nr, int, 0); |
58 | 59 | ||
59 | static struct usb_driver se401_driver; | 60 | static struct usb_driver se401_driver; |
@@ -78,8 +79,8 @@ static void *rvmalloc(unsigned long size) | |||
78 | adr = (unsigned long) mem; | 79 | adr = (unsigned long) mem; |
79 | while (size > 0) { | 80 | while (size > 0) { |
80 | SetPageReserved(vmalloc_to_page((void *)adr)); | 81 | SetPageReserved(vmalloc_to_page((void *)adr)); |
81 | adr += PAGE_SIZE; | 82 | adr += PAGE_SIZE; |
82 | size -= PAGE_SIZE; | 83 | size -= PAGE_SIZE; |
83 | } | 84 | } |
84 | 85 | ||
85 | return mem; | 86 | return mem; |
@@ -95,8 +96,8 @@ static void rvfree(void *mem, unsigned long size) | |||
95 | adr = (unsigned long) mem; | 96 | adr = (unsigned long) mem; |
96 | while ((long) size > 0) { | 97 | while ((long) size > 0) { |
97 | ClearPageReserved(vmalloc_to_page((void *)adr)); | 98 | ClearPageReserved(vmalloc_to_page((void *)adr)); |
98 | adr += PAGE_SIZE; | 99 | adr += PAGE_SIZE; |
99 | size -= PAGE_SIZE; | 100 | size -= PAGE_SIZE; |
100 | } | 101 | } |
101 | vfree(mem); | 102 | vfree(mem); |
102 | } | 103 | } |
@@ -112,7 +113,7 @@ static void rvfree(void *mem, unsigned long size) | |||
112 | static int se401_sndctrl(int set, struct usb_se401 *se401, unsigned short req, | 113 | static int se401_sndctrl(int set, struct usb_se401 *se401, unsigned short req, |
113 | unsigned short value, unsigned char *cp, int size) | 114 | unsigned short value, unsigned char *cp, int size) |
114 | { | 115 | { |
115 | return usb_control_msg ( | 116 | return usb_control_msg( |
116 | se401->dev, | 117 | se401->dev, |
117 | set ? usb_sndctrlpipe(se401->dev, 0) : usb_rcvctrlpipe(se401->dev, 0), | 118 | set ? usb_sndctrlpipe(se401->dev, 0) : usb_rcvctrlpipe(se401->dev, 0), |
118 | req, | 119 | req, |
@@ -132,7 +133,7 @@ static int se401_set_feature(struct usb_se401 *se401, unsigned short selector, | |||
132 | and the param in index, but in the logs of the windows driver they do | 133 | and the param in index, but in the logs of the windows driver they do |
133 | this the other way around... | 134 | this the other way around... |
134 | */ | 135 | */ |
135 | return usb_control_msg ( | 136 | return usb_control_msg( |
136 | se401->dev, | 137 | se401->dev, |
137 | usb_sndctrlpipe(se401->dev, 0), | 138 | usb_sndctrlpipe(se401->dev, 0), |
138 | SE401_REQ_SET_EXT_FEATURE, | 139 | SE401_REQ_SET_EXT_FEATURE, |
@@ -152,7 +153,7 @@ static unsigned short se401_get_feature(struct usb_se401 *se401, | |||
152 | wrong here to.... | 153 | wrong here to.... |
153 | */ | 154 | */ |
154 | unsigned char cp[2]; | 155 | unsigned char cp[2]; |
155 | usb_control_msg ( | 156 | usb_control_msg( |
156 | se401->dev, | 157 | se401->dev, |
157 | usb_rcvctrlpipe(se401->dev, 0), | 158 | usb_rcvctrlpipe(se401->dev, 0), |
158 | SE401_REQ_GET_EXT_FEATURE, | 159 | SE401_REQ_GET_EXT_FEATURE, |
@@ -175,46 +176,51 @@ static unsigned short se401_get_feature(struct usb_se401 *se401, | |||
175 | 176 | ||
176 | static int se401_send_pict(struct usb_se401 *se401) | 177 | static int se401_send_pict(struct usb_se401 *se401) |
177 | { | 178 | { |
178 | se401_set_feature(se401, HV7131_REG_TITL, se401->expose_l);/* integration time low */ | 179 | /* integration time low */ |
179 | se401_set_feature(se401, HV7131_REG_TITM, se401->expose_m);/* integration time mid */ | 180 | se401_set_feature(se401, HV7131_REG_TITL, se401->expose_l); |
180 | se401_set_feature(se401, HV7131_REG_TITU, se401->expose_h);/* integration time mid */ | 181 | /* integration time mid */ |
181 | se401_set_feature(se401, HV7131_REG_ARLV, se401->resetlevel);/* reset level value */ | 182 | se401_set_feature(se401, HV7131_REG_TITM, se401->expose_m); |
182 | se401_set_feature(se401, HV7131_REG_ARCG, se401->rgain);/* red color gain */ | 183 | /* integration time mid */ |
183 | se401_set_feature(se401, HV7131_REG_AGCG, se401->ggain);/* green color gain */ | 184 | se401_set_feature(se401, HV7131_REG_TITU, se401->expose_h); |
184 | se401_set_feature(se401, HV7131_REG_ABCG, se401->bgain);/* blue color gain */ | 185 | /* reset level value */ |
186 | se401_set_feature(se401, HV7131_REG_ARLV, se401->resetlevel); | ||
187 | /* red color gain */ | ||
188 | se401_set_feature(se401, HV7131_REG_ARCG, se401->rgain); | ||
189 | /* green color gain */ | ||
190 | se401_set_feature(se401, HV7131_REG_AGCG, se401->ggain); | ||
191 | /* blue color gain */ | ||
192 | se401_set_feature(se401, HV7131_REG_ABCG, se401->bgain); | ||
185 | 193 | ||
186 | return 0; | 194 | return 0; |
187 | } | 195 | } |
188 | 196 | ||
189 | static void se401_set_exposure(struct usb_se401 *se401, int brightness) | 197 | static void se401_set_exposure(struct usb_se401 *se401, int brightness) |
190 | { | 198 | { |
191 | int integration=brightness<<5; | 199 | int integration = brightness << 5; |
192 | 200 | ||
193 | if (flickerless==50) { | 201 | if (flickerless == 50) |
194 | integration=integration-integration%106667; | 202 | integration = integration-integration % 106667; |
195 | } | 203 | if (flickerless == 60) |
196 | if (flickerless==60) { | 204 | integration = integration-integration % 88889; |
197 | integration=integration-integration%88889; | 205 | se401->brightness = integration >> 5; |
198 | } | 206 | se401->expose_h = (integration >> 16) & 0xff; |
199 | se401->brightness=integration>>5; | 207 | se401->expose_m = (integration >> 8) & 0xff; |
200 | se401->expose_h=(integration>>16)&0xff; | 208 | se401->expose_l = integration & 0xff; |
201 | se401->expose_m=(integration>>8)&0xff; | ||
202 | se401->expose_l=integration&0xff; | ||
203 | } | 209 | } |
204 | 210 | ||
205 | static int se401_get_pict(struct usb_se401 *se401, struct video_picture *p) | 211 | static int se401_get_pict(struct usb_se401 *se401, struct video_picture *p) |
206 | { | 212 | { |
207 | p->brightness=se401->brightness; | 213 | p->brightness = se401->brightness; |
208 | if (se401->enhance) { | 214 | if (se401->enhance) |
209 | p->whiteness=32768; | 215 | p->whiteness = 32768; |
210 | } else { | 216 | else |
211 | p->whiteness=0; | 217 | p->whiteness = 0; |
212 | } | 218 | |
213 | p->colour=65535; | 219 | p->colour = 65535; |
214 | p->contrast=65535; | 220 | p->contrast = 65535; |
215 | p->hue=se401->rgain<<10; | 221 | p->hue = se401->rgain << 10; |
216 | p->palette=se401->palette; | 222 | p->palette = se401->palette; |
217 | p->depth=3; /* rgb24 */ | 223 | p->depth = 3; /* rgb24 */ |
218 | return 0; | 224 | return 0; |
219 | } | 225 | } |
220 | 226 | ||
@@ -223,20 +229,19 @@ static int se401_set_pict(struct usb_se401 *se401, struct video_picture *p) | |||
223 | { | 229 | { |
224 | if (p->palette != VIDEO_PALETTE_RGB24) | 230 | if (p->palette != VIDEO_PALETTE_RGB24) |
225 | return 1; | 231 | return 1; |
226 | se401->palette=p->palette; | 232 | se401->palette = p->palette; |
227 | if (p->hue!=se401->hue) { | 233 | if (p->hue != se401->hue) { |
228 | se401->rgain= p->hue>>10; | 234 | se401->rgain = p->hue >> 10; |
229 | se401->bgain= 0x40-(p->hue>>10); | 235 | se401->bgain = 0x40-(p->hue >> 10); |
230 | se401->hue=p->hue; | 236 | se401->hue = p->hue; |
231 | } | 237 | } |
232 | if (p->brightness!=se401->brightness) { | 238 | if (p->brightness != se401->brightness) |
233 | se401_set_exposure(se401, p->brightness); | 239 | se401_set_exposure(se401, p->brightness); |
234 | } | 240 | |
235 | if (p->whiteness>=32768) { | 241 | if (p->whiteness >= 32768) |
236 | se401->enhance=1; | 242 | se401->enhance = 1; |
237 | } else { | 243 | else |
238 | se401->enhance=0; | 244 | se401->enhance = 0; |
239 | } | ||
240 | se401_send_pict(se401); | 245 | se401_send_pict(se401); |
241 | se401_send_pict(se401); | 246 | se401_send_pict(se401); |
242 | return 0; | 247 | return 0; |
@@ -249,7 +254,7 @@ static int se401_set_pict(struct usb_se401 *se401, struct video_picture *p) | |||
249 | static void se401_auto_resetlevel(struct usb_se401 *se401) | 254 | static void se401_auto_resetlevel(struct usb_se401 *se401) |
250 | { | 255 | { |
251 | unsigned int ahrc, alrc; | 256 | unsigned int ahrc, alrc; |
252 | int oldreset=se401->resetlevel; | 257 | int oldreset = se401->resetlevel; |
253 | 258 | ||
254 | /* For some reason this normally read-only register doesn't get reset | 259 | /* For some reason this normally read-only register doesn't get reset |
255 | to zero after reading them just once... | 260 | to zero after reading them just once... |
@@ -258,24 +263,24 @@ static void se401_auto_resetlevel(struct usb_se401 *se401) | |||
258 | se401_get_feature(se401, HV7131_REG_HIREFNOL); | 263 | se401_get_feature(se401, HV7131_REG_HIREFNOL); |
259 | se401_get_feature(se401, HV7131_REG_LOREFNOH); | 264 | se401_get_feature(se401, HV7131_REG_LOREFNOH); |
260 | se401_get_feature(se401, HV7131_REG_LOREFNOL); | 265 | se401_get_feature(se401, HV7131_REG_LOREFNOL); |
261 | ahrc=256*se401_get_feature(se401, HV7131_REG_HIREFNOH) + | 266 | ahrc = 256*se401_get_feature(se401, HV7131_REG_HIREFNOH) + |
262 | se401_get_feature(se401, HV7131_REG_HIREFNOL); | 267 | se401_get_feature(se401, HV7131_REG_HIREFNOL); |
263 | alrc=256*se401_get_feature(se401, HV7131_REG_LOREFNOH) + | 268 | alrc = 256*se401_get_feature(se401, HV7131_REG_LOREFNOH) + |
264 | se401_get_feature(se401, HV7131_REG_LOREFNOL); | 269 | se401_get_feature(se401, HV7131_REG_LOREFNOL); |
265 | 270 | ||
266 | /* Not an exact science, but it seems to work pretty well... */ | 271 | /* Not an exact science, but it seems to work pretty well... */ |
267 | if (alrc > 10) { | 272 | if (alrc > 10) { |
268 | while (alrc>=10 && se401->resetlevel < 63) { | 273 | while (alrc >= 10 && se401->resetlevel < 63) { |
269 | se401->resetlevel++; | 274 | se401->resetlevel++; |
270 | alrc /=2; | 275 | alrc /= 2; |
271 | } | 276 | } |
272 | } else if (ahrc > 20) { | 277 | } else if (ahrc > 20) { |
273 | while (ahrc>=20 && se401->resetlevel > 0) { | 278 | while (ahrc >= 20 && se401->resetlevel > 0) { |
274 | se401->resetlevel--; | 279 | se401->resetlevel--; |
275 | ahrc /=2; | 280 | ahrc /= 2; |
276 | } | 281 | } |
277 | } | 282 | } |
278 | if (se401->resetlevel!=oldreset) | 283 | if (se401->resetlevel != oldreset) |
279 | se401_set_feature(se401, HV7131_REG_ARLV, se401->resetlevel); | 284 | se401_set_feature(se401, HV7131_REG_ARLV, se401->resetlevel); |
280 | 285 | ||
281 | return; | 286 | return; |
@@ -300,21 +305,22 @@ static void se401_button_irq(struct urb *urb) | |||
300 | case -ENOENT: | 305 | case -ENOENT: |
301 | case -ESHUTDOWN: | 306 | case -ESHUTDOWN: |
302 | /* this urb is terminated, clean up */ | 307 | /* this urb is terminated, clean up */ |
303 | dbg("%s - urb shutting down with status: %d", __func__, urb->status); | 308 | dbg("%s - urb shutting down with status: %d", |
309 | __func__, urb->status); | ||
304 | return; | 310 | return; |
305 | default: | 311 | default: |
306 | dbg("%s - nonzero urb status received: %d", __func__, urb->status); | 312 | dbg("%s - nonzero urb status received: %d", |
313 | __func__, urb->status); | ||
307 | goto exit; | 314 | goto exit; |
308 | } | 315 | } |
309 | 316 | ||
310 | if (urb->actual_length >=2) { | 317 | if (urb->actual_length >= 2) |
311 | if (se401->button) | 318 | if (se401->button) |
312 | se401->buttonpressed=1; | 319 | se401->buttonpressed = 1; |
313 | } | ||
314 | exit: | 320 | exit: |
315 | status = usb_submit_urb (urb, GFP_ATOMIC); | 321 | status = usb_submit_urb(urb, GFP_ATOMIC); |
316 | if (status) | 322 | if (status) |
317 | err ("%s - usb_submit_urb failed with result %d", | 323 | err("%s - usb_submit_urb failed with result %d", |
318 | __func__, status); | 324 | __func__, status); |
319 | } | 325 | } |
320 | 326 | ||
@@ -336,55 +342,52 @@ static void se401_video_irq(struct urb *urb) | |||
336 | keeps sending them forever... | 342 | keeps sending them forever... |
337 | */ | 343 | */ |
338 | if (length && !urb->status) { | 344 | if (length && !urb->status) { |
339 | se401->nullpackets=0; | 345 | se401->nullpackets = 0; |
340 | switch(se401->scratch[se401->scratch_next].state) { | 346 | switch (se401->scratch[se401->scratch_next].state) { |
341 | case BUFFER_READY: | 347 | case BUFFER_READY: |
342 | case BUFFER_BUSY: { | 348 | case BUFFER_BUSY: |
343 | se401->dropped++; | 349 | se401->dropped++; |
344 | break; | 350 | break; |
345 | } | 351 | case BUFFER_UNUSED: |
346 | case BUFFER_UNUSED: { | 352 | memcpy(se401->scratch[se401->scratch_next].data, |
347 | memcpy(se401->scratch[se401->scratch_next].data, (unsigned char *)urb->transfer_buffer, length); | 353 | (unsigned char *)urb->transfer_buffer, length); |
348 | se401->scratch[se401->scratch_next].state=BUFFER_READY; | 354 | se401->scratch[se401->scratch_next].state |
349 | se401->scratch[se401->scratch_next].offset=se401->bayeroffset; | 355 | = BUFFER_READY; |
350 | se401->scratch[se401->scratch_next].length=length; | 356 | se401->scratch[se401->scratch_next].offset |
351 | if (waitqueue_active(&se401->wq)) { | 357 | = se401->bayeroffset; |
352 | wake_up_interruptible(&se401->wq); | 358 | se401->scratch[se401->scratch_next].length = length; |
353 | } | 359 | if (waitqueue_active(&se401->wq)) |
354 | se401->scratch_overflow=0; | 360 | wake_up_interruptible(&se401->wq); |
355 | se401->scratch_next++; | 361 | se401->scratch_overflow = 0; |
356 | if (se401->scratch_next>=SE401_NUMSCRATCH) | 362 | se401->scratch_next++; |
357 | se401->scratch_next=0; | 363 | if (se401->scratch_next >= SE401_NUMSCRATCH) |
358 | break; | 364 | se401->scratch_next = 0; |
359 | } | 365 | break; |
360 | } | ||
361 | se401->bayeroffset+=length; | ||
362 | if (se401->bayeroffset>=se401->cheight*se401->cwidth) { | ||
363 | se401->bayeroffset=0; | ||
364 | } | 366 | } |
367 | se401->bayeroffset += length; | ||
368 | if (se401->bayeroffset >= se401->cheight * se401->cwidth) | ||
369 | se401->bayeroffset = 0; | ||
365 | } else { | 370 | } else { |
366 | se401->nullpackets++; | 371 | se401->nullpackets++; |
367 | if (se401->nullpackets > SE401_MAX_NULLPACKETS) { | 372 | if (se401->nullpackets > SE401_MAX_NULLPACKETS) |
368 | if (waitqueue_active(&se401->wq)) { | 373 | if (waitqueue_active(&se401->wq)) |
369 | wake_up_interruptible(&se401->wq); | 374 | wake_up_interruptible(&se401->wq); |
370 | } | ||
371 | } | ||
372 | } | 375 | } |
373 | 376 | ||
374 | /* Resubmit urb for new data */ | 377 | /* Resubmit urb for new data */ |
375 | urb->status=0; | 378 | urb->status = 0; |
376 | urb->dev=se401->dev; | 379 | urb->dev = se401->dev; |
377 | if(usb_submit_urb(urb, GFP_KERNEL)) | 380 | if (usb_submit_urb(urb, GFP_KERNEL)) |
378 | dev_info(&urb->dev->dev, "urb burned down\n"); | 381 | dev_info(&urb->dev->dev, "urb burned down\n"); |
379 | return; | 382 | return; |
380 | } | 383 | } |
381 | 384 | ||
382 | static void se401_send_size(struct usb_se401 *se401, int width, int height) | 385 | static void se401_send_size(struct usb_se401 *se401, int width, int height) |
383 | { | 386 | { |
384 | int i=0; | 387 | int i = 0; |
385 | int mode=0x03; /* No compression */ | 388 | int mode = 0x03; /* No compression */ |
386 | int sendheight=height; | 389 | int sendheight = height; |
387 | int sendwidth=width; | 390 | int sendwidth = width; |
388 | 391 | ||
389 | /* JangGu compression can only be used with the camera supported sizes, | 392 | /* JangGu compression can only be used with the camera supported sizes, |
390 | but bayer seems to work with any size that fits on the sensor. | 393 | but bayer seems to work with any size that fits on the sensor. |
@@ -392,18 +395,21 @@ static void se401_send_size(struct usb_se401 *se401, int width, int height) | |||
392 | 4 or 16 times subcapturing, if not we use uncompressed bayer data | 395 | 4 or 16 times subcapturing, if not we use uncompressed bayer data |
393 | but this will result in cutouts of the maximum size.... | 396 | but this will result in cutouts of the maximum size.... |
394 | */ | 397 | */ |
395 | while (i<se401->sizes && !(se401->width[i]==width && se401->height[i]==height)) | 398 | while (i < se401->sizes && !(se401->width[i] == width && |
399 | se401->height[i] == height)) | ||
396 | i++; | 400 | i++; |
397 | while (i<se401->sizes) { | 401 | while (i < se401->sizes) { |
398 | if (se401->width[i]==width*2 && se401->height[i]==height*2) { | 402 | if (se401->width[i] == width * 2 && |
399 | sendheight=se401->height[i]; | 403 | se401->height[i] == height * 2) { |
400 | sendwidth=se401->width[i]; | 404 | sendheight = se401->height[i]; |
401 | mode=0x40; | 405 | sendwidth = se401->width[i]; |
406 | mode = 0x40; | ||
402 | } | 407 | } |
403 | if (se401->width[i]==width*4 && se401->height[i]==height*4) { | 408 | if (se401->width[i] == width * 4 && |
404 | sendheight=se401->height[i]; | 409 | se401->height[i] == height * 4) { |
405 | sendwidth=se401->width[i]; | 410 | sendheight = se401->height[i]; |
406 | mode=0x42; | 411 | sendwidth = se401->width[i]; |
412 | mode = 0x42; | ||
407 | } | 413 | } |
408 | i++; | 414 | i++; |
409 | } | 415 | } |
@@ -412,13 +418,10 @@ static void se401_send_size(struct usb_se401 *se401, int width, int height) | |||
412 | se401_sndctrl(1, se401, SE401_REQ_SET_HEIGHT, sendheight, NULL, 0); | 418 | se401_sndctrl(1, se401, SE401_REQ_SET_HEIGHT, sendheight, NULL, 0); |
413 | se401_set_feature(se401, SE401_OPERATINGMODE, mode); | 419 | se401_set_feature(se401, SE401_OPERATINGMODE, mode); |
414 | 420 | ||
415 | if (mode==0x03) { | 421 | if (mode == 0x03) |
416 | se401->format=FMT_BAYER; | 422 | se401->format = FMT_BAYER; |
417 | } else { | 423 | else |
418 | se401->format=FMT_JANGGU; | 424 | se401->format = FMT_JANGGU; |
419 | } | ||
420 | |||
421 | return; | ||
422 | } | 425 | } |
423 | 426 | ||
424 | /* | 427 | /* |
@@ -429,29 +432,31 @@ static void se401_send_size(struct usb_se401 *se401, int width, int height) | |||
429 | static int se401_start_stream(struct usb_se401 *se401) | 432 | static int se401_start_stream(struct usb_se401 *se401) |
430 | { | 433 | { |
431 | struct urb *urb; | 434 | struct urb *urb; |
432 | int err=0, i; | 435 | int err = 0, i; |
433 | se401->streaming=1; | 436 | se401->streaming = 1; |
434 | 437 | ||
435 | se401_sndctrl(1, se401, SE401_REQ_CAMERA_POWER, 1, NULL, 0); | 438 | se401_sndctrl(1, se401, SE401_REQ_CAMERA_POWER, 1, NULL, 0); |
436 | se401_sndctrl(1, se401, SE401_REQ_LED_CONTROL, 1, NULL, 0); | 439 | se401_sndctrl(1, se401, SE401_REQ_LED_CONTROL, 1, NULL, 0); |
437 | 440 | ||
438 | /* Set picture settings */ | 441 | /* Set picture settings */ |
439 | se401_set_feature(se401, HV7131_REG_MODE_B, 0x05);/*windowed + pix intg */ | 442 | /* windowed + pix intg */ |
443 | se401_set_feature(se401, HV7131_REG_MODE_B, 0x05); | ||
440 | se401_send_pict(se401); | 444 | se401_send_pict(se401); |
441 | 445 | ||
442 | se401_send_size(se401, se401->cwidth, se401->cheight); | 446 | se401_send_size(se401, se401->cwidth, se401->cheight); |
443 | 447 | ||
444 | se401_sndctrl(1, se401, SE401_REQ_START_CONTINUOUS_CAPTURE, 0, NULL, 0); | 448 | se401_sndctrl(1, se401, SE401_REQ_START_CONTINUOUS_CAPTURE, |
449 | 0, NULL, 0); | ||
445 | 450 | ||
446 | /* Do some memory allocation */ | 451 | /* Do some memory allocation */ |
447 | for (i=0; i<SE401_NUMFRAMES; i++) { | 452 | for (i = 0; i < SE401_NUMFRAMES; i++) { |
448 | se401->frame[i].data=se401->fbuf + i * se401->maxframesize; | 453 | se401->frame[i].data = se401->fbuf + i * se401->maxframesize; |
449 | se401->frame[i].curpix=0; | 454 | se401->frame[i].curpix = 0; |
450 | } | 455 | } |
451 | for (i=0; i<SE401_NUMSBUF; i++) { | 456 | for (i = 0; i < SE401_NUMSBUF; i++) { |
452 | se401->sbuf[i].data=kmalloc(SE401_PACKETSIZE, GFP_KERNEL); | 457 | se401->sbuf[i].data = kmalloc(SE401_PACKETSIZE, GFP_KERNEL); |
453 | if (!se401->sbuf[i].data) { | 458 | if (!se401->sbuf[i].data) { |
454 | for(i = i - 1; i >= 0; i--) { | 459 | for (i = i - 1; i >= 0; i--) { |
455 | kfree(se401->sbuf[i].data); | 460 | kfree(se401->sbuf[i].data); |
456 | se401->sbuf[i].data = NULL; | 461 | se401->sbuf[i].data = NULL; |
457 | } | 462 | } |
@@ -459,26 +464,26 @@ static int se401_start_stream(struct usb_se401 *se401) | |||
459 | } | 464 | } |
460 | } | 465 | } |
461 | 466 | ||
462 | se401->bayeroffset=0; | 467 | se401->bayeroffset = 0; |
463 | se401->scratch_next=0; | 468 | se401->scratch_next = 0; |
464 | se401->scratch_use=0; | 469 | se401->scratch_use = 0; |
465 | se401->scratch_overflow=0; | 470 | se401->scratch_overflow = 0; |
466 | for (i=0; i<SE401_NUMSCRATCH; i++) { | 471 | for (i = 0; i < SE401_NUMSCRATCH; i++) { |
467 | se401->scratch[i].data=kmalloc(SE401_PACKETSIZE, GFP_KERNEL); | 472 | se401->scratch[i].data = kmalloc(SE401_PACKETSIZE, GFP_KERNEL); |
468 | if (!se401->scratch[i].data) { | 473 | if (!se401->scratch[i].data) { |
469 | for(i = i - 1; i >= 0; i--) { | 474 | for (i = i - 1; i >= 0; i--) { |
470 | kfree(se401->scratch[i].data); | 475 | kfree(se401->scratch[i].data); |
471 | se401->scratch[i].data = NULL; | 476 | se401->scratch[i].data = NULL; |
472 | } | 477 | } |
473 | goto nomem_sbuf; | 478 | goto nomem_sbuf; |
474 | } | 479 | } |
475 | se401->scratch[i].state=BUFFER_UNUSED; | 480 | se401->scratch[i].state = BUFFER_UNUSED; |
476 | } | 481 | } |
477 | 482 | ||
478 | for (i=0; i<SE401_NUMSBUF; i++) { | 483 | for (i = 0; i < SE401_NUMSBUF; i++) { |
479 | urb=usb_alloc_urb(0, GFP_KERNEL); | 484 | urb = usb_alloc_urb(0, GFP_KERNEL); |
480 | if(!urb) { | 485 | if (!urb) { |
481 | for(i = i - 1; i >= 0; i--) { | 486 | for (i = i - 1; i >= 0; i--) { |
482 | usb_kill_urb(se401->urb[i]); | 487 | usb_kill_urb(se401->urb[i]); |
483 | usb_free_urb(se401->urb[i]); | 488 | usb_free_urb(se401->urb[i]); |
484 | se401->urb[i] = NULL; | 489 | se401->urb[i] = NULL; |
@@ -492,24 +497,24 @@ static int se401_start_stream(struct usb_se401 *se401) | |||
492 | se401_video_irq, | 497 | se401_video_irq, |
493 | se401); | 498 | se401); |
494 | 499 | ||
495 | se401->urb[i]=urb; | 500 | se401->urb[i] = urb; |
496 | 501 | ||
497 | err=usb_submit_urb(se401->urb[i], GFP_KERNEL); | 502 | err = usb_submit_urb(se401->urb[i], GFP_KERNEL); |
498 | if(err) | 503 | if (err) |
499 | err("urb burned down"); | 504 | err("urb burned down"); |
500 | } | 505 | } |
501 | 506 | ||
502 | se401->framecount=0; | 507 | se401->framecount = 0; |
503 | 508 | ||
504 | return 0; | 509 | return 0; |
505 | 510 | ||
506 | nomem_scratch: | 511 | nomem_scratch: |
507 | for (i=0; i<SE401_NUMSCRATCH; i++) { | 512 | for (i = 0; i < SE401_NUMSCRATCH; i++) { |
508 | kfree(se401->scratch[i].data); | 513 | kfree(se401->scratch[i].data); |
509 | se401->scratch[i].data = NULL; | 514 | se401->scratch[i].data = NULL; |
510 | } | 515 | } |
511 | nomem_sbuf: | 516 | nomem_sbuf: |
512 | for (i=0; i<SE401_NUMSBUF; i++) { | 517 | for (i = 0; i < SE401_NUMSBUF; i++) { |
513 | kfree(se401->sbuf[i].data); | 518 | kfree(se401->sbuf[i].data); |
514 | se401->sbuf[i].data = NULL; | 519 | se401->sbuf[i].data = NULL; |
515 | } | 520 | } |
@@ -523,22 +528,23 @@ static int se401_stop_stream(struct usb_se401 *se401) | |||
523 | if (!se401->streaming || !se401->dev) | 528 | if (!se401->streaming || !se401->dev) |
524 | return 1; | 529 | return 1; |
525 | 530 | ||
526 | se401->streaming=0; | 531 | se401->streaming = 0; |
527 | 532 | ||
528 | se401_sndctrl(1, se401, SE401_REQ_STOP_CONTINUOUS_CAPTURE, 0, NULL, 0); | 533 | se401_sndctrl(1, se401, SE401_REQ_STOP_CONTINUOUS_CAPTURE, 0, NULL, 0); |
529 | 534 | ||
530 | se401_sndctrl(1, se401, SE401_REQ_LED_CONTROL, 0, NULL, 0); | 535 | se401_sndctrl(1, se401, SE401_REQ_LED_CONTROL, 0, NULL, 0); |
531 | se401_sndctrl(1, se401, SE401_REQ_CAMERA_POWER, 0, NULL, 0); | 536 | se401_sndctrl(1, se401, SE401_REQ_CAMERA_POWER, 0, NULL, 0); |
532 | 537 | ||
533 | for (i=0; i<SE401_NUMSBUF; i++) if (se401->urb[i]) { | 538 | for (i = 0; i < SE401_NUMSBUF; i++) |
534 | usb_kill_urb(se401->urb[i]); | 539 | if (se401->urb[i]) { |
535 | usb_free_urb(se401->urb[i]); | 540 | usb_kill_urb(se401->urb[i]); |
536 | se401->urb[i]=NULL; | 541 | usb_free_urb(se401->urb[i]); |
537 | kfree(se401->sbuf[i].data); | 542 | se401->urb[i] = NULL; |
538 | } | 543 | kfree(se401->sbuf[i].data); |
539 | for (i=0; i<SE401_NUMSCRATCH; i++) { | 544 | } |
545 | for (i = 0; i < SE401_NUMSCRATCH; i++) { | ||
540 | kfree(se401->scratch[i].data); | 546 | kfree(se401->scratch[i].data); |
541 | se401->scratch[i].data=NULL; | 547 | se401->scratch[i].data = NULL; |
542 | } | 548 | } |
543 | 549 | ||
544 | return 0; | 550 | return 0; |
@@ -546,9 +552,9 @@ static int se401_stop_stream(struct usb_se401 *se401) | |||
546 | 552 | ||
547 | static int se401_set_size(struct usb_se401 *se401, int width, int height) | 553 | static int se401_set_size(struct usb_se401 *se401, int width, int height) |
548 | { | 554 | { |
549 | int wasstreaming=se401->streaming; | 555 | int wasstreaming = se401->streaming; |
550 | /* Check to see if we need to change */ | 556 | /* Check to see if we need to change */ |
551 | if (se401->cwidth==width && se401->cheight==height) | 557 | if (se401->cwidth == width && se401->cheight == height) |
552 | return 0; | 558 | return 0; |
553 | 559 | ||
554 | /* Check for a valid mode */ | 560 | /* Check for a valid mode */ |
@@ -556,16 +562,16 @@ static int se401_set_size(struct usb_se401 *se401, int width, int height) | |||
556 | return 1; | 562 | return 1; |
557 | if ((width & 1) || (height & 1)) | 563 | if ((width & 1) || (height & 1)) |
558 | return 1; | 564 | return 1; |
559 | if (width>se401->width[se401->sizes-1]) | 565 | if (width > se401->width[se401->sizes-1]) |
560 | return 1; | 566 | return 1; |
561 | if (height>se401->height[se401->sizes-1]) | 567 | if (height > se401->height[se401->sizes-1]) |
562 | return 1; | 568 | return 1; |
563 | 569 | ||
564 | /* Stop a current stream and start it again at the new size */ | 570 | /* Stop a current stream and start it again at the new size */ |
565 | if (wasstreaming) | 571 | if (wasstreaming) |
566 | se401_stop_stream(se401); | 572 | se401_stop_stream(se401); |
567 | se401->cwidth=width; | 573 | se401->cwidth = width; |
568 | se401->cheight=height; | 574 | se401->cheight = height; |
569 | if (wasstreaming) | 575 | if (wasstreaming) |
570 | se401_start_stream(se401); | 576 | se401_start_stream(se401); |
571 | return 0; | 577 | return 0; |
@@ -586,68 +592,68 @@ static int se401_set_size(struct usb_se401 *se401, int width, int height) | |||
586 | static inline void enhance_picture(unsigned char *frame, int len) | 592 | static inline void enhance_picture(unsigned char *frame, int len) |
587 | { | 593 | { |
588 | while (len--) { | 594 | while (len--) { |
589 | *frame=(((*frame^255)*(*frame^255))/255)^255; | 595 | *frame = (((*frame^255)*(*frame^255))/255)^255; |
590 | frame++; | 596 | frame++; |
591 | } | 597 | } |
592 | } | 598 | } |
593 | 599 | ||
594 | static inline void decode_JangGu_integrate(struct usb_se401 *se401, int data) | 600 | static inline void decode_JangGu_integrate(struct usb_se401 *se401, int data) |
595 | { | 601 | { |
596 | struct se401_frame *frame=&se401->frame[se401->curframe]; | 602 | struct se401_frame *frame = &se401->frame[se401->curframe]; |
597 | int linelength=se401->cwidth*3; | 603 | int linelength = se401->cwidth * 3; |
598 | 604 | ||
599 | if (frame->curlinepix >= linelength) { | 605 | if (frame->curlinepix >= linelength) { |
600 | frame->curlinepix=0; | 606 | frame->curlinepix = 0; |
601 | frame->curline+=linelength; | 607 | frame->curline += linelength; |
602 | } | 608 | } |
603 | 609 | ||
604 | /* First three are absolute, all others relative. | 610 | /* First three are absolute, all others relative. |
605 | * Format is rgb from right to left (mirrorred image), | 611 | * Format is rgb from right to left (mirrorred image), |
606 | * we flip it to get bgr from left to right. */ | 612 | * we flip it to get bgr from left to right. */ |
607 | if (frame->curlinepix < 3) { | 613 | if (frame->curlinepix < 3) |
608 | *(frame->curline-frame->curlinepix)=1+data*4; | 614 | *(frame->curline-frame->curlinepix) = 1 + data * 4; |
609 | } else { | 615 | else |
610 | *(frame->curline-frame->curlinepix)= | 616 | *(frame->curline-frame->curlinepix) = |
611 | *(frame->curline-frame->curlinepix+3)+data*4; | 617 | *(frame->curline-frame->curlinepix + 3) + data * 4; |
612 | } | ||
613 | frame->curlinepix++; | 618 | frame->curlinepix++; |
614 | } | 619 | } |
615 | 620 | ||
616 | static inline void decode_JangGu_vlc (struct usb_se401 *se401, unsigned char *data, int bit_exp, int packetlength) | 621 | static inline void decode_JangGu_vlc(struct usb_se401 *se401, |
622 | unsigned char *data, int bit_exp, int packetlength) | ||
617 | { | 623 | { |
618 | int pos=0; | 624 | int pos = 0; |
619 | int vlc_cod=0; | 625 | int vlc_cod = 0; |
620 | int vlc_size=0; | 626 | int vlc_size = 0; |
621 | int vlc_data=0; | 627 | int vlc_data = 0; |
622 | int bit_cur; | 628 | int bit_cur; |
623 | int bit; | 629 | int bit; |
624 | data+=4; | 630 | data += 4; |
625 | while (pos < packetlength) { | 631 | while (pos < packetlength) { |
626 | bit_cur=8; | 632 | bit_cur = 8; |
627 | while (bit_cur && bit_exp) { | 633 | while (bit_cur && bit_exp) { |
628 | bit=((*data)>>(bit_cur-1))&1; | 634 | bit = ((*data) >> (bit_cur-1))&1; |
629 | if (!vlc_cod) { | 635 | if (!vlc_cod) { |
630 | if (bit) { | 636 | if (bit) { |
631 | vlc_size++; | 637 | vlc_size++; |
632 | } else { | 638 | } else { |
633 | if (!vlc_size) { | 639 | if (!vlc_size) |
634 | decode_JangGu_integrate(se401, 0); | 640 | decode_JangGu_integrate(se401, 0); |
635 | } else { | 641 | else { |
636 | vlc_cod=2; | 642 | vlc_cod = 2; |
637 | vlc_data=0; | 643 | vlc_data = 0; |
638 | } | 644 | } |
639 | } | 645 | } |
640 | } else { | 646 | } else { |
641 | if (vlc_cod==2) { | 647 | if (vlc_cod == 2) { |
642 | if (!bit) | 648 | if (!bit) |
643 | vlc_data = -(1<<vlc_size) + 1; | 649 | vlc_data = -(1 << vlc_size) + 1; |
644 | vlc_cod--; | 650 | vlc_cod--; |
645 | } | 651 | } |
646 | vlc_size--; | 652 | vlc_size--; |
647 | vlc_data+=bit<<vlc_size; | 653 | vlc_data += bit << vlc_size; |
648 | if (!vlc_size) { | 654 | if (!vlc_size) { |
649 | decode_JangGu_integrate(se401, vlc_data); | 655 | decode_JangGu_integrate(se401, vlc_data); |
650 | vlc_cod=0; | 656 | vlc_cod = 0; |
651 | } | 657 | } |
652 | } | 658 | } |
653 | bit_cur--; | 659 | bit_cur--; |
@@ -658,186 +664,188 @@ static inline void decode_JangGu_vlc (struct usb_se401 *se401, unsigned char *da | |||
658 | } | 664 | } |
659 | } | 665 | } |
660 | 666 | ||
661 | static inline void decode_JangGu (struct usb_se401 *se401, struct se401_scratch *buffer) | 667 | static inline void decode_JangGu(struct usb_se401 *se401, |
668 | struct se401_scratch *buffer) | ||
662 | { | 669 | { |
663 | unsigned char *data=buffer->data; | 670 | unsigned char *data = buffer->data; |
664 | int len=buffer->length; | 671 | int len = buffer->length; |
665 | int bit_exp=0, pix_exp=0, frameinfo=0, packetlength=0, size; | 672 | int bit_exp = 0, pix_exp = 0, frameinfo = 0, packetlength = 0, size; |
666 | int datapos=0; | 673 | int datapos = 0; |
667 | 674 | ||
668 | /* New image? */ | 675 | /* New image? */ |
669 | if (!se401->frame[se401->curframe].curpix) { | 676 | if (!se401->frame[se401->curframe].curpix) { |
670 | se401->frame[se401->curframe].curlinepix=0; | 677 | se401->frame[se401->curframe].curlinepix = 0; |
671 | se401->frame[se401->curframe].curline= | 678 | se401->frame[se401->curframe].curline = |
672 | se401->frame[se401->curframe].data+ | 679 | se401->frame[se401->curframe].data+ |
673 | se401->cwidth*3-1; | 680 | se401->cwidth * 3 - 1; |
674 | if (se401->frame[se401->curframe].grabstate==FRAME_READY) | 681 | if (se401->frame[se401->curframe].grabstate == FRAME_READY) |
675 | se401->frame[se401->curframe].grabstate=FRAME_GRABBING; | 682 | se401->frame[se401->curframe].grabstate = FRAME_GRABBING; |
676 | se401->vlcdatapos=0; | 683 | se401->vlcdatapos = 0; |
677 | } | 684 | } |
678 | while (datapos < len) { | 685 | while (datapos < len) { |
679 | size=1024-se401->vlcdatapos; | 686 | size = 1024 - se401->vlcdatapos; |
680 | if (size+datapos > len) | 687 | if (size+datapos > len) |
681 | size=len-datapos; | 688 | size = len-datapos; |
682 | memcpy(se401->vlcdata+se401->vlcdatapos, data+datapos, size); | 689 | memcpy(se401->vlcdata+se401->vlcdatapos, data+datapos, size); |
683 | se401->vlcdatapos+=size; | 690 | se401->vlcdatapos += size; |
684 | packetlength=0; | 691 | packetlength = 0; |
685 | if (se401->vlcdatapos >= 4) { | 692 | if (se401->vlcdatapos >= 4) { |
686 | bit_exp=se401->vlcdata[3]+(se401->vlcdata[2]<<8); | 693 | bit_exp = se401->vlcdata[3] + (se401->vlcdata[2] << 8); |
687 | pix_exp=se401->vlcdata[1]+((se401->vlcdata[0]&0x3f)<<8); | 694 | pix_exp = se401->vlcdata[1] + |
688 | frameinfo=se401->vlcdata[0]&0xc0; | 695 | ((se401->vlcdata[0] & 0x3f) << 8); |
689 | packetlength=((bit_exp+47)>>4)<<1; | 696 | frameinfo = se401->vlcdata[0] & 0xc0; |
697 | packetlength = ((bit_exp + 47) >> 4) << 1; | ||
690 | if (packetlength > 1024) { | 698 | if (packetlength > 1024) { |
691 | se401->vlcdatapos=0; | 699 | se401->vlcdatapos = 0; |
692 | datapos=len; | 700 | datapos = len; |
693 | packetlength=0; | 701 | packetlength = 0; |
694 | se401->error++; | 702 | se401->error++; |
695 | se401->frame[se401->curframe].curpix=0; | 703 | se401->frame[se401->curframe].curpix = 0; |
696 | } | 704 | } |
697 | } | 705 | } |
698 | if (packetlength && se401->vlcdatapos >= packetlength) { | 706 | if (packetlength && se401->vlcdatapos >= packetlength) { |
699 | decode_JangGu_vlc(se401, se401->vlcdata, bit_exp, packetlength); | 707 | decode_JangGu_vlc(se401, se401->vlcdata, bit_exp, |
700 | se401->frame[se401->curframe].curpix+=pix_exp*3; | 708 | packetlength); |
701 | datapos+=size-(se401->vlcdatapos-packetlength); | 709 | se401->frame[se401->curframe].curpix += pix_exp * 3; |
702 | se401->vlcdatapos=0; | 710 | datapos += size-(se401->vlcdatapos-packetlength); |
703 | if (se401->frame[se401->curframe].curpix>=se401->cwidth*se401->cheight*3) { | 711 | se401->vlcdatapos = 0; |
704 | if (se401->frame[se401->curframe].curpix==se401->cwidth*se401->cheight*3) { | 712 | if (se401->frame[se401->curframe].curpix >= se401->cwidth * se401->cheight * 3) { |
705 | if (se401->frame[se401->curframe].grabstate==FRAME_GRABBING) { | 713 | if (se401->frame[se401->curframe].curpix == se401->cwidth * se401->cheight * 3) { |
706 | se401->frame[se401->curframe].grabstate=FRAME_DONE; | 714 | if (se401->frame[se401->curframe].grabstate == FRAME_GRABBING) { |
715 | se401->frame[se401->curframe].grabstate = FRAME_DONE; | ||
707 | se401->framecount++; | 716 | se401->framecount++; |
708 | se401->readcount++; | 717 | se401->readcount++; |
709 | } | 718 | } |
710 | if (se401->frame[(se401->curframe+1)&(SE401_NUMFRAMES-1)].grabstate==FRAME_READY) { | 719 | if (se401->frame[(se401->curframe + 1) & (SE401_NUMFRAMES - 1)].grabstate == FRAME_READY) |
711 | se401->curframe=(se401->curframe+1) & (SE401_NUMFRAMES-1); | 720 | se401->curframe = (se401->curframe + 1) & (SE401_NUMFRAMES - 1); |
712 | } | 721 | } else |
713 | } else { | ||
714 | se401->error++; | 722 | se401->error++; |
715 | } | 723 | se401->frame[se401->curframe].curpix = 0; |
716 | se401->frame[se401->curframe].curpix=0; | 724 | datapos = len; |
717 | datapos=len; | ||
718 | } | 725 | } |
719 | } else { | 726 | } else |
720 | datapos+=size; | 727 | datapos += size; |
721 | } | ||
722 | } | 728 | } |
723 | } | 729 | } |
724 | 730 | ||
725 | static inline void decode_bayer (struct usb_se401 *se401, struct se401_scratch *buffer) | 731 | static inline void decode_bayer(struct usb_se401 *se401, |
732 | struct se401_scratch *buffer) | ||
726 | { | 733 | { |
727 | unsigned char *data=buffer->data; | 734 | unsigned char *data = buffer->data; |
728 | int len=buffer->length; | 735 | int len = buffer->length; |
729 | int offset=buffer->offset; | 736 | int offset = buffer->offset; |
730 | int datasize=se401->cwidth*se401->cheight; | 737 | int datasize = se401->cwidth * se401->cheight; |
731 | struct se401_frame *frame=&se401->frame[se401->curframe]; | 738 | struct se401_frame *frame = &se401->frame[se401->curframe]; |
739 | unsigned char *framedata = frame->data, *curline, *nextline; | ||
740 | int width = se401->cwidth; | ||
741 | int blineoffset = 0, bline; | ||
742 | int linelength = width * 3, i; | ||
732 | 743 | ||
733 | unsigned char *framedata=frame->data, *curline, *nextline; | ||
734 | int width=se401->cwidth; | ||
735 | int blineoffset=0, bline; | ||
736 | int linelength=width*3, i; | ||
737 | 744 | ||
745 | if (frame->curpix == 0) { | ||
746 | if (frame->grabstate == FRAME_READY) | ||
747 | frame->grabstate = FRAME_GRABBING; | ||
738 | 748 | ||
739 | if (frame->curpix==0) { | 749 | frame->curline = framedata + linelength; |
740 | if (frame->grabstate==FRAME_READY) { | 750 | frame->curlinepix = 0; |
741 | frame->grabstate=FRAME_GRABBING; | ||
742 | } | ||
743 | frame->curline=framedata+linelength; | ||
744 | frame->curlinepix=0; | ||
745 | } | 751 | } |
746 | 752 | ||
747 | if (offset!=frame->curpix) { | 753 | if (offset != frame->curpix) { |
748 | /* Regard frame as lost :( */ | 754 | /* Regard frame as lost :( */ |
749 | frame->curpix=0; | 755 | frame->curpix = 0; |
750 | se401->error++; | 756 | se401->error++; |
751 | return; | 757 | return; |
752 | } | 758 | } |
753 | 759 | ||
754 | /* Check if we have to much data */ | 760 | /* Check if we have to much data */ |
755 | if (frame->curpix+len > datasize) { | 761 | if (frame->curpix + len > datasize) |
756 | len=datasize-frame->curpix; | 762 | len = datasize-frame->curpix; |
757 | } | 763 | |
758 | if (se401->cheight%4) | 764 | if (se401->cheight % 4) |
759 | blineoffset=1; | 765 | blineoffset = 1; |
760 | bline=frame->curpix/se401->cwidth+blineoffset; | 766 | bline = frame->curpix / se401->cwidth+blineoffset; |
761 | 767 | ||
762 | curline=frame->curline; | 768 | curline = frame->curline; |
763 | nextline=curline+linelength; | 769 | nextline = curline + linelength; |
764 | if (nextline >= framedata+datasize*3) | 770 | if (nextline >= framedata+datasize * 3) |
765 | nextline=curline; | 771 | nextline = curline; |
766 | while (len) { | 772 | while (len) { |
767 | if (frame->curlinepix>=width) { | 773 | if (frame->curlinepix >= width) { |
768 | frame->curlinepix-=width; | 774 | frame->curlinepix -= width; |
769 | bline=frame->curpix/width+blineoffset; | 775 | bline = frame->curpix / width + blineoffset; |
770 | curline+=linelength*2; | 776 | curline += linelength*2; |
771 | nextline+=linelength*2; | 777 | nextline += linelength*2; |
772 | if (curline >= framedata+datasize*3) { | 778 | if (curline >= framedata+datasize * 3) { |
773 | frame->curlinepix++; | 779 | frame->curlinepix++; |
774 | curline-=3; | 780 | curline -= 3; |
775 | nextline-=3; | 781 | nextline -= 3; |
776 | len--; | 782 | len--; |
777 | data++; | 783 | data++; |
778 | frame->curpix++; | 784 | frame->curpix++; |
779 | } | 785 | } |
780 | if (nextline >= framedata+datasize*3) | 786 | if (nextline >= framedata+datasize*3) |
781 | nextline=curline; | 787 | nextline = curline; |
782 | } | 788 | } |
783 | if ((bline&1)) { | 789 | if (bline & 1) { |
784 | if ((frame->curlinepix&1)) { | 790 | if (frame->curlinepix & 1) { |
785 | *(curline+2)=*data; | 791 | *(curline + 2) = *data; |
786 | *(curline-1)=*data; | 792 | *(curline - 1) = *data; |
787 | *(nextline+2)=*data; | 793 | *(nextline + 2) = *data; |
788 | *(nextline-1)=*data; | 794 | *(nextline - 1) = *data; |
789 | } else { | 795 | } else { |
790 | *(curline+1)= | 796 | *(curline + 1) = |
791 | (*(curline+1)+*data)/2; | 797 | (*(curline + 1) + *data) / 2; |
792 | *(curline-2)= | 798 | *(curline-2) = |
793 | (*(curline-2)+*data)/2; | 799 | (*(curline - 2) + *data) / 2; |
794 | *(nextline+1)=*data; | 800 | *(nextline + 1) = *data; |
795 | *(nextline-2)=*data; | 801 | *(nextline - 2) = *data; |
796 | } | 802 | } |
797 | } else { | 803 | } else { |
798 | if ((frame->curlinepix&1)) { | 804 | if (frame->curlinepix & 1) { |
799 | *(curline+1)= | 805 | *(curline + 1) = |
800 | (*(curline+1)+*data)/2; | 806 | (*(curline + 1) + *data) / 2; |
801 | *(curline-2)= | 807 | *(curline - 2) = |
802 | (*(curline-2)+*data)/2; | 808 | (*(curline - 2) + *data) / 2; |
803 | *(nextline+1)=*data; | 809 | *(nextline + 1) = *data; |
804 | *(nextline-2)=*data; | 810 | *(nextline - 2) = *data; |
805 | } else { | 811 | } else { |
806 | *curline=*data; | 812 | *curline = *data; |
807 | *(curline-3)=*data; | 813 | *(curline - 3) = *data; |
808 | *nextline=*data; | 814 | *nextline = *data; |
809 | *(nextline-3)=*data; | 815 | *(nextline - 3) = *data; |
810 | } | 816 | } |
811 | } | 817 | } |
812 | frame->curlinepix++; | 818 | frame->curlinepix++; |
813 | curline-=3; | 819 | curline -= 3; |
814 | nextline-=3; | 820 | nextline -= 3; |
815 | len--; | 821 | len--; |
816 | data++; | 822 | data++; |
817 | frame->curpix++; | 823 | frame->curpix++; |
818 | } | 824 | } |
819 | frame->curline=curline; | 825 | frame->curline = curline; |
820 | 826 | ||
821 | if (frame->curpix>=datasize) { | 827 | if (frame->curpix >= datasize) { |
822 | /* Fix the top line */ | 828 | /* Fix the top line */ |
823 | framedata+=linelength; | 829 | framedata += linelength; |
824 | for (i=0; i<linelength; i++) { | 830 | for (i = 0; i < linelength; i++) { |
825 | framedata--; | 831 | framedata--; |
826 | *framedata=*(framedata+linelength); | 832 | *framedata = *(framedata + linelength); |
827 | } | 833 | } |
828 | /* Fix the left side (green is already present) */ | 834 | /* Fix the left side (green is already present) */ |
829 | for (i=0; i<se401->cheight; i++) { | 835 | for (i = 0; i < se401->cheight; i++) { |
830 | *framedata=*(framedata+3); | 836 | *framedata = *(framedata + 3); |
831 | *(framedata+1)=*(framedata+4); | 837 | *(framedata + 1) = *(framedata + 4); |
832 | *(framedata+2)=*(framedata+5); | 838 | *(framedata + 2) = *(framedata + 5); |
833 | framedata+=linelength; | 839 | framedata += linelength; |
834 | } | 840 | } |
835 | frame->curpix=0; | 841 | frame->curpix = 0; |
836 | frame->grabstate=FRAME_DONE; | 842 | frame->grabstate = FRAME_DONE; |
837 | se401->framecount++; | 843 | se401->framecount++; |
838 | se401->readcount++; | 844 | se401->readcount++; |
839 | if (se401->frame[(se401->curframe+1)&(SE401_NUMFRAMES-1)].grabstate==FRAME_READY) { | 845 | if (se401->frame[(se401->curframe + 1) & |
840 | se401->curframe=(se401->curframe+1) & (SE401_NUMFRAMES-1); | 846 | (SE401_NUMFRAMES - 1)].grabstate == FRAME_READY) { |
847 | se401->curframe = (se401->curframe+1) & | ||
848 | (SE401_NUMFRAMES-1); | ||
841 | } | 849 | } |
842 | } | 850 | } |
843 | } | 851 | } |
@@ -845,72 +853,76 @@ static inline void decode_bayer (struct usb_se401 *se401, struct se401_scratch * | |||
845 | static int se401_newframe(struct usb_se401 *se401, int framenr) | 853 | static int se401_newframe(struct usb_se401 *se401, int framenr) |
846 | { | 854 | { |
847 | DECLARE_WAITQUEUE(wait, current); | 855 | DECLARE_WAITQUEUE(wait, current); |
848 | int errors=0; | 856 | int errors = 0; |
849 | 857 | ||
850 | while (se401->streaming && | 858 | while (se401->streaming && |
851 | (se401->frame[framenr].grabstate==FRAME_READY || | 859 | (se401->frame[framenr].grabstate == FRAME_READY || |
852 | se401->frame[framenr].grabstate==FRAME_GRABBING) ) { | 860 | se401->frame[framenr].grabstate == FRAME_GRABBING)) { |
853 | if(!se401->frame[framenr].curpix) { | 861 | if (!se401->frame[framenr].curpix) |
854 | errors++; | 862 | errors++; |
855 | } | 863 | |
856 | wait_interruptible( | 864 | wait_interruptible( |
857 | se401->scratch[se401->scratch_use].state!=BUFFER_READY, | 865 | se401->scratch[se401->scratch_use].state != BUFFER_READY, |
858 | &se401->wq, | 866 | &se401->wq, &wait); |
859 | &wait | ||
860 | ); | ||
861 | if (se401->nullpackets > SE401_MAX_NULLPACKETS) { | 867 | if (se401->nullpackets > SE401_MAX_NULLPACKETS) { |
862 | se401->nullpackets=0; | 868 | se401->nullpackets = 0; |
863 | dev_info(&se401->dev->dev, | 869 | dev_info(&se401->dev->dev, |
864 | "too many null length packets, restarting capture\n"); | 870 | "too many null length packets, restarting capture\n"); |
865 | se401_stop_stream(se401); | 871 | se401_stop_stream(se401); |
866 | se401_start_stream(se401); | 872 | se401_start_stream(se401); |
867 | } else { | 873 | } else { |
868 | if (se401->scratch[se401->scratch_use].state!=BUFFER_READY) { | 874 | if (se401->scratch[se401->scratch_use].state != |
869 | se401->frame[framenr].grabstate=FRAME_ERROR; | 875 | BUFFER_READY) { |
876 | se401->frame[framenr].grabstate = FRAME_ERROR; | ||
870 | return -EIO; | 877 | return -EIO; |
871 | } | 878 | } |
872 | se401->scratch[se401->scratch_use].state=BUFFER_BUSY; | 879 | se401->scratch[se401->scratch_use].state = BUFFER_BUSY; |
873 | if (se401->format==FMT_JANGGU) { | 880 | if (se401->format == FMT_JANGGU) |
874 | decode_JangGu(se401, &se401->scratch[se401->scratch_use]); | 881 | decode_JangGu(se401, |
875 | } else { | 882 | &se401->scratch[se401->scratch_use]); |
876 | decode_bayer(se401, &se401->scratch[se401->scratch_use]); | 883 | else |
877 | } | 884 | decode_bayer(se401, |
878 | se401->scratch[se401->scratch_use].state=BUFFER_UNUSED; | 885 | &se401->scratch[se401->scratch_use]); |
886 | |||
887 | se401->scratch[se401->scratch_use].state = | ||
888 | BUFFER_UNUSED; | ||
879 | se401->scratch_use++; | 889 | se401->scratch_use++; |
880 | if (se401->scratch_use>=SE401_NUMSCRATCH) | 890 | if (se401->scratch_use >= SE401_NUMSCRATCH) |
881 | se401->scratch_use=0; | 891 | se401->scratch_use = 0; |
882 | if (errors > SE401_MAX_ERRORS) { | 892 | if (errors > SE401_MAX_ERRORS) { |
883 | errors=0; | 893 | errors = 0; |
884 | dev_info(&se401->dev->dev, | 894 | dev_info(&se401->dev->dev, |
885 | "too many errors, restarting capture\n"); | 895 | "too many errors, restarting capture\n"); |
886 | se401_stop_stream(se401); | 896 | se401_stop_stream(se401); |
887 | se401_start_stream(se401); | 897 | se401_start_stream(se401); |
888 | } | 898 | } |
889 | } | 899 | } |
890 | } | 900 | } |
891 | 901 | ||
892 | if (se401->frame[framenr].grabstate==FRAME_DONE) | 902 | if (se401->frame[framenr].grabstate == FRAME_DONE) |
893 | if (se401->enhance) | 903 | if (se401->enhance) |
894 | enhance_picture(se401->frame[framenr].data, se401->cheight*se401->cwidth*3); | 904 | enhance_picture(se401->frame[framenr].data, |
905 | se401->cheight * se401->cwidth * 3); | ||
895 | return 0; | 906 | return 0; |
896 | } | 907 | } |
897 | 908 | ||
898 | static void usb_se401_remove_disconnected (struct usb_se401 *se401) | 909 | static void usb_se401_remove_disconnected(struct usb_se401 *se401) |
899 | { | 910 | { |
900 | int i; | 911 | int i; |
901 | 912 | ||
902 | se401->dev = NULL; | 913 | se401->dev = NULL; |
903 | 914 | ||
904 | for (i=0; i<SE401_NUMSBUF; i++) | 915 | for (i = 0; i < SE401_NUMSBUF; i++) |
905 | if (se401->urb[i]) { | 916 | if (se401->urb[i]) { |
906 | usb_kill_urb(se401->urb[i]); | 917 | usb_kill_urb(se401->urb[i]); |
907 | usb_free_urb(se401->urb[i]); | 918 | usb_free_urb(se401->urb[i]); |
908 | se401->urb[i] = NULL; | 919 | se401->urb[i] = NULL; |
909 | kfree(se401->sbuf[i].data); | 920 | kfree(se401->sbuf[i].data); |
910 | } | 921 | } |
911 | for (i=0; i<SE401_NUMSCRATCH; i++) { | 922 | |
923 | for (i = 0; i < SE401_NUMSCRATCH; i++) | ||
912 | kfree(se401->scratch[i].data); | 924 | kfree(se401->scratch[i].data); |
913 | } | 925 | |
914 | if (se401->inturb) { | 926 | if (se401->inturb) { |
915 | usb_kill_urb(se401->inturb); | 927 | usb_kill_urb(se401->inturb); |
916 | usb_free_urb(se401->inturb); | 928 | usb_free_urb(se401->inturb); |
@@ -965,11 +977,11 @@ static int se401_close(struct file *file) | |||
965 | dev_info(&se401->dev->dev, "device unregistered\n"); | 977 | dev_info(&se401->dev->dev, "device unregistered\n"); |
966 | usb_se401_remove_disconnected(se401); | 978 | usb_se401_remove_disconnected(se401); |
967 | } else { | 979 | } else { |
968 | for (i=0; i<SE401_NUMFRAMES; i++) | 980 | for (i = 0; i < SE401_NUMFRAMES; i++) |
969 | se401->frame[i].grabstate=FRAME_UNUSED; | 981 | se401->frame[i].grabstate = FRAME_UNUSED; |
970 | if (se401->streaming) | 982 | if (se401->streaming) |
971 | se401_stop_stream(se401); | 983 | se401_stop_stream(se401); |
972 | se401->user=0; | 984 | se401->user = 0; |
973 | } | 985 | } |
974 | file->private_data = NULL; | 986 | file->private_data = NULL; |
975 | return 0; | 987 | return 0; |
@@ -1065,7 +1077,7 @@ static long se401_do_ioctl(struct file *file, unsigned int cmd, void *arg) | |||
1065 | memset(vm, 0, sizeof(*vm)); | 1077 | memset(vm, 0, sizeof(*vm)); |
1066 | vm->size = SE401_NUMFRAMES * se401->maxframesize; | 1078 | vm->size = SE401_NUMFRAMES * se401->maxframesize; |
1067 | vm->frames = SE401_NUMFRAMES; | 1079 | vm->frames = SE401_NUMFRAMES; |
1068 | for (i=0; i<SE401_NUMFRAMES; i++) | 1080 | for (i = 0; i < SE401_NUMFRAMES; i++) |
1069 | vm->offsets[i] = se401->maxframesize * i; | 1081 | vm->offsets[i] = se401->maxframesize * i; |
1070 | return 0; | 1082 | return 0; |
1071 | } | 1083 | } |
@@ -1083,16 +1095,16 @@ static long se401_do_ioctl(struct file *file, unsigned int cmd, void *arg) | |||
1083 | /* Is this according to the v4l spec??? */ | 1095 | /* Is this according to the v4l spec??? */ |
1084 | if (se401_set_size(se401, vm->width, vm->height)) | 1096 | if (se401_set_size(se401, vm->width, vm->height)) |
1085 | return -EINVAL; | 1097 | return -EINVAL; |
1086 | se401->frame[vm->frame].grabstate=FRAME_READY; | 1098 | se401->frame[vm->frame].grabstate = FRAME_READY; |
1087 | 1099 | ||
1088 | if (!se401->streaming) | 1100 | if (!se401->streaming) |
1089 | se401_start_stream(se401); | 1101 | se401_start_stream(se401); |
1090 | 1102 | ||
1091 | /* Set the picture properties */ | 1103 | /* Set the picture properties */ |
1092 | if (se401->framecount==0) | 1104 | if (se401->framecount == 0) |
1093 | se401_send_pict(se401); | 1105 | se401_send_pict(se401); |
1094 | /* Calibrate the reset level after a few frames. */ | 1106 | /* Calibrate the reset level after a few frames. */ |
1095 | if (se401->framecount%20==1) | 1107 | if (se401->framecount % 20 == 1) |
1096 | se401_auto_resetlevel(se401); | 1108 | se401_auto_resetlevel(se401); |
1097 | 1109 | ||
1098 | return 0; | 1110 | return 0; |
@@ -1100,13 +1112,13 @@ static long se401_do_ioctl(struct file *file, unsigned int cmd, void *arg) | |||
1100 | case VIDIOCSYNC: | 1112 | case VIDIOCSYNC: |
1101 | { | 1113 | { |
1102 | int *frame = arg; | 1114 | int *frame = arg; |
1103 | int ret=0; | 1115 | int ret = 0; |
1104 | 1116 | ||
1105 | if(*frame <0 || *frame >= SE401_NUMFRAMES) | 1117 | if (*frame < 0 || *frame >= SE401_NUMFRAMES) |
1106 | return -EINVAL; | 1118 | return -EINVAL; |
1107 | 1119 | ||
1108 | ret=se401_newframe(se401, *frame); | 1120 | ret = se401_newframe(se401, *frame); |
1109 | se401->frame[*frame].grabstate=FRAME_UNUSED; | 1121 | se401->frame[*frame].grabstate = FRAME_UNUSED; |
1110 | return ret; | 1122 | return ret; |
1111 | } | 1123 | } |
1112 | case VIDIOCGFBUF: | 1124 | case VIDIOCGFBUF: |
@@ -1147,36 +1159,36 @@ static long se401_ioctl(struct file *file, | |||
1147 | static ssize_t se401_read(struct file *file, char __user *buf, | 1159 | static ssize_t se401_read(struct file *file, char __user *buf, |
1148 | size_t count, loff_t *ppos) | 1160 | size_t count, loff_t *ppos) |
1149 | { | 1161 | { |
1150 | int realcount=count, ret=0; | 1162 | int realcount = count, ret = 0; |
1151 | struct video_device *dev = file->private_data; | 1163 | struct video_device *dev = file->private_data; |
1152 | struct usb_se401 *se401 = (struct usb_se401 *)dev; | 1164 | struct usb_se401 *se401 = (struct usb_se401 *)dev; |
1153 | 1165 | ||
1154 | 1166 | ||
1155 | if (se401->dev == NULL) | 1167 | if (se401->dev == NULL) |
1156 | return -EIO; | 1168 | return -EIO; |
1157 | if (realcount > se401->cwidth*se401->cheight*3) | 1169 | if (realcount > se401->cwidth*se401->cheight*3) |
1158 | realcount=se401->cwidth*se401->cheight*3; | 1170 | realcount = se401->cwidth*se401->cheight*3; |
1159 | 1171 | ||
1160 | /* Shouldn't happen: */ | 1172 | /* Shouldn't happen: */ |
1161 | if (se401->frame[0].grabstate==FRAME_GRABBING) | 1173 | if (se401->frame[0].grabstate == FRAME_GRABBING) |
1162 | return -EBUSY; | 1174 | return -EBUSY; |
1163 | se401->frame[0].grabstate=FRAME_READY; | 1175 | se401->frame[0].grabstate = FRAME_READY; |
1164 | se401->frame[1].grabstate=FRAME_UNUSED; | 1176 | se401->frame[1].grabstate = FRAME_UNUSED; |
1165 | se401->curframe=0; | 1177 | se401->curframe = 0; |
1166 | 1178 | ||
1167 | if (!se401->streaming) | 1179 | if (!se401->streaming) |
1168 | se401_start_stream(se401); | 1180 | se401_start_stream(se401); |
1169 | 1181 | ||
1170 | /* Set the picture properties */ | 1182 | /* Set the picture properties */ |
1171 | if (se401->framecount==0) | 1183 | if (se401->framecount == 0) |
1172 | se401_send_pict(se401); | 1184 | se401_send_pict(se401); |
1173 | /* Calibrate the reset level after a few frames. */ | 1185 | /* Calibrate the reset level after a few frames. */ |
1174 | if (se401->framecount%20==1) | 1186 | if (se401->framecount%20 == 1) |
1175 | se401_auto_resetlevel(se401); | 1187 | se401_auto_resetlevel(se401); |
1176 | 1188 | ||
1177 | ret=se401_newframe(se401, 0); | 1189 | ret = se401_newframe(se401, 0); |
1178 | 1190 | ||
1179 | se401->frame[0].grabstate=FRAME_UNUSED; | 1191 | se401->frame[0].grabstate = FRAME_UNUSED; |
1180 | if (ret) | 1192 | if (ret) |
1181 | return ret; | 1193 | return ret; |
1182 | if (copy_to_user(buf, se401->frame[0].data, realcount)) | 1194 | if (copy_to_user(buf, se401->frame[0].data, realcount)) |
@@ -1195,11 +1207,12 @@ static int se401_mmap(struct file *file, struct vm_area_struct *vma) | |||
1195 | 1207 | ||
1196 | mutex_lock(&se401->lock); | 1208 | mutex_lock(&se401->lock); |
1197 | 1209 | ||
1198 | if (se401->dev == NULL) { | 1210 | if (se401->dev == NULL) { |
1199 | mutex_unlock(&se401->lock); | 1211 | mutex_unlock(&se401->lock); |
1200 | return -EIO; | 1212 | return -EIO; |
1201 | } | 1213 | } |
1202 | if (size > (((SE401_NUMFRAMES * se401->maxframesize) + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1))) { | 1214 | if (size > (((SE401_NUMFRAMES * se401->maxframesize) + PAGE_SIZE - 1) |
1215 | & ~(PAGE_SIZE - 1))) { | ||
1203 | mutex_unlock(&se401->lock); | 1216 | mutex_unlock(&se401->lock); |
1204 | return -EINVAL; | 1217 | return -EINVAL; |
1205 | } | 1218 | } |
@@ -1210,10 +1223,10 @@ static int se401_mmap(struct file *file, struct vm_area_struct *vma) | |||
1210 | mutex_unlock(&se401->lock); | 1223 | mutex_unlock(&se401->lock); |
1211 | return -EAGAIN; | 1224 | return -EAGAIN; |
1212 | } | 1225 | } |
1213 | start += PAGE_SIZE; | 1226 | start += PAGE_SIZE; |
1214 | pos += PAGE_SIZE; | 1227 | pos += PAGE_SIZE; |
1215 | if (size > PAGE_SIZE) | 1228 | if (size > PAGE_SIZE) |
1216 | size -= PAGE_SIZE; | 1229 | size -= PAGE_SIZE; |
1217 | else | 1230 | else |
1218 | size = 0; | 1231 | size = 0; |
1219 | } | 1232 | } |
@@ -1223,7 +1236,7 @@ static int se401_mmap(struct file *file, struct vm_area_struct *vma) | |||
1223 | } | 1236 | } |
1224 | 1237 | ||
1225 | static const struct v4l2_file_operations se401_fops = { | 1238 | static const struct v4l2_file_operations se401_fops = { |
1226 | .owner = THIS_MODULE, | 1239 | .owner = THIS_MODULE, |
1227 | .open = se401_open, | 1240 | .open = se401_open, |
1228 | .release = se401_close, | 1241 | .release = se401_close, |
1229 | .read = se401_read, | 1242 | .read = se401_read, |
@@ -1241,7 +1254,7 @@ static struct video_device se401_template = { | |||
1241 | /***************************/ | 1254 | /***************************/ |
1242 | static int se401_init(struct usb_se401 *se401, int button) | 1255 | static int se401_init(struct usb_se401 *se401, int button) |
1243 | { | 1256 | { |
1244 | int i=0, rc; | 1257 | int i = 0, rc; |
1245 | unsigned char cp[0x40]; | 1258 | unsigned char cp[0x40]; |
1246 | char temp[200]; | 1259 | char temp[200]; |
1247 | int slen; | 1260 | int slen; |
@@ -1250,64 +1263,67 @@ static int se401_init(struct usb_se401 *se401, int button) | |||
1250 | se401_sndctrl(1, se401, SE401_REQ_LED_CONTROL, 1, NULL, 0); | 1263 | se401_sndctrl(1, se401, SE401_REQ_LED_CONTROL, 1, NULL, 0); |
1251 | 1264 | ||
1252 | /* get camera descriptor */ | 1265 | /* get camera descriptor */ |
1253 | rc=se401_sndctrl(0, se401, SE401_REQ_GET_CAMERA_DESCRIPTOR, 0, cp, sizeof(cp)); | 1266 | rc = se401_sndctrl(0, se401, SE401_REQ_GET_CAMERA_DESCRIPTOR, 0, |
1267 | cp, sizeof(cp)); | ||
1254 | if (cp[1] != 0x41) { | 1268 | if (cp[1] != 0x41) { |
1255 | err("Wrong descriptor type"); | 1269 | err("Wrong descriptor type"); |
1256 | return 1; | 1270 | return 1; |
1257 | } | 1271 | } |
1258 | slen = snprintf(temp, 200, "ExtraFeatures: %d", cp[3]); | 1272 | slen = snprintf(temp, 200, "ExtraFeatures: %d", cp[3]); |
1259 | 1273 | ||
1260 | se401->sizes=cp[4]+cp[5]*256; | 1274 | se401->sizes = cp[4] + cp[5] * 256; |
1261 | se401->width=kmalloc(se401->sizes*sizeof(int), GFP_KERNEL); | 1275 | se401->width = kmalloc(se401->sizes*sizeof(int), GFP_KERNEL); |
1262 | if (!se401->width) | 1276 | if (!se401->width) |
1263 | return 1; | 1277 | return 1; |
1264 | se401->height=kmalloc(se401->sizes*sizeof(int), GFP_KERNEL); | 1278 | se401->height = kmalloc(se401->sizes*sizeof(int), GFP_KERNEL); |
1265 | if (!se401->height) { | 1279 | if (!se401->height) { |
1266 | kfree(se401->width); | 1280 | kfree(se401->width); |
1267 | return 1; | 1281 | return 1; |
1268 | } | 1282 | } |
1269 | for (i=0; i<se401->sizes; i++) { | 1283 | for (i = 0; i < se401->sizes; i++) { |
1270 | se401->width[i]=cp[6+i*4+0]+cp[6+i*4+1]*256; | 1284 | se401->width[i] = cp[6 + i * 4 + 0] + cp[6 + i*4 + 1] * 256; |
1271 | se401->height[i]=cp[6+i*4+2]+cp[6+i*4+3]*256; | 1285 | se401->height[i] = cp[6 + i * 4 + 2] + cp[6 + i * 4 + 3] * 256; |
1272 | } | 1286 | } |
1273 | slen += snprintf (temp + slen, 200 - slen, " Sizes:"); | 1287 | slen += snprintf(temp + slen, 200 - slen, " Sizes:"); |
1274 | for (i=0; i<se401->sizes; i++) { | 1288 | for (i = 0; i < se401->sizes; i++) { |
1275 | slen += snprintf(temp + slen, 200 - slen, | 1289 | slen += snprintf(temp + slen, 200 - slen, |
1276 | " %dx%d", se401->width[i], se401->height[i]); | 1290 | " %dx%d", se401->width[i], se401->height[i]); |
1277 | } | 1291 | } |
1278 | dev_info(&se401->dev->dev, "%s\n", temp); | 1292 | dev_info(&se401->dev->dev, "%s\n", temp); |
1279 | se401->maxframesize=se401->width[se401->sizes-1]*se401->height[se401->sizes-1]*3; | 1293 | se401->maxframesize = se401->width[se401->sizes-1] * |
1294 | se401->height[se401->sizes - 1] * 3; | ||
1280 | 1295 | ||
1281 | rc=se401_sndctrl(0, se401, SE401_REQ_GET_WIDTH, 0, cp, sizeof(cp)); | 1296 | rc = se401_sndctrl(0, se401, SE401_REQ_GET_WIDTH, 0, cp, sizeof(cp)); |
1282 | se401->cwidth=cp[0]+cp[1]*256; | 1297 | se401->cwidth = cp[0]+cp[1]*256; |
1283 | rc=se401_sndctrl(0, se401, SE401_REQ_GET_HEIGHT, 0, cp, sizeof(cp)); | 1298 | rc = se401_sndctrl(0, se401, SE401_REQ_GET_HEIGHT, 0, cp, sizeof(cp)); |
1284 | se401->cheight=cp[0]+cp[1]*256; | 1299 | se401->cheight = cp[0]+cp[1]*256; |
1285 | 1300 | ||
1286 | if (!(cp[2] & SE401_FORMAT_BAYER)) { | 1301 | if (!(cp[2] & SE401_FORMAT_BAYER)) { |
1287 | err("Bayer format not supported!"); | 1302 | err("Bayer format not supported!"); |
1288 | return 1; | 1303 | return 1; |
1289 | } | 1304 | } |
1290 | /* set output mode (BAYER) */ | 1305 | /* set output mode (BAYER) */ |
1291 | se401_sndctrl(1, se401, SE401_REQ_SET_OUTPUT_MODE, SE401_FORMAT_BAYER, NULL, 0); | 1306 | se401_sndctrl(1, se401, SE401_REQ_SET_OUTPUT_MODE, |
1307 | SE401_FORMAT_BAYER, NULL, 0); | ||
1292 | 1308 | ||
1293 | rc=se401_sndctrl(0, se401, SE401_REQ_GET_BRT, 0, cp, sizeof(cp)); | 1309 | rc = se401_sndctrl(0, se401, SE401_REQ_GET_BRT, 0, cp, sizeof(cp)); |
1294 | se401->brightness=cp[0]+cp[1]*256; | 1310 | se401->brightness = cp[0]+cp[1]*256; |
1295 | /* some default values */ | 1311 | /* some default values */ |
1296 | se401->resetlevel=0x2d; | 1312 | se401->resetlevel = 0x2d; |
1297 | se401->rgain=0x20; | 1313 | se401->rgain = 0x20; |
1298 | se401->ggain=0x20; | 1314 | se401->ggain = 0x20; |
1299 | se401->bgain=0x20; | 1315 | se401->bgain = 0x20; |
1300 | se401_set_exposure(se401, 20000); | 1316 | se401_set_exposure(se401, 20000); |
1301 | se401->palette=VIDEO_PALETTE_RGB24; | 1317 | se401->palette = VIDEO_PALETTE_RGB24; |
1302 | se401->enhance=1; | 1318 | se401->enhance = 1; |
1303 | se401->dropped=0; | 1319 | se401->dropped = 0; |
1304 | se401->error=0; | 1320 | se401->error = 0; |
1305 | se401->framecount=0; | 1321 | se401->framecount = 0; |
1306 | se401->readcount=0; | 1322 | se401->readcount = 0; |
1307 | 1323 | ||
1308 | /* Start interrupt transfers for snapshot button */ | 1324 | /* Start interrupt transfers for snapshot button */ |
1309 | if (button) { | 1325 | if (button) { |
1310 | se401->inturb=usb_alloc_urb(0, GFP_KERNEL); | 1326 | se401->inturb = usb_alloc_urb(0, GFP_KERNEL); |
1311 | if (!se401->inturb) { | 1327 | if (!se401->inturb) { |
1312 | dev_info(&se401->dev->dev, | 1328 | dev_info(&se401->dev->dev, |
1313 | "Allocation of inturb failed\n"); | 1329 | "Allocation of inturb failed\n"); |
@@ -1325,7 +1341,7 @@ static int se401_init(struct usb_se401 *se401, int button) | |||
1325 | return 1; | 1341 | return 1; |
1326 | } | 1342 | } |
1327 | } else | 1343 | } else |
1328 | se401->inturb=NULL; | 1344 | se401->inturb = NULL; |
1329 | 1345 | ||
1330 | /* Flash the led */ | 1346 | /* Flash the led */ |
1331 | se401_sndctrl(1, se401, SE401_REQ_CAMERA_POWER, 1, NULL, 0); | 1347 | se401_sndctrl(1, se401, SE401_REQ_CAMERA_POWER, 1, NULL, 0); |
@@ -1342,8 +1358,8 @@ static int se401_probe(struct usb_interface *intf, | |||
1342 | struct usb_device *dev = interface_to_usbdev(intf); | 1358 | struct usb_device *dev = interface_to_usbdev(intf); |
1343 | struct usb_interface_descriptor *interface; | 1359 | struct usb_interface_descriptor *interface; |
1344 | struct usb_se401 *se401; | 1360 | struct usb_se401 *se401; |
1345 | char *camera_name=NULL; | 1361 | char *camera_name = NULL; |
1346 | int button=1; | 1362 | int button = 1; |
1347 | 1363 | ||
1348 | /* We don't handle multi-config cameras */ | 1364 | /* We don't handle multi-config cameras */ |
1349 | if (dev->descriptor.bNumConfigurations != 1) | 1365 | if (dev->descriptor.bNumConfigurations != 1) |
@@ -1352,22 +1368,22 @@ static int se401_probe(struct usb_interface *intf, | |||
1352 | interface = &intf->cur_altsetting->desc; | 1368 | interface = &intf->cur_altsetting->desc; |
1353 | 1369 | ||
1354 | /* Is it an se401? */ | 1370 | /* Is it an se401? */ |
1355 | if (le16_to_cpu(dev->descriptor.idVendor) == 0x03e8 && | 1371 | if (le16_to_cpu(dev->descriptor.idVendor) == 0x03e8 && |
1356 | le16_to_cpu(dev->descriptor.idProduct) == 0x0004) { | 1372 | le16_to_cpu(dev->descriptor.idProduct) == 0x0004) { |
1357 | camera_name="Endpoints/Aox SE401"; | 1373 | camera_name = "Endpoints/Aox SE401"; |
1358 | } else if (le16_to_cpu(dev->descriptor.idVendor) == 0x0471 && | 1374 | } else if (le16_to_cpu(dev->descriptor.idVendor) == 0x0471 && |
1359 | le16_to_cpu(dev->descriptor.idProduct) == 0x030b) { | 1375 | le16_to_cpu(dev->descriptor.idProduct) == 0x030b) { |
1360 | camera_name="Philips PCVC665K"; | 1376 | camera_name = "Philips PCVC665K"; |
1361 | } else if (le16_to_cpu(dev->descriptor.idVendor) == 0x047d && | 1377 | } else if (le16_to_cpu(dev->descriptor.idVendor) == 0x047d && |
1362 | le16_to_cpu(dev->descriptor.idProduct) == 0x5001) { | 1378 | le16_to_cpu(dev->descriptor.idProduct) == 0x5001) { |
1363 | camera_name="Kensington VideoCAM 67014"; | 1379 | camera_name = "Kensington VideoCAM 67014"; |
1364 | } else if (le16_to_cpu(dev->descriptor.idVendor) == 0x047d && | 1380 | } else if (le16_to_cpu(dev->descriptor.idVendor) == 0x047d && |
1365 | le16_to_cpu(dev->descriptor.idProduct) == 0x5002) { | 1381 | le16_to_cpu(dev->descriptor.idProduct) == 0x5002) { |
1366 | camera_name="Kensington VideoCAM 6701(5/7)"; | 1382 | camera_name = "Kensington VideoCAM 6701(5/7)"; |
1367 | } else if (le16_to_cpu(dev->descriptor.idVendor) == 0x047d && | 1383 | } else if (le16_to_cpu(dev->descriptor.idVendor) == 0x047d && |
1368 | le16_to_cpu(dev->descriptor.idProduct) == 0x5003) { | 1384 | le16_to_cpu(dev->descriptor.idProduct) == 0x5003) { |
1369 | camera_name="Kensington VideoCAM 67016"; | 1385 | camera_name = "Kensington VideoCAM 67016"; |
1370 | button=0; | 1386 | button = 0; |
1371 | } else | 1387 | } else |
1372 | return -ENODEV; | 1388 | return -ENODEV; |
1373 | 1389 | ||
@@ -1380,7 +1396,8 @@ static int se401_probe(struct usb_interface *intf, | |||
1380 | /* We found one */ | 1396 | /* We found one */ |
1381 | dev_info(&intf->dev, "SE401 camera found: %s\n", camera_name); | 1397 | dev_info(&intf->dev, "SE401 camera found: %s\n", camera_name); |
1382 | 1398 | ||
1383 | if ((se401 = kzalloc(sizeof(*se401), GFP_KERNEL)) == NULL) { | 1399 | se401 = kzalloc(sizeof(*se401), GFP_KERNEL); |
1400 | if (se401 == NULL) { | ||
1384 | err("couldn't kmalloc se401 struct"); | 1401 | err("couldn't kmalloc se401 struct"); |
1385 | return -ENOMEM; | 1402 | return -ENOMEM; |
1386 | } | 1403 | } |
@@ -1398,12 +1415,14 @@ static int se401_probe(struct usb_interface *intf, | |||
1398 | } | 1415 | } |
1399 | 1416 | ||
1400 | memcpy(&se401->vdev, &se401_template, sizeof(se401_template)); | 1417 | memcpy(&se401->vdev, &se401_template, sizeof(se401_template)); |
1401 | memcpy(se401->vdev.name, se401->camera_name, strlen(se401->camera_name)); | 1418 | memcpy(se401->vdev.name, se401->camera_name, |
1419 | strlen(se401->camera_name)); | ||
1402 | init_waitqueue_head(&se401->wq); | 1420 | init_waitqueue_head(&se401->wq); |
1403 | mutex_init(&se401->lock); | 1421 | mutex_init(&se401->lock); |
1404 | wmb(); | 1422 | wmb(); |
1405 | 1423 | ||
1406 | if (video_register_device(&se401->vdev, VFL_TYPE_GRABBER, video_nr) < 0) { | 1424 | if (video_register_device(&se401->vdev, |
1425 | VFL_TYPE_GRABBER, video_nr) < 0) { | ||
1407 | kfree(se401); | 1426 | kfree(se401); |
1408 | err("video_register_device failed"); | 1427 | err("video_register_device failed"); |
1409 | return -EIO; | 1428 | return -EIO; |
@@ -1411,20 +1430,20 @@ static int se401_probe(struct usb_interface *intf, | |||
1411 | dev_info(&intf->dev, "registered new video device: video%d\n", | 1430 | dev_info(&intf->dev, "registered new video device: video%d\n", |
1412 | se401->vdev.num); | 1431 | se401->vdev.num); |
1413 | 1432 | ||
1414 | usb_set_intfdata (intf, se401); | 1433 | usb_set_intfdata(intf, se401); |
1415 | return 0; | 1434 | return 0; |
1416 | } | 1435 | } |
1417 | 1436 | ||
1418 | static void se401_disconnect(struct usb_interface *intf) | 1437 | static void se401_disconnect(struct usb_interface *intf) |
1419 | { | 1438 | { |
1420 | struct usb_se401 *se401 = usb_get_intfdata (intf); | 1439 | struct usb_se401 *se401 = usb_get_intfdata(intf); |
1421 | 1440 | ||
1422 | usb_set_intfdata (intf, NULL); | 1441 | usb_set_intfdata(intf, NULL); |
1423 | if (se401) { | 1442 | if (se401) { |
1424 | video_unregister_device(&se401->vdev); | 1443 | video_unregister_device(&se401->vdev); |
1425 | if (!se401->user){ | 1444 | if (!se401->user) |
1426 | usb_se401_remove_disconnected(se401); | 1445 | usb_se401_remove_disconnected(se401); |
1427 | } else { | 1446 | else { |
1428 | se401->frame[0].grabstate = FRAME_ERROR; | 1447 | se401->frame[0].grabstate = FRAME_ERROR; |
1429 | se401->frame[0].grabstate = FRAME_ERROR; | 1448 | se401->frame[0].grabstate = FRAME_ERROR; |
1430 | 1449 | ||
@@ -1437,10 +1456,10 @@ static void se401_disconnect(struct usb_interface *intf) | |||
1437 | } | 1456 | } |
1438 | 1457 | ||
1439 | static struct usb_driver se401_driver = { | 1458 | static struct usb_driver se401_driver = { |
1440 | .name = "se401", | 1459 | .name = "se401", |
1441 | .id_table = device_table, | 1460 | .id_table = device_table, |
1442 | .probe = se401_probe, | 1461 | .probe = se401_probe, |
1443 | .disconnect = se401_disconnect, | 1462 | .disconnect = se401_disconnect, |
1444 | }; | 1463 | }; |
1445 | 1464 | ||
1446 | 1465 | ||
@@ -1453,9 +1472,10 @@ static struct usb_driver se401_driver = { | |||
1453 | 1472 | ||
1454 | static int __init usb_se401_init(void) | 1473 | static int __init usb_se401_init(void) |
1455 | { | 1474 | { |
1456 | printk(KERN_INFO "SE401 usb camera driver version %s registering\n", version); | 1475 | printk(KERN_INFO "SE401 usb camera driver version %s registering\n", |
1476 | version); | ||
1457 | if (flickerless) | 1477 | if (flickerless) |
1458 | if (flickerless!=50 && flickerless!=60) { | 1478 | if (flickerless != 50 && flickerless != 60) { |
1459 | printk(KERN_ERR "Invallid flickerless value, use 0, 50 or 60.\n"); | 1479 | printk(KERN_ERR "Invallid flickerless value, use 0, 50 or 60.\n"); |
1460 | return -1; | 1480 | return -1; |
1461 | } | 1481 | } |
diff --git a/drivers/media/video/se401.h b/drivers/media/video/se401.h index 2ce685db5d8b..bf7d2e9765b0 100644 --- a/drivers/media/video/se401.h +++ b/drivers/media/video/se401.h | |||
@@ -2,7 +2,7 @@ | |||
2 | #ifndef __LINUX_se401_H | 2 | #ifndef __LINUX_se401_H |
3 | #define __LINUX_se401_H | 3 | #define __LINUX_se401_H |
4 | 4 | ||
5 | #include <asm/uaccess.h> | 5 | #include <linux/uaccess.h> |
6 | #include <linux/videodev.h> | 6 | #include <linux/videodev.h> |
7 | #include <media/v4l2-common.h> | 7 | #include <media/v4l2-common.h> |
8 | #include <media/v4l2-ioctl.h> | 8 | #include <media/v4l2-ioctl.h> |
@@ -12,9 +12,10 @@ | |||
12 | 12 | ||
13 | #ifdef se401_DEBUG | 13 | #ifdef se401_DEBUG |
14 | # define PDEBUG(level, fmt, args...) \ | 14 | # define PDEBUG(level, fmt, args...) \ |
15 | if (debug >= level) info("[" __PRETTY_FUNCTION__ ":%d] " fmt, __LINE__ , ## args) | 15 | if (debug >= level) \ |
16 | info("[" __PRETTY_FUNCTION__ ":%d] " fmt, __LINE__ , ## args) | ||
16 | #else | 17 | #else |
17 | # define PDEBUG(level, fmt, args...) do {} while(0) | 18 | # define PDEBUG(level, fmt, args...) do {} while (0) |
18 | #endif | 19 | #endif |
19 | 20 | ||
20 | /* An almost drop-in replacement for sleep_on_interruptible */ | 21 | /* An almost drop-in replacement for sleep_on_interruptible */ |