patch-2.3.13 linux/drivers/usb/cpia.c

Next file: linux/drivers/usb/hub.c
Previous file: linux/drivers/usb/audio.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.3.12/linux/drivers/usb/cpia.c linux/drivers/usb/cpia.c
@@ -25,6 +25,8 @@
 #include "usb.h"
 #include "cpia.h"
 
+#define CPIA_DEBUG	/* Gobs of debugging info */
+
 #define MAX_FRAME_SIZE (384 * 288 * 3)
 
 /*******************************/
@@ -319,11 +321,13 @@
 	return dev->bus->op->control_msg(dev, usb_sndctrlpipe(dev,0), &dr, NULL, 0);
 }
 
+/* How much data is left in the scratch buf? */
 #define scratch_left(x)	(cpia->scratchlen - (int)((char *)x - (char *)cpia->scratch))
 
 static void cpia_parse_data(struct usb_cpia *cpia)
 {
 	unsigned char *data = cpia->scratch;
+	unsigned long l;
 	int done;
 
 	done = 0;
@@ -339,6 +343,7 @@
 				break;
 			}
 
+			/* 0x1968 is magic */
 			printk("header: %X\n", (*data << 8) + *(data + 1));
 			if ((*data == 0x19) && (*(data + 1) == 0x68)) {
 				cpia->state = STATE_HEADER;
@@ -346,6 +351,7 @@
 				break;
 			}
 
+			/* Woops, lost the header, find the end of the frame */
 			if (scratch_left(data) < 4) {
 				done = 1;
 				break;
@@ -362,7 +368,9 @@
 				}
 				data++;
 			}
-printk("scan: scanned %d bytes\n", data-begin);
+#ifdef CPIA_DEBUG
+			printk("scan: scanned %d bytes\n", data-begin);
+#endif
 			break;
 		}
 		case STATE_HEADER:
@@ -372,7 +380,9 @@
 				break;
 			}
 
-printk("header: framerate %d\n", data[41]);
+#ifdef CPIA_DEBUG
+			printk("header: framerate %d\n", data[41]);
+#endif
 
 			data += 64;
 
@@ -390,11 +400,11 @@
 					found = 1;
 					break;
 				} else if ((*data == 0xFF) &&
-					(scratch_left(data) >= 3) &&
-					(*(data + 1) == 0xFF) &&
-					(*(data + 2) == 0xFF) &&
-					(*(data + 3) == 0xFF)) {
-					data+=4;
+						(scratch_left(data) >= 3) &&
+						(*(data + 1) == 0xFF) &&
+						(*(data + 2) == 0xFF) &&
+						(*(data + 3) == 0xFF)) {
+					data += 4;
 					cpia->curline = 144;
 					found = 1;
 					break;
@@ -402,25 +412,21 @@
 
 				data++;
 			}
-#if 0
-printk("line %d: scanned %d bytes\n", cpia->curline, data-begin);
-#endif
-if (data-begin == 355 && cpia->frame[cpia->curframe].width != 64) {
-	int i;
-	char *f = cpia->frame[cpia->curframe].data, *b = begin;
 
-#if 0
-printk("copying\n");
-#endif
+			if (data-begin == 355 && cpia->frame[cpia->curframe].width != 64) {
+				int i;
+				char *f = cpia->frame[cpia->curframe].data, *b = begin;
+
+				b += 2;
+				f += (cpia->frame[cpia->curframe].width * 3) * cpia->curline;
+
+				for (i = 0; i < 176; i++)
+					f[(i * 3) + 0] =
+					f[(i * 3) + 1] =
+					f[(i * 3) + 2] =
+						b[(i * 2)];
+			}
 
-	b+=2;
-	f+=(cpia->frame[cpia->curframe].width*3)*cpia->curline;
-	for (i = 0; i < 176; i++)
-		f[(i * 3) + 0] =
-		f[(i * 3) + 1] =
-		f[(i * 3) + 2] =
-			b[(i * 2)];
-}
 			if (found) {
 				cpia->curline++;
 				if (cpia->curline >= 144) {
@@ -440,13 +446,11 @@
 		}
 	}
 
