Lines Matching refs:usbvision
2 * usbvision-core.c - driver for NT100x USB video capture devices
8 * This module is part of usbvision driver project.
46 #include "usbvision.h"
110 static int usbvision_request_intra (struct usb_usbvision *usbvision);
111 static int usbvision_unrequest_intra (struct usb_usbvision *usbvision);
112 static int usbvision_adjust_compression (struct usb_usbvision *usbvision);
113 static int usbvision_measure_bandwidth (struct usb_usbvision *usbvision);
186 static int scratch_len(struct usb_usbvision *usbvision) /*This returns the amount of data actually in the buffer */
188 int len = usbvision->scratch_write_ptr - usbvision->scratch_read_ptr;
199 static int scratch_free(struct usb_usbvision *usbvision)
201 int free = usbvision->scratch_read_ptr - usbvision->scratch_write_ptr;
216 static int scratch_put(struct usb_usbvision *usbvision, unsigned char *data,
221 if (usbvision->scratch_write_ptr + len < scratch_buf_size) {
222 memcpy(usbvision->scratch + usbvision->scratch_write_ptr, data, len);
223 usbvision->scratch_write_ptr += len;
226 len_part = scratch_buf_size - usbvision->scratch_write_ptr;
227 memcpy(usbvision->scratch + usbvision->scratch_write_ptr, data, len_part);
229 usbvision->scratch_write_ptr = 0; /* just set write_ptr to zero */
232 memcpy(usbvision->scratch, data + len_part, len - len_part);
233 usbvision->scratch_write_ptr = len - len_part;
237 PDEBUG(DBG_SCRATCH, "len=%d, new write_ptr=%d\n", len, usbvision->scratch_write_ptr);
243 static void scratch_mark_header(struct usb_usbvision *usbvision)
245 PDEBUG(DBG_SCRATCH, "header at write_ptr=%d\n", usbvision->scratch_headermarker_write_ptr);
247 usbvision->scratch_headermarker[usbvision->scratch_headermarker_write_ptr] =
248 usbvision->scratch_write_ptr;
249 usbvision->scratch_headermarker_write_ptr += 1;
250 usbvision->scratch_headermarker_write_ptr %= USBVISION_NUM_HEADERMARKER;
254 static int scratch_get_extra(struct usb_usbvision *usbvision,
259 memcpy(data, usbvision->scratch + *ptr, len);
264 memcpy(data, usbvision->scratch + *ptr, len_part);
269 memcpy(data + len_part, usbvision->scratch, len - len_part);
281 static void scratch_set_extra_ptr(struct usb_usbvision *usbvision, int *ptr,
284 *ptr = (usbvision->scratch_read_ptr + len)%scratch_buf_size;
300 static int scratch_get(struct usb_usbvision *usbvision, unsigned char *data,
304 if (usbvision->scratch_read_ptr + len < scratch_buf_size) {
305 memcpy(data, usbvision->scratch + usbvision->scratch_read_ptr, len);
306 usbvision->scratch_read_ptr += len;
309 len_part = scratch_buf_size - usbvision->scratch_read_ptr;
310 memcpy(data, usbvision->scratch + usbvision->scratch_read_ptr, len_part);
312 usbvision->scratch_read_ptr = 0; /* just set the read_ptr to zero */
315 memcpy(data + len_part, usbvision->scratch, len - len_part);
316 usbvision->scratch_read_ptr = len - len_part;
320 PDEBUG(DBG_SCRATCH, "len=%d, new read_ptr=%d\n", len, usbvision->scratch_read_ptr);
327 static int scratch_get_header(struct usb_usbvision *usbvision,
332 PDEBUG(DBG_SCRATCH, "from read_ptr=%d", usbvision->scratch_headermarker_read_ptr);
334 while (usbvision->scratch_headermarker_write_ptr -
335 usbvision->scratch_headermarker_read_ptr != 0) {
336 usbvision->scratch_read_ptr =
337 usbvision->scratch_headermarker[usbvision->scratch_headermarker_read_ptr];
338 usbvision->scratch_headermarker_read_ptr += 1;
339 usbvision->scratch_headermarker_read_ptr %= USBVISION_NUM_HEADERMARKER;
340 scratch_get(usbvision, (unsigned char *)header, USBVISION_HEADER_LENGTH);
356 static void scratch_rm_old(struct usb_usbvision *usbvision, int len)
359 usbvision->scratch_read_ptr += len;
360 usbvision->scratch_read_ptr %= scratch_buf_size;
361 PDEBUG(DBG_SCRATCH, "read_ptr is now %d\n", usbvision->scratch_read_ptr);
366 static void scratch_reset(struct usb_usbvision *usbvision)
370 usbvision->scratch_read_ptr = 0;
371 usbvision->scratch_write_ptr = 0;
372 usbvision->scratch_headermarker_read_ptr = 0;
373 usbvision->scratch_headermarker_write_ptr = 0;
374 usbvision->isocstate = IsocState_NoFrame;
377 int usbvision_scratch_alloc(struct usb_usbvision *usbvision)
379 usbvision->scratch = vmalloc_32(scratch_buf_size);
380 scratch_reset(usbvision);
381 if(usbvision->scratch == NULL) {
382 dev_err(&usbvision->dev->dev,
390 void usbvision_scratch_free(struct usb_usbvision *usbvision)
392 vfree(usbvision->scratch);
393 usbvision->scratch = NULL;
409 static void usbvision_testpattern(struct usb_usbvision *usbvision,
419 if (usbvision == NULL) {
420 printk(KERN_ERR "%s: usbvision == NULL\n", proc);
423 if (usbvision->curFrame == NULL) {
424 printk(KERN_ERR "%s: usbvision->curFrame is NULL.\n", proc);
429 frame = usbvision->curFrame;
441 f = frame->data + (usbvision->curwidth * 3 * frame->curline);
442 for (i = 0; i < usbvision->curwidth; i++) {
487 int usbvision_decompress_alloc(struct usb_usbvision *usbvision)
490 usbvision->IntraFrameBuffer = vmalloc_32(IFB_size);
491 if (usbvision->IntraFrameBuffer == NULL) {
492 dev_err(&usbvision->dev->dev,
505 void usbvision_decompress_free(struct usb_usbvision *usbvision)
507 vfree(usbvision->IntraFrameBuffer);
508 usbvision->IntraFrameBuffer = NULL;
520 static enum ParseState usbvision_find_header(struct usb_usbvision *usbvision)
525 frame = usbvision->curFrame;
527 while (scratch_get_header(usbvision, &frame->isocHeader) == USBVISION_HEADER_LENGTH) {
541 if (usbvision->requestIntra) {
544 usbvision->lastIsocFrameNum = -1; // do not check for lost frames this time
545 usbvision_unrequest_intra(usbvision);
556 frame->frmwidth = frame->isocHeader.frameWidth * usbvision->stretch_width;
557 frame->frmheight = frame->isocHeader.frameHeight * usbvision->stretch_height;
562 scratch_reset(usbvision);
569 if (usbvision->lastIsocFrameNum >= 0) {
570 if (((usbvision->lastIsocFrameNum + 1) % 32) != frame->isocHeader.frameNum) {
573 usbvision_request_intra(usbvision);
577 usbvision->lastIsocFrameNum = frame->isocHeader.frameNum;
579 usbvision->header_count++;
584 usbvision_testpattern(usbvision, 1, 1);
590 static enum ParseState usbvision_parse_lines_422(struct usb_usbvision *usbvision,
602 frame = usbvision->curFrame;
607 if (scratch_len(usbvision) < len) {
617 stretch_bytes = (usbvision->stretch_width - 1) * bytes_per_pixel;
619 clipmask_add = usbvision->stretch_width;
621 for (i = 0; i < frame->frmwidth; i+=(2 * usbvision->stretch_width)) {
623 scratch_get(usbvision, &yuyv[0], 4);
698 frame->curline += usbvision->stretch_height;
699 *pcopylen += frame->v4l2_linesize * usbvision->stretch_height;
710 static int usbvision_decompress(struct usb_usbvision *usbvision,unsigned char *Compressed,
741 usbvision->ComprBlockTypes[BlockType]++;
806 static enum ParseState usbvision_parse_compress(struct usb_usbvision *usbvision,
823 frame = usbvision->curFrame;
847 usbvision_adjust_compression(usbvision);
850 if (scratch_len(usbvision) < USBVISION_STRIP_HEADER_LEN) {
855 scratch_set_extra_ptr(usbvision, &StripPtr, 0);
856 scratch_get_extra(usbvision, &StripHeader[0], &StripPtr,
861 usbvision->stripMagicErrors++;
867 usbvision->stripLineNumberErrors++;
874 usbvision_request_intra(usbvision);
877 if (scratch_len(usbvision) < StripLen) {
882 if (usbvision->IntraFrameBuffer) {
883 Y = usbvision->IntraFrameBuffer + frame->frmwidth * frame->curline;
884 U = usbvision->IntraFrameBuffer + imageSize + (frame->frmwidth / 2) * (frame->curline / 2);
885 V = usbvision->IntraFrameBuffer + imageSize / 4 * 5 + (frame->frmwidth / 2) * (frame->curline / 2);
894 scratch_get(usbvision, StripData, StripLen);
901 usbvision->BlockPos = BlockPos;
903 if ((rc = usbvision_decompress(usbvision, StripData, Y, &BlockPos, &BlockTypePos, IdxEnd)) != IdxEnd) {
906 if (StripLen > usbvision->maxStripLen) {
907 usbvision->maxStripLen = StripLen;
911 if ((rc = usbvision_decompress(usbvision, StripData, V, &BlockPos, &BlockTypePos, IdxEnd/2)) != IdxEnd/2) {
916 if ((rc = usbvision_decompress(usbvision, StripData, U, &BlockPos, &BlockTypePos, IdxEnd/2)) != IdxEnd/2) {
921 if (BlockPos > usbvision->comprBlockPos) {
922 usbvision->comprBlockPos = BlockPos;
925 usbvision->stripLenErrors++;
1011 static enum ParseState usbvision_parse_lines_420(struct usb_usbvision *usbvision,
1031 frame = usbvision->curFrame;
1033 f_odd = f_even + frame->v4l2_linesize * usbvision->stretch_height;
1036 /* In this mode usbvision transfer 3 bytes for every 2 pixels */
1039 stretch_bytes = (usbvision->stretch_width - 1) * bytes_per_pixel;
1042 clipmask_add = usbvision->stretch_width;
1045 if (scratch_len(usbvision) < (int)pixel_per_line * 3) {
1059 scratch_set_extra_ptr(usbvision, &y_ptr, y_odd_offset);
1060 scratch_set_extra_ptr(usbvision, &u_ptr, y_block_size);
1061 scratch_set_extra_ptr(usbvision, &v_ptr, y_odd_offset
1069 scratch_get(usbvision, &y[0], 2);
1070 scratch_get_extra(usbvision, &u, &u_ptr, 1);
1071 scratch_get_extra(usbvision, &v, &v_ptr, 1);
1168 scratch_get_extra(usbvision, &y[0], &y_ptr, 2);
1259 scratch_rm_old(usbvision,y_step[block % y_step_size] * sub_block_size);
1268 scratch_rm_old(usbvision, pixel_per_line * 3 / 2
1271 frame->curline += 2 * usbvision->stretch_height;
1272 *pcopylen += frame->v4l2_linesize * 2 * usbvision->stretch_height;
1288 static void usbvision_parse_data(struct usb_usbvision *usbvision)
1295 frame = usbvision->curFrame;
1297 PDEBUG(DBG_PARSE, "parsing len=%d\n", scratch_len(usbvision));
1302 if (scratch_len(usbvision)) {
1304 newstate = usbvision_find_header(usbvision);
1307 if (usbvision->isocMode == ISOC_MODE_YUV420) {
1308 newstate = usbvision_parse_lines_420(usbvision, ©len);
1310 else if (usbvision->isocMode == ISOC_MODE_YUV422) {
1311 newstate = usbvision_parse_lines_422(usbvision, ©len);
1313 else if (usbvision->isocMode == ISOC_MODE_COMPRESS) {
1314 newstate = usbvision_parse_compress(usbvision, ©len);
1333 frame->sequence = usbvision->frame_num;
1335 spin_lock_irqsave(&usbvision->queue_lock, lock_flags);
1336 list_move_tail(&(frame->frame), &usbvision->outqueue);
1337 usbvision->curFrame = NULL;
1338 spin_unlock_irqrestore(&usbvision->queue_lock, lock_flags);
1340 usbvision->frame_num++;
1343 if (waitqueue_active(&usbvision->wait_frame)) {
1345 wake_up_interruptible(&usbvision->wait_frame);
1360 static int usbvision_compress_isochronous(struct usb_usbvision *usbvision,
1375 usbvision->isocErrCount++;
1382 usbvision->isocSkipCount++;
1387 usbvision->isocstate=IsocState_NoFrame;
1388 usbvision->isocSkipCount++;
1391 else if (packet_len > usbvision->isocPacketSize) {
1393 usbvision->isocSkipCount++;
1399 if (usbvision->isocstate==IsocState_NoFrame) { //new frame begins
1400 usbvision->isocstate=IsocState_InFrame;
1401 scratch_mark_header(usbvision);
1402 usbvision_measure_bandwidth(usbvision);
1407 * If usbvision continues to feed us with data but there is no
1414 if (scratch_free(usbvision) < packet_len) {
1416 usbvision->scratch_ovf_count++;
1418 scratch_len(usbvision), packet_len);
1419 scratch_rm_old(usbvision, packet_len - scratch_free(usbvision));
1423 scratch_put(usbvision, packet_data, packet_len);
1425 usbvision->isocDataCount += packet_len;
1426 usbvision->isocPacketCount++;
1432 printk(KERN_DEBUG "+%d.\n", usbvision->scratchlen);
1445 struct usb_usbvision *usbvision = urb->context;
1451 if (!USBVISION_IS_OPERATIONAL(usbvision))
1459 f = &usbvision->curFrame;
1462 if (usbvision->streaming == Stream_Interrupt) {
1463 usbvision->streaming = Stream_Idle;
1469 wake_up_interruptible(&usbvision->wait_stream);
1473 len = usbvision_compress_isochronous(usbvision, urb);
1475 usbvision->isocUrbCount++;
1476 usbvision->urb_length = len;
1478 if (usbvision->streaming == Stream_On) {
1481 if ((scratch_len(usbvision) > USBVISION_HEADER_LENGTH) &&
1482 (!list_empty(&(usbvision->inqueue))) ) {
1484 (*f) = list_entry(usbvision->inqueue.next,
1488 usbvision_parse_data(usbvision);
1495 scratch_reset(usbvision);
1500 scratch_reset(usbvision);
1503 usbvision->timeInIrq += jiffies - startTime;
1511 urb->dev = usbvision->dev;
1515 dev_err(&usbvision->dev->dev,
1524 /* Low level usbvision access functions */
1534 int usbvision_read_reg(struct usb_usbvision *usbvision, unsigned char reg)
1539 if (!USBVISION_IS_OPERATIONAL(usbvision))
1542 errCode = usb_control_msg(usbvision->dev, usb_rcvctrlpipe(usbvision->dev, 1),
1548 dev_err(&usbvision->dev->dev,
1559 * 0 -> usbvision is not yet ready
1563 int usbvision_write_reg(struct usb_usbvision *usbvision, unsigned char reg,
1568 if (!USBVISION_IS_OPERATIONAL(usbvision))
1571 errCode = usb_control_msg(usbvision->dev, usb_sndctrlpipe(usbvision->dev, 1),
1577 dev_err(&usbvision->dev->dev,
1586 struct usb_usbvision *usbvision = (struct usb_usbvision *)urb->context;
1589 usbvision->ctrlUrbBusy = 0;
1590 if (waitqueue_active(&usbvision->ctrlUrb_wq)) {
1591 wake_up_interruptible(&usbvision->ctrlUrb_wq);
1596 static int usbvision_write_reg_irq(struct usb_usbvision *usbvision,int address,
1605 if (usbvision->ctrlUrbBusy) {
1608 usbvision->ctrlUrbBusy = 1;
1610 usbvision->ctrlUrbSetup.bRequestType = USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT;
1611 usbvision->ctrlUrbSetup.bRequest = USBVISION_OP_CODE;
1612 usbvision->ctrlUrbSetup.wValue = 0;
1613 usbvision->ctrlUrbSetup.wIndex = cpu_to_le16(address);
1614 usbvision->ctrlUrbSetup.wLength = cpu_to_le16(len);
1615 usb_fill_control_urb (usbvision->ctrlUrb, usbvision->dev,
1616 usb_sndctrlpipe(usbvision->dev, 1),
1617 (unsigned char *)&usbvision->ctrlUrbSetup,
1618 (void *)usbvision->ctrlUrbBuffer, len,
1620 (void *)usbvision);
1622 memcpy(usbvision->ctrlUrbBuffer, data, len);
1624 errCode = usb_submit_urb(usbvision->ctrlUrb, GFP_ATOMIC);
1627 usbvision->ctrlUrbBusy = 0;
1634 static int usbvision_init_compression(struct usb_usbvision *usbvision)
1638 usbvision->lastIsocFrameNum = -1;
1639 usbvision->isocDataCount = 0;
1640 usbvision->isocPacketCount = 0;
1641 usbvision->isocSkipCount = 0;
1642 usbvision->comprLevel = 50;
1643 usbvision->lastComprLevel = -1;
1644 usbvision->isocUrbCount = 0;
1645 usbvision->requestIntra = 1;
1646 usbvision->isocMeasureBandwidthCount = 0;
1655 static int usbvision_measure_bandwidth (struct usb_usbvision *usbvision)
1659 if (usbvision->isocMeasureBandwidthCount < 2) { // this gives an average bandwidth of 3 frames
1660 usbvision->isocMeasureBandwidthCount++;
1663 if ((usbvision->isocPacketSize > 0) && (usbvision->isocPacketCount > 0)) {
1664 usbvision->usedBandwidth = usbvision->isocDataCount /
1665 (usbvision->isocPacketCount + usbvision->isocSkipCount) *
1666 100 / usbvision->isocPacketSize;
1668 usbvision->isocMeasureBandwidthCount = 0;
1669 usbvision->isocDataCount = 0;
1670 usbvision->isocPacketCount = 0;
1671 usbvision->isocSkipCount = 0;
1675 static int usbvision_adjust_compression (struct usb_usbvision *usbvision)
1681 if ((adjustCompression) && (usbvision->usedBandwidth > 0)) {
1682 usbvision->comprLevel += (usbvision->usedBandwidth - 90) / 2;
1683 RESTRICT_TO_RANGE(usbvision->comprLevel, 0, 100);
1684 if (usbvision->comprLevel != usbvision->lastComprLevel) {
1686 if (usbvision->bridgeType == BRIDGE_NT1004 || usbvision->bridgeType == BRIDGE_NT1005) {
1687 buffer[0] = (unsigned char)(4 + 16 * usbvision->comprLevel / 100); // PCM Threshold 1
1688 buffer[1] = (unsigned char)(4 + 8 * usbvision->comprLevel / 100); // PCM Threshold 2
1689 distorsion = 7 + 248 * usbvision->comprLevel / 100;
1692 distorsion = 1 + 42 * usbvision->comprLevel / 100;
1697 buffer[0] = (unsigned char)(4 + 16 * usbvision->comprLevel / 100); // PCM threshold 1
1698 buffer[1] = (unsigned char)(4 + 8 * usbvision->comprLevel / 100); // PCM threshold 2
1699 distorsion = 2 + 253 * usbvision->comprLevel / 100;
1702 distorsion = 0 + 43 * usbvision->comprLevel / 100;
1706 errCode = usbvision_write_reg_irq(usbvision, USBVISION_PCM_THR1, buffer, 6);
1710 usbvision->lastComprLevel = usbvision->comprLevel;
1717 static int usbvision_request_intra (struct usb_usbvision *usbvision)
1723 usbvision->requestIntra = 1;
1725 usbvision_write_reg_irq(usbvision, USBVISION_FORCE_INTRA, buffer, 1);
1729 static int usbvision_unrequest_intra (struct usb_usbvision *usbvision)
1735 usbvision->requestIntra = 0;
1737 usbvision_write_reg_irq(usbvision, USBVISION_FORCE_INTRA, buffer, 1);
1742 * usbvision utility functions
1745 int usbvision_power_off(struct usb_usbvision *usbvision)
1751 errCode = usbvision_write_reg(usbvision, USBVISION_PWR_REG, USBVISION_SSPND_EN);
1753 usbvision->power = 0;
1763 static int usbvision_set_video_format(struct usb_usbvision *usbvision, int format)
1769 if (!USBVISION_IS_OPERATIONAL(usbvision))
1777 printk(KERN_ERR "usbvision: unknown video format %02x, using default YUV420",
1783 rc = usb_control_msg(usbvision->dev, usb_sndctrlpipe(usbvision->dev, 1),
1793 usbvision->isocMode = format;
1802 int usbvision_set_output(struct usb_usbvision *usbvision, int width,
1810 if (!USBVISION_IS_OPERATIONAL(usbvision)) {
1816 usbvision->stretch_width = 2;
1820 usbvision->stretch_width = 1;
1825 usbvision->stretch_height = 2;
1829 usbvision->stretch_height = 1;
1839 usbvision->stretch_width, usbvision->stretch_height);
1842 if ((UsbWidth != usbvision->curwidth) || (UsbHeight != usbvision->curheight)) {
1848 errCode = usb_control_msg(usbvision->dev, usb_sndctrlpipe(usbvision->dev, 1),
1854 dev_err(&usbvision->dev->dev,
1858 usbvision->curwidth = usbvision->stretch_width * UsbWidth;
1859 usbvision->curheight = usbvision->stretch_height * UsbHeight;
1862 if (usbvision->isocMode == ISOC_MODE_YUV422) {
1863 frameRate = (usbvision->isocPacketSize * 1000) / (UsbWidth * UsbHeight * 2);
1865 else if (usbvision->isocMode == ISOC_MODE_YUV420) {
1866 frameRate = (usbvision->isocPacketSize * 1000) / ((UsbWidth * UsbHeight * 12) / 8);
1872 if (usbvision->tvnormId & V4L2_STD_625_50) {
1875 else if (usbvision->tvnormId & V4L2_STD_525_60) {
1893 errCode = usbvision_write_reg(usbvision, USBVISION_FRM_RATE, frameDrop);
1902 int usbvision_frames_alloc(struct usb_usbvision *usbvision, int number_of_frames)
1907 usbvision->max_frame_size = PAGE_ALIGN(usbvision->curwidth *
1908 usbvision->curheight *
1909 usbvision->palette.bytes_per_pixel);
1912 usbvision->num_frames = number_of_frames;
1913 while (usbvision->num_frames > 0) {
1914 usbvision->fbuf_size = usbvision->num_frames * usbvision->max_frame_size;
1915 if((usbvision->fbuf = usbvision_rvmalloc(usbvision->fbuf_size))) {
1918 usbvision->num_frames--;
1921 spin_lock_init(&usbvision->queue_lock);
1922 init_waitqueue_head(&usbvision->wait_frame);
1923 init_waitqueue_head(&usbvision->wait_stream);
1926 for (i = 0; i < usbvision->num_frames; i++) {
1927 usbvision->frame[i].index = i;
1928 usbvision->frame[i].grabstate = FrameState_Unused;
1929 usbvision->frame[i].data = usbvision->fbuf +
1930 i * usbvision->max_frame_size;
1934 usbvision->stretch_width = 1;
1935 usbvision->stretch_height = 1;
1936 usbvision->frame[i].width = usbvision->curwidth;
1937 usbvision->frame[i].height = usbvision->curheight;
1938 usbvision->frame[i].bytes_read = 0;
1940 PDEBUG(DBG_FUNC, "allocated %d frames (%d bytes per frame)",usbvision->num_frames,usbvision->max_frame_size);
1941 return usbvision->num_frames;
1948 void usbvision_frames_free(struct usb_usbvision *usbvision)
1951 PDEBUG(DBG_FUNC, "free %d frames",usbvision->num_frames);
1953 if (usbvision->fbuf != NULL) {
1954 usbvision_rvfree(usbvision->fbuf, usbvision->fbuf_size);
1955 usbvision->fbuf = NULL;
1957 usbvision->num_frames = 0;
1964 void usbvision_empty_framequeues(struct usb_usbvision *usbvision)
1968 INIT_LIST_HEAD(&(usbvision->inqueue));
1969 INIT_LIST_HEAD(&(usbvision->outqueue));
1972 usbvision->frame[i].grabstate = FrameState_Unused;
1973 usbvision->frame[i].bytes_read = 0;
1981 int usbvision_stream_interrupt(struct usb_usbvision *usbvision)
1987 usbvision->streaming = Stream_Interrupt;
1988 ret = wait_event_timeout(usbvision->wait_stream,
1989 (usbvision->streaming == Stream_Idle),
1999 static int usbvision_set_compress_params(struct usb_usbvision *usbvision)
2018 if (!USBVISION_IS_OPERATIONAL(usbvision))
2021 rc = usb_control_msg(usbvision->dev, usb_sndctrlpipe(usbvision->dev, 1),
2033 if (usbvision->bridgeType == BRIDGE_NT1004) {
2050 if (!USBVISION_IS_OPERATIONAL(usbvision))
2053 rc = usb_control_msg(usbvision->dev, usb_sndctrlpipe(usbvision->dev, 1),
2077 int usbvision_set_input(struct usb_usbvision *usbvision)
2084 if (!USBVISION_IS_OPERATIONAL(usbvision))
2088 if (usbvision_device_data[usbvision->DevModel].Vin_Reg1_override) {
2089 value[0] = usbvision_device_data[usbvision->DevModel].Vin_Reg1;
2090 } else if(usbvision_device_data[usbvision->DevModel].Codec == CODEC_SAA7113) {
2100 rc = usbvision_write_reg(usbvision, USBVISION_VIN_REG1, value[0]);
2108 if (usbvision->tvnormId & V4L2_STD_PAL) {
2117 } else if (usbvision->tvnormId & V4L2_STD_SECAM) {
2137 if (usbvision_device_data[usbvision->DevModel].X_Offset >= 0) {
2138 value[4]=usbvision_device_data[usbvision->DevModel].X_Offset & 0xff;
2139 value[5]=(usbvision_device_data[usbvision->DevModel].X_Offset & 0x0300) >> 8;
2147 if (usbvision_device_data[usbvision->DevModel].Y_Offset >= 0) {
2148 value[6]=usbvision_device_data[usbvision->DevModel].Y_Offset & 0xff;
2149 value[7]=(usbvision_device_data[usbvision->DevModel].Y_Offset & 0x0300) >> 8;
2157 rc = usb_control_msg(usbvision->dev, usb_sndctrlpipe(usbvision->dev, 1),
2170 if(usbvision_device_data[usbvision->DevModel].Dvi_yuv_override){
2171 dvi_yuv_value = usbvision_device_data[usbvision->DevModel].Dvi_yuv;
2173 else if(usbvision_device_data[usbvision->DevModel].Codec == CODEC_SAA7113) {
2178 return (usbvision_write_reg(usbvision, USBVISION_DVI_YUV, dvi_yuv_value));
2185 * Set the buffer address needed by the usbvision dram to operate
2190 static int usbvision_set_dram_settings(struct usb_usbvision *usbvision)
2195 if (usbvision->isocMode == ISOC_MODE_COMPRESS) {
2231 if (!USBVISION_IS_OPERATIONAL(usbvision))
2234 rc = usb_control_msg(usbvision->dev, usb_sndctrlpipe(usbvision->dev, 1),
2241 dev_err(&usbvision->dev->dev, "%sERROR=%d\n", __func__, rc);
2246 if ((rc = usbvision_write_reg(usbvision, USBVISION_DRM_CONT, USBVISION_RES_UR |
2249 rc = usbvision_write_reg(usbvision, USBVISION_DRM_CONT, 0x00);
2262 int usbvision_power_on(struct usb_usbvision *usbvision)
2268 usbvision_write_reg(usbvision, USBVISION_PWR_REG, USBVISION_SSPND_EN);
2269 usbvision_write_reg(usbvision, USBVISION_PWR_REG,
2272 usbvision_write_reg(usbvision, USBVISION_PWR_REG,
2274 errCode = usbvision_write_reg(usbvision, USBVISION_PWR_REG,
2277 usbvision->power = 1;
2285 * usbvision timer stuff
2291 struct usb_usbvision *usbvision = container_of(work, struct usb_usbvision, powerOffWork);
2294 if(mutex_lock_interruptible(&usbvision->lock)) {
2299 if(usbvision->user == 0) {
2300 usbvision_i2c_unregister(usbvision);
2302 usbvision_power_off(usbvision);
2303 usbvision->initialized = 0;
2305 mutex_unlock(&usbvision->lock);
2310 struct usb_usbvision *usbvision = (void *) data;
2313 del_timer(&usbvision->powerOffTimer);
2314 INIT_WORK(&usbvision->powerOffWork, call_usbvision_power_off);
2315 (void) schedule_work(&usbvision->powerOffWork);
2318 void usbvision_init_powerOffTimer(struct usb_usbvision *usbvision)
2320 init_timer(&usbvision->powerOffTimer);
2321 usbvision->powerOffTimer.data = (long) usbvision;
2322 usbvision->powerOffTimer.function = usbvision_powerOffTimer;
2325 void usbvision_set_powerOffTimer(struct usb_usbvision *usbvision)
2327 mod_timer(&usbvision->powerOffTimer, jiffies + USBVISION_POWEROFF_TIME);
2330 void usbvision_reset_powerOffTimer(struct usb_usbvision *usbvision)
2332 if (timer_pending(&usbvision->powerOffTimer)) {
2333 del_timer(&usbvision->powerOffTimer);
2342 int usbvision_begin_streaming(struct usb_usbvision *usbvision)
2346 if (usbvision->isocMode == ISOC_MODE_COMPRESS) {
2347 usbvision_init_compression(usbvision);
2349 errCode = usbvision_write_reg(usbvision, USBVISION_VIN_REG2, USBVISION_NOHVALID |
2350 usbvision->Vin_Reg2_Preset);
2359 int usbvision_restart_isoc(struct usb_usbvision *usbvision)
2365 usbvision_write_reg(usbvision, USBVISION_PWR_REG,
2370 usbvision_write_reg(usbvision, USBVISION_PWR_REG,
2376 usbvision_write_reg(usbvision, USBVISION_VIN_REG2,
2378 usbvision->Vin_Reg2_Preset)) < 0) return ret;
2381 while ((usbvision_read_reg(usbvision, USBVISION_STATUS_REG) & 0x01) != 1);
2386 int usbvision_audio_off(struct usb_usbvision *usbvision)
2388 if (usbvision_write_reg(usbvision, USBVISION_IOPIN_REG, USBVISION_AUDIO_MUTE) < 0) {
2392 usbvision->AudioMute = 0;
2393 usbvision->AudioChannel = USBVISION_AUDIO_MUTE;
2397 int usbvision_set_audio(struct usb_usbvision *usbvision, int AudioChannel)
2399 if (!usbvision->AudioMute) {
2400 if (usbvision_write_reg(usbvision, USBVISION_IOPIN_REG, AudioChannel) < 0) {
2405 usbvision->AudioChannel = AudioChannel;
2409 int usbvision_setup(struct usb_usbvision *usbvision,int format)
2411 usbvision_set_video_format(usbvision, format);
2412 usbvision_set_dram_settings(usbvision);
2413 usbvision_set_compress_params(usbvision);
2414 usbvision_set_input(usbvision);
2415 usbvision_set_output(usbvision, MAX_USB_WIDTH, MAX_USB_HEIGHT);
2416 usbvision_restart_isoc(usbvision);
2419 return USBVISION_IS_OPERATIONAL(usbvision);
2453 int usbvision_init_isoc(struct usb_usbvision *usbvision)
2455 struct usb_device *dev = usbvision->dev;
2459 if (!USBVISION_IS_OPERATIONAL(usbvision))
2462 usbvision->curFrame = NULL;
2463 scratch_reset(usbvision);
2466 errCode = usbvision_set_alternate(usbvision);
2468 usbvision->last_error = errCode;
2471 sb_size = USBVISION_URB_FRAMES * usbvision->isocPacketSize;
2473 regValue = (16 - usbvision_read_reg(usbvision,
2476 usbvision->usb_bandwidth = regValue >> 1;
2478 usbvision->usb_bandwidth);
2490 dev_err(&usbvision->dev->dev,
2494 usbvision->sbuf[bufIdx].urb = urb;
2495 usbvision->sbuf[bufIdx].data =
2496 usb_alloc_coherent(usbvision->dev,
2501 urb->context = usbvision;
2502 urb->pipe = usb_rcvisocpipe(dev, usbvision->video_endp);
2505 urb->transfer_buffer = usbvision->sbuf[bufIdx].data;
2509 usbvision->isocPacketSize * USBVISION_URB_FRAMES;
2511 k += usbvision->isocPacketSize) {
2514 usbvision->isocPacketSize;
2520 errCode = usb_submit_urb(usbvision->sbuf[bufIdx].urb,
2523 dev_err(&usbvision->dev->dev,
2529 usbvision->streaming = Stream_Idle;
2530 PDEBUG(DBG_ISOC, "%s: streaming=1 usbvision->video_endp=$%02x",
2532 usbvision->video_endp);
2543 void usbvision_stop_isoc(struct usb_usbvision *usbvision)
2546 int sb_size = USBVISION_URB_FRAMES * usbvision->isocPacketSize;
2548 if ((usbvision->streaming == Stream_Off) || (usbvision->dev == NULL))
2553 usb_kill_urb(usbvision->sbuf[bufIdx].urb);
2554 if (usbvision->sbuf[bufIdx].data){
2555 usb_free_coherent(usbvision->dev,
2557 usbvision->sbuf[bufIdx].data,
2558 usbvision->sbuf[bufIdx].urb->transfer_dma);
2560 usb_free_urb(usbvision->sbuf[bufIdx].urb);
2561 usbvision->sbuf[bufIdx].urb = NULL;
2565 usbvision->streaming = Stream_Off;
2567 if (!usbvision->remove_pending) {
2570 usbvision->ifaceAlt=0;
2571 errCode = usb_set_interface(usbvision->dev, usbvision->iface,
2572 usbvision->ifaceAlt);
2574 dev_err(&usbvision->dev->dev,
2577 usbvision->last_error = errCode;
2579 regValue = (16-usbvision_read_reg(usbvision, USBVISION_ALTER_REG)) & 0x0F;
2580 usbvision->isocPacketSize =
2583 usbvision->isocPacketSize);
2585 usbvision->usb_bandwidth = regValue >> 1;
2587 usbvision->usb_bandwidth);
2591 int usbvision_muxsel(struct usb_usbvision *usbvision, int channel)
2602 RESTRICT_TO_RANGE(channel, 0, usbvision->video_inputs);
2603 usbvision->ctl_input = channel;
2609 switch (usbvision_device_data[usbvision->DevModel].Codec) {
2629 call_all(usbvision, video, s_routing, mode[channel], 0, 0);
2630 usbvision_set_audio(usbvision, audio[channel]);