This changeset upgrades the ov511 driver in kernel 2.5.6-pre1 to version 
1.52. It compiles cleanly but has not been otherwise tested (under 
2.5.6-pre1). Please apply.

Summary of changes:

1.49 -> 1.50:
- Increased size of directory name string in /proc code, to allow >13 
bit minor
  numbers.
- sprintf() => snprintf()
- Set proc_dir_entry owner field to THIS_MODULE, to prevent driver 
unload while
  /proc interface is in use.

1.50 -> 1.51:
- Moved common code from *_move_data() functions to interrupt handler.
- *move_data() functions cleaned up and optimized
- Finished cleanups started in 1.49

1.51 -> 1.52:
[no actual changes; fixes regressions from 1.51]

-- 
Mark McClelland
[EMAIL PROTECTED]

This BitKeeper patch contains the following changesets:
1.363

# This is a BitKeeper patch.  What follows are the unified diffs for the
# set of deltas contained in the patch.  The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User: mark
# Host: hal9000.dyndns.org
# Root: /mnt/home2/mark/tmp/bk/usb-2.5

#
#--- 1.15/drivers/usb/ov511.c   Tue Feb 26 13:32:29 2002
#+++ 1.16/drivers/usb/ov511.c   Wed Feb 27 22:09:21 2002
#@@ -1,7 +1,7 @@
# /*
#  * OmniVision OV511 Camera-to-USB Bridge Driver
#  *
#- * Copyright (c) 1999-2001 Mark W. McClelland
#+ * Copyright (c) 1999-2002 Mark W. McClelland
#  * Original decompression code Copyright 1998-2000 OmniVision Technologies
#  * Many improvements by Bret Wallach <[EMAIL PROTECTED]>
#  * Color fixes by by Orion Sky Lawlor <[EMAIL PROTECTED]> (2/26/2000)
#@@ -58,7 +58,7 @@
# /*
#  * Version Information
#  */
#-#define DRIVER_VERSION "v1.49 for Linux 2.5"
#+#define DRIVER_VERSION "v1.52 for Linux 2.5"
# #define EMAIL "[EMAIL PROTECTED]"
# #define DRIVER_AUTHOR "Mark McClelland <[EMAIL PROTECTED]> & Bret Wallach \
#       & Orion Sky Lawlor <[EMAIL PROTECTED]> & Kevin Moore & Charl P. Botha \
#@@ -375,7 +375,9 @@
# static unsigned char uvQuanTable518[] = OV518_UVQUANTABLE;
# 
# /**********************************************************************
#+ *
#  * Memory management
#+ *
#  **********************************************************************/
# 
# /* Here we want the physical address of the memory.
#@@ -582,89 +584,91 @@
# }
# 
# static void 
#-create_proc_ov511_cam(struct usb_ov511 *ov511)
#+create_proc_ov511_cam(struct usb_ov511 *ov)
# {
#-      char dirname[4];
#+      char dirname[10];
# 
#-      if (!ov511_proc_entry || !ov511)
#+      if (!ov511_proc_entry || !ov)
#               return;
# 
#       /* Create per-device directory */
#-      sprintf(dirname, "%d", ov511->vdev.minor);
#+      snprintf(dirname, 10, "%d", ov->vdev.minor);
#       PDEBUG(4, "creating /proc/video/ov511/%s/", dirname);
#-      ov511->proc_devdir = create_proc_entry(dirname, S_IFDIR,
#-              ov511_proc_entry);
#-      if (!ov511->proc_devdir)
#+      ov->proc_devdir = create_proc_entry(dirname, S_IFDIR, ov511_proc_entry);
#+      if (!ov->proc_devdir)
#               return;
#+      ov->proc_devdir->owner = THIS_MODULE;
# 
#       /* Create "info" entry (human readable device information) */
#       PDEBUG(4, "creating /proc/video/ov511/%s/info", dirname);
#-      ov511->proc_info = create_proc_read_entry("info",
#-              S_IFREG|S_IRUGO|S_IWUSR, ov511->proc_devdir,
#-              ov511_read_proc_info, ov511);
#-      if (!ov511->proc_info)
#+      ov->proc_info = create_proc_read_entry("info", S_IFREG|S_IRUGO|S_IWUSR,
#+              ov->proc_devdir, ov511_read_proc_info, ov);
#+      if (!ov->proc_info)
#               return;
#+      ov->proc_info->owner = THIS_MODULE;
# 
#       /* Don't create it if old snapshot mode on (would cause race cond.) */
#       if (!snapshot) {
#               /* Create "button" entry (snapshot button status) */
#               PDEBUG(4, "creating /proc/video/ov511/%s/button", dirname);
#-              ov511->proc_button = create_proc_read_entry("button",
#-                      S_IFREG|S_IRUGO|S_IWUSR, ov511->proc_devdir,
#-                      ov511_read_proc_button, ov511);
#-              if (!ov511->proc_button)
#+              ov->proc_button = create_proc_read_entry("button",
#+                      S_IFREG|S_IRUGO|S_IWUSR, ov->proc_devdir,
#+                      ov511_read_proc_button, ov);
#+              if (!ov->proc_button)
#                       return;
#       }
#+      ov->proc_button->owner = THIS_MODULE;
# 
#       /* Create "control" entry (ioctl() interface) */
#       PDEBUG(4, "creating /proc/video/ov511/%s/control", dirname);
#       lock_kernel();
#-      ov511->proc_control = create_proc_entry("control",
#-              S_IFREG|S_IRUGO|S_IWUSR, ov511->proc_devdir);
#-      if (!ov511->proc_control) {
#+      ov->proc_control = create_proc_entry("control", S_IFREG|S_IRUGO|S_IWUSR,
#+              ov->proc_devdir);
#+      if (!ov->proc_control) {
#               unlock_kernel();
#               return;
#       }
#-      ov511->proc_control->data = ov511;
#-      ov511->proc_control->proc_fops = &ov511_control_fops;
#+      ov->proc_control->owner = THIS_MODULE;
#+      ov->proc_control->data = ov;
#+      ov->proc_control->proc_fops = &ov511_control_fops;
#       unlock_kernel();
# }
# 
# static void 
#-destroy_proc_ov511_cam(struct usb_ov511 *ov511)
#+destroy_proc_ov511_cam(struct usb_ov511 *ov)
# {
#-      char dirname[4];
#+      char dirname[10];
#       
#-      if (!ov511 || !ov511->proc_devdir)
#+      if (!ov || !ov->proc_devdir)
#               return;
# 
#-      sprintf(dirname, "%d", ov511->vdev.minor);
#+      snprintf(dirname, 10, "%d", ov->vdev.minor);
# 
#       /* Destroy "control" entry */
#-      if (ov511->proc_control) {
#+      if (ov->proc_control) {
#               PDEBUG(4, "destroying /proc/video/ov511/%s/control", dirname);
#-              remove_proc_entry("control", ov511->proc_devdir);
#-              ov511->proc_control = NULL;
#+              remove_proc_entry("control", ov->proc_devdir);
#+              ov->proc_control = NULL;
#       }
# 
#       /* Destroy "button" entry */
#-      if (ov511->proc_button) {
#+      if (ov->proc_button) {
#               PDEBUG(4, "destroying /proc/video/ov511/%s/button", dirname);
#-              remove_proc_entry("button", ov511->proc_devdir);
#-              ov511->proc_button = NULL;
#+              remove_proc_entry("button", ov->proc_devdir);
#+              ov->proc_button = NULL;
#       }
# 
#       /* Destroy "info" entry */
#-      if (ov511->proc_info) {
#+      if (ov->proc_info) {
#               PDEBUG(4, "destroying /proc/video/ov511/%s/info", dirname);
#-              remove_proc_entry("info", ov511->proc_devdir);
#-              ov511->proc_info = NULL;
#+              remove_proc_entry("info", ov->proc_devdir);
#+              ov->proc_info = NULL;
#       }
# 
#       /* Destroy per-device directory */
#       PDEBUG(4, "destroying /proc/video/ov511/%s/", dirname);
#       remove_proc_entry(dirname, ov511_proc_entry);
#-      ov511->proc_devdir = NULL;
#+      ov->proc_devdir = NULL;
# }
# 
# static void 
#@@ -2803,11 +2807,11 @@
# //            /* Here I'm assuming that snapshot size == image size.
# //             * I hope that's always true. --claudio
# //             */
#-//            pxcnt = sub_flag ? (ov511->subw >> 3) - 1 : mlist[i].pxcnt;
#-//            lncnt = sub_flag ? (ov511->subh >> 3) - 1 : mlist[i].lncnt;
#+//            pxcnt = sub_flag ? (ov->subw >> 3) - 1 : mlist[i].pxcnt;
#+//            lncnt = sub_flag ? (ov->subh >> 3) - 1 : mlist[i].lncnt;
# //
#-//            reg_w(ov511, 0x12, pxcnt);
#-//            reg_w(ov511, 0x13, lncnt);
#+//            reg_w(ov, 0x12, pxcnt);
#+//            reg_w(ov, 0x13, lncnt);
# 
#               /******** Set the mode ********/                
# 
#@@ -3771,435 +3775,335 @@
#  *
#  **********************************************************************/
# 
#-static int 
#-ov511_move_data(struct usb_ov511 *ov, struct urb *urb)
#+static inline void 
#+ov511_move_data(struct usb_ov511 *ov, unsigned char *in, int n)
# {
#-      unsigned char *cdata;
#-      int data_size, num, offset, i, totlen = 0;
#-      int aPackNum[FRAMES_PER_DESC];
#-      struct ov511_frame *frame;
#+      int num, offset;
#+      int pnum = in[ov->packet_size - 1];             /* Get packet number */
#+      int max_raw = MAX_RAW_DATA_SIZE(ov->maxwidth, ov->maxheight);
#+      struct ov511_frame *frame = &ov->frame[ov->curframe];
#       struct timeval *ts;
# 
#-      PDEBUG(5, "Moving %d packets", urb->number_of_packets);
#-
#-      data_size = ov->packet_size - 1;
#+      /* SOF/EOF packets have 1st to 8th bytes zeroed and the 9th
#+       * byte non-zero. The EOF packet has image width/height in the
#+       * 10th and 11th bytes. The 9th byte is given as follows:
#+       *
#+       * bit 7: EOF
#+       *     6: compression enabled
#+       *     5: 422/420/400 modes
#+       *     4: 422/420/400 modes
#+       *     3: 1
#+       *     2: snapshot button on
#+       *     1: snapshot frame
#+       *     0: even/odd field
#+       */
# 
#-      for (i = 0; i < urb->number_of_packets; i++) {
#-              int n = urb->iso_frame_desc[i].actual_length;
#-              int st = urb->iso_frame_desc[i].status;
#+      if (printph) {
#+              info("ph(%3d): %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x",
#+                   pnum, in[0], in[1], in[2], in[3], in[4], in[5], in[6],
#+                   in[7], in[8], in[9], in[10], in[11]);
#+      }
# 
#-              urb->iso_frame_desc[i].actual_length = 0;
#-              urb->iso_frame_desc[i].status = 0;
#+      /* Check for SOF/EOF packet */
#+      if ((in[0] | in[1] | in[2] | in[3] | in[4] | in[5] | in[6] | in[7]) ||
#+          (~in[8] & 0x08))
#+              goto check_middle;
#+
#+      /* Frame end */
#+      if (in[8] & 0x80) {
#+              ts = (struct timeval *)(frame->data 
#+                    + MAX_FRAME_SIZE(ov->maxwidth, ov->maxheight));
#+              do_gettimeofday(ts);
# 
#-              cdata = urb->transfer_buffer + urb->iso_frame_desc[i].offset;
#+              /* Get the actual frame size from the EOF header */
#+              frame->rawwidth = ((int)(in[9]) + 1) * 8;
#+              frame->rawheight = ((int)(in[10]) + 1) * 8;
# 
#-              aPackNum[i] = n ? cdata[ov->packet_size - 1] : -1;
#+              PDEBUG(4, "Frame end, frame=%d, pnum=%d, w=%d, h=%d, recvd=%d",
#+                      ov->curframe, pnum, frame->rawwidth, frame->rawheight,
#+                      frame->bytes_recvd);
# 
#-              if (!n || ov->curframe == -1)
#-                      continue;
#+              /* Validate the header data */
#+              RESTRICT_TO_RANGE(frame->rawwidth, ov->minwidth, ov->maxwidth);
#+              RESTRICT_TO_RANGE(frame->rawheight, ov->minheight,
#+                                ov->maxheight);
# 
#-              if (st)
#-                      PDEBUG(2, "data error: [%d] len=%d, status=%d", i, n, st);
#+              /* Don't allow byte count to exceed buffer size */
#+              RESTRICT_TO_RANGE(frame->bytes_recvd, 8, max_raw);
# 
#-              frame = &ov->frame[ov->curframe];
#+              if (frame->scanstate == STATE_LINES) {
#+                      int nextf;
# 
#-              /* SOF/EOF packets have 1st to 8th bytes zeroed and the 9th
#-               * byte non-zero. The EOF packet has image width/height in the
#-               * 10th and 11th bytes. The 9th byte is given as follows:
#-               *
#-               * bit 7: EOF
#-               *     6: compression enabled
#-               *     5: 422/420/400 modes
#-               *     4: 422/420/400 modes
#-               *     3: 1
#-               *     2: snapshot button on
#-               *     1: snapshot frame
#-               *     0: even/odd field
#-               */
#+                      frame->grabstate = FRAME_DONE;  // FIXME: Is this right?
# 
#-              if (printph) {
#-                      info("packet header (%3d): %2x %2x %2x %2x %2x %2x %2x %2x %2x 
%2x %2x %2x",
#-                              cdata[ov->packet_size - 1],
#-                              cdata[0], cdata[1], cdata[2], cdata[3], cdata[4], 
cdata[5],
#-                              cdata[6], cdata[7], cdata[8], cdata[9], cdata[10], 
cdata[11]);
#-              }
#-
#-              /* Check for SOF/EOF packet */
#-              if ((cdata[0] | cdata[1] | cdata[2] | cdata[3] |
#-                   cdata[4] | cdata[5] | cdata[6] | cdata[7]) ||
#-                   (~cdata[8] & 0x08))
#-                      goto check_middle;
#-
#-              /* Frame end */
#-              if (cdata[8] & 0x80) {
#-                      ts = (struct timeval *)(frame->data 
#-                            + MAX_FRAME_SIZE(ov->maxwidth, ov->maxheight));
#-                      do_gettimeofday(ts);
#-
#-                      /* Get the actual frame size from the EOF header */
#-                      frame->rawwidth = ((int)(cdata[9]) + 1) * 8;
#-                      frame->rawheight = ((int)(cdata[10]) + 1) * 8;
#-
#-                      PDEBUG(4, "Frame end, curframe = %d, packnum=%d, hw=%d, vw=%d, 
recvd=%d",
#-                              ov->curframe,
#-                              (int)(cdata[ov->packet_size - 1]),
#-                              frame->rawwidth,
#-                              frame->rawheight,
#-                              frame->bytes_recvd);
#-
#-                      /* Validate the header data */
#-                      RESTRICT_TO_RANGE(frame->rawwidth, ov->minwidth, ov->maxwidth);
#-                      RESTRICT_TO_RANGE(frame->rawheight, ov->minheight, 
ov->maxheight);
#-
#-                      /* Don't allow byte count to exceed buffer size */
#-                      RESTRICT_TO_RANGE(frame->bytes_recvd,
#-                                        8, 
#-                                        MAX_RAW_DATA_SIZE(ov->maxwidth,
#-                                                          ov->maxheight));
#-
#-                      if (frame->scanstate == STATE_LINES) {
#-                              int iFrameNext;
#-
#-                              frame->grabstate = FRAME_DONE;  // FIXME: Is this 
right?
#-
#-                              if (waitqueue_active(&frame->wq)) {
#-                                      frame->grabstate = FRAME_DONE;
#-                                      wake_up_interruptible(&frame->wq);
#-                              }
#+                      if (waitqueue_active(&frame->wq)) {
#+                              frame->grabstate = FRAME_DONE;
#+                              wake_up_interruptible(&frame->wq);
#+                      }
# 
#-                              /* If next frame is ready or grabbing,
#-                                 * point to it */
#-                              iFrameNext = (ov->curframe + 1) % OV511_NUMFRAMES;
#-                              if (ov->frame[iFrameNext].grabstate == FRAME_READY
#-                                  || ov->frame[iFrameNext].grabstate == 
FRAME_GRABBING) {
#-                                      ov->curframe = iFrameNext;
#-                                      ov->frame[iFrameNext].scanstate = 
STATE_SCANNING;
#+                      /* If next frame is ready or grabbing,
#+                       * point to it */
#+                      nextf = (ov->curframe + 1) % OV511_NUMFRAMES;
#+                      if (ov->frame[nextf].grabstate == FRAME_READY
#+                          || ov->frame[nextf].grabstate == FRAME_GRABBING) {
#+                              ov->curframe = nextf;
#+                              ov->frame[nextf].scanstate = STATE_SCANNING;
#+                      } else {
#+                              if (frame->grabstate == FRAME_DONE) {
#+                                      PDEBUG(4, "** Frame done **");
#                               } else {
#-                                      if (frame->grabstate == FRAME_DONE) {
#-                                              PDEBUG(4, "Frame done! 
congratulations");
#-                                      } else {
#-                                              PDEBUG(4, "Frame not ready? state = 
%d",
#-                                                      
ov->frame[iFrameNext].grabstate);
#-                                      }
#-
#-                                      ov->curframe = -1;
#+                                      PDEBUG(4, "Frame not ready? state = %d",
#+                                              ov->frame[nextf].grabstate);
#                               }
#-                      } else {
#-                              PDEBUG(5, "Frame done, but not scanning");
#-                      }
#-                      /* Image corruption caused by misplaced frame->segment = 0
#-                       * fixed by [EMAIL PROTECTED]
#-                       */
#-              } else {
#-                      /* Frame start */
#-                      PDEBUG(4, "Frame start, framenum = %d", ov->curframe);
# 
#-                      /* Check to see if it's a snapshot frame */
#-                      /* FIXME?? Should the snapshot reset go here? Performance? */
#-                      if (cdata[8] & 0x02) {
#-                              frame->snapshot = 1;
#-                              PDEBUG(3, "snapshot detected");
#+                              ov->curframe = -1;
#                       }
#-
#-                      frame->scanstate = STATE_LINES;
#-                      frame->bytes_recvd = 0;
#-                      frame->compressed = cdata[8] & 0x40;
#+              } else {
#+                      PDEBUG(5, "Frame done, but not scanning");
#               }
#+              /* Image corruption caused by misplaced frame->segment = 0
#+               * fixed by [EMAIL PROTECTED]
#+               */
#+      } else {
#+              /* Frame start */
#+              PDEBUG(4, "Frame start, framenum = %d", ov->curframe);
# 
#-check_middle:
#-              /* Are we in a frame? */
#-              if (frame->scanstate != STATE_LINES) {
#-                      PDEBUG(5, "Not in a frame; packet skipped");
#-                      continue;
#+              /* Check to see if it's a snapshot frame */
#+              /* FIXME?? Should the snapshot reset go here? Performance? */
#+              if (in[8] & 0x02) {
#+                      frame->snapshot = 1;
#+                      PDEBUG(3, "snapshot detected");
#               }
# 
#-#if 0
#-              /* Skip packet if first 9 bytes are zero. These are common, so
#-               * we use a less expensive test here instead of later */
#-              if (frame->compressed) {
#-                      int b, skip = 1;
#-
#-                      for (b = 0; b < 9; b++) { 
#-                              if (cdata[b])
#-                                      skip=0;
#-                      }
#+              frame->scanstate = STATE_LINES;
#+              frame->bytes_recvd = 0;
#+              frame->compressed = in[8] & 0x40;
#+      }
# 
#-                      if (skip) {
#-                              PDEBUG(5, "Skipping packet (all zero)");
#-                              continue;
#-                      }
#-              }
#-#endif
#-              /* If frame start, skip header */
#-              if (frame->bytes_recvd == 0)
#-                      offset = 9;
#-              else
#-                      offset = 0;
#+check_middle:
#+      /* Are we in a frame? */
#+      if (frame->scanstate != STATE_LINES) {
#+              PDEBUG(5, "Not in a frame; packet skipped");
#+              return;
#+      }
# 
#-              num = n - offset - 1;
#+      /* If frame start, skip header */
#+      if (frame->bytes_recvd == 0)
#+              offset = 9;
#+      else
#+              offset = 0;
# 
#-              /* Dump all data exactly as received */
#-              if (dumppix == 2) {
#-                      frame->bytes_recvd += n - 1;
#-                      if (frame->bytes_recvd <= MAX_RAW_DATA_SIZE(ov->maxwidth, 
ov->maxheight))
#-                              memmove(frame->rawdata + frame->bytes_recvd - (n - 1),
#-                                      &cdata[0], n - 1);
#-                      else
#-                              PDEBUG(3, "Raw data buffer overrun!! (%d)",
#-                                      frame->bytes_recvd
#-                                      - MAX_RAW_DATA_SIZE(ov->maxwidth,
#-                                                          ov->maxheight));
#-              } else if (!frame->compressed && !remove_zeros) {
#-                      frame->bytes_recvd += num;
#-                      if (frame->bytes_recvd <= MAX_RAW_DATA_SIZE(ov->maxwidth, 
ov->maxheight))
#-                              memmove(frame->rawdata + frame->bytes_recvd - num,
#-                                      &cdata[offset], num);
#-                      else
#-                              PDEBUG(3, "Raw data buffer overrun!! (%d)",
#-                                      frame->bytes_recvd
#-                                      - MAX_RAW_DATA_SIZE(ov->maxwidth,
#-                                                          ov->maxheight));
#-              } else { /* Remove all-zero FIFO lines (aligned 32-byte blocks) */
#-                      int b, in = 0, allzero, copied=0;
#-                      if (offset) {
#-                              frame->bytes_recvd += 32 - offset;      // Bytes out
#-                              memmove(frame->rawdata,
#-                                      &cdata[offset], 32 - offset);
#-                              in += 32;
#-                      }
#+      num = n - offset - 1;
# 
#-                      while (in < n - 1) {
#-                              allzero = 1;
#-                              for (b = 0; b < 32; b++) {
#-                                      if (cdata[in + b]) {
#-                                              allzero = 0;
#-                                              break;
#-                                      }
#+      /* Dump all data exactly as received */
#+      if (dumppix == 2) {
#+              frame->bytes_recvd += n - 1;
#+              if (frame->bytes_recvd <= max_raw)
#+                      memmove(frame->rawdata + frame->bytes_recvd - (n - 1),
#+                              in, n - 1);
#+              else
#+                      PDEBUG(3, "Raw data buffer overrun!! (%d)",
#+                              frame->bytes_recvd - max_raw);
#+      } else if (!frame->compressed && !remove_zeros) {
#+              frame->bytes_recvd += num;
#+              if (frame->bytes_recvd <= max_raw)
#+                      memmove(frame->rawdata + frame->bytes_recvd - num,
#+                              in + offset, num);
#+              else
#+                      PDEBUG(3, "Raw data buffer overrun!! (%d)",
#+                              frame->bytes_recvd - max_raw);
#+      } else { /* Remove all-zero FIFO lines (aligned 32-byte blocks) */
#+              int b, read = 0, allzero, copied = 0;
#+              if (offset) {
#+                      frame->bytes_recvd += 32 - offset;      // Bytes out
#+                      memmove(frame->rawdata, in + offset, 32 - offset);
#+                      read += 32;
#+              }
#+
#+              while (read < n - 1) {
#+                      allzero = 1;
#+                      for (b = 0; b < 32; b++) {
#+                              if (in[read + b]) {
#+                                      allzero = 0;
#+                                      break;
#                               }
#+                      }
# 
#-                              if (allzero) {
#-                                      /* Don't copy it */
#+                      if (allzero) {
#+                              /* Don't copy it */
#+                      } else {
#+                              if (frame->bytes_recvd + copied + 32 <= max_raw)
#+                              {
#+                                      memmove(frame->rawdata
#+                                              + frame->bytes_recvd + copied,
#+                                              in + read, 32);
#+                                      copied += 32;
#                               } else {
#-                                      if (frame->bytes_recvd + copied + 32
#-                                          <= MAX_RAW_DATA_SIZE(ov->maxwidth, 
ov->maxheight)) {
#-                                              memmove(frame->rawdata + 
frame->bytes_recvd + copied,
#-                                                      &cdata[in], 32);
#-                                              copied += 32;
#-                                      } else {
#-                                              PDEBUG(3, "Raw data buffer overrun!!");
#-                                      }
#+                                      PDEBUG(3, "Raw data buffer overrun!!");
#                               }
#-                              in += 32;
#                       }
#-
#-                      frame->bytes_recvd += copied;
#+                      read += 32;
#               }
# 
#+              frame->bytes_recvd += copied;
#       }
#-
#-      PDEBUG(5, "pn: %d %d %d %d %d %d %d %d %d %d",
#-              aPackNum[0], aPackNum[1], aPackNum[2], aPackNum[3], aPackNum[4],
#-              aPackNum[5],aPackNum[6], aPackNum[7], aPackNum[8], aPackNum[9]);
#-
#-      return totlen;
# }
# 
#-static int 
#-ov518_move_data(struct usb_ov511 *ov, struct urb *urb)
#+static inline void 
#+ov518_move_data(struct usb_ov511 *ov, unsigned char *in, int n)
# {
#-      unsigned char *cdata;
#-      int i, data_size, totlen = 0;
#-      struct ov511_frame *frame;
#+      int max_raw = MAX_RAW_DATA_SIZE(ov->maxwidth, ov->maxheight);
#+      struct ov511_frame *frame = &ov->frame[ov->curframe];
#       struct timeval *ts;
# 
#-      PDEBUG(5, "Moving %d packets", urb->number_of_packets);
#-
#-      /* OV518(+) has no packet numbering */
#-      data_size = ov->packet_size;
#-
#-      for (i = 0; i < urb->number_of_packets; i++) {
#-              int n = urb->iso_frame_desc[i].actual_length;
#-              int st = urb->iso_frame_desc[i].status;
#-
#-              urb->iso_frame_desc[i].actual_length = 0;
#-              urb->iso_frame_desc[i].status = 0;
#-
#-              cdata = urb->transfer_buffer + urb->iso_frame_desc[i].offset;
#-
#-              if (!n) {
#-                      PDEBUG(4, "Zero-length packet");
#-                      continue;
#-              }
#-
#-              if (ov->curframe == -1) {
#-                      PDEBUG(4, "No frame currently active");
#-                      continue;
#-              }
#-
#-              if (st)
#-                      PDEBUG(2, "data error: [%d] len=%d, status=%d", i, n, st);
#-
#-              frame = &ov->frame[ov->curframe];
#+      if (printph) {
#+              info("ph: %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x",
#+                   in[0], in[1], in[2], in[3], in[4], in[5], in[6], in[7],
#+                   in[8], in[9], in[10], in[11]);
#+      }
# 
#-              if (printph) {
#-                      info("packet header: %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x 
%2x %2x",
#-                              cdata[0], cdata[1], cdata[2], cdata[3], cdata[4], 
cdata[5],
#-                              cdata[6], cdata[7], cdata[8], cdata[9], cdata[10], 
cdata[11]);
#+      /* A false positive here is likely, until OVT gives me
#+       * the definitive SOF/EOF format */
#+      if ((!(in[0] | in[1] | in[2] | in[3] | in[5])) && in[6]) {
#+              if (frame->scanstate == STATE_LINES) {
#+                      PDEBUG(4, "Detected frame end/start");
#+                      goto eof;
#+              } else { //scanstate == STATE_SCANNING
#+                      /* Frame start */
#+                      PDEBUG(4, "Frame start, framenum = %d", ov->curframe);
#+                      goto sof;
#               }
#+      } else {
#+              goto check_middle;
#+      }
# 
#-              /* A false positive here is likely, until OVT gives me
#-               * the definitive SOF/EOF format */
#-              if ((!(cdata[0] | cdata[1] | cdata[2] | cdata[3] |
#-                    cdata[5])) && cdata[6]) {
#-                      
#-                      if (frame->scanstate == STATE_LINES) {
#-                              PDEBUG(4, "Detected frame end/start");
#-                              goto eof;
#-                      } else { //scanstate == STATE_SCANNING
#-                              /* Frame start */
#-                              PDEBUG(4, "Frame start, framenum = %d", ov->curframe);
#-                              goto sof;
#-                      }
#-              } else {
#-                      goto check_middle;
#-              }
#-      
# eof:
#-              ts = (struct timeval *)(frame->data
#-                    + MAX_FRAME_SIZE(ov->maxwidth, ov->maxheight));
#-              do_gettimeofday(ts);
#-
#-              PDEBUG(4, "Frame end, curframe = %d, hw=%d, vw=%d, recvd=%d",
#-                      ov->curframe,
#-                      (int)(cdata[9]), (int)(cdata[10]), frame->bytes_recvd);
#-
#-              // FIXME: Since we don't know the header formats yet,
#-              // there is no way to know what the actual image size is
#-              frame->rawwidth = frame->width;
#-              frame->rawheight = frame->height;
#-
#-              /* Validate the header data */
#-              RESTRICT_TO_RANGE(frame->rawwidth, ov->minwidth, ov->maxwidth);
#-              RESTRICT_TO_RANGE(frame->rawheight, ov->minheight, ov->maxheight);
#-
#-              /* Don't allow byte count to exceed buffer size */
#-              RESTRICT_TO_RANGE(frame->bytes_recvd,
#-                                8, 
#-                                MAX_RAW_DATA_SIZE(ov->maxwidth, ov->maxheight));
#-
#-              if (frame->scanstate == STATE_LINES) {
#-                      int iFrameNext;
#-
#-                      frame->grabstate = FRAME_DONE;  // FIXME: Is this right?
#-
#-                      if (waitqueue_active(&frame->wq)) {
#-                              frame->grabstate = FRAME_DONE;
#-                              wake_up_interruptible(&frame->wq);
#-                      }
#-
#-                      /* If next frame is ready or grabbing,
#-                       * point to it */
#-                      iFrameNext = (ov->curframe + 1) % OV511_NUMFRAMES;
#-                      if (ov->frame[iFrameNext].grabstate == FRAME_READY
#-                          || ov->frame[iFrameNext].grabstate == FRAME_GRABBING) {
#-                              ov->curframe = iFrameNext;
#-                              ov->frame[iFrameNext].scanstate = STATE_SCANNING;
#-                              frame = &ov->frame[iFrameNext];
#+      ts = (struct timeval *)(frame->data
#+            + MAX_FRAME_SIZE(ov->maxwidth, ov->maxheight));
#+      do_gettimeofday(ts);
#+
#+      PDEBUG(4, "Frame end, curframe = %d, hw=%d, vw=%d, recvd=%d",
#+              ov->curframe,
#+              (int)(in[9]), (int)(in[10]), frame->bytes_recvd);
#+
#+      // FIXME: Since we don't know the header formats yet,
#+      // there is no way to know what the actual image size is
#+      frame->rawwidth = frame->width;
#+      frame->rawheight = frame->height;
#+
#+      /* Validate the header data */
#+      RESTRICT_TO_RANGE(frame->rawwidth, ov->minwidth, ov->maxwidth);
#+      RESTRICT_TO_RANGE(frame->rawheight, ov->minheight, ov->maxheight);
#+
#+      /* Don't allow byte count to exceed buffer size */
#+      RESTRICT_TO_RANGE(frame->bytes_recvd, 8, max_raw);
#+
#+      if (frame->scanstate == STATE_LINES) {
#+              int nextf;
#+
#+              frame->grabstate = FRAME_DONE;  // FIXME: Is this right?
#+
#+              if (waitqueue_active(&frame->wq)) {
#+                      frame->grabstate = FRAME_DONE;
#+                      wake_up_interruptible(&frame->wq);
#+              }
#+
#+              /* If next frame is ready or grabbing,
#+               * point to it */
#+              nextf = (ov->curframe + 1) % OV511_NUMFRAMES;
#+              if (ov->frame[nextf].grabstate == FRAME_READY
#+                  || ov->frame[nextf].grabstate == FRAME_GRABBING) {
#+                      ov->curframe = nextf;
#+                      ov->frame[nextf].scanstate = STATE_SCANNING;
#+                      frame = &ov->frame[nextf];
#+              } else {
#+                      if (frame->grabstate == FRAME_DONE) {
#+                              PDEBUG(4, "** Frame done **");
#                       } else {
#-                              if (frame->grabstate == FRAME_DONE) {
#-                                      PDEBUG(4, "Frame done! congratulations");
#-                              } else {
#-                                      PDEBUG(4, "Frame not ready? state = %d",
#-                                              ov->frame[iFrameNext].grabstate);
#-                              }
#-
#-                              ov->curframe = -1;
#-                              PDEBUG(4, "SOF dropped (no active frame)");
#-                              continue;  /* Nowhere to store this frame */
#+                              PDEBUG(4, "Frame not ready? state = %d",
#+                                     ov->frame[nextf].grabstate);
#                       }
#+
#+                      ov->curframe = -1;
#+                      PDEBUG(4, "SOF dropped (no active frame)");
#+                      return;  /* Nowhere to store this frame */
#               }
#-              /* Image corruption caused by misplaced frame->segment = 0
#-               * fixed by [EMAIL PROTECTED]
#-               */
#+      }
# sof:
#-              PDEBUG(4, "Starting capture on frame %d", frame->framenum);
#+      PDEBUG(4, "Starting capture on frame %d", frame->framenum);
#+
# // Snapshot not reverse-engineered yet.
# #if 0
#-              /* Check to see if it's a snapshot frame */
#-              /* FIXME?? Should the snapshot reset go here? Performance? */
#-              if (cdata[8] & 0x02) {
#-                      frame->snapshot = 1;
#-                      PDEBUG(3, "snapshot detected");
#-              }
#+      /* Check to see if it's a snapshot frame */
#+      /* FIXME?? Should the snapshot reset go here? Performance? */
#+      if (in[8] & 0x02) {
#+              frame->snapshot = 1;
#+              PDEBUG(3, "snapshot detected");
#+      }
# #endif
#-              frame->scanstate = STATE_LINES;
#-              frame->bytes_recvd = 0;
#+      frame->scanstate = STATE_LINES;
#+      frame->bytes_recvd = 0;
# //            frame->compressed = 1;
# 
# check_middle:
#-              /* Are we in a frame? */
#-              if (frame->scanstate != STATE_LINES) {
#-                      PDEBUG(4, "scanstate: no SOF yet");
#-                      continue;
#-              }
#+      /* Are we in a frame? */
#+      if (frame->scanstate != STATE_LINES) {
#+              PDEBUG(4, "scanstate: no SOF yet");
#+              return;
#+      }
# 
#-              /* Dump all data exactly as received */
#-              if (dumppix == 2) {
#-                      frame->bytes_recvd += n;
#-                      if (frame->bytes_recvd <= MAX_RAW_DATA_SIZE(ov->maxwidth, 
ov->maxheight))
#-                              memmove(frame->rawdata + frame->bytes_recvd - n,
#-                                      &cdata[0], n);
#-                      else
#-                              PDEBUG(3, "Raw data buffer overrun!! (%d)",
#-                                      frame->bytes_recvd
#-                                      - MAX_RAW_DATA_SIZE(ov->maxwidth,
#-                                                          ov->maxheight));
#-              } else {
#-                      /* All incoming data are divided into 8-byte segments. If the
#-                       * segment contains all zero bytes, it must be skipped. These
#-                       * zero-segments allow the OV518 to mainain a constant data 
rate
#-                       * regardless of the effectiveness of the compression. Segments
#-                       * are aligned relative to the beginning of each isochronous
#-                       * packet. The first segment is a header (the decompressor
#-                       * skips it later).
#-                       */
#-
#-                      int b, in = 0, allzero, copied=0;
#-
#-                      while (in < n) {
#-                              allzero = 1;
#-                              for (b = 0; b < 8; b++) {
#-                                      if (cdata[in + b]) {
#-                                              allzero = 0;
#-                                              break;
#-                                      }
#+      /* Dump all data exactly as received */
#+      if (dumppix == 2) {
#+              frame->bytes_recvd += n;
#+              if (frame->bytes_recvd <= max_raw)
#+                      memmove(frame->rawdata + frame->bytes_recvd - n, in, n);
#+              else
#+                      PDEBUG(3, "Raw data buffer overrun!! (%d)",
#+                              frame->bytes_recvd - max_raw);
#+      } else {
#+              /* All incoming data are divided into 8-byte segments. If the
#+               * segment contains all zero bytes, it must be skipped. These
#+               * zero-segments allow the OV518 to mainain a constant data rate
#+               * regardless of the effectiveness of the compression. Segments
#+               * are aligned relative to the beginning of each isochronous
#+               * packet. The first segment is a header (the decompressor
#+               * skips it later).
#+               */
#+
#+              int b, read = 0, allzero, copied = 0;
#+
#+              while (read < n) {
#+                      allzero = 1;
#+                      for (b = 0; b < 8; b++) {
#+                              if (in[read + b]) {
#+                                      allzero = 0;
#+                                      break;
#                               }
#+                      }
# 
#-                              if (allzero) {
#-                              /* Don't copy it */
#+                      if (allzero) {
#+                      /* Don't copy it */
#+                      } else {
#+                              if (frame->bytes_recvd + copied + 8 <= max_raw)
#+                              {
#+                                      memmove(frame->rawdata 
#+                                              + frame->bytes_recvd + copied,
#+                                              in + read, 8);
#+                                      copied += 8;
#                               } else {
#-                                      if (frame->bytes_recvd + copied + 8
#-                                          <= MAX_RAW_DATA_SIZE(ov->maxwidth, 
ov->maxheight)) {
#-                                              memmove(frame->rawdata + 
frame->bytes_recvd + copied,
#-                                                      &cdata[in], 8);
#-                                              copied += 8;
#-                                      } else {
#-                                              PDEBUG(3, "Raw data buffer overrun!!");
#-                                      }
#+                                      PDEBUG(3, "Raw data buffer overrun!!");
#                               }
#-                              in += 8;
#                       }
#-                      frame->bytes_recvd += copied;
#+                      read += 8;
#               }
#+              frame->bytes_recvd += copied;
#       }
#-
#-      return totlen;
# }
# 
# static void 
# ov51x_isoc_irq(struct urb *urb)
# {
#-      int len;
#+      int i;
#       struct usb_ov511 *ov;
# 
#       if (!urb->context) {
#@@ -4220,15 +4124,39 @@
#       }
# 
#       /* Copy the data received into our frame buffer */
#-      if (ov->curframe >= 0) {
#-              if (ov->bclass == BCL_OV511)
#-                      len = ov511_move_data(ov, urb);
#-              else if (ov->bclass == BCL_OV518)
#-                      len = ov518_move_data(ov, urb);
#-              else
#-                      err("Unknown bridge device (%d)", ov->bridge);
#-      } else if (waitqueue_active(&ov->wq)) {
#-              wake_up_interruptible(&ov->wq);
#+      PDEBUG(5, "Moving %d packets", urb->number_of_packets);
#+      for (i = 0; i < urb->number_of_packets; i++) {
#+              /* Warning: Don't call *_move_data() if no frame active! */
#+              if (ov->curframe >= 0) {
#+                      int n = urb->iso_frame_desc[i].actual_length;
#+                      int st = urb->iso_frame_desc[i].status;
#+                      unsigned char *cdata;
#+
#+                      urb->iso_frame_desc[i].actual_length = 0;
#+                      urb->iso_frame_desc[i].status = 0;
#+
#+                      cdata = urb->transfer_buffer
#+                              + urb->iso_frame_desc[i].offset;
#+
#+                      if (!n) {
#+                              PDEBUG(4, "Zero-length packet");
#+                              continue;
#+                      }
#+
#+                      if (st)
#+                              PDEBUG(2, "data error: [%d] len=%d, status=%d",
#+                                     i, n, st);
#+
#+                      if (ov->bclass == BCL_OV511)
#+                              ov511_move_data(ov, cdata, n);
#+                      else if (ov->bclass == BCL_OV518)
#+                              ov518_move_data(ov, cdata, n);
#+                      else
#+                              err("Unknown bridge device (%d)", ov->bridge);
#+
#+              } else if (waitqueue_active(&ov->wq)) {
#+                      wake_up_interruptible(&ov->wq);
#+              }
#       }
# 
#       urb->dev = ov->dev;
#@@ -5453,7 +5381,8 @@
#       pos = (unsigned long)ov->fbuf;
#       while (size > 0) {
#               page = kvirt_to_pa(pos);
#-              if (remap_page_range(vma, start, page, PAGE_SIZE, PAGE_SHARED)) {
#+              if (remap_page_range(vma, start, page, PAGE_SIZE,
#+                                   PAGE_SHARED)) {
#                       up(&ov->lock);
#                       return -EAGAIN;
#               }
#@@ -5497,7 +5426,7 @@
#       if (!pde)
#               return -ENOENT;
# 
#-      ov = (struct usb_ov511 *) pde->data;
#+      ov = pde->data;
#       if (!ov)
#               return -ENODEV;
# 
#@@ -6165,7 +6094,7 @@
# 
# /* This initializes the SAA7111A video decoder. */
# static int 
#-saa7111a_configure(struct usb_ov511 *ov511)
#+saa7111a_configure(struct usb_ov511 *ov)
# {
#       int rc;
# 
#@@ -6210,44 +6139,44 @@
# #endif
# 
#       /* Set sensor-specific vars */
#-      ov511->maxwidth = 640;
#-      ov511->maxheight = 480;         /* Even/Odd fields */
#-      ov511->minwidth = 320;
#-      ov511->minheight = 240;         /* Even field only */
#-
#-      ov511->has_decoder = 1;
#-      ov511->num_inputs = 8;
#-      ov511->norm = VIDEO_MODE_AUTO;
#-      ov511->stop_during_set = 0;     /* Decoder guarantees stable image */
#+      ov->maxwidth = 640;
#+      ov->maxheight = 480;            /* Even/Odd fields */
#+      ov->minwidth = 320;
#+      ov->minheight = 240;            /* Even field only */
#+
#+      ov->has_decoder = 1;
#+      ov->num_inputs = 8;
#+      ov->norm = VIDEO_MODE_AUTO;
#+      ov->stop_during_set = 0;        /* Decoder guarantees stable image */
# 
#       /* Decoder doesn't change these values, so we use these instead of
#        * acutally reading the registers (which doesn't work) */
#-      ov511->brightness = 0x80 << 8;
#-      ov511->contrast = 0x40 << 9;
#-      ov511->colour = 0x40 << 9;
#-      ov511->hue = 32768;
#+      ov->brightness = 0x80 << 8;
#+      ov->contrast = 0x40 << 9;
#+      ov->colour = 0x40 << 9;
#+      ov->hue = 32768;
# 
#       PDEBUG(4, "Writing SAA7111A registers");
#-      if (write_regvals(ov511, aRegvalsNormSAA7111A))
#+      if (write_regvals(ov, aRegvalsNormSAA7111A))
#               return -1;
# 
#       /* Detect version of decoder. This must be done after writing the
#          * initial regs or the decoder will lock up. */
#-      rc = i2c_r(ov511, 0x00);
#+      rc = i2c_r(ov, 0x00);
# 
#       if (rc < 0) {
#               err("Error detecting sensor version");
#               return -1;
#       } else {
#               info("Sensor is an SAA7111A (version 0x%x)", rc);
#-              ov511->sensor = SEN_SAA7111A;
#+              ov->sensor = SEN_SAA7111A;
#       }
# 
#       // FIXME: Fix this for OV518(+)
#       /* Latch to negative edge of clock. Otherwise, we get incorrect
#        * colors and jitter in the digital signal. */
#-      if (ov511->bclass == BCL_OV511)
#-              reg_w(ov511, 0x11, 0x00);
#+      if (ov->bclass == BCL_OV511)
#+              reg_w(ov, 0x11, 0x00);
#       else
#               warn("SAA7111A not yet supported with OV518/OV518+");
# 
#@@ -6545,7 +6474,6 @@
#  *
#  ***************************************************************************/
# 
#-/* 2.2.x compatibility */
# static void *
# ov51x_probe(struct usb_device *dev, unsigned int ifnum,
#           const struct usb_device_id *id)
#

# Diff checksum=19a993d1


# Patch vers:   1.3
# Patch type:   REGULAR

== ChangeSet ==
[EMAIL PROTECTED]|ChangeSet|20011125035615|28334|160bd283d279fb69
[EMAIL PROTECTED]|ChangeSet|20020227191438|57904
D 1.363 02/02/27 22:09:24-08:00 [EMAIL PROTECTED] +1 -0
B [EMAIL PROTECTED]|ChangeSet|20011125035615|28334|160bd283d279fb69
C
c Upgrade ov511 driver to version 1.52
K 58599
P ChangeSet
------------------------------------------------

0a0
> [EMAIL PROTECTED]|drivers/usb/ov511.c|20011125040916|39092|234d3ea0cb539d7 
>[EMAIL PROTECTED]|drivers/usb/ov511.c|20020228060921|09631

== drivers/usb/ov511.c ==
[EMAIL PROTECTED]|drivers/usb/ov511.c|20011125040916|39092|234d3ea0cb539d7
[EMAIL PROTECTED]|drivers/usb/ov511.c|20020226213229|39205
D 1.16 02/02/27 22:09:21-08:00 [EMAIL PROTECTED] +363 -435
B [EMAIL PROTECTED]|ChangeSet|20011125035615|28334|160bd283d279fb69
C
c 1.49 -> 1.50:
c - Increased size of directory name string in /proc code, to allow >13 bit minor
c   numbers.
c - sprintf() => snprintf()
c - Set proc_dir_entry owner field to THIS_MODULE, to prevent driver unload while
c   /proc interface is in use.
c 
c 1.50 -> 1.51:
c - Moved common code from *_move_data() functions to interrupt handler.
c - *move_data() functions cleaned up and optimized
c - Finished cleanups started in 1.49
c 
c 1.51 -> 1.52:
c [no actual changes; fixes regressions from 1.51]
c 
c 
K 9631
O -rw-rw-r--
P drivers/usb/ov511.c
------------------------------------------------

D4 1
I4 1
 * Copyright (c) 1999-2002 Mark W. McClelland
D61 1
I61 1
#define DRIVER_VERSION "v1.52 for Linux 2.5"
I377 1
 *
I378 1
 *
D585 1
I585 1
create_proc_ov511_cam(struct usb_ov511 *ov)
D587 1
I587 1
        char dirname[10];
D589 1
I589 1
        if (!ov511_proc_entry || !ov)
D593 1
I593 1
        snprintf(dirname, 10, "%d", ov->vdev.minor);
D595 3
I597 2
        ov->proc_devdir = create_proc_entry(dirname, S_IFDIR, ov511_proc_entry);
        if (!ov->proc_devdir)
I598 1
        ov->proc_devdir->owner = THIS_MODULE;
D602 4
I605 3
        ov->proc_info = create_proc_read_entry("info", S_IFREG|S_IRUGO|S_IWUSR,
                ov->proc_devdir, ov511_read_proc_info, ov);
        if (!ov->proc_info)
I606 1
        ov->proc_info->owner = THIS_MODULE;
D612 4
I615 4
                ov->proc_button = create_proc_read_entry("button",
                        S_IFREG|S_IRUGO|S_IWUSR, ov->proc_devdir,
                        ov511_read_proc_button, ov);
                if (!ov->proc_button)
I617 1
        ov->proc_button->owner = THIS_MODULE;
D622 3
I624 3
        ov->proc_control = create_proc_entry("control", S_IFREG|S_IRUGO|S_IWUSR,
                ov->proc_devdir);
        if (!ov->proc_control) {
D628 2
I629 3
        ov->proc_control->owner = THIS_MODULE;
        ov->proc_control->data = ov;
        ov->proc_control->proc_fops = &ov511_control_fops;
D634 1
I634 1
destroy_proc_ov511_cam(struct usb_ov511 *ov)
D636 1
I636 1
        char dirname[10];
D638 1
I638 1
        if (!ov || !ov->proc_devdir)
D641 1
I641 1
        snprintf(dirname, 10, "%d", ov->vdev.minor);
D644 1
I644 1
        if (ov->proc_control) {
D646 2
I647 2
                remove_proc_entry("control", ov->proc_devdir);
                ov->proc_control = NULL;
D651 1
I651 1
        if (ov->proc_button) {
D653 2
I654 2
                remove_proc_entry("button", ov->proc_devdir);
                ov->proc_button = NULL;
D658 1
I658 1
        if (ov->proc_info) {
D660 2
I661 2
                remove_proc_entry("info", ov->proc_devdir);
                ov->proc_info = NULL;
D667 1
I667 1
        ov->proc_devdir = NULL;
D2806 2
I2807 2
//              pxcnt = sub_flag ? (ov->subw >> 3) - 1 : mlist[i].pxcnt;
//              lncnt = sub_flag ? (ov->subh >> 3) - 1 : mlist[i].lncnt;
D2809 2
I2810 2
//              reg_w(ov, 0x12, pxcnt);
//              reg_w(ov, 0x13, lncnt);
D3774 2
I3775 2
static inline void 
ov511_move_data(struct usb_ov511 *ov, unsigned char *in, int n)
D3777 4
I3780 4
        int num, offset;
        int pnum = in[ov->packet_size - 1];             /* Get packet number */
        int max_raw = MAX_RAW_DATA_SIZE(ov->maxwidth, ov->maxheight);
        struct ov511_frame *frame = &ov->frame[ov->curframe];
D3783 3
I3785 13
        /* SOF/EOF packets have 1st to 8th bytes zeroed and the 9th
         * byte non-zero. The EOF packet has image width/height in the
         * 10th and 11th bytes. The 9th byte is given as follows:
         *
         * bit 7: EOF
         *     6: compression enabled
         *     5: 422/420/400 modes
         *     4: 422/420/400 modes
         *     3: 1
         *     2: snapshot button on
         *     1: snapshot frame
         *     0: even/odd field
         */
D3787 3
I3789 5
        if (printph) {
                info("ph(%3d): %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x",
                     pnum, in[0], in[1], in[2], in[3], in[4], in[5], in[6],
                     in[7], in[8], in[9], in[10], in[11]);
        }
D3791 2
I3792 10
        /* Check for SOF/EOF packet */
        if ((in[0] | in[1] | in[2] | in[3] | in[4] | in[5] | in[6] | in[7]) ||
            (~in[8] & 0x08))
                goto check_middle;
\
        /* Frame end */
        if (in[8] & 0x80) {
                ts = (struct timeval *)(frame->data 
                      + MAX_FRAME_SIZE(ov->maxwidth, ov->maxheight));
                do_gettimeofday(ts);
D3794 1
I3794 3
                /* Get the actual frame size from the EOF header */
                frame->rawwidth = ((int)(in[9]) + 1) * 8;
                frame->rawheight = ((int)(in[10]) + 1) * 8;
D3796 1
I3796 3
                PDEBUG(4, "Frame end, frame=%d, pnum=%d, w=%d, h=%d, recvd=%d",
                        ov->curframe, pnum, frame->rawwidth, frame->rawheight,
                        frame->bytes_recvd);
D3798 2
I3799 4
                /* Validate the header data */
                RESTRICT_TO_RANGE(frame->rawwidth, ov->minwidth, ov->maxwidth);
                RESTRICT_TO_RANGE(frame->rawheight, ov->minheight,
                                  ov->maxheight);
D3801 2
I3802 2
                /* Don't allow byte count to exceed buffer size */
                RESTRICT_TO_RANGE(frame->bytes_recvd, 8, max_raw);
D3804 1
I3804 2
                if (frame->scanstate == STATE_LINES) {
                        int nextf;
D3806 13
I3818 1
                        frame->grabstate = FRAME_DONE;  // FIXME: Is this right?
D3820 49
I3868 4
                        if (waitqueue_active(&frame->wq)) {
                                frame->grabstate = FRAME_DONE;
                                wake_up_interruptible(&frame->wq);
                        }
D3870 7
I3876 10
                        /* If next frame is ready or grabbing,
                         * point to it */
                        nextf = (ov->curframe + 1) % OV511_NUMFRAMES;
                        if (ov->frame[nextf].grabstate == FRAME_READY
                            || ov->frame[nextf].grabstate == FRAME_GRABBING) {
                                ov->curframe = nextf;
                                ov->frame[nextf].scanstate = STATE_SCANNING;
                        } else {
                                if (frame->grabstate == FRAME_DONE) {
                                        PDEBUG(4, "** Frame done **");
D3878 8
I3885 2
                                        PDEBUG(4, "Frame not ready? state = %d",
                                                ov->frame[nextf].grabstate);
D3887 9
D3897 5
I3901 1
                                ov->curframe = -1;
D3903 4
I3906 2
                } else {
                        PDEBUG(5, "Frame done, but not scanning");
I3907 6
                /* Image corruption caused by misplaced frame->segment = 0
                 * fixed by [EMAIL PROTECTED]
                 */
        } else {
                /* Frame start */
                PDEBUG(4, "Frame start, framenum = %d", ov->curframe);
D3909 5
I3913 5
                /* Check to see if it's a snapshot frame */
                /* FIXME?? Should the snapshot reset go here? Performance? */
                if (in[8] & 0x02) {
                        frame->snapshot = 1;
                        PDEBUG(3, "snapshot detected");
D3916 10
I3925 4
                frame->scanstate = STATE_LINES;
                frame->bytes_recvd = 0;
                frame->compressed = in[8] & 0x40;
        }
D3927 11
I3937 6
check_middle:
        /* Are we in a frame? */
        if (frame->scanstate != STATE_LINES) {
                PDEBUG(5, "Not in a frame; packet skipped");
                return;
        }
D3939 1
I3939 5
        /* If frame start, skip header */
        if (frame->bytes_recvd == 0)
                offset = 9;
        else
                offset = 0;
D3941 29
I3969 1
        num = n - offset - 1;
D3971 7
I3977 31
        /* Dump all data exactly as received */
        if (dumppix == 2) {
                frame->bytes_recvd += n - 1;
                if (frame->bytes_recvd <= max_raw)
                        memmove(frame->rawdata + frame->bytes_recvd - (n - 1),
                                in, n - 1);
                else
                        PDEBUG(3, "Raw data buffer overrun!! (%d)",
                                frame->bytes_recvd - max_raw);
        } else if (!frame->compressed && !remove_zeros) {
                frame->bytes_recvd += num;
                if (frame->bytes_recvd <= max_raw)
                        memmove(frame->rawdata + frame->bytes_recvd - num,
                                in + offset, num);
                else
                        PDEBUG(3, "Raw data buffer overrun!! (%d)",
                                frame->bytes_recvd - max_raw);
        } else { /* Remove all-zero FIFO lines (aligned 32-byte blocks) */
                int b, read = 0, allzero, copied = 0;
                if (offset) {
                        frame->bytes_recvd += 32 - offset;      // Bytes out
                        memmove(frame->rawdata, in + offset, 32 - offset);
                        read += 32;
                }
\
                while (read < n - 1) {
                        allzero = 1;
                        for (b = 0; b < 32; b++) {
                                if (in[read + b]) {
                                        allzero = 0;
                                        break;
I3978 1
                        }
D3980 2
I3981 9
                        if (allzero) {
                                /* Don't copy it */
                        } else {
                                if (frame->bytes_recvd + copied + 32 <= max_raw)
                                {
                                        memmove(frame->rawdata
                                                + frame->bytes_recvd + copied,
                                                in + read, 32);
                                        copied += 32;
D3983 8
I3990 1
                                        PDEBUG(3, "Raw data buffer overrun!!");
D3992 1
D3994 2
I3995 1
                        read += 32;
I3997 1
                frame->bytes_recvd += copied;
D3999 6
D4007 2
I4008 2
static inline void 
ov518_move_data(struct usb_ov511 *ov, unsigned char *in, int n)
D4010 3
I4012 2
        int max_raw = MAX_RAW_DATA_SIZE(ov->maxwidth, ov->maxheight);
        struct ov511_frame *frame = &ov->frame[ov->curframe];
D4015 28
I4042 5
        if (printph) {
                info("ph: %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x",
                     in[0], in[1], in[2], in[3], in[4], in[5], in[6], in[7],
                     in[8], in[9], in[10], in[11]);
        }
D4044 4
I4047 10
        /* A false positive here is likely, until OVT gives me
         * the definitive SOF/EOF format */
        if ((!(in[0] | in[1] | in[2] | in[3] | in[5])) && in[6]) {
                if (frame->scanstate == STATE_LINES) {
                        PDEBUG(4, "Detected frame end/start");
                        goto eof;
                } else { //scanstate == STATE_SCANNING
                        /* Frame start */
                        PDEBUG(4, "Frame start, framenum = %d", ov->curframe);
                        goto sof;
I4048 3
        } else {
                goto check_middle;
        }
D4050 17
D4068 40
I4107 41
        ts = (struct timeval *)(frame->data
              + MAX_FRAME_SIZE(ov->maxwidth, ov->maxheight));
        do_gettimeofday(ts);
\
        PDEBUG(4, "Frame end, curframe = %d, hw=%d, vw=%d, recvd=%d",
                ov->curframe,
                (int)(in[9]), (int)(in[10]), frame->bytes_recvd);
\
        // FIXME: Since we don't know the header formats yet,
        // there is no way to know what the actual image size is
        frame->rawwidth = frame->width;
        frame->rawheight = frame->height;
\
        /* Validate the header data */
        RESTRICT_TO_RANGE(frame->rawwidth, ov->minwidth, ov->maxwidth);
        RESTRICT_TO_RANGE(frame->rawheight, ov->minheight, ov->maxheight);
\
        /* Don't allow byte count to exceed buffer size */
        RESTRICT_TO_RANGE(frame->bytes_recvd, 8, max_raw);
\
        if (frame->scanstate == STATE_LINES) {
                int nextf;
\
                frame->grabstate = FRAME_DONE;  // FIXME: Is this right?
\
                if (waitqueue_active(&frame->wq)) {
                        frame->grabstate = FRAME_DONE;
                        wake_up_interruptible(&frame->wq);
                }
\
                /* If next frame is ready or grabbing,
                 * point to it */
                nextf = (ov->curframe + 1) % OV511_NUMFRAMES;
                if (ov->frame[nextf].grabstate == FRAME_READY
                    || ov->frame[nextf].grabstate == FRAME_GRABBING) {
                        ov->curframe = nextf;
                        ov->frame[nextf].scanstate = STATE_SCANNING;
                        frame = &ov->frame[nextf];
                } else {
                        if (frame->grabstate == FRAME_DONE) {
                                PDEBUG(4, "** Frame done **");
D4109 10
I4118 2
                                PDEBUG(4, "Frame not ready? state = %d",
                                       ov->frame[nextf].grabstate);
I4119 4
\
                        ov->curframe = -1;
                        PDEBUG(4, "SOF dropped (no active frame)");
                        return;  /* Nowhere to store this frame */
D4121 3
I4123 1
        }
D4125 1
I4125 2
        PDEBUG(4, "Starting capture on frame %d", frame->framenum);
\
D4128 6
I4133 6
        /* Check to see if it's a snapshot frame */
        /* FIXME?? Should the snapshot reset go here? Performance? */
        if (in[8] & 0x02) {
                frame->snapshot = 1;
                PDEBUG(3, "snapshot detected");
        }
D4135 2
I4136 2
        frame->scanstate = STATE_LINES;
        frame->bytes_recvd = 0;
D4140 5
I4144 5
        /* Are we in a frame? */
        if (frame->scanstate != STATE_LINES) {
                PDEBUG(4, "scanstate: no SOF yet");
                return;
        }
D4146 30
I4175 26
        /* Dump all data exactly as received */
        if (dumppix == 2) {
                frame->bytes_recvd += n;
                if (frame->bytes_recvd <= max_raw)
                        memmove(frame->rawdata + frame->bytes_recvd - n, in, n);
                else
                        PDEBUG(3, "Raw data buffer overrun!! (%d)",
                                frame->bytes_recvd - max_raw);
        } else {
                /* All incoming data are divided into 8-byte segments. If the
                 * segment contains all zero bytes, it must be skipped. These
                 * zero-segments allow the OV518 to mainain a constant data rate
                 * regardless of the effectiveness of the compression. Segments
                 * are aligned relative to the beginning of each isochronous
                 * packet. The first segment is a header (the decompressor
                 * skips it later).
                 */
\
                int b, read = 0, allzero, copied = 0;
\
                while (read < n) {
                        allzero = 1;
                        for (b = 0; b < 8; b++) {
                                if (in[read + b]) {
                                        allzero = 0;
                                        break;
I4176 1
                        }
D4178 2
I4179 9
                        if (allzero) {
                        /* Don't copy it */
                        } else {
                                if (frame->bytes_recvd + copied + 8 <= max_raw)
                                {
                                        memmove(frame->rawdata 
                                                + frame->bytes_recvd + copied,
                                                in + read, 8);
                                        copied += 8;
D4181 8
I4188 1
                                        PDEBUG(3, "Raw data buffer overrun!!");
D4190 1
D4192 1
I4192 1
                        read += 8;
I4193 1
                frame->bytes_recvd += copied;
D4195 2
D4202 1
I4202 1
        int i;
D4223 9
I4231 33
        PDEBUG(5, "Moving %d packets", urb->number_of_packets);
        for (i = 0; i < urb->number_of_packets; i++) {
                /* Warning: Don't call *_move_data() if no frame active! */
                if (ov->curframe >= 0) {
                        int n = urb->iso_frame_desc[i].actual_length;
                        int st = urb->iso_frame_desc[i].status;
                        unsigned char *cdata;
\
                        urb->iso_frame_desc[i].actual_length = 0;
                        urb->iso_frame_desc[i].status = 0;
\
                        cdata = urb->transfer_buffer
                                + urb->iso_frame_desc[i].offset;
\
                        if (!n) {
                                PDEBUG(4, "Zero-length packet");
                                continue;
                        }
\
                        if (st)
                                PDEBUG(2, "data error: [%d] len=%d, status=%d",
                                       i, n, st);
\
                        if (ov->bclass == BCL_OV511)
                                ov511_move_data(ov, cdata, n);
                        else if (ov->bclass == BCL_OV518)
                                ov518_move_data(ov, cdata, n);
                        else
                                err("Unknown bridge device (%d)", ov->bridge);
\
                } else if (waitqueue_active(&ov->wq)) {
                        wake_up_interruptible(&ov->wq);
                }
D5456 1
I5456 2
                if (remap_page_range(vma, start, page, PAGE_SIZE,
                                     PAGE_SHARED)) {
D5500 1
I5500 1
        ov = pde->data;
D6168 1
I6168 1
saa7111a_configure(struct usb_ov511 *ov)
D6213 9
I6221 9
        ov->maxwidth = 640;
        ov->maxheight = 480;            /* Even/Odd fields */
        ov->minwidth = 320;
        ov->minheight = 240;            /* Even field only */
\
        ov->has_decoder = 1;
        ov->num_inputs = 8;
        ov->norm = VIDEO_MODE_AUTO;
        ov->stop_during_set = 0;        /* Decoder guarantees stable image */
D6225 4
I6228 4
        ov->brightness = 0x80 << 8;
        ov->contrast = 0x40 << 9;
        ov->colour = 0x40 << 9;
        ov->hue = 32768;
D6231 1
I6231 1
        if (write_regvals(ov, aRegvalsNormSAA7111A))
D6236 1
I6236 1
        rc = i2c_r(ov, 0x00);
D6243 1
I6243 1
                ov->sensor = SEN_SAA7111A;
D6249 2
I6250 2
        if (ov->bclass == BCL_OV511)
                reg_w(ov, 0x11, 0x00);
D6548 1

# Patch checksum=00ba4d00

Reply via email to