-	{
-	int l;
-
+	/* Grab the remaining */
 	l = scratch_left(data);
 	memmove(cpia->scratch, data, l);
+
 	cpia->scratchlen = l;
-	}
 }
 
 static int cpia_isoc_irq(int status, void *__buffer, int len, void *dev_id)
@@ -466,13 +470,21 @@
 		if (cpia->frame[0].state == FRAME_READY) {
 			cpia->curframe = 0;
 			cpia->frame[0].state = FRAME_GRABBING;
-printk("capturing to frame 0\n");
+#ifdef CPIA_DEBUG
+			printk("capturing to frame 0\n");
+#endif
 		} else if (cpia->frame[1].state == FRAME_READY) {
 			cpia->curframe = 1;
 			cpia->frame[1].state = FRAME_GRABBING;
-printk("capturing to frame 1\n");
+#ifdef CPIA_DEBUG
+			printk("capturing to frame 1\n");
+#endif
+#ifdef CPIA_DEBUG
 		} else
-printk("no frame available\n");
+			printk("no frame available\n");
+#else
+		}
+#endif
 	}
 
 	sbuf = &cpia->sbuf[cpia->receivesbuf];
@@ -482,8 +494,10 @@
 	/* Do something to it now */
 	sbuf->len = usb_compress_isochronous(dev, sbuf->isodesc);
 
+#ifdef CPIA_DEBUG
 	if (sbuf->len)
