34 #include <linux/module.h>
35 #include <linux/init.h>
36 #include <linux/kernel.h>
37 #include <linux/version.h>
38 #include <linux/errno.h>
39 #include <linux/slab.h>
40 #include <linux/kref.h>
41 #include <linux/vmalloc.h>
44 #include <linux/usb.h>
45 #include <media/v4l2-common.h>
46 #include <media/v4l2-ioctl.h>
72 size = PAGE_ALIGN(size);
73 mem = vmalloc_32(size);
80 addr = (
unsigned long) mem;
83 SetPageReserved(vmalloc_to_page((
void *) addr));
107 addr = (
unsigned long) mem;
109 while ((
long) size > 0) {
110 ClearPageReserved(vmalloc_to_page((
void *) addr));
140 if (dev->isobuf[i].data == NULL) {
144 STK_ERROR(
"Failed to allocate iso buffer %d\n", i);
148 STK_DEBUG(
"Allocated iso buffer at %p\n", kbuf);
150 dev->isobuf[i].data = kbuf;
155 if (dev->framebuf == NULL) {
159 STK_ERROR(
"Failed to allocate frame buffer structure\n");
163 STK_DEBUG(
"Allocated frame buffer structure at %p\n", kbuf);
165 dev->framebuf = kbuf;
170 if (dev->framebuf[i].data == NULL) {
174 STK_ERROR(
"Failed to allocate frame buffer %d\n", i);
178 STK_DEBUG(
"Allocated frame buffer %d at %p.\n", i, kbuf);
180 dev->framebuf[i].data = kbuf;
189 STK_ERROR(
"Failed to allocate image buffer(s). needed (%d)\n",
190 dev->nbuffers * dev->len_per_image);
194 STK_DEBUG(
"Allocated image buffer at %p\n", kbuf);
196 dev->image_data = kbuf;
198 for (i = 0; i < dev->nbuffers; i++) {
199 dev->images[i].
offset = i * dev->len_per_image;
204 dev->images[i].
offset = 0;
228 spin_lock_irqsave(&dev->
spinlock, flags);
230 dev->full_frames = NULL;
231 dev->full_frames_tail = NULL;
233 for (i=0; i<dev->nbuffers; i++) {
234 dev->framebuf[i].filled = 0;
235 dev->framebuf[i].errors = 0;
238 dev->framebuf[i].next = &dev->framebuf[i - 1];
240 dev->framebuf->next = NULL;
243 dev->empty_frames = &dev->framebuf[dev->nbuffers - 1];
244 dev->empty_frames_tail = dev->framebuf;
245 dev->read_frame = NULL;
246 dev->fill_frame = dev->empty_frames;
247 dev->empty_frames = dev->empty_frames->next;
249 dev->image_read_pos = 0;
252 spin_unlock_irqrestore(&dev->
spinlock, flags);
254 for (i=0; i<dev->nbuffers; i++)
255 dev->image_used[i] = 0;
272 memset(dev->image_data, 0x00, dev->nbuffers * dev->len_per_image);
298 if (dev->isobuf[i].data != NULL) {
299 kfree(dev->isobuf[i].data);
300 dev->isobuf[i].data = NULL;
305 if (dev->framebuf != NULL) {
307 if (dev->framebuf[i].data != NULL) {
308 vfree(dev->framebuf[i].data);
309 dev->framebuf[i].data = NULL;
313 kfree(dev->framebuf);
314 dev->framebuf = NULL;
318 if (dev->image_data != NULL)
319 stk11xx_rvfree(dev->image_data, dev->nbuffers * dev->len_per_image);
321 dev->image_data = NULL;
338 dev->image_used[dev->fill_image] = 0;
339 dev->fill_image = (dev->fill_image + 1) % dev->nbuffers;
359 spin_lock_irqsave(&dev->
spinlock, flags);
361 if (dev->fill_frame != NULL) {
362 if (dev->full_frames == NULL) {
363 dev->full_frames = dev->fill_frame;
364 dev->full_frames_tail = dev->full_frames;
367 dev->full_frames_tail->next = dev->fill_frame;
368 dev->full_frames_tail = dev->fill_frame;
372 if (dev->empty_frames != NULL) {
373 dev->fill_frame = dev->empty_frames;
374 dev->empty_frames = dev->empty_frames->next;
377 if (dev->full_frames == NULL) {
378 STK_ERROR(
"Neither empty or full frames available!\n");
379 spin_unlock_irqrestore(&dev->
spinlock, flags);
383 dev->fill_frame = dev->full_frames;
384 dev->full_frames = dev->full_frames->next;
389 dev->fill_frame->next = NULL;
391 spin_unlock_irqrestore(&dev->
spinlock, flags);
414 spin_lock_irqsave(&dev->
spinlock, flags);
416 if (dev->read_frame != NULL) {
417 spin_unlock_irqrestore(&dev->
spinlock, flags);
421 if (dev->full_frames == NULL) {
424 dev->read_frame = dev->full_frames;
425 dev->full_frames = dev->full_frames->next;
426 dev->read_frame->next = NULL;
429 if (dev->read_frame != NULL) {
430 spin_unlock_irqrestore(&dev->
spinlock, flags);
432 spin_lock_irqsave(&dev->
spinlock, flags);
434 if (dev->empty_frames == NULL) {
435 dev->empty_frames = dev->read_frame;
436 dev->empty_frames_tail = dev->empty_frames;
439 dev->empty_frames_tail->next = dev->read_frame;
440 dev->empty_frames_tail = dev->read_frame;
443 dev->read_frame = NULL;
446 spin_unlock_irqrestore(&dev->
spinlock, flags);
int dev_stk11xx_decompress(struct usb_stk11xx *dev)
Decompress/convert a frame from the video stream.
int stk11xx_reset_buffers(struct usb_stk11xx *dev)
Reset all ISOC buffers.
void * stk11xx_rvmalloc(unsigned long size)
Allocate a buffer.
int dev_stk11xx_watchdog_camera(struct usb_stk11xx *dev)
A espece of software watchdog.
#define STK_DEBUG(str, args...)
#define STK_ERROR(str, args...)
#define STK11XX_MAX_IMAGES
#define STK_STREAM(str, args...)
int stk11xx_next_frame(struct usb_stk11xx *dev)
Prepare the next frame.
void stk11xx_next_image(struct usb_stk11xx *dev)
Prepare the next image.
static int default_nbrframebuf
int stk11xx_clear_buffers(struct usb_stk11xx *dev)
Clear current buffers.
#define STK11XX_FRAME_SIZE
int stk11xx_handle_frame(struct usb_stk11xx *dev)
Handler frame.
void stk11xx_rvfree(void *mem, unsigned long size)
Free a buffer.
Driver for Syntek USB video camera.
int stk11xx_free_buffers(struct usb_stk11xx *dev)
Release all buffers.
int stk11xx_allocate_buffers(struct usb_stk11xx *dev)
Allocate all ISOC buffers.