diff options
author | Dean Anderson <linux-dev@sensoray.com> | 2010-06-01 18:12:07 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2010-08-02 14:28:22 -0400 |
commit | fe85ce90abae7f7876a9ae8f76649586fe73d5a2 (patch) | |
tree | 2ac2b6e458f401e4928eff796d117093b7ac1916 | |
parent | 2e9157f8ab028ccc5d155320a3f1e49494bcfc18 (diff) |
V4L/DVB: s2255drv: cleanup of device structure
s2255drv: cleanup of device structure
cleanup of device structure.
single channel array instead of multiple arrays in device for
each channel property.
simplifies open callback by removing search for channel index.
Signed-off-by: Dean Anderson <linux-dev@sensoray.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
-rw-r--r-- | drivers/media/video/s2255drv.c | 724 |
1 files changed, 352 insertions, 372 deletions
diff --git a/drivers/media/video/s2255drv.c b/drivers/media/video/s2255drv.c index 3c7a79f3812a..8ec7c9a45a17 100644 --- a/drivers/media/video/s2255drv.c +++ b/drivers/media/video/s2255drv.c | |||
@@ -191,7 +191,6 @@ struct s2255_bufferi { | |||
191 | struct s2255_dmaqueue { | 191 | struct s2255_dmaqueue { |
192 | struct list_head active; | 192 | struct list_head active; |
193 | struct s2255_dev *dev; | 193 | struct s2255_dev *dev; |
194 | int channel; | ||
195 | }; | 194 | }; |
196 | 195 | ||
197 | /* for firmware loading, fw_state */ | 196 | /* for firmware loading, fw_state */ |
@@ -226,51 +225,60 @@ struct s2255_pipeinfo { | |||
226 | }; | 225 | }; |
227 | 226 | ||
228 | struct s2255_fmt; /*forward declaration */ | 227 | struct s2255_fmt; /*forward declaration */ |
228 | struct s2255_dev; | ||
229 | |||
230 | struct s2255_channel { | ||
231 | struct video_device vdev; | ||
232 | int resources; | ||
233 | struct s2255_dmaqueue vidq; | ||
234 | struct s2255_bufferi buffer; | ||
235 | struct s2255_mode mode; | ||
236 | /* jpeg compression */ | ||
237 | struct v4l2_jpegcompression jc; | ||
238 | /* capture parameters (for high quality mode full size) */ | ||
239 | struct v4l2_captureparm cap_parm; | ||
240 | int cur_frame; | ||
241 | int last_frame; | ||
242 | |||
243 | int b_acquire; | ||
244 | /* allocated image size */ | ||
245 | unsigned long req_image_size; | ||
246 | /* received packet size */ | ||
247 | unsigned long pkt_size; | ||
248 | int bad_payload; | ||
249 | unsigned long frame_count; | ||
250 | /* if JPEG image */ | ||
251 | int jpg_size; | ||
252 | /* if channel configured to default state */ | ||
253 | int configured; | ||
254 | wait_queue_head_t wait_setmode; | ||
255 | int setmode_ready; | ||
256 | /* video status items */ | ||
257 | int vidstatus; | ||
258 | wait_queue_head_t wait_vidstatus; | ||
259 | int vidstatus_ready; | ||
260 | unsigned int width; | ||
261 | unsigned int height; | ||
262 | const struct s2255_fmt *fmt; | ||
263 | int idx; /* channel number on device, 0-3 */ | ||
264 | }; | ||
265 | |||
229 | 266 | ||
230 | struct s2255_dev { | 267 | struct s2255_dev { |
231 | struct video_device vdev[MAX_CHANNELS]; | 268 | struct s2255_channel channel[MAX_CHANNELS]; |
232 | struct v4l2_device v4l2_dev; | 269 | struct v4l2_device v4l2_dev; |
233 | atomic_t channels; /* number of channels registered */ | 270 | atomic_t num_channels; |
234 | int frames; | 271 | int frames; |
235 | struct mutex lock; | 272 | struct mutex lock; |
236 | struct mutex open_lock; | 273 | struct mutex open_lock; |
237 | int resources[MAX_CHANNELS]; | ||
238 | struct usb_device *udev; | 274 | struct usb_device *udev; |
239 | struct usb_interface *interface; | 275 | struct usb_interface *interface; |
240 | u8 read_endpoint; | 276 | u8 read_endpoint; |
241 | |||
242 | struct s2255_dmaqueue vidq[MAX_CHANNELS]; | ||
243 | struct timer_list timer; | 277 | struct timer_list timer; |
244 | struct s2255_fw *fw_data; | 278 | struct s2255_fw *fw_data; |
245 | struct s2255_pipeinfo pipe; | 279 | struct s2255_pipeinfo pipe; |
246 | struct s2255_bufferi buffer[MAX_CHANNELS]; | ||
247 | struct s2255_mode mode[MAX_CHANNELS]; | ||
248 | /* jpeg compression */ | ||
249 | struct v4l2_jpegcompression jc[MAX_CHANNELS]; | ||
250 | /* capture parameters (for high quality mode full size) */ | ||
251 | struct v4l2_captureparm cap_parm[MAX_CHANNELS]; | ||
252 | const struct s2255_fmt *cur_fmt[MAX_CHANNELS]; | ||
253 | int cur_frame[MAX_CHANNELS]; | ||
254 | int last_frame[MAX_CHANNELS]; | ||
255 | u32 cc; /* current channel */ | 280 | u32 cc; /* current channel */ |
256 | int b_acquire[MAX_CHANNELS]; | ||
257 | /* allocated image size */ | ||
258 | unsigned long req_image_size[MAX_CHANNELS]; | ||
259 | /* received packet size */ | ||
260 | unsigned long pkt_size[MAX_CHANNELS]; | ||
261 | int bad_payload[MAX_CHANNELS]; | ||
262 | unsigned long frame_count[MAX_CHANNELS]; | ||
263 | int frame_ready; | 281 | int frame_ready; |
264 | /* if JPEG image */ | ||
265 | int jpg_size[MAX_CHANNELS]; | ||
266 | /* if channel configured to default state */ | ||
267 | int chn_configured[MAX_CHANNELS]; | ||
268 | wait_queue_head_t wait_setmode[MAX_CHANNELS]; | ||
269 | int setmode_ready[MAX_CHANNELS]; | ||
270 | /* video status items */ | ||
271 | int vidstatus[MAX_CHANNELS]; | ||
272 | wait_queue_head_t wait_vidstatus[MAX_CHANNELS]; | ||
273 | int vidstatus_ready[MAX_CHANNELS]; | ||
274 | int chn_ready; | 282 | int chn_ready; |
275 | spinlock_t slock; | 283 | spinlock_t slock; |
276 | /* dsp firmware version (f2255usb.bin) */ | 284 | /* dsp firmware version (f2255usb.bin) */ |
@@ -298,16 +306,10 @@ struct s2255_buffer { | |||
298 | 306 | ||
299 | struct s2255_fh { | 307 | struct s2255_fh { |
300 | struct s2255_dev *dev; | 308 | struct s2255_dev *dev; |
301 | const struct s2255_fmt *fmt; | ||
302 | unsigned int width; | ||
303 | unsigned int height; | ||
304 | struct videobuf_queue vb_vidq; | 309 | struct videobuf_queue vb_vidq; |
305 | enum v4l2_buf_type type; | 310 | enum v4l2_buf_type type; |
306 | int channel; | 311 | struct s2255_channel *channel; |
307 | /* mode below is the desired mode. | 312 | int resources; |
308 | mode in s2255_dev is the current mode that was last set */ | ||
309 | struct s2255_mode mode; | ||
310 | int resources[MAX_CHANNELS]; | ||
311 | }; | 313 | }; |
312 | 314 | ||
313 | /* current cypress EEPROM firmware version */ | 315 | /* current cypress EEPROM firmware version */ |
@@ -360,12 +362,11 @@ static int *s2255_debug = &debug; | |||
360 | 362 | ||
361 | static int s2255_start_readpipe(struct s2255_dev *dev); | 363 | static int s2255_start_readpipe(struct s2255_dev *dev); |
362 | static void s2255_stop_readpipe(struct s2255_dev *dev); | 364 | static void s2255_stop_readpipe(struct s2255_dev *dev); |
363 | static int s2255_start_acquire(struct s2255_dev *dev, unsigned long chn); | 365 | static int s2255_start_acquire(struct s2255_channel *channel); |
364 | static int s2255_stop_acquire(struct s2255_dev *dev, unsigned long chn); | 366 | static int s2255_stop_acquire(struct s2255_channel *channel); |
365 | static void s2255_fillbuff(struct s2255_dev *dev, struct s2255_buffer *buf, | 367 | static void s2255_fillbuff(struct s2255_channel *chn, struct s2255_buffer *buf, |
366 | int chn, int jpgsize); | 368 | int jpgsize); |
367 | static int s2255_set_mode(struct s2255_dev *dev, unsigned long chn, | 369 | static int s2255_set_mode(struct s2255_channel *chan, struct s2255_mode *mode); |
368 | struct s2255_mode *mode); | ||
369 | static int s2255_board_shutdown(struct s2255_dev *dev); | 370 | static int s2255_board_shutdown(struct s2255_dev *dev); |
370 | static void s2255_fwload_start(struct s2255_dev *dev, int reset); | 371 | static void s2255_fwload_start(struct s2255_dev *dev, int reset); |
371 | static void s2255_destroy(struct s2255_dev *dev); | 372 | static void s2255_destroy(struct s2255_dev *dev); |
@@ -577,10 +578,11 @@ static void s2255_fwchunk_complete(struct urb *urb) | |||
577 | 578 | ||
578 | } | 579 | } |
579 | 580 | ||
580 | static int s2255_got_frame(struct s2255_dev *dev, int chn, int jpgsize) | 581 | static int s2255_got_frame(struct s2255_channel *channel, int jpgsize) |
581 | { | 582 | { |
582 | struct s2255_dmaqueue *dma_q = &dev->vidq[chn]; | 583 | struct s2255_dmaqueue *dma_q = &channel->vidq; |
583 | struct s2255_buffer *buf; | 584 | struct s2255_buffer *buf; |
585 | struct s2255_dev *dev = to_s2255_dev(channel->vdev.v4l2_dev); | ||
584 | unsigned long flags = 0; | 586 | unsigned long flags = 0; |
585 | int rc = 0; | 587 | int rc = 0; |
586 | spin_lock_irqsave(&dev->slock, flags); | 588 | spin_lock_irqsave(&dev->slock, flags); |
@@ -593,7 +595,7 @@ static int s2255_got_frame(struct s2255_dev *dev, int chn, int jpgsize) | |||
593 | struct s2255_buffer, vb.queue); | 595 | struct s2255_buffer, vb.queue); |
594 | list_del(&buf->vb.queue); | 596 | list_del(&buf->vb.queue); |
595 | do_gettimeofday(&buf->vb.ts); | 597 | do_gettimeofday(&buf->vb.ts); |
596 | s2255_fillbuff(dev, buf, dma_q->channel, jpgsize); | 598 | s2255_fillbuff(channel, buf, jpgsize); |
597 | wake_up(&buf->vb.done); | 599 | wake_up(&buf->vb.done); |
598 | dprintk(2, "%s: [buf/i] [%p/%d]\n", __func__, buf, buf->vb.i); | 600 | dprintk(2, "%s: [buf/i] [%p/%d]\n", __func__, buf, buf->vb.i); |
599 | unlock: | 601 | unlock: |
@@ -621,8 +623,8 @@ static const struct s2255_fmt *format_by_fourcc(int fourcc) | |||
621 | * http://v4l.videotechnology.com/ | 623 | * http://v4l.videotechnology.com/ |
622 | * | 624 | * |
623 | */ | 625 | */ |
624 | static void s2255_fillbuff(struct s2255_dev *dev, struct s2255_buffer *buf, | 626 | static void s2255_fillbuff(struct s2255_channel *channel, |
625 | int chn, int jpgsize) | 627 | struct s2255_buffer *buf, int jpgsize) |
626 | { | 628 | { |
627 | int pos = 0; | 629 | int pos = 0; |
628 | struct timeval ts; | 630 | struct timeval ts; |
@@ -633,12 +635,11 @@ static void s2255_fillbuff(struct s2255_dev *dev, struct s2255_buffer *buf, | |||
633 | 635 | ||
634 | if (!vbuf) | 636 | if (!vbuf) |
635 | return; | 637 | return; |
636 | 638 | last_frame = channel->last_frame; | |
637 | last_frame = dev->last_frame[chn]; | ||
638 | if (last_frame != -1) { | 639 | if (last_frame != -1) { |
639 | frm = &dev->buffer[chn].frame[last_frame]; | 640 | frm = &channel->buffer.frame[last_frame]; |
640 | tmpbuf = | 641 | tmpbuf = |
641 | (const char *)dev->buffer[chn].frame[last_frame].lpvbits; | 642 | (const char *)channel->buffer.frame[last_frame].lpvbits; |
642 | switch (buf->fmt->fourcc) { | 643 | switch (buf->fmt->fourcc) { |
643 | case V4L2_PIX_FMT_YUYV: | 644 | case V4L2_PIX_FMT_YUYV: |
644 | case V4L2_PIX_FMT_UYVY: | 645 | case V4L2_PIX_FMT_UYVY: |
@@ -661,7 +662,7 @@ static void s2255_fillbuff(struct s2255_dev *dev, struct s2255_buffer *buf, | |||
661 | default: | 662 | default: |
662 | printk(KERN_DEBUG "s2255: unknown format?\n"); | 663 | printk(KERN_DEBUG "s2255: unknown format?\n"); |
663 | } | 664 | } |
664 | dev->last_frame[chn] = -1; | 665 | channel->last_frame = -1; |
665 | } else { | 666 | } else { |
666 | printk(KERN_ERR "s2255: =======no frame\n"); | 667 | printk(KERN_ERR "s2255: =======no frame\n"); |
667 | return; | 668 | return; |
@@ -671,7 +672,7 @@ static void s2255_fillbuff(struct s2255_dev *dev, struct s2255_buffer *buf, | |||
671 | (unsigned long)vbuf, pos); | 672 | (unsigned long)vbuf, pos); |
672 | /* tell v4l buffer was filled */ | 673 | /* tell v4l buffer was filled */ |
673 | 674 | ||
674 | buf->vb.field_count = dev->frame_count[chn] * 2; | 675 | buf->vb.field_count = channel->frame_count * 2; |
675 | do_gettimeofday(&ts); | 676 | do_gettimeofday(&ts); |
676 | buf->vb.ts = ts; | 677 | buf->vb.ts = ts; |
677 | buf->vb.state = VIDEOBUF_DONE; | 678 | buf->vb.state = VIDEOBUF_DONE; |
@@ -686,8 +687,8 @@ static int buffer_setup(struct videobuf_queue *vq, unsigned int *count, | |||
686 | unsigned int *size) | 687 | unsigned int *size) |
687 | { | 688 | { |
688 | struct s2255_fh *fh = vq->priv_data; | 689 | struct s2255_fh *fh = vq->priv_data; |
689 | 690 | struct s2255_channel *channel = fh->channel; | |
690 | *size = fh->width * fh->height * (fh->fmt->depth >> 3); | 691 | *size = channel->width * channel->height * (channel->fmt->depth >> 3); |
691 | 692 | ||
692 | if (0 == *count) | 693 | if (0 == *count) |
693 | *count = S2255_DEF_BUFS; | 694 | *count = S2255_DEF_BUFS; |
@@ -710,30 +711,31 @@ static int buffer_prepare(struct videobuf_queue *vq, struct videobuf_buffer *vb, | |||
710 | enum v4l2_field field) | 711 | enum v4l2_field field) |
711 | { | 712 | { |
712 | struct s2255_fh *fh = vq->priv_data; | 713 | struct s2255_fh *fh = vq->priv_data; |
714 | struct s2255_channel *channel = fh->channel; | ||
713 | struct s2255_buffer *buf = container_of(vb, struct s2255_buffer, vb); | 715 | struct s2255_buffer *buf = container_of(vb, struct s2255_buffer, vb); |
714 | int rc; | 716 | int rc; |
717 | int w = channel->width; | ||
718 | int h = channel->height; | ||
715 | dprintk(4, "%s, field=%d\n", __func__, field); | 719 | dprintk(4, "%s, field=%d\n", __func__, field); |
716 | if (fh->fmt == NULL) | 720 | if (channel->fmt == NULL) |
717 | return -EINVAL; | 721 | return -EINVAL; |
718 | 722 | ||
719 | if ((fh->width < norm_minw(&fh->dev->vdev[fh->channel])) || | 723 | if ((w < norm_minw(&channel->vdev)) || |
720 | (fh->width > norm_maxw(&fh->dev->vdev[fh->channel])) || | 724 | (w > norm_maxw(&channel->vdev)) || |
721 | (fh->height < norm_minh(&fh->dev->vdev[fh->channel])) || | 725 | (h < norm_minh(&channel->vdev)) || |
722 | (fh->height > norm_maxh(&fh->dev->vdev[fh->channel]))) { | 726 | (h > norm_maxh(&channel->vdev))) { |
723 | dprintk(4, "invalid buffer prepare\n"); | 727 | dprintk(4, "invalid buffer prepare\n"); |
724 | return -EINVAL; | 728 | return -EINVAL; |
725 | } | 729 | } |
726 | 730 | buf->vb.size = w * h * (channel->fmt->depth >> 3); | |
727 | buf->vb.size = fh->width * fh->height * (fh->fmt->depth >> 3); | ||
728 | |||
729 | if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size) { | 731 | if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size) { |
730 | dprintk(4, "invalid buffer prepare\n"); | 732 | dprintk(4, "invalid buffer prepare\n"); |
731 | return -EINVAL; | 733 | return -EINVAL; |
732 | } | 734 | } |
733 | 735 | ||
734 | buf->fmt = fh->fmt; | 736 | buf->fmt = channel->fmt; |
735 | buf->vb.width = fh->width; | 737 | buf->vb.width = w; |
736 | buf->vb.height = fh->height; | 738 | buf->vb.height = h; |
737 | buf->vb.field = field; | 739 | buf->vb.field = field; |
738 | 740 | ||
739 | if (VIDEOBUF_NEEDS_INIT == buf->vb.state) { | 741 | if (VIDEOBUF_NEEDS_INIT == buf->vb.state) { |
@@ -753,8 +755,8 @@ static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb) | |||
753 | { | 755 | { |
754 | struct s2255_buffer *buf = container_of(vb, struct s2255_buffer, vb); | 756 | struct s2255_buffer *buf = container_of(vb, struct s2255_buffer, vb); |
755 | struct s2255_fh *fh = vq->priv_data; | 757 | struct s2255_fh *fh = vq->priv_data; |
756 | struct s2255_dev *dev = fh->dev; | 758 | struct s2255_channel *channel = fh->channel; |
757 | struct s2255_dmaqueue *vidq = &dev->vidq[fh->channel]; | 759 | struct s2255_dmaqueue *vidq = &channel->vidq; |
758 | dprintk(1, "%s\n", __func__); | 760 | dprintk(1, "%s\n", __func__); |
759 | buf->vb.state = VIDEOBUF_QUEUED; | 761 | buf->vb.state = VIDEOBUF_QUEUED; |
760 | list_add_tail(&buf->vb.queue, &vidq->active); | 762 | list_add_tail(&buf->vb.queue, &vidq->active); |
@@ -765,7 +767,7 @@ static void buffer_release(struct videobuf_queue *vq, | |||
765 | { | 767 | { |
766 | struct s2255_buffer *buf = container_of(vb, struct s2255_buffer, vb); | 768 | struct s2255_buffer *buf = container_of(vb, struct s2255_buffer, vb); |
767 | struct s2255_fh *fh = vq->priv_data; | 769 | struct s2255_fh *fh = vq->priv_data; |
768 | dprintk(4, "%s %d\n", __func__, fh->channel); | 770 | dprintk(4, "%s %d\n", __func__, fh->channel->idx); |
769 | free_buffer(vq, buf); | 771 | free_buffer(vq, buf); |
770 | } | 772 | } |
771 | 773 | ||
@@ -777,39 +779,43 @@ static struct videobuf_queue_ops s2255_video_qops = { | |||
777 | }; | 779 | }; |
778 | 780 | ||
779 | 781 | ||
780 | static int res_get(struct s2255_dev *dev, struct s2255_fh *fh) | 782 | static int res_get(struct s2255_fh *fh) |
781 | { | 783 | { |
784 | struct s2255_dev *dev = fh->dev; | ||
782 | /* is it free? */ | 785 | /* is it free? */ |
786 | struct s2255_channel *channel = fh->channel; | ||
783 | mutex_lock(&dev->lock); | 787 | mutex_lock(&dev->lock); |
784 | if (dev->resources[fh->channel]) { | 788 | if (channel->resources) { |
785 | /* no, someone else uses it */ | 789 | /* no, someone else uses it */ |
786 | mutex_unlock(&dev->lock); | 790 | mutex_unlock(&dev->lock); |
787 | return 0; | 791 | return 0; |
788 | } | 792 | } |
789 | /* it's free, grab it */ | 793 | /* it's free, grab it */ |
790 | dev->resources[fh->channel] = 1; | 794 | channel->resources = 1; |
791 | fh->resources[fh->channel] = 1; | 795 | fh->resources = 1; |
792 | dprintk(1, "s2255: res: get\n"); | 796 | dprintk(1, "s2255: res: get\n"); |
793 | mutex_unlock(&dev->lock); | 797 | mutex_unlock(&dev->lock); |
794 | return 1; | 798 | return 1; |
795 | } | 799 | } |
796 | 800 | ||
797 | static int res_locked(struct s2255_dev *dev, struct s2255_fh *fh) | 801 | static int res_locked(struct s2255_fh *fh) |
798 | { | 802 | { |
799 | return dev->resources[fh->channel]; | 803 | return fh->channel->resources; |
800 | } | 804 | } |
801 | 805 | ||
802 | static int res_check(struct s2255_fh *fh) | 806 | static int res_check(struct s2255_fh *fh) |
803 | { | 807 | { |
804 | return fh->resources[fh->channel]; | 808 | return fh->resources; |
805 | } | 809 | } |
806 | 810 | ||
807 | 811 | ||
808 | static void res_free(struct s2255_dev *dev, struct s2255_fh *fh) | 812 | static void res_free(struct s2255_fh *fh) |
809 | { | 813 | { |
814 | struct s2255_channel *channel = fh->channel; | ||
815 | struct s2255_dev *dev = fh->dev; | ||
810 | mutex_lock(&dev->lock); | 816 | mutex_lock(&dev->lock); |
811 | dev->resources[fh->channel] = 0; | 817 | channel->resources = 0; |
812 | fh->resources[fh->channel] = 0; | 818 | fh->resources = 0; |
813 | mutex_unlock(&dev->lock); | 819 | mutex_unlock(&dev->lock); |
814 | dprintk(1, "res: put\n"); | 820 | dprintk(1, "res: put\n"); |
815 | } | 821 | } |
@@ -869,12 +875,13 @@ static int vidioc_g_fmt_vid_cap(struct file *file, void *priv, | |||
869 | struct v4l2_format *f) | 875 | struct v4l2_format *f) |
870 | { | 876 | { |
871 | struct s2255_fh *fh = priv; | 877 | struct s2255_fh *fh = priv; |
878 | struct s2255_channel *channel = fh->channel; | ||
872 | 879 | ||
873 | f->fmt.pix.width = fh->width; | 880 | f->fmt.pix.width = channel->width; |
874 | f->fmt.pix.height = fh->height; | 881 | f->fmt.pix.height = channel->height; |
875 | f->fmt.pix.field = fh->vb_vidq.field; | 882 | f->fmt.pix.field = fh->vb_vidq.field; |
876 | f->fmt.pix.pixelformat = fh->fmt->fourcc; | 883 | f->fmt.pix.pixelformat = channel->fmt->fourcc; |
877 | f->fmt.pix.bytesperline = f->fmt.pix.width * (fh->fmt->depth >> 3); | 884 | f->fmt.pix.bytesperline = f->fmt.pix.width * (channel->fmt->depth >> 3); |
878 | f->fmt.pix.sizeimage = f->fmt.pix.height * f->fmt.pix.bytesperline; | 885 | f->fmt.pix.sizeimage = f->fmt.pix.height * f->fmt.pix.bytesperline; |
879 | return 0; | 886 | return 0; |
880 | } | 887 | } |
@@ -886,11 +893,10 @@ static int vidioc_try_fmt_vid_cap(struct file *file, void *priv, | |||
886 | enum v4l2_field field; | 893 | enum v4l2_field field; |
887 | int b_any_field = 0; | 894 | int b_any_field = 0; |
888 | struct s2255_fh *fh = priv; | 895 | struct s2255_fh *fh = priv; |
889 | struct s2255_dev *dev = fh->dev; | 896 | struct s2255_channel *channel = fh->channel; |
890 | int is_ntsc; | 897 | int is_ntsc; |
891 | |||
892 | is_ntsc = | 898 | is_ntsc = |
893 | (dev->vdev[fh->channel].current_norm & V4L2_STD_NTSC) ? 1 : 0; | 899 | (channel->vdev.current_norm & V4L2_STD_NTSC) ? 1 : 0; |
894 | 900 | ||
895 | fmt = format_by_fourcc(f->fmt.pix.pixelformat); | 901 | fmt = format_by_fourcc(f->fmt.pix.pixelformat); |
896 | 902 | ||
@@ -982,8 +988,10 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, | |||
982 | struct v4l2_format *f) | 988 | struct v4l2_format *f) |
983 | { | 989 | { |
984 | struct s2255_fh *fh = priv; | 990 | struct s2255_fh *fh = priv; |
991 | struct s2255_channel *channel = fh->channel; | ||
985 | const struct s2255_fmt *fmt; | 992 | const struct s2255_fmt *fmt; |
986 | struct videobuf_queue *q = &fh->vb_vidq; | 993 | struct videobuf_queue *q = &fh->vb_vidq; |
994 | struct s2255_mode mode; | ||
987 | int ret; | 995 | int ret; |
988 | int norm; | 996 | int norm; |
989 | 997 | ||
@@ -1005,54 +1013,61 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, | |||
1005 | goto out_s_fmt; | 1013 | goto out_s_fmt; |
1006 | } | 1014 | } |
1007 | 1015 | ||
1008 | if (res_locked(fh->dev, fh)) { | 1016 | if (res_locked(fh)) { |
1009 | dprintk(1, "%s: channel busy\n", __func__); | 1017 | dprintk(1, "%s: channel busy\n", __func__); |
1010 | ret = -EBUSY; | 1018 | ret = -EBUSY; |
1011 | goto out_s_fmt; | 1019 | goto out_s_fmt; |
1012 | } | 1020 | } |
1013 | 1021 | mode = channel->mode; | |
1014 | fh->fmt = fmt; | 1022 | channel->fmt = fmt; |
1015 | fh->width = f->fmt.pix.width; | 1023 | channel->width = f->fmt.pix.width; |
1016 | fh->height = f->fmt.pix.height; | 1024 | channel->height = f->fmt.pix.height; |
1017 | fh->vb_vidq.field = f->fmt.pix.field; | 1025 | fh->vb_vidq.field = f->fmt.pix.field; |
1018 | fh->type = f->type; | 1026 | fh->type = f->type; |
1019 | norm = norm_minw(&fh->dev->vdev[fh->channel]); | 1027 | norm = norm_minw(&channel->vdev); |
1020 | if (fh->width > norm_minw(&fh->dev->vdev[fh->channel])) { | 1028 | if (channel->width > norm_minw(&channel->vdev)) { |
1021 | if (fh->height > norm_minh(&fh->dev->vdev[fh->channel])) { | 1029 | if (channel->height > norm_minh(&channel->vdev)) { |
1022 | if (fh->dev->cap_parm[fh->channel].capturemode & | 1030 | if (channel->cap_parm.capturemode & |
1023 | V4L2_MODE_HIGHQUALITY) | 1031 | V4L2_MODE_HIGHQUALITY) |
1024 | fh->mode.scale = SCALE_4CIFSI; | 1032 | mode.scale = SCALE_4CIFSI; |
1025 | else | 1033 | else |
1026 | fh->mode.scale = SCALE_4CIFS; | 1034 | mode.scale = SCALE_4CIFS; |
1027 | } else | 1035 | } else |
1028 | fh->mode.scale = SCALE_2CIFS; | 1036 | mode.scale = SCALE_2CIFS; |
1029 | 1037 | ||
1030 | } else { | 1038 | } else { |
1031 | fh->mode.scale = SCALE_1CIFS; | 1039 | mode.scale = SCALE_1CIFS; |
1032 | } | 1040 | } |
1033 | |||
1034 | /* color mode */ | 1041 | /* color mode */ |
1035 | switch (fh->fmt->fourcc) { | 1042 | switch (channel->fmt->fourcc) { |
1036 | case V4L2_PIX_FMT_GREY: | 1043 | case V4L2_PIX_FMT_GREY: |
1037 | fh->mode.color &= ~MASK_COLOR; | 1044 | mode.color &= ~MASK_COLOR; |
1038 | fh->mode.color |= COLOR_Y8; | 1045 | mode.color |= COLOR_Y8; |
1039 | break; | 1046 | break; |
1040 | case V4L2_PIX_FMT_JPEG: | 1047 | case V4L2_PIX_FMT_JPEG: |
1041 | fh->mode.color &= ~MASK_COLOR; | 1048 | mode.color &= ~MASK_COLOR; |
1042 | fh->mode.color |= COLOR_JPG; | 1049 | mode.color |= COLOR_JPG; |
1043 | fh->mode.color |= (fh->dev->jc[fh->channel].quality << 8); | 1050 | mode.color |= (channel->jc.quality << 8); |
1044 | break; | 1051 | break; |
1045 | case V4L2_PIX_FMT_YUV422P: | 1052 | case V4L2_PIX_FMT_YUV422P: |
1046 | fh->mode.color &= ~MASK_COLOR; | 1053 | mode.color &= ~MASK_COLOR; |
1047 | fh->mode.color |= COLOR_YUVPL; | 1054 | mode.color |= COLOR_YUVPL; |
1048 | break; | 1055 | break; |
1049 | case V4L2_PIX_FMT_YUYV: | 1056 | case V4L2_PIX_FMT_YUYV: |
1050 | case V4L2_PIX_FMT_UYVY: | 1057 | case V4L2_PIX_FMT_UYVY: |
1051 | default: | 1058 | default: |
1052 | fh->mode.color &= ~MASK_COLOR; | 1059 | mode.color &= ~MASK_COLOR; |
1053 | fh->mode.color |= COLOR_YUVPK; | 1060 | mode.color |= COLOR_YUVPK; |
1054 | break; | 1061 | break; |
1055 | } | 1062 | } |
1063 | if ((mode.color & MASK_COLOR) != (channel->mode.color & MASK_COLOR)) | ||
1064 | mode.restart = 1; | ||
1065 | else if (mode.scale != channel->mode.scale) | ||
1066 | mode.restart = 1; | ||
1067 | else if (mode.format != channel->mode.format) | ||
1068 | mode.restart = 1; | ||
1069 | channel->mode = mode; | ||
1070 | (void) s2255_set_mode(channel, &mode); | ||
1056 | ret = 0; | 1071 | ret = 0; |
1057 | out_s_fmt: | 1072 | out_s_fmt: |
1058 | mutex_unlock(&q->vb_lock); | 1073 | mutex_unlock(&q->vb_lock); |
@@ -1197,26 +1212,27 @@ static void s2255_print_cfg(struct s2255_dev *sdev, struct s2255_mode *mode) | |||
1197 | * When the restart parameter is set, we sleep for ONE frame to allow the | 1212 | * When the restart parameter is set, we sleep for ONE frame to allow the |
1198 | * DSP time to get the new frame | 1213 | * DSP time to get the new frame |
1199 | */ | 1214 | */ |
1200 | static int s2255_set_mode(struct s2255_dev *dev, unsigned long chn, | 1215 | static int s2255_set_mode(struct s2255_channel *channel, |
1201 | struct s2255_mode *mode) | 1216 | struct s2255_mode *mode) |
1202 | { | 1217 | { |
1203 | int res; | 1218 | int res; |
1204 | __le32 *buffer; | 1219 | __le32 *buffer; |
1205 | unsigned long chn_rev; | 1220 | unsigned long chn_rev; |
1221 | struct s2255_dev *dev = to_s2255_dev(channel->vdev.v4l2_dev); | ||
1206 | mutex_lock(&dev->lock); | 1222 | mutex_lock(&dev->lock); |
1207 | chn_rev = G_chnmap[chn]; | 1223 | chn_rev = G_chnmap[channel->idx]; |
1208 | dprintk(3, "%s channel %lu\n", __func__, chn); | 1224 | dprintk(3, "%s channel: %d\n", __func__, channel->idx); |
1209 | /* if JPEG, set the quality */ | 1225 | /* if JPEG, set the quality */ |
1210 | if ((mode->color & MASK_COLOR) == COLOR_JPG) { | 1226 | if ((mode->color & MASK_COLOR) == COLOR_JPG) { |
1211 | mode->color &= ~MASK_COLOR; | 1227 | mode->color &= ~MASK_COLOR; |
1212 | mode->color |= COLOR_JPG; | 1228 | mode->color |= COLOR_JPG; |
1213 | mode->color &= ~MASK_JPG_QUALITY; | 1229 | mode->color &= ~MASK_JPG_QUALITY; |
1214 | mode->color |= (dev->jc[chn].quality << 8); | 1230 | mode->color |= (channel->jc.quality << 8); |
1215 | } | 1231 | } |
1216 | /* save the mode */ | 1232 | /* save the mode */ |
1217 | dev->mode[chn] = *mode; | 1233 | channel->mode = *mode; |
1218 | dev->req_image_size[chn] = get_transfer_size(mode); | 1234 | channel->req_image_size = get_transfer_size(mode); |
1219 | dprintk(1, "%s: reqsize %ld\n", __func__, dev->req_image_size[chn]); | 1235 | dprintk(1, "%s: reqsize %ld\n", __func__, channel->req_image_size); |
1220 | buffer = kzalloc(512, GFP_KERNEL); | 1236 | buffer = kzalloc(512, GFP_KERNEL); |
1221 | if (buffer == NULL) { | 1237 | if (buffer == NULL) { |
1222 | dev_err(&dev->udev->dev, "out of mem\n"); | 1238 | dev_err(&dev->udev->dev, "out of mem\n"); |
@@ -1227,38 +1243,38 @@ static int s2255_set_mode(struct s2255_dev *dev, unsigned long chn, | |||
1227 | buffer[0] = IN_DATA_TOKEN; | 1243 | buffer[0] = IN_DATA_TOKEN; |
1228 | buffer[1] = (__le32) cpu_to_le32(chn_rev); | 1244 | buffer[1] = (__le32) cpu_to_le32(chn_rev); |
1229 | buffer[2] = CMD_SET_MODE; | 1245 | buffer[2] = CMD_SET_MODE; |
1230 | memcpy(&buffer[3], &dev->mode[chn], sizeof(struct s2255_mode)); | 1246 | memcpy(&buffer[3], &channel->mode, sizeof(struct s2255_mode)); |
1231 | dev->setmode_ready[chn] = 0; | 1247 | channel->setmode_ready = 0; |
1232 | res = s2255_write_config(dev->udev, (unsigned char *)buffer, 512); | 1248 | res = s2255_write_config(dev->udev, (unsigned char *)buffer, 512); |
1233 | if (debug) | 1249 | if (debug) |
1234 | s2255_print_cfg(dev, mode); | 1250 | s2255_print_cfg(dev, mode); |
1235 | kfree(buffer); | 1251 | kfree(buffer); |
1236 | /* wait at least 3 frames before continuing */ | 1252 | /* wait at least 3 frames before continuing */ |
1237 | if (mode->restart) { | 1253 | if (mode->restart) { |
1238 | wait_event_timeout(dev->wait_setmode[chn], | 1254 | wait_event_timeout(channel->wait_setmode, |
1239 | (dev->setmode_ready[chn] != 0), | 1255 | (channel->setmode_ready != 0), |
1240 | msecs_to_jiffies(S2255_SETMODE_TIMEOUT)); | 1256 | msecs_to_jiffies(S2255_SETMODE_TIMEOUT)); |
1241 | if (dev->setmode_ready[chn] != 1) { | 1257 | if (channel->setmode_ready != 1) { |
1242 | printk(KERN_DEBUG "s2255: no set mode response\n"); | 1258 | printk(KERN_DEBUG "s2255: no set mode response\n"); |
1243 | res = -EFAULT; | 1259 | res = -EFAULT; |
1244 | } | 1260 | } |
1245 | } | 1261 | } |
1246 | /* clear the restart flag */ | 1262 | /* clear the restart flag */ |
1247 | dev->mode[chn].restart = 0; | 1263 | channel->mode.restart = 0; |
1248 | mutex_unlock(&dev->lock); | 1264 | mutex_unlock(&dev->lock); |
1249 | dprintk(1, "%s chn %lu, result: %d\n", __func__, chn, res); | 1265 | dprintk(1, "%s chn %d, result: %d\n", __func__, channel->idx, res); |
1250 | return res; | 1266 | return res; |
1251 | } | 1267 | } |
1252 | 1268 | ||
1253 | static int s2255_cmd_status(struct s2255_dev *dev, unsigned long chn, | 1269 | static int s2255_cmd_status(struct s2255_channel *channel, u32 *pstatus) |
1254 | u32 *pstatus) | ||
1255 | { | 1270 | { |
1256 | int res; | 1271 | int res; |
1257 | __le32 *buffer; | 1272 | __le32 *buffer; |
1258 | u32 chn_rev; | 1273 | u32 chn_rev; |
1274 | struct s2255_dev *dev = to_s2255_dev(channel->vdev.v4l2_dev); | ||
1259 | mutex_lock(&dev->lock); | 1275 | mutex_lock(&dev->lock); |
1260 | chn_rev = G_chnmap[chn]; | 1276 | chn_rev = G_chnmap[channel->idx]; |
1261 | dprintk(4, "%s chan %lu\n", __func__, chn); | 1277 | dprintk(4, "%s chan %d\n", __func__, channel->idx); |
1262 | buffer = kzalloc(512, GFP_KERNEL); | 1278 | buffer = kzalloc(512, GFP_KERNEL); |
1263 | if (buffer == NULL) { | 1279 | if (buffer == NULL) { |
1264 | dev_err(&dev->udev->dev, "out of mem\n"); | 1280 | dev_err(&dev->udev->dev, "out of mem\n"); |
@@ -1270,17 +1286,17 @@ static int s2255_cmd_status(struct s2255_dev *dev, unsigned long chn, | |||
1270 | buffer[1] = (__le32) cpu_to_le32(chn_rev); | 1286 | buffer[1] = (__le32) cpu_to_le32(chn_rev); |
1271 | buffer[2] = CMD_STATUS; | 1287 | buffer[2] = CMD_STATUS; |
1272 | *pstatus = 0; | 1288 | *pstatus = 0; |
1273 | dev->vidstatus_ready[chn] = 0; | 1289 | channel->vidstatus_ready = 0; |
1274 | res = s2255_write_config(dev->udev, (unsigned char *)buffer, 512); | 1290 | res = s2255_write_config(dev->udev, (unsigned char *)buffer, 512); |
1275 | kfree(buffer); | 1291 | kfree(buffer); |
1276 | wait_event_timeout(dev->wait_vidstatus[chn], | 1292 | wait_event_timeout(channel->wait_vidstatus, |
1277 | (dev->vidstatus_ready[chn] != 0), | 1293 | (channel->vidstatus_ready != 0), |
1278 | msecs_to_jiffies(S2255_VIDSTATUS_TIMEOUT)); | 1294 | msecs_to_jiffies(S2255_VIDSTATUS_TIMEOUT)); |
1279 | if (dev->vidstatus_ready[chn] != 1) { | 1295 | if (channel->vidstatus_ready != 1) { |
1280 | printk(KERN_DEBUG "s2255: no vidstatus response\n"); | 1296 | printk(KERN_DEBUG "s2255: no vidstatus response\n"); |
1281 | res = -EFAULT; | 1297 | res = -EFAULT; |
1282 | } | 1298 | } |
1283 | *pstatus = dev->vidstatus[chn]; | 1299 | *pstatus = channel->vidstatus; |
1284 | dprintk(4, "%s, vid status %d\n", __func__, *pstatus); | 1300 | dprintk(4, "%s, vid status %d\n", __func__, *pstatus); |
1285 | mutex_unlock(&dev->lock); | 1301 | mutex_unlock(&dev->lock); |
1286 | return res; | 1302 | return res; |
@@ -1291,9 +1307,7 @@ static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i) | |||
1291 | int res; | 1307 | int res; |
1292 | struct s2255_fh *fh = priv; | 1308 | struct s2255_fh *fh = priv; |
1293 | struct s2255_dev *dev = fh->dev; | 1309 | struct s2255_dev *dev = fh->dev; |
1294 | struct s2255_mode *new_mode; | 1310 | struct s2255_channel *channel = fh->channel; |
1295 | struct s2255_mode *old_mode; | ||
1296 | int chn; | ||
1297 | int j; | 1311 | int j; |
1298 | dprintk(4, "%s\n", __func__); | 1312 | dprintk(4, "%s\n", __func__); |
1299 | if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) { | 1313 | if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) { |
@@ -1305,51 +1319,32 @@ static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i) | |||
1305 | return -EINVAL; | 1319 | return -EINVAL; |
1306 | } | 1320 | } |
1307 | 1321 | ||
1308 | if (!res_get(dev, fh)) { | 1322 | if (!res_get(fh)) { |
1309 | s2255_dev_err(&dev->udev->dev, "stream busy\n"); | 1323 | s2255_dev_err(&dev->udev->dev, "stream busy\n"); |
1310 | return -EBUSY; | 1324 | return -EBUSY; |
1311 | } | 1325 | } |
1312 | 1326 | channel->last_frame = -1; | |
1313 | /* send a set mode command everytime with restart. | 1327 | channel->bad_payload = 0; |
1314 | in case we switch resolutions or other parameters */ | 1328 | channel->cur_frame = 0; |
1315 | chn = fh->channel; | 1329 | channel->frame_count = 0; |
1316 | new_mode = &fh->mode; | ||
1317 | old_mode = &fh->dev->mode[chn]; | ||
1318 | |||
1319 | if ((new_mode->color & MASK_COLOR) != (old_mode->color & MASK_COLOR)) | ||
1320 | new_mode->restart = 1; | ||
1321 | else if (new_mode->scale != old_mode->scale) | ||
1322 | new_mode->restart = 1; | ||
1323 | else if (new_mode->format != old_mode->format) | ||
1324 | new_mode->restart = 1; | ||
1325 | |||
1326 | s2255_set_mode(dev, chn, new_mode); | ||
1327 | new_mode->restart = 0; | ||
1328 | *old_mode = *new_mode; | ||
1329 | dev->cur_fmt[chn] = fh->fmt; | ||
1330 | dev->last_frame[chn] = -1; | ||
1331 | dev->bad_payload[chn] = 0; | ||
1332 | dev->cur_frame[chn] = 0; | ||
1333 | dev->frame_count[chn] = 0; | ||
1334 | for (j = 0; j < SYS_FRAMES; j++) { | 1330 | for (j = 0; j < SYS_FRAMES; j++) { |
1335 | dev->buffer[chn].frame[j].ulState = S2255_READ_IDLE; | 1331 | channel->buffer.frame[j].ulState = S2255_READ_IDLE; |
1336 | dev->buffer[chn].frame[j].cur_size = 0; | 1332 | channel->buffer.frame[j].cur_size = 0; |
1337 | } | 1333 | } |
1338 | res = videobuf_streamon(&fh->vb_vidq); | 1334 | res = videobuf_streamon(&fh->vb_vidq); |
1339 | if (res == 0) { | 1335 | if (res == 0) { |
1340 | s2255_start_acquire(dev, chn); | 1336 | s2255_start_acquire(channel); |
1341 | dev->b_acquire[chn] = 1; | 1337 | channel->b_acquire = 1; |
1342 | } else { | 1338 | } else |
1343 | res_free(dev, fh); | 1339 | res_free(fh); |
1344 | } | 1340 | |
1345 | return res; | 1341 | return res; |
1346 | } | 1342 | } |
1347 | 1343 | ||
1348 | static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i) | 1344 | static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i) |
1349 | { | 1345 | { |
1350 | struct s2255_fh *fh = priv; | 1346 | struct s2255_fh *fh = priv; |
1351 | struct s2255_dev *dev = fh->dev; | 1347 | dprintk(4, "%s\n, channel: %d", __func__, fh->channel->idx); |
1352 | dprintk(4, "%s\n, channel: %d", __func__, fh->channel); | ||
1353 | if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) { | 1348 | if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) { |
1354 | printk(KERN_ERR "invalid fh type0\n"); | 1349 | printk(KERN_ERR "invalid fh type0\n"); |
1355 | return -EINVAL; | 1350 | return -EINVAL; |
@@ -1358,16 +1353,16 @@ static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i) | |||
1358 | printk(KERN_ERR "invalid type i\n"); | 1353 | printk(KERN_ERR "invalid type i\n"); |
1359 | return -EINVAL; | 1354 | return -EINVAL; |
1360 | } | 1355 | } |
1361 | s2255_stop_acquire(dev, fh->channel); | 1356 | s2255_stop_acquire(fh->channel); |
1362 | videobuf_streamoff(&fh->vb_vidq); | 1357 | videobuf_streamoff(&fh->vb_vidq); |
1363 | res_free(dev, fh); | 1358 | res_free(fh); |
1364 | return 0; | 1359 | return 0; |
1365 | } | 1360 | } |
1366 | 1361 | ||
1367 | static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *i) | 1362 | static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *i) |
1368 | { | 1363 | { |
1369 | struct s2255_fh *fh = priv; | 1364 | struct s2255_fh *fh = priv; |
1370 | struct s2255_mode *mode; | 1365 | struct s2255_mode mode; |
1371 | struct videobuf_queue *q = &fh->vb_vidq; | 1366 | struct videobuf_queue *q = &fh->vb_vidq; |
1372 | int ret = 0; | 1367 | int ret = 0; |
1373 | mutex_lock(&q->vb_lock); | 1368 | mutex_lock(&q->vb_lock); |
@@ -1376,29 +1371,32 @@ static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *i) | |||
1376 | ret = -EBUSY; | 1371 | ret = -EBUSY; |
1377 | goto out_s_std; | 1372 | goto out_s_std; |
1378 | } | 1373 | } |
1379 | if (res_locked(fh->dev, fh)) { | 1374 | if (res_locked(fh)) { |
1380 | dprintk(1, "can't change standard after started\n"); | 1375 | dprintk(1, "can't change standard after started\n"); |
1381 | ret = -EBUSY; | 1376 | ret = -EBUSY; |
1382 | goto out_s_std; | 1377 | goto out_s_std; |
1383 | } | 1378 | } |
1384 | mode = &fh->mode; | 1379 | mode = fh->channel->mode; |
1385 | if (*i & V4L2_STD_NTSC) { | 1380 | if (*i & V4L2_STD_NTSC) { |
1386 | dprintk(4, "%s NTSC\n", __func__); | 1381 | dprintk(4, "%s NTSC\n", __func__); |
1387 | /* if changing format, reset frame decimation/intervals */ | 1382 | /* if changing format, reset frame decimation/intervals */ |
1388 | if (mode->format != FORMAT_NTSC) { | 1383 | if (mode.format != FORMAT_NTSC) { |
1389 | mode->format = FORMAT_NTSC; | 1384 | mode.restart = 1; |
1390 | mode->fdec = FDEC_1; | 1385 | mode.format = FORMAT_NTSC; |
1386 | mode.fdec = FDEC_1; | ||
1391 | } | 1387 | } |
1392 | } else if (*i & V4L2_STD_PAL) { | 1388 | } else if (*i & V4L2_STD_PAL) { |
1393 | dprintk(4, "%s PAL\n", __func__); | 1389 | dprintk(4, "%s PAL\n", __func__); |
1394 | mode->format = FORMAT_PAL; | 1390 | if (mode.format != FORMAT_PAL) { |
1395 | if (mode->format != FORMAT_PAL) { | 1391 | mode.restart = 1; |
1396 | mode->format = FORMAT_PAL; | 1392 | mode.format = FORMAT_PAL; |
1397 | mode->fdec = FDEC_1; | 1393 | mode.fdec = FDEC_1; |
1398 | } | 1394 | } |
1399 | } else { | 1395 | } else { |
1400 | ret = -EINVAL; | 1396 | ret = -EINVAL; |
1401 | } | 1397 | } |
1398 | if (mode.restart) | ||
1399 | s2255_set_mode(fh->channel, &mode); | ||
1402 | out_s_std: | 1400 | out_s_std: |
1403 | mutex_unlock(&q->vb_lock); | 1401 | mutex_unlock(&q->vb_lock); |
1404 | return ret; | 1402 | return ret; |
@@ -1416,6 +1414,7 @@ static int vidioc_enum_input(struct file *file, void *priv, | |||
1416 | { | 1414 | { |
1417 | struct s2255_fh *fh = priv; | 1415 | struct s2255_fh *fh = priv; |
1418 | struct s2255_dev *dev = fh->dev; | 1416 | struct s2255_dev *dev = fh->dev; |
1417 | struct s2255_channel *channel = fh->channel; | ||
1419 | u32 status = 0; | 1418 | u32 status = 0; |
1420 | if (inp->index != 0) | 1419 | if (inp->index != 0) |
1421 | return -EINVAL; | 1420 | return -EINVAL; |
@@ -1424,7 +1423,7 @@ static int vidioc_enum_input(struct file *file, void *priv, | |||
1424 | inp->status = 0; | 1423 | inp->status = 0; |
1425 | if (dev->dsp_fw_ver >= S2255_MIN_DSP_STATUS) { | 1424 | if (dev->dsp_fw_ver >= S2255_MIN_DSP_STATUS) { |
1426 | int rc; | 1425 | int rc; |
1427 | rc = s2255_cmd_status(dev, fh->channel, &status); | 1426 | rc = s2255_cmd_status(fh->channel, &status); |
1428 | dprintk(4, "s2255_cmd_status rc: %d status %x\n", rc, status); | 1427 | dprintk(4, "s2255_cmd_status rc: %d status %x\n", rc, status); |
1429 | if (rc == 0) | 1428 | if (rc == 0) |
1430 | inp->status = (status & 0x01) ? 0 | 1429 | inp->status = (status & 0x01) ? 0 |
@@ -1436,7 +1435,7 @@ static int vidioc_enum_input(struct file *file, void *priv, | |||
1436 | strlcpy(inp->name, "Composite", sizeof(inp->name)); | 1435 | strlcpy(inp->name, "Composite", sizeof(inp->name)); |
1437 | break; | 1436 | break; |
1438 | case 0x2257: | 1437 | case 0x2257: |
1439 | strlcpy(inp->name, (fh->channel < 2) ? "Composite" : "S-Video", | 1438 | strlcpy(inp->name, (channel->idx < 2) ? "Composite" : "S-Video", |
1440 | sizeof(inp->name)); | 1439 | sizeof(inp->name)); |
1441 | break; | 1440 | break; |
1442 | } | 1441 | } |
@@ -1460,6 +1459,7 @@ static int vidioc_queryctrl(struct file *file, void *priv, | |||
1460 | struct v4l2_queryctrl *qc) | 1459 | struct v4l2_queryctrl *qc) |
1461 | { | 1460 | { |
1462 | struct s2255_fh *fh = priv; | 1461 | struct s2255_fh *fh = priv; |
1462 | struct s2255_channel *channel = fh->channel; | ||
1463 | struct s2255_dev *dev = fh->dev; | 1463 | struct s2255_dev *dev = fh->dev; |
1464 | switch (qc->id) { | 1464 | switch (qc->id) { |
1465 | case V4L2_CID_BRIGHTNESS: | 1465 | case V4L2_CID_BRIGHTNESS: |
@@ -1477,7 +1477,7 @@ static int vidioc_queryctrl(struct file *file, void *priv, | |||
1477 | case V4L2_CID_PRIVATE_COLORFILTER: | 1477 | case V4L2_CID_PRIVATE_COLORFILTER: |
1478 | if (dev->dsp_fw_ver < S2255_MIN_DSP_COLORFILTER) | 1478 | if (dev->dsp_fw_ver < S2255_MIN_DSP_COLORFILTER) |
1479 | return -EINVAL; | 1479 | return -EINVAL; |
1480 | if ((dev->pid == 0x2257) && (fh->channel > 1)) | 1480 | if ((dev->pid == 0x2257) && (channel->idx > 1)) |
1481 | return -EINVAL; | 1481 | return -EINVAL; |
1482 | strlcpy(qc->name, "Color Filter", sizeof(qc->name)); | 1482 | strlcpy(qc->name, "Color Filter", sizeof(qc->name)); |
1483 | qc->type = V4L2_CTRL_TYPE_MENU; | 1483 | qc->type = V4L2_CTRL_TYPE_MENU; |
@@ -1499,25 +1499,26 @@ static int vidioc_g_ctrl(struct file *file, void *priv, | |||
1499 | { | 1499 | { |
1500 | struct s2255_fh *fh = priv; | 1500 | struct s2255_fh *fh = priv; |
1501 | struct s2255_dev *dev = fh->dev; | 1501 | struct s2255_dev *dev = fh->dev; |
1502 | struct s2255_channel *channel = fh->channel; | ||
1502 | switch (ctrl->id) { | 1503 | switch (ctrl->id) { |
1503 | case V4L2_CID_BRIGHTNESS: | 1504 | case V4L2_CID_BRIGHTNESS: |
1504 | ctrl->value = fh->mode.bright; | 1505 | ctrl->value = channel->mode.bright; |
1505 | break; | 1506 | break; |
1506 | case V4L2_CID_CONTRAST: | 1507 | case V4L2_CID_CONTRAST: |
1507 | ctrl->value = fh->mode.contrast; | 1508 | ctrl->value = channel->mode.contrast; |
1508 | break; | 1509 | break; |
1509 | case V4L2_CID_SATURATION: | 1510 | case V4L2_CID_SATURATION: |
1510 | ctrl->value = fh->mode.saturation; | 1511 | ctrl->value = channel->mode.saturation; |
1511 | break; | 1512 | break; |
1512 | case V4L2_CID_HUE: | 1513 | case V4L2_CID_HUE: |
1513 | ctrl->value = fh->mode.hue; | 1514 | ctrl->value = channel->mode.hue; |
1514 | break; | 1515 | break; |
1515 | case V4L2_CID_PRIVATE_COLORFILTER: | 1516 | case V4L2_CID_PRIVATE_COLORFILTER: |
1516 | if (dev->dsp_fw_ver < S2255_MIN_DSP_COLORFILTER) | 1517 | if (dev->dsp_fw_ver < S2255_MIN_DSP_COLORFILTER) |
1517 | return -EINVAL; | 1518 | return -EINVAL; |
1518 | if ((dev->pid == 0x2257) && (fh->channel > 1)) | 1519 | if ((dev->pid == 0x2257) && (channel->idx > 1)) |
1519 | return -EINVAL; | 1520 | return -EINVAL; |
1520 | ctrl->value = !((fh->mode.color & MASK_INPUT_TYPE) >> 16); | 1521 | ctrl->value = !((channel->mode.color & MASK_INPUT_TYPE) >> 16); |
1521 | break; | 1522 | break; |
1522 | default: | 1523 | default: |
1523 | return -EINVAL; | 1524 | return -EINVAL; |
@@ -1530,41 +1531,42 @@ static int vidioc_s_ctrl(struct file *file, void *priv, | |||
1530 | struct v4l2_control *ctrl) | 1531 | struct v4l2_control *ctrl) |
1531 | { | 1532 | { |
1532 | struct s2255_fh *fh = priv; | 1533 | struct s2255_fh *fh = priv; |
1533 | struct s2255_dev *dev = fh->dev; | 1534 | struct s2255_channel *channel = fh->channel; |
1534 | struct s2255_mode *mode; | 1535 | struct s2255_dev *dev = to_s2255_dev(channel->vdev.v4l2_dev); |
1535 | mode = &fh->mode; | 1536 | struct s2255_mode mode; |
1537 | mode = channel->mode; | ||
1536 | dprintk(4, "%s\n", __func__); | 1538 | dprintk(4, "%s\n", __func__); |
1537 | /* update the mode to the corresponding value */ | 1539 | /* update the mode to the corresponding value */ |
1538 | switch (ctrl->id) { | 1540 | switch (ctrl->id) { |
1539 | case V4L2_CID_BRIGHTNESS: | 1541 | case V4L2_CID_BRIGHTNESS: |
1540 | mode->bright = ctrl->value; | 1542 | mode.bright = ctrl->value; |
1541 | break; | 1543 | break; |
1542 | case V4L2_CID_CONTRAST: | 1544 | case V4L2_CID_CONTRAST: |
1543 | mode->contrast = ctrl->value; | 1545 | mode.contrast = ctrl->value; |
1544 | break; | 1546 | break; |
1545 | case V4L2_CID_HUE: | 1547 | case V4L2_CID_HUE: |
1546 | mode->hue = ctrl->value; | 1548 | mode.hue = ctrl->value; |
1547 | break; | 1549 | break; |
1548 | case V4L2_CID_SATURATION: | 1550 | case V4L2_CID_SATURATION: |
1549 | mode->saturation = ctrl->value; | 1551 | mode.saturation = ctrl->value; |
1550 | break; | 1552 | break; |
1551 | case V4L2_CID_PRIVATE_COLORFILTER: | 1553 | case V4L2_CID_PRIVATE_COLORFILTER: |
1552 | if (dev->dsp_fw_ver < S2255_MIN_DSP_COLORFILTER) | 1554 | if (dev->dsp_fw_ver < S2255_MIN_DSP_COLORFILTER) |
1553 | return -EINVAL; | 1555 | return -EINVAL; |
1554 | if ((dev->pid == 0x2257) && (fh->channel > 1)) | 1556 | if ((dev->pid == 0x2257) && (channel->idx > 1)) |
1555 | return -EINVAL; | 1557 | return -EINVAL; |
1556 | mode->color &= ~MASK_INPUT_TYPE; | 1558 | mode.color &= ~MASK_INPUT_TYPE; |
1557 | mode->color |= ((ctrl->value ? 0 : 1) << 16); | 1559 | mode.color |= ((ctrl->value ? 0 : 1) << 16); |
1558 | break; | 1560 | break; |
1559 | default: | 1561 | default: |
1560 | return -EINVAL; | 1562 | return -EINVAL; |
1561 | } | 1563 | } |
1562 | mode->restart = 0; | 1564 | mode.restart = 0; |
1563 | /* set mode here. Note: stream does not need restarted. | 1565 | /* set mode here. Note: stream does not need restarted. |
1564 | some V4L programs restart stream unnecessarily | 1566 | some V4L programs restart stream unnecessarily |
1565 | after a s_crtl. | 1567 | after a s_crtl. |
1566 | */ | 1568 | */ |
1567 | s2255_set_mode(dev, fh->channel, mode); | 1569 | s2255_set_mode(fh->channel, &mode); |
1568 | return 0; | 1570 | return 0; |
1569 | } | 1571 | } |
1570 | 1572 | ||
@@ -1572,8 +1574,8 @@ static int vidioc_g_jpegcomp(struct file *file, void *priv, | |||
1572 | struct v4l2_jpegcompression *jc) | 1574 | struct v4l2_jpegcompression *jc) |
1573 | { | 1575 | { |
1574 | struct s2255_fh *fh = priv; | 1576 | struct s2255_fh *fh = priv; |
1575 | struct s2255_dev *dev = fh->dev; | 1577 | struct s2255_channel *channel = fh->channel; |
1576 | *jc = dev->jc[fh->channel]; | 1578 | *jc = channel->jc; |
1577 | dprintk(2, "%s: quality %d\n", __func__, jc->quality); | 1579 | dprintk(2, "%s: quality %d\n", __func__, jc->quality); |
1578 | return 0; | 1580 | return 0; |
1579 | } | 1581 | } |
@@ -1582,10 +1584,10 @@ static int vidioc_s_jpegcomp(struct file *file, void *priv, | |||
1582 | struct v4l2_jpegcompression *jc) | 1584 | struct v4l2_jpegcompression *jc) |
1583 | { | 1585 | { |
1584 | struct s2255_fh *fh = priv; | 1586 | struct s2255_fh *fh = priv; |
1585 | struct s2255_dev *dev = fh->dev; | 1587 | struct s2255_channel *channel = fh->channel; |
1586 | if (jc->quality < 0 || jc->quality > 100) | 1588 | if (jc->quality < 0 || jc->quality > 100) |
1587 | return -EINVAL; | 1589 | return -EINVAL; |
1588 | dev->jc[fh->channel].quality = jc->quality; | 1590 | channel->jc.quality = jc->quality; |
1589 | dprintk(2, "%s: quality %d\n", __func__, jc->quality); | 1591 | dprintk(2, "%s: quality %d\n", __func__, jc->quality); |
1590 | return 0; | 1592 | return 0; |
1591 | } | 1593 | } |
@@ -1594,17 +1596,17 @@ static int vidioc_g_parm(struct file *file, void *priv, | |||
1594 | struct v4l2_streamparm *sp) | 1596 | struct v4l2_streamparm *sp) |
1595 | { | 1597 | { |
1596 | struct s2255_fh *fh = priv; | 1598 | struct s2255_fh *fh = priv; |
1597 | struct s2255_dev *dev = fh->dev; | ||
1598 | __u32 def_num, def_dem; | 1599 | __u32 def_num, def_dem; |
1600 | struct s2255_channel *channel = fh->channel; | ||
1599 | if (sp->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) | 1601 | if (sp->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
1600 | return -EINVAL; | 1602 | return -EINVAL; |
1601 | memset(sp, 0, sizeof(struct v4l2_streamparm)); | 1603 | memset(sp, 0, sizeof(struct v4l2_streamparm)); |
1602 | sp->parm.capture.capability = V4L2_CAP_TIMEPERFRAME; | 1604 | sp->parm.capture.capability = V4L2_CAP_TIMEPERFRAME; |
1603 | sp->parm.capture.capturemode = dev->cap_parm[fh->channel].capturemode; | 1605 | sp->parm.capture.capturemode = channel->cap_parm.capturemode; |
1604 | def_num = (fh->mode.format == FORMAT_NTSC) ? 1001 : 1000; | 1606 | def_num = (channel->mode.format == FORMAT_NTSC) ? 1001 : 1000; |
1605 | def_dem = (fh->mode.format == FORMAT_NTSC) ? 30000 : 25000; | 1607 | def_dem = (channel->mode.format == FORMAT_NTSC) ? 30000 : 25000; |
1606 | sp->parm.capture.timeperframe.denominator = def_dem; | 1608 | sp->parm.capture.timeperframe.denominator = def_dem; |
1607 | switch (fh->mode.fdec) { | 1609 | switch (channel->mode.fdec) { |
1608 | default: | 1610 | default: |
1609 | case FDEC_1: | 1611 | case FDEC_1: |
1610 | sp->parm.capture.timeperframe.numerator = def_num; | 1612 | sp->parm.capture.timeperframe.numerator = def_num; |
@@ -1630,17 +1632,19 @@ static int vidioc_s_parm(struct file *file, void *priv, | |||
1630 | struct v4l2_streamparm *sp) | 1632 | struct v4l2_streamparm *sp) |
1631 | { | 1633 | { |
1632 | struct s2255_fh *fh = priv; | 1634 | struct s2255_fh *fh = priv; |
1633 | struct s2255_dev *dev = fh->dev; | 1635 | struct s2255_channel *channel = fh->channel; |
1636 | struct s2255_mode mode; | ||
1634 | int fdec = FDEC_1; | 1637 | int fdec = FDEC_1; |
1635 | __u32 def_num, def_dem; | 1638 | __u32 def_num, def_dem; |
1636 | if (sp->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) | 1639 | if (sp->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
1637 | return -EINVAL; | 1640 | return -EINVAL; |
1641 | mode = channel->mode; | ||
1638 | /* high quality capture mode requires a stream restart */ | 1642 | /* high quality capture mode requires a stream restart */ |
1639 | if (dev->cap_parm[fh->channel].capturemode | 1643 | if (channel->cap_parm.capturemode |
1640 | != sp->parm.capture.capturemode && res_locked(fh->dev, fh)) | 1644 | != sp->parm.capture.capturemode && res_locked(fh)) |
1641 | return -EBUSY; | 1645 | return -EBUSY; |
1642 | def_num = (fh->mode.format == FORMAT_NTSC) ? 1001 : 1000; | 1646 | def_num = (mode.format == FORMAT_NTSC) ? 1001 : 1000; |
1643 | def_dem = (fh->mode.format == FORMAT_NTSC) ? 30000 : 25000; | 1647 | def_dem = (mode.format == FORMAT_NTSC) ? 30000 : 25000; |
1644 | if (def_dem != sp->parm.capture.timeperframe.denominator) | 1648 | if (def_dem != sp->parm.capture.timeperframe.denominator) |
1645 | sp->parm.capture.timeperframe.numerator = def_num; | 1649 | sp->parm.capture.timeperframe.numerator = def_num; |
1646 | else if (sp->parm.capture.timeperframe.numerator <= def_num) | 1650 | else if (sp->parm.capture.timeperframe.numerator <= def_num) |
@@ -1655,9 +1659,9 @@ static int vidioc_s_parm(struct file *file, void *priv, | |||
1655 | sp->parm.capture.timeperframe.numerator = def_num * 5; | 1659 | sp->parm.capture.timeperframe.numerator = def_num * 5; |
1656 | fdec = FDEC_5; | 1660 | fdec = FDEC_5; |
1657 | } | 1661 | } |
1658 | fh->mode.fdec = fdec; | 1662 | mode.fdec = fdec; |
1659 | sp->parm.capture.timeperframe.denominator = def_dem; | 1663 | sp->parm.capture.timeperframe.denominator = def_dem; |
1660 | s2255_set_mode(dev, fh->channel, &fh->mode); | 1664 | s2255_set_mode(channel, &mode); |
1661 | dprintk(4, "%s capture mode, %d timeperframe %d/%d, fdec %d\n", | 1665 | dprintk(4, "%s capture mode, %d timeperframe %d/%d, fdec %d\n", |
1662 | __func__, | 1666 | __func__, |
1663 | sp->parm.capture.capturemode, | 1667 | sp->parm.capture.capturemode, |
@@ -1707,24 +1711,13 @@ static int vidioc_enum_frameintervals(struct file *file, void *priv, | |||
1707 | static int s2255_open(struct file *file) | 1711 | static int s2255_open(struct file *file) |
1708 | { | 1712 | { |
1709 | struct video_device *vdev = video_devdata(file); | 1713 | struct video_device *vdev = video_devdata(file); |
1710 | struct s2255_dev *dev = video_drvdata(file); | 1714 | struct s2255_channel *channel = video_drvdata(file); |
1715 | struct s2255_dev *dev = to_s2255_dev(vdev->v4l2_dev); | ||
1711 | struct s2255_fh *fh; | 1716 | struct s2255_fh *fh; |
1712 | enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE; | 1717 | enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
1713 | int i = 0; | ||
1714 | int cur_channel = -1; | ||
1715 | int state; | 1718 | int state; |
1716 | dprintk(1, "s2255: open called (dev=%s)\n", | 1719 | dprintk(1, "s2255: open called (dev=%s)\n", |
1717 | video_device_node_name(vdev)); | 1720 | video_device_node_name(vdev)); |
1718 | |||
1719 | for (i = 0; i < MAX_CHANNELS; i++) { | ||
1720 | if (&dev->vdev[i] == vdev) { | ||
1721 | cur_channel = i; | ||
1722 | break; | ||
1723 | } | ||
1724 | } | ||
1725 | if (i == MAX_CHANNELS) | ||
1726 | return -ENODEV; | ||
1727 | |||
1728 | /* | 1721 | /* |
1729 | * open lock necessary to prevent multiple instances | 1722 | * open lock necessary to prevent multiple instances |
1730 | * of v4l-conf (or other programs) from simultaneously | 1723 | * of v4l-conf (or other programs) from simultaneously |
@@ -1806,24 +1799,20 @@ static int s2255_open(struct file *file) | |||
1806 | file->private_data = fh; | 1799 | file->private_data = fh; |
1807 | fh->dev = dev; | 1800 | fh->dev = dev; |
1808 | fh->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; | 1801 | fh->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
1809 | fh->mode = dev->mode[cur_channel]; | 1802 | fh->channel = channel; |
1810 | fh->fmt = dev->cur_fmt[cur_channel]; | 1803 | if (!channel->configured) { |
1811 | /* default 4CIF NTSC */ | 1804 | /* configure channel to default state */ |
1812 | fh->width = LINE_SZ_4CIFS_NTSC; | 1805 | channel->fmt = &formats[0]; |
1813 | fh->height = NUM_LINES_4CIFS_NTSC * 2; | 1806 | s2255_set_mode(channel, &channel->mode); |
1814 | fh->channel = cur_channel; | 1807 | channel->configured = 1; |
1815 | /* configure channel to default state */ | ||
1816 | if (!dev->chn_configured[cur_channel]) { | ||
1817 | s2255_set_mode(dev, cur_channel, &fh->mode); | ||
1818 | dev->chn_configured[cur_channel] = 1; | ||
1819 | } | 1808 | } |
1820 | dprintk(1, "%s: dev=%s type=%s\n", __func__, | 1809 | dprintk(1, "%s: dev=%s type=%s\n", __func__, |
1821 | video_device_node_name(vdev), v4l2_type_names[type]); | 1810 | video_device_node_name(vdev), v4l2_type_names[type]); |
1822 | dprintk(2, "%s: fh=0x%08lx, dev=0x%08lx, vidq=0x%08lx\n", __func__, | 1811 | dprintk(2, "%s: fh=0x%08lx, dev=0x%08lx, vidq=0x%08lx\n", __func__, |
1823 | (unsigned long)fh, (unsigned long)dev, | 1812 | (unsigned long)fh, (unsigned long)dev, |
1824 | (unsigned long)&dev->vidq[cur_channel]); | 1813 | (unsigned long)&channel->vidq); |
1825 | dprintk(4, "%s: list_empty active=%d\n", __func__, | 1814 | dprintk(4, "%s: list_empty active=%d\n", __func__, |
1826 | list_empty(&dev->vidq[cur_channel].active)); | 1815 | list_empty(&channel->vidq.active)); |
1827 | videobuf_queue_vmalloc_init(&fh->vb_vidq, &s2255_video_qops, | 1816 | videobuf_queue_vmalloc_init(&fh->vb_vidq, &s2255_video_qops, |
1828 | NULL, &dev->slock, | 1817 | NULL, &dev->slock, |
1829 | fh->type, | 1818 | fh->type, |
@@ -1865,6 +1854,7 @@ static void s2255_destroy(struct s2255_dev *dev) | |||
1865 | mutex_destroy(&dev->open_lock); | 1854 | mutex_destroy(&dev->open_lock); |
1866 | mutex_destroy(&dev->lock); | 1855 | mutex_destroy(&dev->lock); |
1867 | usb_put_dev(dev->udev); | 1856 | usb_put_dev(dev->udev); |
1857 | v4l2_device_unregister(&dev->v4l2_dev); | ||
1868 | dprintk(1, "%s", __func__); | 1858 | dprintk(1, "%s", __func__); |
1869 | kfree(dev); | 1859 | kfree(dev); |
1870 | } | 1860 | } |
@@ -1874,14 +1864,15 @@ static int s2255_release(struct file *file) | |||
1874 | struct s2255_fh *fh = file->private_data; | 1864 | struct s2255_fh *fh = file->private_data; |
1875 | struct s2255_dev *dev = fh->dev; | 1865 | struct s2255_dev *dev = fh->dev; |
1876 | struct video_device *vdev = video_devdata(file); | 1866 | struct video_device *vdev = video_devdata(file); |
1867 | struct s2255_channel *channel = fh->channel; | ||
1877 | if (!dev) | 1868 | if (!dev) |
1878 | return -ENODEV; | 1869 | return -ENODEV; |
1879 | /* turn off stream */ | 1870 | /* turn off stream */ |
1880 | if (res_check(fh)) { | 1871 | if (res_check(fh)) { |
1881 | if (dev->b_acquire[fh->channel]) | 1872 | if (channel->b_acquire) |
1882 | s2255_stop_acquire(dev, fh->channel); | 1873 | s2255_stop_acquire(fh->channel); |
1883 | videobuf_streamoff(&fh->vb_vidq); | 1874 | videobuf_streamoff(&fh->vb_vidq); |
1884 | res_free(dev, fh); | 1875 | res_free(fh); |
1885 | } | 1876 | } |
1886 | videobuf_mmap_free(&fh->vb_vidq); | 1877 | videobuf_mmap_free(&fh->vb_vidq); |
1887 | dprintk(1, "%s (dev=%s)\n", __func__, video_device_node_name(vdev)); | 1878 | dprintk(1, "%s (dev=%s)\n", __func__, video_device_node_name(vdev)); |
@@ -1945,9 +1936,10 @@ static const struct v4l2_ioctl_ops s2255_ioctl_ops = { | |||
1945 | 1936 | ||
1946 | static void s2255_video_device_release(struct video_device *vdev) | 1937 | static void s2255_video_device_release(struct video_device *vdev) |
1947 | { | 1938 | { |
1948 | struct s2255_dev *dev = video_get_drvdata(vdev); | 1939 | struct s2255_dev *dev = to_s2255_dev(vdev->v4l2_dev); |
1949 | dprintk(4, "%s, chnls: %d \n", __func__, atomic_read(&dev->channels)); | 1940 | dprintk(4, "%s, chnls: %d \n", __func__, |
1950 | if (atomic_dec_and_test(&dev->channels)) | 1941 | atomic_read(&dev->num_channels)); |
1942 | if (atomic_dec_and_test(&dev->num_channels)) | ||
1951 | s2255_destroy(dev); | 1943 | s2255_destroy(dev); |
1952 | return; | 1944 | return; |
1953 | } | 1945 | } |
@@ -1966,47 +1958,48 @@ static int s2255_probe_v4l(struct s2255_dev *dev) | |||
1966 | int ret; | 1958 | int ret; |
1967 | int i; | 1959 | int i; |
1968 | int cur_nr = video_nr; | 1960 | int cur_nr = video_nr; |
1961 | struct s2255_channel *channel; | ||
1969 | ret = v4l2_device_register(&dev->interface->dev, &dev->v4l2_dev); | 1962 | ret = v4l2_device_register(&dev->interface->dev, &dev->v4l2_dev); |
1970 | if (ret) | 1963 | if (ret) |
1971 | return ret; | 1964 | return ret; |
1972 | /* initialize all video 4 linux */ | 1965 | /* initialize all video 4 linux */ |
1973 | /* register 4 video devices */ | 1966 | /* register 4 video devices */ |
1974 | for (i = 0; i < MAX_CHANNELS; i++) { | 1967 | for (i = 0; i < MAX_CHANNELS; i++) { |
1975 | INIT_LIST_HEAD(&dev->vidq[i].active); | 1968 | channel = &dev->channel[i]; |
1976 | dev->vidq[i].dev = dev; | 1969 | INIT_LIST_HEAD(&channel->vidq.active); |
1977 | dev->vidq[i].channel = i; | 1970 | channel->vidq.dev = dev; |
1978 | /* register 4 video devices */ | 1971 | /* register 4 video devices */ |
1979 | memcpy(&dev->vdev[i], &template, sizeof(struct video_device)); | 1972 | channel->vdev = template; |
1980 | dev->vdev[i].v4l2_dev = &dev->v4l2_dev; | 1973 | channel->vdev.v4l2_dev = &dev->v4l2_dev; |
1981 | video_set_drvdata(&dev->vdev[i], dev); | 1974 | video_set_drvdata(&channel->vdev, channel); |
1982 | if (video_nr == -1) | 1975 | if (video_nr == -1) |
1983 | ret = video_register_device(&dev->vdev[i], | 1976 | ret = video_register_device(&channel->vdev, |
1984 | VFL_TYPE_GRABBER, | 1977 | VFL_TYPE_GRABBER, |
1985 | video_nr); | 1978 | video_nr); |
1986 | else | 1979 | else |
1987 | ret = video_register_device(&dev->vdev[i], | 1980 | ret = video_register_device(&channel->vdev, |
1988 | VFL_TYPE_GRABBER, | 1981 | VFL_TYPE_GRABBER, |
1989 | cur_nr + i); | 1982 | cur_nr + i); |
1983 | |||
1990 | if (ret) { | 1984 | if (ret) { |
1991 | dev_err(&dev->udev->dev, | 1985 | dev_err(&dev->udev->dev, |
1992 | "failed to register video device!\n"); | 1986 | "failed to register video device!\n"); |
1993 | break; | 1987 | break; |
1994 | } | 1988 | } |
1995 | atomic_inc(&dev->channels); | 1989 | atomic_inc(&dev->num_channels); |
1996 | v4l2_info(&dev->v4l2_dev, "V4L2 device registered as %s\n", | 1990 | v4l2_info(&dev->v4l2_dev, "V4L2 device registered as %s\n", |
1997 | video_device_node_name(&dev->vdev[i])); | 1991 | video_device_node_name(&channel->vdev)); |
1998 | 1992 | ||
1999 | } | 1993 | } |
2000 | |||
2001 | printk(KERN_INFO "Sensoray 2255 V4L driver Revision: %d.%d\n", | 1994 | printk(KERN_INFO "Sensoray 2255 V4L driver Revision: %d.%d\n", |
2002 | S2255_MAJOR_VERSION, | 1995 | S2255_MAJOR_VERSION, |
2003 | S2255_MINOR_VERSION); | 1996 | S2255_MINOR_VERSION); |
2004 | /* if no channels registered, return error and probe will fail*/ | 1997 | /* if no channels registered, return error and probe will fail*/ |
2005 | if (atomic_read(&dev->channels) == 0) { | 1998 | if (atomic_read(&dev->num_channels) == 0) { |
2006 | v4l2_device_unregister(&dev->v4l2_dev); | 1999 | v4l2_device_unregister(&dev->v4l2_dev); |
2007 | return ret; | 2000 | return ret; |
2008 | } | 2001 | } |
2009 | if (atomic_read(&dev->channels) != MAX_CHANNELS) | 2002 | if (atomic_read(&dev->num_channels) != MAX_CHANNELS) |
2010 | printk(KERN_WARNING "s2255: Not all channels available.\n"); | 2003 | printk(KERN_WARNING "s2255: Not all channels available.\n"); |
2011 | return 0; | 2004 | return 0; |
2012 | } | 2005 | } |
@@ -2033,12 +2026,11 @@ static int save_frame(struct s2255_dev *dev, struct s2255_pipeinfo *pipe_info) | |||
2033 | s32 idx = -1; | 2026 | s32 idx = -1; |
2034 | struct s2255_framei *frm; | 2027 | struct s2255_framei *frm; |
2035 | unsigned char *pdata; | 2028 | unsigned char *pdata; |
2036 | 2029 | struct s2255_channel *channel; | |
2037 | dprintk(100, "buffer to user\n"); | 2030 | dprintk(100, "buffer to user\n"); |
2038 | 2031 | channel = &dev->channel[dev->cc]; | |
2039 | idx = dev->cur_frame[dev->cc]; | 2032 | idx = channel->cur_frame; |
2040 | frm = &dev->buffer[dev->cc].frame[idx]; | 2033 | frm = &channel->buffer.frame[idx]; |
2041 | |||
2042 | if (frm->ulState == S2255_READ_IDLE) { | 2034 | if (frm->ulState == S2255_READ_IDLE) { |
2043 | int jj; | 2035 | int jj; |
2044 | unsigned int cc; | 2036 | unsigned int cc; |
@@ -2063,16 +2055,18 @@ static int save_frame(struct s2255_dev *dev, struct s2255_pipeinfo *pipe_info) | |||
2063 | } | 2055 | } |
2064 | /* reverse it */ | 2056 | /* reverse it */ |
2065 | dev->cc = G_chnmap[cc]; | 2057 | dev->cc = G_chnmap[cc]; |
2058 | channel = &dev->channel[dev->cc]; | ||
2066 | payload = pdword[3]; | 2059 | payload = pdword[3]; |
2067 | if (payload > dev->req_image_size[dev->cc]) { | 2060 | if (payload > channel->req_image_size) { |
2068 | dev->bad_payload[dev->cc]++; | 2061 | channel->bad_payload++; |
2069 | /* discard the bad frame */ | 2062 | /* discard the bad frame */ |
2070 | return -EINVAL; | 2063 | return -EINVAL; |
2071 | } | 2064 | } |
2072 | dev->pkt_size[dev->cc] = payload; | 2065 | channel->pkt_size = payload; |
2073 | dev->jpg_size[dev->cc] = pdword[4]; | 2066 | channel->jpg_size = pdword[4]; |
2074 | break; | 2067 | break; |
2075 | case S2255_MARKER_RESPONSE: | 2068 | case S2255_MARKER_RESPONSE: |
2069 | |||
2076 | pdata += DEF_USB_BLOCK; | 2070 | pdata += DEF_USB_BLOCK; |
2077 | jj += DEF_USB_BLOCK; | 2071 | jj += DEF_USB_BLOCK; |
2078 | if (pdword[1] >= MAX_CHANNELS) | 2072 | if (pdword[1] >= MAX_CHANNELS) |
@@ -2080,12 +2074,13 @@ static int save_frame(struct s2255_dev *dev, struct s2255_pipeinfo *pipe_info) | |||
2080 | cc = G_chnmap[pdword[1]]; | 2074 | cc = G_chnmap[pdword[1]]; |
2081 | if (cc >= MAX_CHANNELS) | 2075 | if (cc >= MAX_CHANNELS) |
2082 | break; | 2076 | break; |
2077 | channel = &dev->channel[cc]; | ||
2083 | switch (pdword[2]) { | 2078 | switch (pdword[2]) { |
2084 | case S2255_RESPONSE_SETMODE: | 2079 | case S2255_RESPONSE_SETMODE: |
2085 | /* check if channel valid */ | 2080 | /* check if channel valid */ |
2086 | /* set mode ready */ | 2081 | /* set mode ready */ |
2087 | dev->setmode_ready[cc] = 1; | 2082 | channel->setmode_ready = 1; |
2088 | wake_up(&dev->wait_setmode[cc]); | 2083 | wake_up(&channel->wait_setmode); |
2089 | dprintk(5, "setmode ready %d\n", cc); | 2084 | dprintk(5, "setmode ready %d\n", cc); |
2090 | break; | 2085 | break; |
2091 | case S2255_RESPONSE_FW: | 2086 | case S2255_RESPONSE_FW: |
@@ -2099,9 +2094,9 @@ static int save_frame(struct s2255_dev *dev, struct s2255_pipeinfo *pipe_info) | |||
2099 | wake_up(&dev->fw_data->wait_fw); | 2094 | wake_up(&dev->fw_data->wait_fw); |
2100 | break; | 2095 | break; |
2101 | case S2255_RESPONSE_STATUS: | 2096 | case S2255_RESPONSE_STATUS: |
2102 | dev->vidstatus[cc] = pdword[3]; | 2097 | channel->vidstatus = pdword[3]; |
2103 | dev->vidstatus_ready[cc] = 1; | 2098 | channel->vidstatus_ready = 1; |
2104 | wake_up(&dev->wait_vidstatus[cc]); | 2099 | wake_up(&channel->wait_vidstatus); |
2105 | dprintk(5, "got vidstatus %x chan %d\n", | 2100 | dprintk(5, "got vidstatus %x chan %d\n", |
2106 | pdword[3], cc); | 2101 | pdword[3], cc); |
2107 | break; | 2102 | break; |
@@ -2118,13 +2113,11 @@ static int save_frame(struct s2255_dev *dev, struct s2255_pipeinfo *pipe_info) | |||
2118 | if (!bframe) | 2113 | if (!bframe) |
2119 | return -EINVAL; | 2114 | return -EINVAL; |
2120 | } | 2115 | } |
2121 | 2116 | channel = &dev->channel[dev->cc]; | |
2122 | 2117 | idx = channel->cur_frame; | |
2123 | idx = dev->cur_frame[dev->cc]; | 2118 | frm = &channel->buffer.frame[idx]; |
2124 | frm = &dev->buffer[dev->cc].frame[idx]; | ||
2125 | |||
2126 | /* search done. now find out if should be acquiring on this channel */ | 2119 | /* search done. now find out if should be acquiring on this channel */ |
2127 | if (!dev->b_acquire[dev->cc]) { | 2120 | if (!channel->b_acquire) { |
2128 | /* we found a frame, but this channel is turned off */ | 2121 | /* we found a frame, but this channel is turned off */ |
2129 | frm->ulState = S2255_READ_IDLE; | 2122 | frm->ulState = S2255_READ_IDLE; |
2130 | return -EINVAL; | 2123 | return -EINVAL; |
@@ -2149,30 +2142,28 @@ static int save_frame(struct s2255_dev *dev, struct s2255_pipeinfo *pipe_info) | |||
2149 | 2142 | ||
2150 | copy_size = (pipe_info->cur_transfer_size - offset); | 2143 | copy_size = (pipe_info->cur_transfer_size - offset); |
2151 | 2144 | ||
2152 | size = dev->pkt_size[dev->cc] - PREFIX_SIZE; | 2145 | size = channel->pkt_size - PREFIX_SIZE; |
2153 | 2146 | ||
2154 | /* sanity check on pdest */ | 2147 | /* sanity check on pdest */ |
2155 | if ((copy_size + frm->cur_size) < dev->req_image_size[dev->cc]) | 2148 | if ((copy_size + frm->cur_size) < channel->req_image_size) |
2156 | memcpy(pdest, psrc, copy_size); | 2149 | memcpy(pdest, psrc, copy_size); |
2157 | 2150 | ||
2158 | frm->cur_size += copy_size; | 2151 | frm->cur_size += copy_size; |
2159 | dprintk(4, "cur_size size %lu size %lu \n", frm->cur_size, size); | 2152 | dprintk(4, "cur_size size %lu size %lu \n", frm->cur_size, size); |
2160 | 2153 | ||
2161 | if (frm->cur_size >= size) { | 2154 | if (frm->cur_size >= size) { |
2162 | |||
2163 | u32 cc = dev->cc; | ||
2164 | dprintk(2, "****************[%d]Buffer[%d]full*************\n", | 2155 | dprintk(2, "****************[%d]Buffer[%d]full*************\n", |
2165 | cc, idx); | 2156 | dev->cc, idx); |
2166 | dev->last_frame[cc] = dev->cur_frame[cc]; | 2157 | channel->last_frame = channel->cur_frame; |
2167 | dev->cur_frame[cc]++; | 2158 | channel->cur_frame++; |
2168 | /* end of system frame ring buffer, start at zero */ | 2159 | /* end of system frame ring buffer, start at zero */ |
2169 | if ((dev->cur_frame[cc] == SYS_FRAMES) || | 2160 | if ((channel->cur_frame == SYS_FRAMES) || |
2170 | (dev->cur_frame[cc] == dev->buffer[cc].dwFrames)) | 2161 | (channel->cur_frame == channel->buffer.dwFrames)) |
2171 | dev->cur_frame[cc] = 0; | 2162 | channel->cur_frame = 0; |
2172 | /* frame ready */ | 2163 | /* frame ready */ |
2173 | if (dev->b_acquire[cc]) | 2164 | if (channel->b_acquire) |
2174 | s2255_got_frame(dev, cc, dev->jpg_size[cc]); | 2165 | s2255_got_frame(channel, channel->jpg_size); |
2175 | dev->frame_count[cc]++; | 2166 | channel->frame_count++; |
2176 | frm->ulState = S2255_READ_IDLE; | 2167 | frm->ulState = S2255_READ_IDLE; |
2177 | frm->cur_size = 0; | 2168 | frm->cur_size = 0; |
2178 | 2169 | ||
@@ -2245,16 +2236,12 @@ static int s2255_get_fx2fw(struct s2255_dev *dev) | |||
2245 | * Create the system ring buffer to copy frames into from the | 2236 | * Create the system ring buffer to copy frames into from the |
2246 | * usb read pipe. | 2237 | * usb read pipe. |
2247 | */ | 2238 | */ |
2248 | static int s2255_create_sys_buffers(struct s2255_dev *dev, unsigned long chn) | 2239 | static int s2255_create_sys_buffers(struct s2255_channel *channel) |
2249 | { | 2240 | { |
2250 | unsigned long i; | 2241 | unsigned long i; |
2251 | unsigned long reqsize; | 2242 | unsigned long reqsize; |
2252 | dprintk(1, "create sys buffers\n"); | 2243 | dprintk(1, "create sys buffers\n"); |
2253 | if (chn >= MAX_CHANNELS) | 2244 | channel->buffer.dwFrames = SYS_FRAMES; |
2254 | return -1; | ||
2255 | |||
2256 | dev->buffer[chn].dwFrames = SYS_FRAMES; | ||
2257 | |||
2258 | /* always allocate maximum size(PAL) for system buffers */ | 2245 | /* always allocate maximum size(PAL) for system buffers */ |
2259 | reqsize = SYS_FRAMES_MAXSIZE; | 2246 | reqsize = SYS_FRAMES_MAXSIZE; |
2260 | 2247 | ||
@@ -2263,42 +2250,40 @@ static int s2255_create_sys_buffers(struct s2255_dev *dev, unsigned long chn) | |||
2263 | 2250 | ||
2264 | for (i = 0; i < SYS_FRAMES; i++) { | 2251 | for (i = 0; i < SYS_FRAMES; i++) { |
2265 | /* allocate the frames */ | 2252 | /* allocate the frames */ |
2266 | dev->buffer[chn].frame[i].lpvbits = vmalloc(reqsize); | 2253 | channel->buffer.frame[i].lpvbits = vmalloc(reqsize); |
2267 | 2254 | dprintk(1, "valloc %p chan %d, idx %lu, pdata %p\n", | |
2268 | dprintk(1, "valloc %p chan %lu, idx %lu, pdata %p\n", | 2255 | &channel->buffer.frame[i], channel->idx, i, |
2269 | &dev->buffer[chn].frame[i], chn, i, | 2256 | channel->buffer.frame[i].lpvbits); |
2270 | dev->buffer[chn].frame[i].lpvbits); | 2257 | channel->buffer.frame[i].size = reqsize; |
2271 | dev->buffer[chn].frame[i].size = reqsize; | 2258 | if (channel->buffer.frame[i].lpvbits == NULL) { |
2272 | if (dev->buffer[chn].frame[i].lpvbits == NULL) { | ||
2273 | printk(KERN_INFO "out of memory. using less frames\n"); | 2259 | printk(KERN_INFO "out of memory. using less frames\n"); |
2274 | dev->buffer[chn].dwFrames = i; | 2260 | channel->buffer.dwFrames = i; |
2275 | break; | 2261 | break; |
2276 | } | 2262 | } |
2277 | } | 2263 | } |
2278 | 2264 | ||
2279 | /* make sure internal states are set */ | 2265 | /* make sure internal states are set */ |
2280 | for (i = 0; i < SYS_FRAMES; i++) { | 2266 | for (i = 0; i < SYS_FRAMES; i++) { |
2281 | dev->buffer[chn].frame[i].ulState = 0; | 2267 | channel->buffer.frame[i].ulState = 0; |
2282 | dev->buffer[chn].frame[i].cur_size = 0; | 2268 | channel->buffer.frame[i].cur_size = 0; |
2283 | } | 2269 | } |
2284 | 2270 | ||
2285 | dev->cur_frame[chn] = 0; | 2271 | channel->cur_frame = 0; |
2286 | dev->last_frame[chn] = -1; | 2272 | channel->last_frame = -1; |
2287 | return 0; | 2273 | return 0; |
2288 | } | 2274 | } |
2289 | 2275 | ||
2290 | static int s2255_release_sys_buffers(struct s2255_dev *dev, | 2276 | static int s2255_release_sys_buffers(struct s2255_channel *channel) |
2291 | unsigned long channel) | ||
2292 | { | 2277 | { |
2293 | unsigned long i; | 2278 | unsigned long i; |
2294 | dprintk(1, "release sys buffers\n"); | 2279 | dprintk(1, "release sys buffers\n"); |
2295 | for (i = 0; i < SYS_FRAMES; i++) { | 2280 | for (i = 0; i < SYS_FRAMES; i++) { |
2296 | if (dev->buffer[channel].frame[i].lpvbits) { | 2281 | if (channel->buffer.frame[i].lpvbits) { |
2297 | dprintk(1, "vfree %p\n", | 2282 | dprintk(1, "vfree %p\n", |
2298 | dev->buffer[channel].frame[i].lpvbits); | 2283 | channel->buffer.frame[i].lpvbits); |
2299 | vfree(dev->buffer[channel].frame[i].lpvbits); | 2284 | vfree(channel->buffer.frame[i].lpvbits); |
2300 | } | 2285 | } |
2301 | dev->buffer[channel].frame[i].lpvbits = NULL; | 2286 | channel->buffer.frame[i].lpvbits = NULL; |
2302 | } | 2287 | } |
2303 | return 0; | 2288 | return 0; |
2304 | } | 2289 | } |
@@ -2335,17 +2320,20 @@ static int s2255_board_init(struct s2255_dev *dev) | |||
2335 | fw_ver & 0xff); | 2320 | fw_ver & 0xff); |
2336 | 2321 | ||
2337 | for (j = 0; j < MAX_CHANNELS; j++) { | 2322 | for (j = 0; j < MAX_CHANNELS; j++) { |
2338 | dev->b_acquire[j] = 0; | 2323 | struct s2255_channel *channel = &dev->channel[j]; |
2339 | dev->mode[j] = mode_def; | 2324 | channel->b_acquire = 0; |
2325 | channel->mode = mode_def; | ||
2340 | if (dev->pid == 0x2257 && j > 1) | 2326 | if (dev->pid == 0x2257 && j > 1) |
2341 | dev->mode[j].color |= (1 << 16); | 2327 | channel->mode.color |= (1 << 16); |
2342 | dev->jc[j].quality = S2255_DEF_JPEG_QUAL; | 2328 | channel->jc.quality = S2255_DEF_JPEG_QUAL; |
2343 | dev->cur_fmt[j] = &formats[0]; | 2329 | channel->width = LINE_SZ_4CIFS_NTSC; |
2344 | dev->mode[j].restart = 1; | 2330 | channel->height = NUM_LINES_4CIFS_NTSC * 2; |
2345 | dev->req_image_size[j] = get_transfer_size(&mode_def); | 2331 | channel->fmt = &formats[0]; |
2346 | dev->frame_count[j] = 0; | 2332 | channel->mode.restart = 1; |
2333 | channel->req_image_size = get_transfer_size(&mode_def); | ||
2334 | channel->frame_count = 0; | ||
2347 | /* create the system buffers */ | 2335 | /* create the system buffers */ |
2348 | s2255_create_sys_buffers(dev, j); | 2336 | s2255_create_sys_buffers(channel); |
2349 | } | 2337 | } |
2350 | /* start read pipe */ | 2338 | /* start read pipe */ |
2351 | s2255_start_readpipe(dev); | 2339 | s2255_start_readpipe(dev); |
@@ -2359,14 +2347,12 @@ static int s2255_board_shutdown(struct s2255_dev *dev) | |||
2359 | dprintk(1, "%s: dev: %p", __func__, dev); | 2347 | dprintk(1, "%s: dev: %p", __func__, dev); |
2360 | 2348 | ||
2361 | for (i = 0; i < MAX_CHANNELS; i++) { | 2349 | for (i = 0; i < MAX_CHANNELS; i++) { |
2362 | if (dev->b_acquire[i]) | 2350 | if (dev->channel[i].b_acquire) |
2363 | s2255_stop_acquire(dev, i); | 2351 | s2255_stop_acquire(&dev->channel[i]); |
2364 | } | 2352 | } |
2365 | |||
2366 | s2255_stop_readpipe(dev); | 2353 | s2255_stop_readpipe(dev); |
2367 | |||
2368 | for (i = 0; i < MAX_CHANNELS; i++) | 2354 | for (i = 0; i < MAX_CHANNELS; i++) |
2369 | s2255_release_sys_buffers(dev, i); | 2355 | s2255_release_sys_buffers(&dev->channel[i]); |
2370 | /* release transfer buffer */ | 2356 | /* release transfer buffer */ |
2371 | kfree(dev->pipe.transfer_buffer); | 2357 | kfree(dev->pipe.transfer_buffer); |
2372 | return 0; | 2358 | return 0; |
@@ -2459,29 +2445,26 @@ static int s2255_start_readpipe(struct s2255_dev *dev) | |||
2459 | } | 2445 | } |
2460 | 2446 | ||
2461 | /* starts acquisition process */ | 2447 | /* starts acquisition process */ |
2462 | static int s2255_start_acquire(struct s2255_dev *dev, unsigned long chn) | 2448 | static int s2255_start_acquire(struct s2255_channel *channel) |
2463 | { | 2449 | { |
2464 | unsigned char *buffer; | 2450 | unsigned char *buffer; |
2465 | int res; | 2451 | int res; |
2466 | unsigned long chn_rev; | 2452 | unsigned long chn_rev; |
2467 | int j; | 2453 | int j; |
2468 | if (chn >= MAX_CHANNELS) { | 2454 | struct s2255_dev *dev = to_s2255_dev(channel->vdev.v4l2_dev); |
2469 | dprintk(2, "start acquire failed, bad channel %lu\n", chn); | 2455 | chn_rev = G_chnmap[channel->idx]; |
2470 | return -1; | ||
2471 | } | ||
2472 | chn_rev = G_chnmap[chn]; | ||
2473 | buffer = kzalloc(512, GFP_KERNEL); | 2456 | buffer = kzalloc(512, GFP_KERNEL); |
2474 | if (buffer == NULL) { | 2457 | if (buffer == NULL) { |
2475 | dev_err(&dev->udev->dev, "out of mem\n"); | 2458 | dev_err(&dev->udev->dev, "out of mem\n"); |
2476 | return -ENOMEM; | 2459 | return -ENOMEM; |
2477 | } | 2460 | } |
2478 | 2461 | ||
2479 | dev->last_frame[chn] = -1; | 2462 | channel->last_frame = -1; |
2480 | dev->bad_payload[chn] = 0; | 2463 | channel->bad_payload = 0; |
2481 | dev->cur_frame[chn] = 0; | 2464 | channel->cur_frame = 0; |
2482 | for (j = 0; j < SYS_FRAMES; j++) { | 2465 | for (j = 0; j < SYS_FRAMES; j++) { |
2483 | dev->buffer[chn].frame[j].ulState = 0; | 2466 | channel->buffer.frame[j].ulState = 0; |
2484 | dev->buffer[chn].frame[j].cur_size = 0; | 2467 | channel->buffer.frame[j].cur_size = 0; |
2485 | } | 2468 | } |
2486 | 2469 | ||
2487 | /* send the start command */ | 2470 | /* send the start command */ |
@@ -2492,21 +2475,18 @@ static int s2255_start_acquire(struct s2255_dev *dev, unsigned long chn) | |||
2492 | if (res != 0) | 2475 | if (res != 0) |
2493 | dev_err(&dev->udev->dev, "CMD_START error\n"); | 2476 | dev_err(&dev->udev->dev, "CMD_START error\n"); |
2494 | 2477 | ||
2495 | dprintk(2, "start acquire exit[%lu] %d \n", chn, res); | 2478 | dprintk(2, "start acquire exit[%d] %d \n", channel->idx, res); |
2496 | kfree(buffer); | 2479 | kfree(buffer); |
2497 | return 0; | 2480 | return 0; |
2498 | } | 2481 | } |
2499 | 2482 | ||
2500 | static int s2255_stop_acquire(struct s2255_dev *dev, unsigned long chn) | 2483 | static int s2255_stop_acquire(struct s2255_channel *channel) |
2501 | { | 2484 | { |
2502 | unsigned char *buffer; | 2485 | unsigned char *buffer; |
2503 | int res; | 2486 | int res; |
2504 | unsigned long chn_rev; | 2487 | unsigned long chn_rev; |
2505 | if (chn >= MAX_CHANNELS) { | 2488 | struct s2255_dev *dev = to_s2255_dev(channel->vdev.v4l2_dev); |
2506 | dprintk(2, "stop acquire failed, bad channel %lu\n", chn); | 2489 | chn_rev = G_chnmap[channel->idx]; |
2507 | return -1; | ||
2508 | } | ||
2509 | chn_rev = G_chnmap[chn]; | ||
2510 | buffer = kzalloc(512, GFP_KERNEL); | 2490 | buffer = kzalloc(512, GFP_KERNEL); |
2511 | if (buffer == NULL) { | 2491 | if (buffer == NULL) { |
2512 | dev_err(&dev->udev->dev, "out of mem\n"); | 2492 | dev_err(&dev->udev->dev, "out of mem\n"); |
@@ -2520,8 +2500,8 @@ static int s2255_stop_acquire(struct s2255_dev *dev, unsigned long chn) | |||
2520 | if (res != 0) | 2500 | if (res != 0) |
2521 | dev_err(&dev->udev->dev, "CMD_STOP error\n"); | 2501 | dev_err(&dev->udev->dev, "CMD_STOP error\n"); |
2522 | kfree(buffer); | 2502 | kfree(buffer); |
2523 | dev->b_acquire[chn] = 0; | 2503 | channel->b_acquire = 0; |
2524 | dprintk(4, "%s: chn %lu, res %d\n", __func__, chn, res); | 2504 | dprintk(4, "%s: chn %d, res %d\n", __func__, channel->idx, res); |
2525 | return res; | 2505 | return res; |
2526 | } | 2506 | } |
2527 | 2507 | ||
@@ -2575,7 +2555,7 @@ static int s2255_probe(struct usb_interface *interface, | |||
2575 | s2255_dev_err(&interface->dev, "out of memory\n"); | 2555 | s2255_dev_err(&interface->dev, "out of memory\n"); |
2576 | return -ENOMEM; | 2556 | return -ENOMEM; |
2577 | } | 2557 | } |
2578 | atomic_set(&dev->channels, 0); | 2558 | atomic_set(&dev->num_channels, 0); |
2579 | dev->pid = id->idProduct; | 2559 | dev->pid = id->idProduct; |
2580 | dev->fw_data = kzalloc(sizeof(struct s2255_fw), GFP_KERNEL); | 2560 | dev->fw_data = kzalloc(sizeof(struct s2255_fw), GFP_KERNEL); |
2581 | if (!dev->fw_data) | 2561 | if (!dev->fw_data) |
@@ -2612,8 +2592,10 @@ static int s2255_probe(struct usb_interface *interface, | |||
2612 | dev->timer.data = (unsigned long)dev->fw_data; | 2592 | dev->timer.data = (unsigned long)dev->fw_data; |
2613 | init_waitqueue_head(&dev->fw_data->wait_fw); | 2593 | init_waitqueue_head(&dev->fw_data->wait_fw); |
2614 | for (i = 0; i < MAX_CHANNELS; i++) { | 2594 | for (i = 0; i < MAX_CHANNELS; i++) { |
2615 | init_waitqueue_head(&dev->wait_setmode[i]); | 2595 | struct s2255_channel *channel = &dev->channel[i]; |
2616 | init_waitqueue_head(&dev->wait_vidstatus[i]); | 2596 | dev->channel[i].idx = i; |
2597 | init_waitqueue_head(&channel->wait_setmode); | ||
2598 | init_waitqueue_head(&channel->wait_vidstatus); | ||
2617 | } | 2599 | } |
2618 | 2600 | ||
2619 | dev->fw_data->fw_urb = usb_alloc_urb(0, GFP_KERNEL); | 2601 | dev->fw_data->fw_urb = usb_alloc_urb(0, GFP_KERNEL); |
@@ -2651,7 +2633,7 @@ static int s2255_probe(struct usb_interface *interface, | |||
2651 | printk(KERN_INFO "s2255: f2255usb.bin out of date.\n"); | 2633 | printk(KERN_INFO "s2255: f2255usb.bin out of date.\n"); |
2652 | if (dev->pid == 0x2257 && *pRel < S2255_MIN_DSP_COLORFILTER) | 2634 | if (dev->pid == 0x2257 && *pRel < S2255_MIN_DSP_COLORFILTER) |
2653 | printk(KERN_WARNING "s2255: 2257 requires firmware %d" | 2635 | printk(KERN_WARNING "s2255: 2257 requires firmware %d" |
2654 | "or above.\n", S2255_MIN_DSP_COLORFILTER); | 2636 | " or above.\n", S2255_MIN_DSP_COLORFILTER); |
2655 | } | 2637 | } |
2656 | usb_reset_device(dev->udev); | 2638 | usb_reset_device(dev->udev); |
2657 | /* load 2255 board specific */ | 2639 | /* load 2255 board specific */ |
@@ -2693,25 +2675,23 @@ static void s2255_disconnect(struct usb_interface *interface) | |||
2693 | { | 2675 | { |
2694 | struct s2255_dev *dev = to_s2255_dev(usb_get_intfdata(interface)); | 2676 | struct s2255_dev *dev = to_s2255_dev(usb_get_intfdata(interface)); |
2695 | int i; | 2677 | int i; |
2696 | int channels = atomic_read(&dev->channels); | 2678 | int channels = atomic_read(&dev->num_channels); |
2697 | v4l2_device_unregister(&dev->v4l2_dev); | 2679 | v4l2_device_disconnect(&dev->v4l2_dev); |
2698 | /*see comments in the uvc_driver.c usb disconnect function */ | 2680 | /*see comments in the uvc_driver.c usb disconnect function */ |
2699 | atomic_inc(&dev->channels); | 2681 | atomic_inc(&dev->num_channels); |
2700 | /* unregister each video device. */ | 2682 | /* unregister each video device. */ |
2701 | for (i = 0; i < channels; i++) { | 2683 | for (i = 0; i < channels; i++) |
2702 | if (video_is_registered(&dev->vdev[i])) | 2684 | video_unregister_device(&dev->channel[i].vdev); |
2703 | video_unregister_device(&dev->vdev[i]); | ||
2704 | } | ||
2705 | /* wake up any of our timers */ | 2685 | /* wake up any of our timers */ |
2706 | atomic_set(&dev->fw_data->fw_state, S2255_FW_DISCONNECTING); | 2686 | atomic_set(&dev->fw_data->fw_state, S2255_FW_DISCONNECTING); |
2707 | wake_up(&dev->fw_data->wait_fw); | 2687 | wake_up(&dev->fw_data->wait_fw); |
2708 | for (i = 0; i < MAX_CHANNELS; i++) { | 2688 | for (i = 0; i < MAX_CHANNELS; i++) { |
2709 | dev->setmode_ready[i] = 1; | 2689 | dev->channel[i].setmode_ready = 1; |
2710 | wake_up(&dev->wait_setmode[i]); | 2690 | wake_up(&dev->channel[i].wait_setmode); |
2711 | dev->vidstatus_ready[i] = 1; | 2691 | dev->channel[i].vidstatus_ready = 1; |
2712 | wake_up(&dev->wait_vidstatus[i]); | 2692 | wake_up(&dev->channel[i].wait_vidstatus); |
2713 | } | 2693 | } |
2714 | if (atomic_dec_and_test(&dev->channels)) | 2694 | if (atomic_dec_and_test(&dev->num_channels)) |
2715 | s2255_destroy(dev); | 2695 | s2255_destroy(dev); |
2716 | dev_info(&interface->dev, "%s\n", __func__); | 2696 | dev_info(&interface->dev, "%s\n", __func__); |
2717 | } | 2697 | } |