Lines Matching +full:fixed +full:- +full:factor +full:- +full:clock
33 *Add support for other ccd-control chips than the saa7111
62 #include <media/v4l2-common.h>
63 #include <media/v4l2-ioctl.h>
64 #include <media/v4l2-device.h>
90 #define W9966_WND_MAX_W (W9966_WND_MAX_X - W9966_WND_MIN_X)
91 #define W9966_WND_MAX_H (W9966_WND_MAX_Y - W9966_WND_MIN_Y)
138 "\teach camera. 'aggressive' means brute-force search.\n"
146 static int video_nr = -1;
159 cam->dev_state = (cam->dev_state & ~mask) ^ val; in w9966_set_state()
165 return ((cam->dev_state & mask) == val); in w9966_get_state()
173 parport_claim_or_block(cam->pdev); in w9966_pdev_claim()
182 parport_release(cam->pdev); in w9966_pdev_release()
186 /* Read register from W9966 interface-chip
188 -1 on error, else register data (byte) */
195 if (parport_negotiate(cam->pport, cam->ppmode | IEEE1284_ADDR) != 0) in w9966_read_reg()
196 return -1; in w9966_read_reg()
197 if (parport_write(cam->pport, &addr, 1) != 1) in w9966_read_reg()
198 return -1; in w9966_read_reg()
199 if (parport_negotiate(cam->pport, cam->ppmode | IEEE1284_DATA) != 0) in w9966_read_reg()
200 return -1; in w9966_read_reg()
201 if (parport_read(cam->pport, &val, 1) != 1) in w9966_read_reg()
202 return -1; in w9966_read_reg()
207 /* Write register to W9966 interface-chip
209 -1 on error */
216 if (parport_negotiate(cam->pport, cam->ppmode | IEEE1284_ADDR) != 0) in w9966_write_reg()
217 return -1; in w9966_write_reg()
218 if (parport_write(cam->pport, &addr, 1) != 1) in w9966_write_reg()
219 return -1; in w9966_write_reg()
220 if (parport_negotiate(cam->pport, cam->ppmode | IEEE1284_DATA) != 0) in w9966_write_reg()
221 return -1; in w9966_write_reg()
222 if (parport_write(cam->pport, &val, 1) != 1) in w9966_write_reg()
223 return -1; in w9966_write_reg()
237 cam->i2c_state |= W9966_I2C_W_DATA; in w9966_i2c_setsda()
239 cam->i2c_state &= ~W9966_I2C_W_DATA; in w9966_i2c_setsda()
241 w9966_write_reg(cam, 0x18, cam->i2c_state); in w9966_i2c_setsda()
245 /* Get peripheral clock line
253 /* Sets the clock line on the i2c bus.
254 Expects a claimed pdev. -1 on error */
260 cam->i2c_state |= W9966_I2C_W_CLOCK; in w9966_i2c_setscl()
262 cam->i2c_state &= ~W9966_I2C_W_CLOCK; in w9966_i2c_setscl()
264 w9966_write_reg(cam, 0x18, cam->i2c_state); in w9966_i2c_setscl()
272 return -1; in w9966_i2c_setscl()
289 Expects a claimed pdev. -1 on error */
294 for (i = 7; i >= 0; i--) { in w9966_i2c_wbyte()
297 if (w9966_i2c_setscl(cam, 1) == -1) in w9966_i2c_wbyte()
298 return -1; in w9966_i2c_wbyte()
304 if (w9966_i2c_setscl(cam, 1) == -1) in w9966_i2c_wbyte()
305 return -1; in w9966_i2c_wbyte()
311 /* Read a data byte with ack from the i2c-bus
312 Expects a claimed pdev. -1 on error */
322 if (w9966_i2c_setscl(cam, 1) == -1)
323 return -1;
335 Expects claimed pdev. -1 on error */
344 if (w9966_i2c_wbyte(cam, W9966_I2C_W_ID) == -1 ||
345 w9966_i2c_wbyte(cam, reg) == -1)
346 return -1;
349 if (w9966_i2c_setscl(cam, 1) == -1)
350 return -1;
354 if (w9966_i2c_wbyte(cam, W9966_I2C_R_ID) == -1)
355 return -1;
357 if (data == -1)
358 return -1;
362 if (w9966_i2c_setscl(cam, 1) == -1)
363 return -1;
371 Expects claimed pdev. -1 on error */
377 if (w9966_i2c_wbyte(cam, W9966_I2C_W_ID) == -1 || in w9966_write_reg_i2c()
378 w9966_i2c_wbyte(cam, reg) == -1 || in w9966_write_reg_i2c()
379 w9966_i2c_wbyte(cam, data) == -1) in w9966_write_reg_i2c()
380 return -1; in w9966_write_reg_i2c()
383 if (w9966_i2c_setscl(cam, 1) == -1) in w9966_write_reg_i2c()
384 return -1; in w9966_write_reg_i2c()
397 int besterr = abs(near - bestlen); in w9966_findlen()
405 err = abs(near - len); in w9966_findlen()
420 Return -1 on error */
421 static int w9966_calcscale(int size, int min, int max, int *beg, int *end, unsigned char *factor) in w9966_calcscale() argument
423 int maxlen = max - min; in w9966_calcscale()
424 int len = *end - *beg + 1; in w9966_calcscale()
426 int err = newlen - len; in w9966_calcscale()
430 return -1; in w9966_calcscale()
432 /* Set factor (6 bit fixed) */ in w9966_calcscale()
433 *factor = (64 * size) / newlen; in w9966_calcscale()
434 if (*factor == 64) in w9966_calcscale()
435 *factor = 0x00; /* downscale is disabled */ in w9966_calcscale()
437 *factor |= 0x80; /* set downscale-enable bit */ in w9966_calcscale()
440 *beg -= err / 2; in w9966_calcscale()
441 *end += err - (err / 2); in w9966_calcscale()
445 *end += min - *beg; in w9966_calcscale()
446 *beg += min - *beg; in w9966_calcscale()
449 *beg -= *end - max; in w9966_calcscale()
450 *end -= *end - max; in w9966_calcscale()
458 return -1 on error */
488 cam->width = w; in w9966_setup()
489 cam->height = h; in w9966_setup()
497 return -1; in w9966_setup()
499 DPRINTF("%dx%d, x: %d<->%d, y: %d<->%d, sx: %d/64, sy: %d/64.\n", in w9966_setup()
505 regs[0x02] = scale_y; /* V-scaling */ in w9966_setup()
506 regs[0x03] = scale_x; /* H-scaling */ in w9966_setup()
509 regs[0x04] = (x1 & 0x0ff); /* X-start (8 low bits) */ in w9966_setup()
510 regs[0x05] = (x1 & 0x300)>>8; /* X-start (2 high bits) */ in w9966_setup()
511 regs[0x06] = (y1 & 0x0ff); /* Y-start (8 low bits) */ in w9966_setup()
512 regs[0x07] = (y1 & 0x300)>>8; /* Y-start (2 high bits) */ in w9966_setup()
513 regs[0x08] = (x2 & 0x0ff); /* X-end (8 low bits) */ in w9966_setup()
514 regs[0x09] = (x2 & 0x300)>>8; /* X-end (2 high bits) */ in w9966_setup()
515 regs[0x0a] = (y2 & 0x0ff); /* Y-end (8 low bits) */ in w9966_setup()
517 regs[0x0c] = W9966_SRAMID; /* SRAM-banks (1x 128kb) */ in w9966_setup()
520 regs[0x0d] = (enh_s & 0x000ff); /* Enh. start (0-7) */ in w9966_setup()
521 regs[0x0e] = (enh_s & 0x0ff00) >> 8; /* Enh. start (8-15) */ in w9966_setup()
522 regs[0x0f] = (enh_s & 0x70000) >> 16; /* Enh. start (16-17/18??) */ in w9966_setup()
523 regs[0x10] = (enh_e & 0x000ff); /* Enh. end (0-7) */ in w9966_setup()
524 regs[0x11] = (enh_e & 0x0ff00) >> 8; /* Enh. end (8-15) */ in w9966_setup()
525 regs[0x12] = (enh_e & 0x70000) >> 16; /* Enh. end (16-17/18??) */ in w9966_setup()
530 regs[0x18] = cam->i2c_state = 0x00; /* Serial bus */ in w9966_setup()
536 saa7111_regs[0x0a] = cam->brightness; in w9966_setup()
537 saa7111_regs[0x0b] = cam->contrast; in w9966_setup()
538 saa7111_regs[0x0c] = cam->color; in w9966_setup()
539 saa7111_regs[0x0d] = cam->hue; in w9966_setup()
541 /* Reset (ECP-fifo & serial-bus) */ in w9966_setup()
542 if (w9966_write_reg(cam, 0x00, 0x03) == -1) in w9966_setup()
543 return -1; in w9966_setup()
547 if (w9966_write_reg(cam, i, regs[i]) == -1) in w9966_setup()
548 return -1; in w9966_setup()
552 if (w9966_write_reg_i2c(cam, i, saa7111_regs[i]) == -1) in w9966_setup()
553 return -1; in w9966_setup()
567 strlcpy(vcap->driver, cam->v4l2_dev.name, sizeof(vcap->driver)); in cam_querycap()
568 strlcpy(vcap->card, W9966_DRIVERNAME, sizeof(vcap->card)); in cam_querycap()
569 strlcpy(vcap->bus_info, "parport", sizeof(vcap->bus_info)); in cam_querycap()
570 vcap->capabilities = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_READWRITE; in cam_querycap()
576 if (vin->index > 0) in cam_enum_input()
577 return -EINVAL; in cam_enum_input()
578 strlcpy(vin->name, "Camera", sizeof(vin->name)); in cam_enum_input()
579 vin->type = V4L2_INPUT_TYPE_CAMERA; in cam_enum_input()
580 vin->audioset = 0; in cam_enum_input()
581 vin->tuner = 0; in cam_enum_input()
582 vin->std = 0; in cam_enum_input()
583 vin->status = 0; in cam_enum_input()
595 return (inp > 0) ? -EINVAL : 0; in cam_s_input()
601 switch (qc->id) { in cam_queryctrl()
605 return v4l2_ctrl_query_fill(qc, -64, 64, 1, 64); in cam_queryctrl()
607 return v4l2_ctrl_query_fill(qc, -64, 64, 1, 64); in cam_queryctrl()
609 return v4l2_ctrl_query_fill(qc, -128, 127, 1, 0); in cam_queryctrl()
611 return -EINVAL; in cam_queryctrl()
620 switch (ctrl->id) { in cam_g_ctrl()
622 ctrl->value = cam->brightness; in cam_g_ctrl()
625 ctrl->value = cam->contrast; in cam_g_ctrl()
628 ctrl->value = cam->color; in cam_g_ctrl()
631 ctrl->value = cam->hue; in cam_g_ctrl()
634 ret = -EINVAL; in cam_g_ctrl()
646 mutex_lock(&cam->lock); in cam_s_ctrl()
647 switch (ctrl->id) { in cam_s_ctrl()
649 cam->brightness = ctrl->value; in cam_s_ctrl()
652 cam->contrast = ctrl->value; in cam_s_ctrl()
655 cam->color = ctrl->value; in cam_s_ctrl()
658 cam->hue = ctrl->value; in cam_s_ctrl()
661 ret = -EINVAL; in cam_s_ctrl()
668 if (w9966_write_reg_i2c(cam, 0x0a, cam->brightness) == -1 || in cam_s_ctrl()
669 w9966_write_reg_i2c(cam, 0x0b, cam->contrast) == -1 || in cam_s_ctrl()
670 w9966_write_reg_i2c(cam, 0x0c, cam->color) == -1 || in cam_s_ctrl()
671 w9966_write_reg_i2c(cam, 0x0d, cam->hue) == -1) { in cam_s_ctrl()
672 ret = -EIO; in cam_s_ctrl()
677 mutex_unlock(&cam->lock); in cam_s_ctrl()
684 struct v4l2_pix_format *pix = &fmt->fmt.pix; in cam_g_fmt_vid_cap()
686 pix->width = cam->width; in cam_g_fmt_vid_cap()
687 pix->height = cam->height; in cam_g_fmt_vid_cap()
688 pix->pixelformat = V4L2_PIX_FMT_YUYV; in cam_g_fmt_vid_cap()
689 pix->field = V4L2_FIELD_NONE; in cam_g_fmt_vid_cap()
690 pix->bytesperline = 2 * cam->width; in cam_g_fmt_vid_cap()
691 pix->sizeimage = 2 * cam->width * cam->height; in cam_g_fmt_vid_cap()
693 pix->colorspace = V4L2_COLORSPACE_SMPTE170M; in cam_g_fmt_vid_cap()
699 struct v4l2_pix_format *pix = &fmt->fmt.pix; in cam_try_fmt_vid_cap()
701 if (pix->width < 2) in cam_try_fmt_vid_cap()
702 pix->width = 2; in cam_try_fmt_vid_cap()
703 if (pix->height < 1) in cam_try_fmt_vid_cap()
704 pix->height = 1; in cam_try_fmt_vid_cap()
705 if (pix->width > W9966_WND_MAX_W) in cam_try_fmt_vid_cap()
706 pix->width = W9966_WND_MAX_W; in cam_try_fmt_vid_cap()
707 if (pix->height > W9966_WND_MAX_H) in cam_try_fmt_vid_cap()
708 pix->height = W9966_WND_MAX_H; in cam_try_fmt_vid_cap()
709 pix->pixelformat = V4L2_PIX_FMT_YUYV; in cam_try_fmt_vid_cap()
710 pix->field = V4L2_FIELD_NONE; in cam_try_fmt_vid_cap()
711 pix->bytesperline = 2 * pix->width; in cam_try_fmt_vid_cap()
712 pix->sizeimage = 2 * pix->width * pix->height; in cam_try_fmt_vid_cap()
714 pix->colorspace = V4L2_COLORSPACE_SMPTE170M; in cam_try_fmt_vid_cap()
721 struct v4l2_pix_format *pix = &fmt->fmt.pix; in cam_s_fmt_vid_cap()
727 mutex_lock(&cam->lock); in cam_s_fmt_vid_cap()
730 ret = w9966_setup(cam, 0, 0, 1023, 1023, pix->width, pix->height); in cam_s_fmt_vid_cap()
732 mutex_unlock(&cam->lock); in cam_s_fmt_vid_cap()
744 enum v4l2_buf_type type = fmt->type; in cam_enum_fmt_vid_cap()
746 if (fmt->index > 0) in cam_enum_fmt_vid_cap()
747 return -EINVAL; in cam_enum_fmt_vid_cap()
749 *fmt = formats[fmt->index]; in cam_enum_fmt_vid_cap()
750 fmt->type = type; in cam_enum_fmt_vid_cap()
759 unsigned char addr = 0xa0; /* ECP, read, CCD-transfer, 00000 */ in w9966_v4l_read()
765 if (count > cam->width * cam->height * 2) in w9966_v4l_read()
766 return -EINVAL; in w9966_v4l_read()
768 mutex_lock(&cam->lock); in w9966_v4l_read()
770 w9966_write_reg(cam, 0x00, 0x02); /* Reset ECP-FIFO buffer */ in w9966_v4l_read()
774 /* write special capture-addr and negotiate into data transfer */ in w9966_v4l_read()
775 if ((parport_negotiate(cam->pport, cam->ppmode|IEEE1284_ADDR) != 0) || in w9966_v4l_read()
776 (parport_write(cam->pport, &addr, 1) != 1) || in w9966_v4l_read()
777 (parport_negotiate(cam->pport, cam->ppmode|IEEE1284_DATA) != 0)) { in w9966_v4l_read()
779 mutex_unlock(&cam->lock); in w9966_v4l_read()
780 return -EFAULT; in w9966_v4l_read()
785 count = -ENOMEM; in w9966_v4l_read()
792 if (parport_read(cam->pport, tbuf, tsize) < tsize) { in w9966_v4l_read()
793 count = -EFAULT; in w9966_v4l_read()
797 count = -EFAULT; in w9966_v4l_read()
801 dleft -= tsize; in w9966_v4l_read()
809 mutex_unlock(&cam->lock); in w9966_v4l_read()
836 default video mode, setup ccd-chip, register v4l device etc..
838 -1 on error */
841 struct v4l2_device *v4l2_dev = &cam->v4l2_dev; in w9966_init()
843 if (cam->dev_state != 0) in w9966_init()
844 return -1; in w9966_init()
846 strlcpy(v4l2_dev->name, "w9966", sizeof(v4l2_dev->name)); in w9966_init()
850 return -1; in w9966_init()
852 cam->pport = port; in w9966_init()
853 cam->brightness = 128; in w9966_init()
854 cam->contrast = 64; in w9966_init()
855 cam->color = 64; in w9966_init()
856 cam->hue = 0; in w9966_init()
860 default: /* Auto-detect (priority: hw-ecp, hw-epp, sw-ecp) */ in w9966_init()
862 if (port->modes & PARPORT_MODE_ECP) in w9966_init()
863 cam->ppmode = IEEE1284_MODE_ECP; in w9966_init()
864 else if (port->modes & PARPORT_MODE_EPP) in w9966_init()
865 cam->ppmode = IEEE1284_MODE_EPP; in w9966_init()
867 cam->ppmode = IEEE1284_MODE_ECP; in w9966_init()
869 case 1: /* hw- or sw-ecp */ in w9966_init()
870 cam->ppmode = IEEE1284_MODE_ECP; in w9966_init()
872 case 2: /* hw- or sw-epp */ in w9966_init()
873 cam->ppmode = IEEE1284_MODE_EPP; in w9966_init()
878 cam->pdev = parport_register_device(port, "w9966", NULL, NULL, NULL, 0, NULL); in w9966_init()
879 if (cam->pdev == NULL) { in w9966_init()
881 return -1; in w9966_init()
890 return -1; in w9966_init()
896 strlcpy(cam->vdev.name, W9966_DRIVERNAME, sizeof(cam->vdev.name)); in w9966_init()
897 cam->vdev.v4l2_dev = v4l2_dev; in w9966_init()
898 cam->vdev.fops = &w9966_fops; in w9966_init()
899 cam->vdev.ioctl_ops = &w9966_ioctl_ops; in w9966_init()
900 cam->vdev.release = video_device_release_empty; in w9966_init()
901 video_set_drvdata(&cam->vdev, cam); in w9966_init()
903 mutex_init(&cam->lock); in w9966_init()
905 if (video_register_device(&cam->vdev, VFL_TYPE_GRABBER, video_nr) < 0) in w9966_init()
906 return -1; in w9966_init()
912 cam->pport->name); in w9966_init()
922 video_unregister_device(&cam->vdev); in w9966_term()
929 parport_negotiate(cam->pport, IEEE1284_MODE_COMPAT); in w9966_term()
935 parport_unregister_device(cam->pdev); in w9966_term()
950 if (strcmp(pardev[i], "aggressive") == 0 || strcmp(pardev[i], port->name) == 0) { in w9966_attach()