-	printk("%d bytes received\n", sbuf->len);
+		printk("%d bytes received\n", sbuf->len);
+#endif
 
 	if (sbuf->len && cpia->curframe >= 0) {
 		if (sbuf->len > (SCRATCH_BUF_SIZE - cpia->scratchlen)) {
@@ -511,10 +525,6 @@
 
 	cpia->receivesbuf = 0;
 
-#if 0
-	cpia->parsesbuf = 0;
-	cpia->parsepos = 0;
-#endif
 	cpia->scratchlen = 0;
 	cpia->curline = 0;
 	cpia->state = STATE_SCANNING;
@@ -524,15 +534,20 @@
 	cpia->sbuf[1].isodesc = usb_allocate_isochronous(dev, usb_rcvisocpipe(dev,1), cpia->sbuf[1].data, STREAM_BUF_SIZE, 960, cpia_isoc_irq, cpia);
 	cpia->sbuf[2].isodesc = usb_allocate_isochronous(dev, usb_rcvisocpipe(dev,1), cpia->sbuf[2].data, STREAM_BUF_SIZE, 960, cpia_isoc_irq, cpia);
 
+#ifdef CPIA_DEBUG
 	printk("isodesc[0] @ %p\n", cpia->sbuf[0].isodesc);
 	printk("isodesc[1] @ %p\n", cpia->sbuf[1].isodesc);
 	printk("isodesc[2] @ %p\n", cpia->sbuf[2].isodesc);
+#endif
 
 	/* Schedule the queues */
 	usb_schedule_isochronous(dev, cpia->sbuf[0].isodesc, NULL);
 	usb_schedule_isochronous(dev, cpia->sbuf[1].isodesc, cpia->sbuf[0].isodesc);
 	usb_schedule_isochronous(dev, cpia->sbuf[2].isodesc, cpia->sbuf[1].isodesc);
 
+#ifdef CPIA_DEBUG
+	printk("done scheduling\n");
+#endif
 	if (usb_set_interface(cpia->dev, 1, 3)) {
 		printk("cpia_set_interface error\n");
 		return -EINVAL;
@@ -541,6 +556,9 @@
 	usb_cpia_startstreamcap(cpia->dev);
 
 	cpia->streaming = 1;
+#ifdef CPIA_DEBUG
+	printk("now streaming\n");
+#endif
 
 	return 0;
 }
@@ -579,7 +597,9 @@
 {
 	struct usb_cpia *cpia = (struct usb_cpia *)dev;
 
-printk("cpia_open\n");
+#ifdef CPIA_DEBUG
+	printk("cpia_open\n");
+#endif
 
 	cpia->fbuf = rvmalloc(2 * MAX_FRAME_SIZE);
 	if (!cpia->fbuf)
@@ -590,8 +610,10 @@
 
 	cpia->frame[0].data = cpia->fbuf;
 	cpia->frame[1].data = cpia->fbuf + MAX_FRAME_SIZE;
+#ifdef CPIA_DEBUG
 	printk("frame [0] @ %p\n", cpia->frame[0].data);
 	printk("frame [1] @ %p\n", cpia->frame[1].data);
+#endif
 
 	cpia->sbuf[0].data = kmalloc(STREAM_BUF_SIZE, GFP_KERNEL);
 	if (!cpia->sbuf[0].data)
@@ -605,9 +627,11 @@
 	if (!cpia->sbuf[2].data)
 		goto open_err_on2;
 
+#ifdef CPIA_DEBUG
 	printk("sbuf[0] @ %p\n", cpia->sbuf[0].data);
 	printk("sbuf[1] @ %p\n", cpia->sbuf[1].data);
 	printk("sbuf[2] @ %p\n", cpia->sbuf[2].data);
+#endif
 
 	cpia->curframe = -1;
 	cpia->receivesbuf = 0;
@@ -632,7 +656,9 @@
 {
 	struct usb_cpia *cpia = (struct usb_cpia *)dev;
 
-printk("cpia_close\n");
+#ifdef CPIA_DEBUG
+	printk("cpia_close\n");
+#endif
 
 	cpia_stop_isoc(cpia);
 
@@ -655,90 +681,6 @@
 	return -EINVAL;
 }
 
-#if 0
-	if (usb_set_interface(dev, 1, 3)) {
-		printk("cpia_set_interface error\n");
-		return -EINVAL;
-	}
-
-	if (usb_cpia_grab_frame(dev, 0)) {
-		printk("cpia_grab_frame error\n");
-		return -EINVAL;
-	}
-
-	if (usb_cpia_upload_frame(dev, 0)) {
-		printk("cpia_upload_frame error\n");
-		return -EINVAL;
-	}
-
-	buf = cpia->ibuf;
-	uhci_receive_isochronous(dev, usb_rcvisocpipe(dev,1), buf, 176*144*4);
-
-	{
-	printk("header magic: %X\n", (buf[0] << 8) + buf[1]);
-
-	while ((buf[0] != 0x19) || (buf[1] != 0x68)) {
-		int i;
-
-		printk("resync'ing\n");
-		for (i=0;i<(176*144*4)-4;i++, buf++)
-			if (
-				(buf[0] == 0xFF) &&
-				(buf[1] == 0xFF) &&
-				(buf[2] == 0xFF) &&
-				(buf[3] == 0xFF)) {
-				buf+=4;
-				i+=4;
-				break;
-			}
-
-		memmove(cpia->ibuf, buf, (176*144*4) - i);
-		uhci_receive_isochronous(dev, usb_rcvisocpipe(dev,1), cpia->ibuf + (176*144*4) - i, i);
-		buf = cpia->ibuf;
-
-#if 0
-		printk("header magic: %X\n", (buf[0] << 8) + buf[1]);
-#endif
-	}
-
-	printk("size: %d, sample: %d, order: %d\n", buf[16], buf[17], buf[18]);
-	printk("comp: %d, decimation: %d\n", buf[28], buf[29]);
-	printk("roi: top left: %d, %d bottom right: %d, %d\n",
-		buf[26] * 4, buf[24] * 8,
-		buf[27] * 4, buf[25] * 8);
-
-	printk("vm->frame: %d\n", vm->frame);
-
-	{
-	int i, i1;
-	char *b = buf + 64, *fbuf = &cpia->fbuffer[MAX_FRAME_SIZE * (vm->frame & 1)];
-	for (i=0;i<144;i++) {
-#if 0
-		printk("line len: %d\n", (b[1] << 8) + b[0]);
-#endif
-		b += 2;
-		for (i1=0;i1<176;i1++) {
-			fbuf[(i * vm->width * 3) + (i1 * 3)] = 
-			fbuf[(i * vm->width * 3) + (i1 * 3) + 1] = 
-			fbuf[(i * vm->width * 3) + (i1 * 3) + 2] = 
-				b[i1 * 2];
-#if 0
-			*((short *)&fbuf[(i * vm->width * 2) + (i1 * 2)]) =
-				((b[i1 * 2] >> 3) << 11) + ((b[i1 * 2] >> 2) << 6) + (b[i1 * 2] >> 3);
-#endif
-		}
-		b += (176 * 2) + 1;
-	}
-	}
-
-	}
-
-	if (usb_set_interface(dev, 1, 0)) {
-		printk("cpia_set_interface error\n");
-		return -EINVAL;
-	}
-#endif
-
 static int cpia_ioctl(struct video_device *dev, unsigned int cmd, void *arg)
 {
 	struct usb_cpia *cpia = (struct usb_cpia *)dev;
@@ -752,10 +694,10 @@
 			b.type = VID_TYPE_CAPTURE /* | VID_TYPE_SUBCAPTURE */;
 			b.channels = 1;
 			b.audios = 0;
-			b.maxwidth = 176 /* 352 */;
-			b.maxheight = 144 /* 240 */;
-			b.minwidth = 176 /* (Something small?) */;
-			b.minheight = 144 /* "         " */;
+			b.maxwidth = 176	/* 352 */;
+			b.maxheight = 144	/* 240 */;
+			b.minwidth = 176	/* (Something small?) */;
+			b.minheight = 144	/* "         " */;
 
 			if (copy_to_user(arg, &b, sizeof(b)))
 				return -EFAULT;
@@ -855,13 +797,9 @@
 			if (copy_from_user(&p, arg, sizeof(p)))
 				return -EFAULT;
 
-printk("Attempting to set palette %d, depth %d\n", p.palette, p.depth);
-
-#if 0
-			if (p.palette != VIDEO_PALETTE_YUYV)
-				return -EINVAL;
-			if (p.depth != 16)
-				return -EINVAL;
+#ifdef CPIA_DEBUG
+			printk("Attempting to set palette %d, depth %d\n",
+				p.palette, p.depth);
 #endif
 
 			return 0;
@@ -870,7 +808,10 @@
 		{
 			struct video_window vw;
 
-printk("VIDIOCSWIN\n");
+#ifdef CPIA_DEBUG
+			printk("VIDIOCSWIN\n");
+#endif
+
 			if (copy_from_user(&vw, arg, sizeof(vw)))
 				return -EFAULT;
 			if (vw.flags)
@@ -888,7 +829,10 @@
 		{
 			struct video_window vw;
 
-printk("VIDIOCGWIN\n");
+#ifdef CPIA_DEBUG
+			printk("VIDIOCGWIN\n");
+#endif
+
 			vw.x = 0;
 			vw.y = 0;
 			vw.width = 176;
@@ -923,8 +867,11 @@
 			if (copy_from_user((void *)&vm, (void *)arg, sizeof(vm)))
 				return -EFAULT;
 
-printk("MCAPTURE\n");
-printk("frame: %d, size: %dx%d, format: %d\n", vm.frame, vm.width, vm.height, vm.format);
+#ifdef CPIA_DEBUG
+			printk("MCAPTURE\n");
+			printk("frame: %d, size: %dx%d, format: %d\n",
+				vm.frame, vm.width, vm.height, vm.format);
+#endif
 
 			if (vm.format != VIDEO_PALETTE_RGB24)
 				return -EINVAL;
@@ -947,7 +894,9 @@
 			if (copy_from_user((void *)&frame, arg, sizeof(int)))
 				return -EFAULT;
 
+#ifdef CPIA_DEBUG
 			printk("syncing to frame %d\n", frame);
+#endif
 			switch (cpia->frame[frame].state) {
 				case FRAME_UNUSED:
 					return -EINVAL;
@@ -958,7 +907,9 @@
 					cpia->frame[frame].state = FRAME_UNUSED;
 					break;
 			}
+#ifdef CPIA_DEBUG
 			printk("synced to frame %d\n", frame);
+#endif
 			return 0;
 		}
 		case VIDIOCCAPTURE:
@@ -988,7 +939,9 @@
 	struct usb_cpia *cpia = (struct usb_cpia *)dev;
 	int len;
 
+#ifdef CPIA_DEBUG
 	printk("cpia_read: %ld bytes\n", count);
+#endif
 #if 0
 	len = cpia_capture(cpia, buf, count);
 
@@ -1003,17 +956,12 @@
 	unsigned long start = (unsigned long)adr;
 	unsigned long page, pos;
 
+#ifdef CPIA_DEBUG
 	printk("mmap: %ld (%lX) bytes\n", size, size);
+#endif
 	if (size > (((2 * MAX_FRAME_SIZE) + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1)))
 		return -EINVAL;
 
-#if 0
-	if (!cpia->fbuffer) {
-		if ((cpia->fbuffer = rvmalloc(2 * MAX_FRAME_SIZE)) == NULL)
-			return -EINVAL;
-	}
-#endif
-
 	pos = (unsigned long)cpia->fbuf;
 	while (size > 0)
 	{
@@ -1123,39 +1071,6 @@
 		printk("cpia_set_compression error\n");
 		return;
 	}
-
-#if 0
-	if (usb_cpia_grab_frame(dev, 0)) {
-		printk("cpia_grab_frame error\n");
-		return;
-	}
-
-	if (usb_cpia_upload_frame(dev, 1)) {
-		printk("cpia_upload_frame error\n");
-		return;
-	}
-
-	buf = (void *)__get_free_page(GFP_KERNEL);
-
-	{
-	int i;
-	for (i=0;i<448;i++)
-		buf[i]=0;
-	}
-	uhci_receive_isochronous(dev, usb_rcvisocpipe(dev,1), buf, 448);
-
-	{
-	int i;
-	for (i=0;i<448;i++) {
-		printk("%02X ", buf[i]);
-		if ((i % 16) == 15)
-			printk("\n");
-	}
-	printk("\n");
-	}
-
-	free_page((unsigned long)buf);
-#endif
 }
 
 static int cpia_probe(struct usb_device *dev)
@@ -1168,29 +1083,9 @@
 	if (dev->descriptor.bNumConfigurations != 1)
 		return -1;
 
-#if 0
-	/* We don't handle multi-interface hubs */
-	if (dev->config[0].bNumInterfaces != 1)
-		return -1;
-#endif
-
 	interface = &dev->config[0].altsetting[0].interface[0];
 
 	/* Is it a CPiA? */
-/*
-Apr 24 17:49:04 bjorn kernel:   Vendor:  0545 
-Apr 24 17:49:04 bjorn kernel:   Product: 8080 
-*/
-/*
-	if (dev->descriptor.idVendor != 0x0545)
-		return -1;
-	if (dev->descriptor.idProduct != 0x8080)
-		return -1;
-	if (interface->bInterfaceClass != 0xFF)
-		return -1;
-	if (interface->bInterfaceSubClass != 0xFF)
-		return -1;
-*/
 	if (dev->descriptor.idVendor != 0x0553)
 		return -1;
 	if (dev->descriptor.idProduct != 0x0002)
@@ -1200,22 +1095,6 @@
 	if (interface->bInterfaceSubClass != 0x00)
 		return -1;
 
-#if 0
-	/* Multiple endpoints? What kind of mutant ninja-hub is this? */
-	if (interface->bNumEndpoints != 1)
-		return -1;
-
-	endpoint = &interface->endpoint[0];
-
-	/* Output endpoint? Curiousier and curiousier.. */
-	if (!(endpoint->bEndpointAddress & 0x80))
-		return -1;
-
-	/* If it's not an interrupt endpoint, we'd better punt! */
-	if ((endpoint->bmAttributes & 3) != 3)
-		return -1;
-#endif
-
 	/* We found a CPiA */
 	printk("USB CPiA camera found\n");
 
@@ -1231,10 +1110,6 @@
 
 	usb_cpia_configure(cpia);
 
-#if 0
-	usb_request_irq(dev, usb_rcvctrlpipe(dev, endpoint->bEndpointAddress), pport_irq, endpoint->bInterval, pport);
-#endif
-
 	return 0;
 }
 
@@ -1270,6 +1145,7 @@
 {
 	return usb_cpia_init();
 }
+
 void cleanup_module(void)
 {
 }

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)