| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Driver for the VIA Chrome integrated camera controller. |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * Copyright 2009,2010 Jonathan Corbet <corbet@lwn.net> |
|---|
| 5 | | - * Distributable under the terms of the GNU General Public License, version 2 |
|---|
| 6 | 6 | * |
|---|
| 7 | 7 | * This work was supported by the One Laptop Per Child project |
|---|
| 8 | 8 | */ |
|---|
| .. | .. |
|---|
| 18 | 18 | #include <media/v4l2-device.h> |
|---|
| 19 | 19 | #include <media/v4l2-ioctl.h> |
|---|
| 20 | 20 | #include <media/v4l2-ctrls.h> |
|---|
| 21 | +#include <media/v4l2-event.h> |
|---|
| 21 | 22 | #include <media/v4l2-image-sizes.h> |
|---|
| 22 | 23 | #include <media/i2c/ov7670.h> |
|---|
| 23 | | -#include <media/videobuf-dma-sg.h> |
|---|
| 24 | +#include <media/videobuf2-dma-sg.h> |
|---|
| 24 | 25 | #include <linux/delay.h> |
|---|
| 25 | 26 | #include <linux/dma-mapping.h> |
|---|
| 26 | 27 | #include <linux/pm_qos.h> |
|---|
| .. | .. |
|---|
| 84 | 85 | * live in frame buffer memory, so we don't call them "DMA". |
|---|
| 85 | 86 | */ |
|---|
| 86 | 87 | unsigned int cb_offsets[3]; /* offsets into fb mem */ |
|---|
| 87 | | - u8 __iomem *cb_addrs[3]; /* Kernel-space addresses */ |
|---|
| 88 | + u8 __iomem *cb_addrs[3]; /* Kernel-space addresses */ |
|---|
| 88 | 89 | int n_cap_bufs; /* How many are we using? */ |
|---|
| 89 | | - int next_buf; |
|---|
| 90 | | - struct videobuf_queue vb_queue; |
|---|
| 91 | | - struct list_head buffer_queue; /* prot. by reg_lock */ |
|---|
| 92 | | - /* |
|---|
| 93 | | - * User tracking. |
|---|
| 94 | | - */ |
|---|
| 95 | | - int users; |
|---|
| 96 | | - struct file *owner; |
|---|
| 90 | + struct vb2_queue vq; |
|---|
| 91 | + struct list_head buffer_queue; |
|---|
| 92 | + u32 sequence; |
|---|
| 97 | 93 | /* |
|---|
| 98 | 94 | * Video format information. sensor_format is kept in a form |
|---|
| 99 | 95 | * that we can use to pass to the sensor. We always run the |
|---|
| .. | .. |
|---|
| 104 | 100 | struct v4l2_pix_format sensor_format; |
|---|
| 105 | 101 | struct v4l2_pix_format user_format; |
|---|
| 106 | 102 | u32 mbus_code; |
|---|
| 103 | +}; |
|---|
| 104 | + |
|---|
| 105 | +/* buffer for one video frame */ |
|---|
| 106 | +struct via_buffer { |
|---|
| 107 | + /* common v4l buffer stuff -- must be first */ |
|---|
| 108 | + struct vb2_v4l2_buffer vbuf; |
|---|
| 109 | + struct list_head queue; |
|---|
| 107 | 110 | }; |
|---|
| 108 | 111 | |
|---|
| 109 | 112 | /* |
|---|
| .. | .. |
|---|
| 142 | 145 | * now this information must be managed at this level too. |
|---|
| 143 | 146 | */ |
|---|
| 144 | 147 | static struct via_format { |
|---|
| 145 | | - __u8 *desc; |
|---|
| 146 | 148 | __u32 pixelformat; |
|---|
| 147 | 149 | int bpp; /* Bytes per pixel */ |
|---|
| 148 | 150 | u32 mbus_code; |
|---|
| 149 | 151 | } via_formats[] = { |
|---|
| 150 | 152 | { |
|---|
| 151 | | - .desc = "YUYV 4:2:2", |
|---|
| 152 | 153 | .pixelformat = V4L2_PIX_FMT_YUYV, |
|---|
| 153 | 154 | .mbus_code = MEDIA_BUS_FMT_YUYV8_2X8, |
|---|
| 154 | 155 | .bpp = 2, |
|---|
| .. | .. |
|---|
| 324 | 325 | } |
|---|
| 325 | 326 | |
|---|
| 326 | 327 | /* |
|---|
| 327 | | - * Find the next videobuf buffer which has somebody waiting on it. |
|---|
| 328 | + * Find the next buffer which has somebody waiting on it. |
|---|
| 328 | 329 | */ |
|---|
| 329 | | -static struct videobuf_buffer *viacam_next_buffer(struct via_camera *cam) |
|---|
| 330 | +static struct via_buffer *viacam_next_buffer(struct via_camera *cam) |
|---|
| 330 | 331 | { |
|---|
| 331 | | - unsigned long flags; |
|---|
| 332 | | - struct videobuf_buffer *buf = NULL; |
|---|
| 333 | | - |
|---|
| 334 | | - spin_lock_irqsave(&cam->viadev->reg_lock, flags); |
|---|
| 335 | 332 | if (cam->opstate != S_RUNNING) |
|---|
| 336 | | - goto out; |
|---|
| 333 | + return NULL; |
|---|
| 337 | 334 | if (list_empty(&cam->buffer_queue)) |
|---|
| 338 | | - goto out; |
|---|
| 339 | | - buf = list_entry(cam->buffer_queue.next, struct videobuf_buffer, queue); |
|---|
| 340 | | - if (!waitqueue_active(&buf->done)) {/* Nobody waiting */ |
|---|
| 341 | | - buf = NULL; |
|---|
| 342 | | - goto out; |
|---|
| 343 | | - } |
|---|
| 344 | | - list_del(&buf->queue); |
|---|
| 345 | | - buf->state = VIDEOBUF_ACTIVE; |
|---|
| 346 | | -out: |
|---|
| 347 | | - spin_unlock_irqrestore(&cam->viadev->reg_lock, flags); |
|---|
| 348 | | - return buf; |
|---|
| 335 | + return NULL; |
|---|
| 336 | + return list_entry(cam->buffer_queue.next, struct via_buffer, queue); |
|---|
| 349 | 337 | } |
|---|
| 350 | 338 | |
|---|
| 351 | 339 | /* |
|---|
| .. | .. |
|---|
| 353 | 341 | */ |
|---|
| 354 | 342 | static irqreturn_t viacam_irq(int irq, void *data) |
|---|
| 355 | 343 | { |
|---|
| 356 | | - int bufn; |
|---|
| 357 | | - struct videobuf_buffer *vb; |
|---|
| 358 | 344 | struct via_camera *cam = data; |
|---|
| 359 | | - struct videobuf_dmabuf *vdma; |
|---|
| 345 | + struct via_buffer *vb; |
|---|
| 346 | + int bufn; |
|---|
| 347 | + struct sg_table *sgt; |
|---|
| 360 | 348 | |
|---|
| 349 | + mutex_lock(&cam->lock); |
|---|
| 361 | 350 | /* |
|---|
| 362 | 351 | * If there is no place to put the data frame, don't bother |
|---|
| 363 | 352 | * with anything else. |
|---|
| .. | .. |
|---|
| 375 | 364 | /* |
|---|
| 376 | 365 | * Copy over the data and let any waiters know. |
|---|
| 377 | 366 | */ |
|---|
| 378 | | - vdma = videobuf_to_dma(vb); |
|---|
| 379 | | - viafb_dma_copy_out_sg(cam->cb_offsets[bufn], vdma->sglist, vdma->sglen); |
|---|
| 380 | | - vb->state = VIDEOBUF_DONE; |
|---|
| 381 | | - vb->size = cam->user_format.sizeimage; |
|---|
| 382 | | - wake_up(&vb->done); |
|---|
| 367 | + sgt = vb2_dma_sg_plane_desc(&vb->vbuf.vb2_buf, 0); |
|---|
| 368 | + vb->vbuf.vb2_buf.timestamp = ktime_get_ns(); |
|---|
| 369 | + viafb_dma_copy_out_sg(cam->cb_offsets[bufn], sgt->sgl, sgt->nents); |
|---|
| 370 | + vb->vbuf.sequence = cam->sequence++; |
|---|
| 371 | + vb->vbuf.field = V4L2_FIELD_NONE; |
|---|
| 372 | + list_del(&vb->queue); |
|---|
| 373 | + vb2_buffer_done(&vb->vbuf.vb2_buf, VB2_BUF_STATE_DONE); |
|---|
| 383 | 374 | done: |
|---|
| 375 | + mutex_unlock(&cam->lock); |
|---|
| 384 | 376 | return IRQ_HANDLED; |
|---|
| 385 | 377 | } |
|---|
| 386 | 378 | |
|---|
| .. | .. |
|---|
| 556 | 548 | static void viacam_start_engine(struct via_camera *cam) |
|---|
| 557 | 549 | { |
|---|
| 558 | 550 | spin_lock_irq(&cam->viadev->reg_lock); |
|---|
| 559 | | - cam->next_buf = 0; |
|---|
| 560 | 551 | viacam_write_reg_mask(cam, VCR_CAPINTC, VCR_CI_ENABLE, VCR_CI_ENABLE); |
|---|
| 561 | 552 | viacam_int_enable(cam); |
|---|
| 562 | 553 | (void) viacam_read_reg(cam, VCR_CAPINTC); /* Force post */ |
|---|
| .. | .. |
|---|
| 577 | 568 | |
|---|
| 578 | 569 | |
|---|
| 579 | 570 | /* --------------------------------------------------------------------------*/ |
|---|
| 580 | | -/* Videobuf callback ops */ |
|---|
| 571 | +/* vb2 callback ops */ |
|---|
| 581 | 572 | |
|---|
| 582 | | -/* |
|---|
| 583 | | - * buffer_setup. The purpose of this one would appear to be to tell |
|---|
| 584 | | - * videobuf how big a single image is. It's also evidently up to us |
|---|
| 585 | | - * to put some sort of limit on the maximum number of buffers allowed. |
|---|
| 586 | | - */ |
|---|
| 587 | | -static int viacam_vb_buf_setup(struct videobuf_queue *q, |
|---|
| 588 | | - unsigned int *count, unsigned int *size) |
|---|
| 573 | +static struct via_buffer *vb2_to_via_buffer(struct vb2_buffer *vb) |
|---|
| 589 | 574 | { |
|---|
| 590 | | - struct via_camera *cam = q->priv_data; |
|---|
| 575 | + struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb); |
|---|
| 591 | 576 | |
|---|
| 592 | | - *size = cam->user_format.sizeimage; |
|---|
| 593 | | - if (*count == 0 || *count > 6) /* Arbitrary number */ |
|---|
| 594 | | - *count = 6; |
|---|
| 595 | | - return 0; |
|---|
| 577 | + return container_of(vbuf, struct via_buffer, vbuf); |
|---|
| 596 | 578 | } |
|---|
| 597 | 579 | |
|---|
| 598 | | -/* |
|---|
| 599 | | - * Prepare a buffer. |
|---|
| 600 | | - */ |
|---|
| 601 | | -static int viacam_vb_buf_prepare(struct videobuf_queue *q, |
|---|
| 602 | | - struct videobuf_buffer *vb, enum v4l2_field field) |
|---|
| 580 | +static void viacam_vb2_queue(struct vb2_buffer *vb) |
|---|
| 603 | 581 | { |
|---|
| 604 | | - struct via_camera *cam = q->priv_data; |
|---|
| 582 | + struct via_camera *cam = vb2_get_drv_priv(vb->vb2_queue); |
|---|
| 583 | + struct via_buffer *via = vb2_to_via_buffer(vb); |
|---|
| 605 | 584 | |
|---|
| 606 | | - vb->size = cam->user_format.sizeimage; |
|---|
| 607 | | - vb->width = cam->user_format.width; /* bytesperline???? */ |
|---|
| 608 | | - vb->height = cam->user_format.height; |
|---|
| 609 | | - vb->field = field; |
|---|
| 610 | | - if (vb->state == VIDEOBUF_NEEDS_INIT) { |
|---|
| 611 | | - int ret = videobuf_iolock(q, vb, NULL); |
|---|
| 612 | | - if (ret) |
|---|
| 613 | | - return ret; |
|---|
| 585 | + list_add_tail(&via->queue, &cam->buffer_queue); |
|---|
| 586 | +} |
|---|
| 587 | + |
|---|
| 588 | +static int viacam_vb2_prepare(struct vb2_buffer *vb) |
|---|
| 589 | +{ |
|---|
| 590 | + struct via_camera *cam = vb2_get_drv_priv(vb->vb2_queue); |
|---|
| 591 | + |
|---|
| 592 | + if (vb2_plane_size(vb, 0) < cam->user_format.sizeimage) { |
|---|
| 593 | + cam_dbg(cam, |
|---|
| 594 | + "Plane size too small (%lu < %u)\n", |
|---|
| 595 | + vb2_plane_size(vb, 0), |
|---|
| 596 | + cam->user_format.sizeimage); |
|---|
| 597 | + return -EINVAL; |
|---|
| 614 | 598 | } |
|---|
| 615 | | - vb->state = VIDEOBUF_PREPARED; |
|---|
| 599 | + |
|---|
| 600 | + vb2_set_plane_payload(vb, 0, cam->user_format.sizeimage); |
|---|
| 601 | + |
|---|
| 616 | 602 | return 0; |
|---|
| 617 | 603 | } |
|---|
| 618 | 604 | |
|---|
| 619 | | -/* |
|---|
| 620 | | - * We've got a buffer to put data into. |
|---|
| 621 | | - * |
|---|
| 622 | | - * FIXME: check for a running engine and valid buffers? |
|---|
| 623 | | - */ |
|---|
| 624 | | -static void viacam_vb_buf_queue(struct videobuf_queue *q, |
|---|
| 625 | | - struct videobuf_buffer *vb) |
|---|
| 605 | +static int viacam_vb2_queue_setup(struct vb2_queue *vq, |
|---|
| 606 | + unsigned int *nbufs, |
|---|
| 607 | + unsigned int *num_planes, unsigned int sizes[], |
|---|
| 608 | + struct device *alloc_devs[]) |
|---|
| 626 | 609 | { |
|---|
| 627 | | - struct via_camera *cam = q->priv_data; |
|---|
| 610 | + struct via_camera *cam = vb2_get_drv_priv(vq); |
|---|
| 611 | + int size = cam->user_format.sizeimage; |
|---|
| 628 | 612 | |
|---|
| 613 | + if (*num_planes) |
|---|
| 614 | + return sizes[0] < size ? -EINVAL : 0; |
|---|
| 615 | + |
|---|
| 616 | + *num_planes = 1; |
|---|
| 617 | + sizes[0] = size; |
|---|
| 618 | + return 0; |
|---|
| 619 | +} |
|---|
| 620 | + |
|---|
| 621 | +static int viacam_vb2_start_streaming(struct vb2_queue *vq, unsigned int count) |
|---|
| 622 | +{ |
|---|
| 623 | + struct via_camera *cam = vb2_get_drv_priv(vq); |
|---|
| 624 | + struct via_buffer *buf, *tmp; |
|---|
| 625 | + int ret = 0; |
|---|
| 626 | + |
|---|
| 627 | + if (cam->opstate != S_IDLE) { |
|---|
| 628 | + ret = -EBUSY; |
|---|
| 629 | + goto out; |
|---|
| 630 | + } |
|---|
| 629 | 631 | /* |
|---|
| 630 | | - * Note that videobuf holds the lock when it calls |
|---|
| 631 | | - * us, so we need not (indeed, cannot) take it here. |
|---|
| 632 | + * Configure things if need be. |
|---|
| 632 | 633 | */ |
|---|
| 633 | | - vb->state = VIDEOBUF_QUEUED; |
|---|
| 634 | | - list_add_tail(&vb->queue, &cam->buffer_queue); |
|---|
| 634 | + if (test_bit(CF_CONFIG_NEEDED, &cam->flags)) { |
|---|
| 635 | + ret = viacam_configure_sensor(cam); |
|---|
| 636 | + if (ret) |
|---|
| 637 | + goto out; |
|---|
| 638 | + ret = viacam_config_controller(cam); |
|---|
| 639 | + if (ret) |
|---|
| 640 | + goto out; |
|---|
| 641 | + } |
|---|
| 642 | + cam->sequence = 0; |
|---|
| 643 | + /* |
|---|
| 644 | + * If the CPU goes into C3, the DMA transfer gets corrupted and |
|---|
| 645 | + * users start filing unsightly bug reports. Put in a "latency" |
|---|
| 646 | + * requirement which will keep the CPU out of the deeper sleep |
|---|
| 647 | + * states. |
|---|
| 648 | + */ |
|---|
| 649 | + cpu_latency_qos_add_request(&cam->qos_request, 50); |
|---|
| 650 | + viacam_start_engine(cam); |
|---|
| 651 | + return 0; |
|---|
| 652 | +out: |
|---|
| 653 | + list_for_each_entry_safe(buf, tmp, &cam->buffer_queue, queue) { |
|---|
| 654 | + list_del(&buf->queue); |
|---|
| 655 | + vb2_buffer_done(&buf->vbuf.vb2_buf, VB2_BUF_STATE_QUEUED); |
|---|
| 656 | + } |
|---|
| 657 | + return ret; |
|---|
| 635 | 658 | } |
|---|
| 636 | 659 | |
|---|
| 637 | | -/* |
|---|
| 638 | | - * Free a buffer. |
|---|
| 639 | | - */ |
|---|
| 640 | | -static void viacam_vb_buf_release(struct videobuf_queue *q, |
|---|
| 641 | | - struct videobuf_buffer *vb) |
|---|
| 660 | +static void viacam_vb2_stop_streaming(struct vb2_queue *vq) |
|---|
| 642 | 661 | { |
|---|
| 643 | | - struct via_camera *cam = q->priv_data; |
|---|
| 662 | + struct via_camera *cam = vb2_get_drv_priv(vq); |
|---|
| 663 | + struct via_buffer *buf, *tmp; |
|---|
| 644 | 664 | |
|---|
| 645 | | - videobuf_dma_unmap(&cam->platdev->dev, videobuf_to_dma(vb)); |
|---|
| 646 | | - videobuf_dma_free(videobuf_to_dma(vb)); |
|---|
| 647 | | - vb->state = VIDEOBUF_NEEDS_INIT; |
|---|
| 665 | + cpu_latency_qos_remove_request(&cam->qos_request); |
|---|
| 666 | + viacam_stop_engine(cam); |
|---|
| 667 | + |
|---|
| 668 | + list_for_each_entry_safe(buf, tmp, &cam->buffer_queue, queue) { |
|---|
| 669 | + list_del(&buf->queue); |
|---|
| 670 | + vb2_buffer_done(&buf->vbuf.vb2_buf, VB2_BUF_STATE_ERROR); |
|---|
| 671 | + } |
|---|
| 648 | 672 | } |
|---|
| 649 | 673 | |
|---|
| 650 | | -static const struct videobuf_queue_ops viacam_vb_ops = { |
|---|
| 651 | | - .buf_setup = viacam_vb_buf_setup, |
|---|
| 652 | | - .buf_prepare = viacam_vb_buf_prepare, |
|---|
| 653 | | - .buf_queue = viacam_vb_buf_queue, |
|---|
| 654 | | - .buf_release = viacam_vb_buf_release, |
|---|
| 674 | +static const struct vb2_ops viacam_vb2_ops = { |
|---|
| 675 | + .queue_setup = viacam_vb2_queue_setup, |
|---|
| 676 | + .buf_queue = viacam_vb2_queue, |
|---|
| 677 | + .buf_prepare = viacam_vb2_prepare, |
|---|
| 678 | + .start_streaming = viacam_vb2_start_streaming, |
|---|
| 679 | + .stop_streaming = viacam_vb2_stop_streaming, |
|---|
| 680 | + .wait_prepare = vb2_ops_wait_prepare, |
|---|
| 681 | + .wait_finish = vb2_ops_wait_finish, |
|---|
| 655 | 682 | }; |
|---|
| 656 | 683 | |
|---|
| 657 | 684 | /* --------------------------------------------------------------------------*/ |
|---|
| .. | .. |
|---|
| 660 | 687 | static int viacam_open(struct file *filp) |
|---|
| 661 | 688 | { |
|---|
| 662 | 689 | struct via_camera *cam = video_drvdata(filp); |
|---|
| 690 | + int ret; |
|---|
| 663 | 691 | |
|---|
| 664 | | - filp->private_data = cam; |
|---|
| 665 | 692 | /* |
|---|
| 666 | 693 | * Note the new user. If this is the first one, we'll also |
|---|
| 667 | 694 | * need to power up the sensor. |
|---|
| 668 | 695 | */ |
|---|
| 669 | 696 | mutex_lock(&cam->lock); |
|---|
| 670 | | - if (cam->users == 0) { |
|---|
| 671 | | - int ret = viafb_request_dma(); |
|---|
| 697 | + ret = v4l2_fh_open(filp); |
|---|
| 698 | + if (ret) |
|---|
| 699 | + goto out; |
|---|
| 700 | + if (v4l2_fh_is_singular_file(filp)) { |
|---|
| 701 | + ret = viafb_request_dma(); |
|---|
| 672 | 702 | |
|---|
| 673 | 703 | if (ret) { |
|---|
| 674 | | - mutex_unlock(&cam->lock); |
|---|
| 675 | | - return ret; |
|---|
| 704 | + v4l2_fh_release(filp); |
|---|
| 705 | + goto out; |
|---|
| 676 | 706 | } |
|---|
| 677 | 707 | via_sensor_power_up(cam); |
|---|
| 678 | 708 | set_bit(CF_CONFIG_NEEDED, &cam->flags); |
|---|
| 679 | | - /* |
|---|
| 680 | | - * Hook into videobuf. Evidently this cannot fail. |
|---|
| 681 | | - */ |
|---|
| 682 | | - videobuf_queue_sg_init(&cam->vb_queue, &viacam_vb_ops, |
|---|
| 683 | | - &cam->platdev->dev, &cam->viadev->reg_lock, |
|---|
| 684 | | - V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_NONE, |
|---|
| 685 | | - sizeof(struct videobuf_buffer), cam, NULL); |
|---|
| 686 | 709 | } |
|---|
| 687 | | - (cam->users)++; |
|---|
| 710 | +out: |
|---|
| 688 | 711 | mutex_unlock(&cam->lock); |
|---|
| 689 | | - return 0; |
|---|
| 712 | + return ret; |
|---|
| 690 | 713 | } |
|---|
| 691 | 714 | |
|---|
| 692 | 715 | static int viacam_release(struct file *filp) |
|---|
| 693 | 716 | { |
|---|
| 694 | 717 | struct via_camera *cam = video_drvdata(filp); |
|---|
| 718 | + bool last_open; |
|---|
| 695 | 719 | |
|---|
| 696 | 720 | mutex_lock(&cam->lock); |
|---|
| 697 | | - (cam->users)--; |
|---|
| 698 | | - /* |
|---|
| 699 | | - * If the "owner" is closing, shut down any ongoing |
|---|
| 700 | | - * operations. |
|---|
| 701 | | - */ |
|---|
| 702 | | - if (filp == cam->owner) { |
|---|
| 703 | | - videobuf_stop(&cam->vb_queue); |
|---|
| 704 | | - /* |
|---|
| 705 | | - * We don't hold the spinlock here, but, if release() |
|---|
| 706 | | - * is being called by the owner, nobody else will |
|---|
| 707 | | - * be changing the state. And an extra stop would |
|---|
| 708 | | - * not hurt anyway. |
|---|
| 709 | | - */ |
|---|
| 710 | | - if (cam->opstate != S_IDLE) |
|---|
| 711 | | - viacam_stop_engine(cam); |
|---|
| 712 | | - cam->owner = NULL; |
|---|
| 713 | | - } |
|---|
| 721 | + last_open = v4l2_fh_is_singular_file(filp); |
|---|
| 722 | + _vb2_fop_release(filp, NULL); |
|---|
| 714 | 723 | /* |
|---|
| 715 | 724 | * Last one out needs to turn out the lights. |
|---|
| 716 | 725 | */ |
|---|
| 717 | | - if (cam->users == 0) { |
|---|
| 718 | | - videobuf_mmap_free(&cam->vb_queue); |
|---|
| 726 | + if (last_open) { |
|---|
| 719 | 727 | via_sensor_power_down(cam); |
|---|
| 720 | 728 | viafb_release_dma(); |
|---|
| 721 | 729 | } |
|---|
| .. | .. |
|---|
| 723 | 731 | return 0; |
|---|
| 724 | 732 | } |
|---|
| 725 | 733 | |
|---|
| 726 | | -/* |
|---|
| 727 | | - * Read a frame from the device. |
|---|
| 728 | | - */ |
|---|
| 729 | | -static ssize_t viacam_read(struct file *filp, char __user *buffer, |
|---|
| 730 | | - size_t len, loff_t *pos) |
|---|
| 731 | | -{ |
|---|
| 732 | | - struct via_camera *cam = video_drvdata(filp); |
|---|
| 733 | | - int ret; |
|---|
| 734 | | - |
|---|
| 735 | | - mutex_lock(&cam->lock); |
|---|
| 736 | | - /* |
|---|
| 737 | | - * Enforce the V4l2 "only one owner gets to read data" rule. |
|---|
| 738 | | - */ |
|---|
| 739 | | - if (cam->owner && cam->owner != filp) { |
|---|
| 740 | | - ret = -EBUSY; |
|---|
| 741 | | - goto out_unlock; |
|---|
| 742 | | - } |
|---|
| 743 | | - cam->owner = filp; |
|---|
| 744 | | - /* |
|---|
| 745 | | - * Do we need to configure the hardware? |
|---|
| 746 | | - */ |
|---|
| 747 | | - if (test_bit(CF_CONFIG_NEEDED, &cam->flags)) { |
|---|
| 748 | | - ret = viacam_configure_sensor(cam); |
|---|
| 749 | | - if (!ret) |
|---|
| 750 | | - ret = viacam_config_controller(cam); |
|---|
| 751 | | - if (ret) |
|---|
| 752 | | - goto out_unlock; |
|---|
| 753 | | - } |
|---|
| 754 | | - /* |
|---|
| 755 | | - * Fire up the capture engine, then have videobuf do |
|---|
| 756 | | - * the heavy lifting. Someday it would be good to avoid |
|---|
| 757 | | - * stopping and restarting the engine each time. |
|---|
| 758 | | - */ |
|---|
| 759 | | - INIT_LIST_HEAD(&cam->buffer_queue); |
|---|
| 760 | | - viacam_start_engine(cam); |
|---|
| 761 | | - ret = videobuf_read_stream(&cam->vb_queue, buffer, len, pos, 0, |
|---|
| 762 | | - filp->f_flags & O_NONBLOCK); |
|---|
| 763 | | - viacam_stop_engine(cam); |
|---|
| 764 | | - /* videobuf_stop() ?? */ |
|---|
| 765 | | - |
|---|
| 766 | | -out_unlock: |
|---|
| 767 | | - mutex_unlock(&cam->lock); |
|---|
| 768 | | - return ret; |
|---|
| 769 | | -} |
|---|
| 770 | | - |
|---|
| 771 | | - |
|---|
| 772 | | -static __poll_t viacam_poll(struct file *filp, struct poll_table_struct *pt) |
|---|
| 773 | | -{ |
|---|
| 774 | | - struct via_camera *cam = video_drvdata(filp); |
|---|
| 775 | | - |
|---|
| 776 | | - return videobuf_poll_stream(filp, &cam->vb_queue, pt); |
|---|
| 777 | | -} |
|---|
| 778 | | - |
|---|
| 779 | | - |
|---|
| 780 | | -static int viacam_mmap(struct file *filp, struct vm_area_struct *vma) |
|---|
| 781 | | -{ |
|---|
| 782 | | - struct via_camera *cam = video_drvdata(filp); |
|---|
| 783 | | - |
|---|
| 784 | | - return videobuf_mmap_mapper(&cam->vb_queue, vma); |
|---|
| 785 | | -} |
|---|
| 786 | | - |
|---|
| 787 | | - |
|---|
| 788 | | - |
|---|
| 789 | 734 | static const struct v4l2_file_operations viacam_fops = { |
|---|
| 790 | 735 | .owner = THIS_MODULE, |
|---|
| 791 | 736 | .open = viacam_open, |
|---|
| 792 | 737 | .release = viacam_release, |
|---|
| 793 | | - .read = viacam_read, |
|---|
| 794 | | - .poll = viacam_poll, |
|---|
| 795 | | - .mmap = viacam_mmap, |
|---|
| 796 | | - .unlocked_ioctl = video_ioctl2, |
|---|
| 738 | + .read = vb2_fop_read, |
|---|
| 739 | + .poll = vb2_fop_poll, |
|---|
| 740 | + .mmap = vb2_fop_mmap, |
|---|
| 741 | + .unlocked_ioctl = video_ioctl2, |
|---|
| 797 | 742 | }; |
|---|
| 798 | 743 | |
|---|
| 799 | 744 | /*----------------------------------------------------------------------------*/ |
|---|
| .. | .. |
|---|
| 811 | 756 | return -EINVAL; |
|---|
| 812 | 757 | |
|---|
| 813 | 758 | input->type = V4L2_INPUT_TYPE_CAMERA; |
|---|
| 814 | | - input->std = V4L2_STD_ALL; /* Not sure what should go here */ |
|---|
| 815 | | - strcpy(input->name, "Camera"); |
|---|
| 759 | + strscpy(input->name, "Camera", sizeof(input->name)); |
|---|
| 816 | 760 | return 0; |
|---|
| 817 | 761 | } |
|---|
| 818 | 762 | |
|---|
| .. | .. |
|---|
| 829 | 773 | return 0; |
|---|
| 830 | 774 | } |
|---|
| 831 | 775 | |
|---|
| 832 | | -static int viacam_s_std(struct file *filp, void *priv, v4l2_std_id std) |
|---|
| 833 | | -{ |
|---|
| 834 | | - return 0; |
|---|
| 835 | | -} |
|---|
| 836 | | - |
|---|
| 837 | | -static int viacam_g_std(struct file *filp, void *priv, v4l2_std_id *std) |
|---|
| 838 | | -{ |
|---|
| 839 | | - *std = V4L2_STD_NTSC_M; |
|---|
| 840 | | - return 0; |
|---|
| 841 | | -} |
|---|
| 842 | | - |
|---|
| 843 | 776 | /* |
|---|
| 844 | 777 | * Video format stuff. Here is our default format until |
|---|
| 845 | 778 | * user space messes with things. |
|---|
| .. | .. |
|---|
| 851 | 784 | .field = V4L2_FIELD_NONE, |
|---|
| 852 | 785 | .bytesperline = VGA_WIDTH * 2, |
|---|
| 853 | 786 | .sizeimage = VGA_WIDTH * VGA_HEIGHT * 2, |
|---|
| 787 | + .colorspace = V4L2_COLORSPACE_SRGB, |
|---|
| 854 | 788 | }; |
|---|
| 855 | 789 | |
|---|
| 856 | 790 | static const u32 via_def_mbus_code = MEDIA_BUS_FMT_YUYV8_2X8; |
|---|
| .. | .. |
|---|
| 860 | 794 | { |
|---|
| 861 | 795 | if (fmt->index >= N_VIA_FMTS) |
|---|
| 862 | 796 | return -EINVAL; |
|---|
| 863 | | - strlcpy(fmt->description, via_formats[fmt->index].desc, |
|---|
| 864 | | - sizeof(fmt->description)); |
|---|
| 865 | 797 | fmt->pixelformat = via_formats[fmt->index].pixelformat; |
|---|
| 866 | 798 | return 0; |
|---|
| 867 | 799 | } |
|---|
| .. | .. |
|---|
| 897 | 829 | userfmt->field = sensorfmt->field; |
|---|
| 898 | 830 | userfmt->bytesperline = 2 * userfmt->width; |
|---|
| 899 | 831 | userfmt->sizeimage = userfmt->bytesperline * userfmt->height; |
|---|
| 832 | + userfmt->colorspace = sensorfmt->colorspace; |
|---|
| 833 | + userfmt->ycbcr_enc = sensorfmt->ycbcr_enc; |
|---|
| 834 | + userfmt->quantization = sensorfmt->quantization; |
|---|
| 835 | + userfmt->xfer_func = sensorfmt->xfer_func; |
|---|
| 900 | 836 | } |
|---|
| 901 | 837 | |
|---|
| 902 | 838 | |
|---|
| .. | .. |
|---|
| 927 | 863 | static int viacam_try_fmt_vid_cap(struct file *filp, void *priv, |
|---|
| 928 | 864 | struct v4l2_format *fmt) |
|---|
| 929 | 865 | { |
|---|
| 930 | | - struct via_camera *cam = priv; |
|---|
| 866 | + struct via_camera *cam = video_drvdata(filp); |
|---|
| 931 | 867 | struct v4l2_format sfmt; |
|---|
| 932 | | - int ret; |
|---|
| 933 | 868 | |
|---|
| 934 | | - mutex_lock(&cam->lock); |
|---|
| 935 | | - ret = viacam_do_try_fmt(cam, &fmt->fmt.pix, &sfmt.fmt.pix); |
|---|
| 936 | | - mutex_unlock(&cam->lock); |
|---|
| 937 | | - return ret; |
|---|
| 869 | + return viacam_do_try_fmt(cam, &fmt->fmt.pix, &sfmt.fmt.pix); |
|---|
| 938 | 870 | } |
|---|
| 939 | 871 | |
|---|
| 940 | 872 | |
|---|
| 941 | 873 | static int viacam_g_fmt_vid_cap(struct file *filp, void *priv, |
|---|
| 942 | 874 | struct v4l2_format *fmt) |
|---|
| 943 | 875 | { |
|---|
| 944 | | - struct via_camera *cam = priv; |
|---|
| 876 | + struct via_camera *cam = video_drvdata(filp); |
|---|
| 945 | 877 | |
|---|
| 946 | | - mutex_lock(&cam->lock); |
|---|
| 947 | 878 | fmt->fmt.pix = cam->user_format; |
|---|
| 948 | | - mutex_unlock(&cam->lock); |
|---|
| 949 | 879 | return 0; |
|---|
| 950 | 880 | } |
|---|
| 951 | 881 | |
|---|
| 952 | 882 | static int viacam_s_fmt_vid_cap(struct file *filp, void *priv, |
|---|
| 953 | 883 | struct v4l2_format *fmt) |
|---|
| 954 | 884 | { |
|---|
| 955 | | - struct via_camera *cam = priv; |
|---|
| 885 | + struct via_camera *cam = video_drvdata(filp); |
|---|
| 956 | 886 | int ret; |
|---|
| 957 | 887 | struct v4l2_format sfmt; |
|---|
| 958 | 888 | struct via_format *f = via_find_format(fmt->fmt.pix.pixelformat); |
|---|
| .. | .. |
|---|
| 961 | 891 | * Camera must be idle or we can't mess with the |
|---|
| 962 | 892 | * video setup. |
|---|
| 963 | 893 | */ |
|---|
| 964 | | - mutex_lock(&cam->lock); |
|---|
| 965 | | - if (cam->opstate != S_IDLE) { |
|---|
| 966 | | - ret = -EBUSY; |
|---|
| 967 | | - goto out; |
|---|
| 968 | | - } |
|---|
| 894 | + if (cam->opstate != S_IDLE) |
|---|
| 895 | + return -EBUSY; |
|---|
| 969 | 896 | /* |
|---|
| 970 | 897 | * Let the sensor code look over and tweak the |
|---|
| 971 | 898 | * requested formatting. |
|---|
| 972 | 899 | */ |
|---|
| 973 | 900 | ret = viacam_do_try_fmt(cam, &fmt->fmt.pix, &sfmt.fmt.pix); |
|---|
| 974 | 901 | if (ret) |
|---|
| 975 | | - goto out; |
|---|
| 902 | + return ret; |
|---|
| 976 | 903 | /* |
|---|
| 977 | 904 | * OK, let's commit to the new format. |
|---|
| 978 | 905 | */ |
|---|
| .. | .. |
|---|
| 982 | 909 | ret = viacam_configure_sensor(cam); |
|---|
| 983 | 910 | if (!ret) |
|---|
| 984 | 911 | ret = viacam_config_controller(cam); |
|---|
| 985 | | -out: |
|---|
| 986 | | - mutex_unlock(&cam->lock); |
|---|
| 987 | 912 | return ret; |
|---|
| 988 | 913 | } |
|---|
| 989 | 914 | |
|---|
| 990 | 915 | static int viacam_querycap(struct file *filp, void *priv, |
|---|
| 991 | 916 | struct v4l2_capability *cap) |
|---|
| 992 | 917 | { |
|---|
| 993 | | - strcpy(cap->driver, "via-camera"); |
|---|
| 994 | | - strcpy(cap->card, "via-camera"); |
|---|
| 995 | | - cap->device_caps = V4L2_CAP_VIDEO_CAPTURE | |
|---|
| 996 | | - V4L2_CAP_READWRITE | V4L2_CAP_STREAMING; |
|---|
| 997 | | - cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS; |
|---|
| 918 | + strscpy(cap->driver, "via-camera", sizeof(cap->driver)); |
|---|
| 919 | + strscpy(cap->card, "via-camera", sizeof(cap->card)); |
|---|
| 920 | + strscpy(cap->bus_info, "platform:via-camera", sizeof(cap->bus_info)); |
|---|
| 998 | 921 | return 0; |
|---|
| 999 | | -} |
|---|
| 1000 | | - |
|---|
| 1001 | | -/* |
|---|
| 1002 | | - * Streaming operations - pure videobuf stuff. |
|---|
| 1003 | | - */ |
|---|
| 1004 | | -static int viacam_reqbufs(struct file *filp, void *priv, |
|---|
| 1005 | | - struct v4l2_requestbuffers *rb) |
|---|
| 1006 | | -{ |
|---|
| 1007 | | - struct via_camera *cam = priv; |
|---|
| 1008 | | - |
|---|
| 1009 | | - return videobuf_reqbufs(&cam->vb_queue, rb); |
|---|
| 1010 | | -} |
|---|
| 1011 | | - |
|---|
| 1012 | | -static int viacam_querybuf(struct file *filp, void *priv, |
|---|
| 1013 | | - struct v4l2_buffer *buf) |
|---|
| 1014 | | -{ |
|---|
| 1015 | | - struct via_camera *cam = priv; |
|---|
| 1016 | | - |
|---|
| 1017 | | - return videobuf_querybuf(&cam->vb_queue, buf); |
|---|
| 1018 | | -} |
|---|
| 1019 | | - |
|---|
| 1020 | | -static int viacam_qbuf(struct file *filp, void *priv, struct v4l2_buffer *buf) |
|---|
| 1021 | | -{ |
|---|
| 1022 | | - struct via_camera *cam = priv; |
|---|
| 1023 | | - |
|---|
| 1024 | | - return videobuf_qbuf(&cam->vb_queue, buf); |
|---|
| 1025 | | -} |
|---|
| 1026 | | - |
|---|
| 1027 | | -static int viacam_dqbuf(struct file *filp, void *priv, struct v4l2_buffer *buf) |
|---|
| 1028 | | -{ |
|---|
| 1029 | | - struct via_camera *cam = priv; |
|---|
| 1030 | | - |
|---|
| 1031 | | - return videobuf_dqbuf(&cam->vb_queue, buf, filp->f_flags & O_NONBLOCK); |
|---|
| 1032 | | -} |
|---|
| 1033 | | - |
|---|
| 1034 | | -static int viacam_streamon(struct file *filp, void *priv, enum v4l2_buf_type t) |
|---|
| 1035 | | -{ |
|---|
| 1036 | | - struct via_camera *cam = priv; |
|---|
| 1037 | | - int ret = 0; |
|---|
| 1038 | | - |
|---|
| 1039 | | - if (t != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
|---|
| 1040 | | - return -EINVAL; |
|---|
| 1041 | | - |
|---|
| 1042 | | - mutex_lock(&cam->lock); |
|---|
| 1043 | | - if (cam->opstate != S_IDLE) { |
|---|
| 1044 | | - ret = -EBUSY; |
|---|
| 1045 | | - goto out; |
|---|
| 1046 | | - } |
|---|
| 1047 | | - /* |
|---|
| 1048 | | - * Enforce the V4l2 "only one owner gets to read data" rule. |
|---|
| 1049 | | - */ |
|---|
| 1050 | | - if (cam->owner && cam->owner != filp) { |
|---|
| 1051 | | - ret = -EBUSY; |
|---|
| 1052 | | - goto out; |
|---|
| 1053 | | - } |
|---|
| 1054 | | - cam->owner = filp; |
|---|
| 1055 | | - /* |
|---|
| 1056 | | - * Configure things if need be. |
|---|
| 1057 | | - */ |
|---|
| 1058 | | - if (test_bit(CF_CONFIG_NEEDED, &cam->flags)) { |
|---|
| 1059 | | - ret = viacam_configure_sensor(cam); |
|---|
| 1060 | | - if (ret) |
|---|
| 1061 | | - goto out; |
|---|
| 1062 | | - ret = viacam_config_controller(cam); |
|---|
| 1063 | | - if (ret) |
|---|
| 1064 | | - goto out; |
|---|
| 1065 | | - } |
|---|
| 1066 | | - /* |
|---|
| 1067 | | - * If the CPU goes into C3, the DMA transfer gets corrupted and |
|---|
| 1068 | | - * users start filing unsightly bug reports. Put in a "latency" |
|---|
| 1069 | | - * requirement which will keep the CPU out of the deeper sleep |
|---|
| 1070 | | - * states. |
|---|
| 1071 | | - */ |
|---|
| 1072 | | - pm_qos_add_request(&cam->qos_request, PM_QOS_CPU_DMA_LATENCY, 50); |
|---|
| 1073 | | - /* |
|---|
| 1074 | | - * Fire things up. |
|---|
| 1075 | | - */ |
|---|
| 1076 | | - INIT_LIST_HEAD(&cam->buffer_queue); |
|---|
| 1077 | | - ret = videobuf_streamon(&cam->vb_queue); |
|---|
| 1078 | | - if (!ret) |
|---|
| 1079 | | - viacam_start_engine(cam); |
|---|
| 1080 | | -out: |
|---|
| 1081 | | - mutex_unlock(&cam->lock); |
|---|
| 1082 | | - return ret; |
|---|
| 1083 | | -} |
|---|
| 1084 | | - |
|---|
| 1085 | | -static int viacam_streamoff(struct file *filp, void *priv, enum v4l2_buf_type t) |
|---|
| 1086 | | -{ |
|---|
| 1087 | | - struct via_camera *cam = priv; |
|---|
| 1088 | | - int ret; |
|---|
| 1089 | | - |
|---|
| 1090 | | - if (t != V4L2_BUF_TYPE_VIDEO_CAPTURE) |
|---|
| 1091 | | - return -EINVAL; |
|---|
| 1092 | | - mutex_lock(&cam->lock); |
|---|
| 1093 | | - if (cam->opstate != S_RUNNING) { |
|---|
| 1094 | | - ret = -EINVAL; |
|---|
| 1095 | | - goto out; |
|---|
| 1096 | | - } |
|---|
| 1097 | | - pm_qos_remove_request(&cam->qos_request); |
|---|
| 1098 | | - viacam_stop_engine(cam); |
|---|
| 1099 | | - /* |
|---|
| 1100 | | - * Videobuf will recycle all of the outstanding buffers, but |
|---|
| 1101 | | - * we should be sure we don't retain any references to |
|---|
| 1102 | | - * any of them. |
|---|
| 1103 | | - */ |
|---|
| 1104 | | - ret = videobuf_streamoff(&cam->vb_queue); |
|---|
| 1105 | | - INIT_LIST_HEAD(&cam->buffer_queue); |
|---|
| 1106 | | -out: |
|---|
| 1107 | | - mutex_unlock(&cam->lock); |
|---|
| 1108 | | - return ret; |
|---|
| 1109 | 922 | } |
|---|
| 1110 | 923 | |
|---|
| 1111 | 924 | /* G/S_PARM */ |
|---|
| .. | .. |
|---|
| 1113 | 926 | static int viacam_g_parm(struct file *filp, void *priv, |
|---|
| 1114 | 927 | struct v4l2_streamparm *parm) |
|---|
| 1115 | 928 | { |
|---|
| 1116 | | - struct via_camera *cam = priv; |
|---|
| 1117 | | - int ret; |
|---|
| 929 | + struct via_camera *cam = video_drvdata(filp); |
|---|
| 1118 | 930 | |
|---|
| 1119 | | - mutex_lock(&cam->lock); |
|---|
| 1120 | | - ret = v4l2_g_parm_cap(video_devdata(filp), cam->sensor, parm); |
|---|
| 1121 | | - mutex_unlock(&cam->lock); |
|---|
| 1122 | | - parm->parm.capture.readbuffers = cam->n_cap_bufs; |
|---|
| 1123 | | - return ret; |
|---|
| 931 | + return v4l2_g_parm_cap(video_devdata(filp), cam->sensor, parm); |
|---|
| 1124 | 932 | } |
|---|
| 1125 | 933 | |
|---|
| 1126 | 934 | static int viacam_s_parm(struct file *filp, void *priv, |
|---|
| 1127 | 935 | struct v4l2_streamparm *parm) |
|---|
| 1128 | 936 | { |
|---|
| 1129 | | - struct via_camera *cam = priv; |
|---|
| 1130 | | - int ret; |
|---|
| 937 | + struct via_camera *cam = video_drvdata(filp); |
|---|
| 1131 | 938 | |
|---|
| 1132 | | - mutex_lock(&cam->lock); |
|---|
| 1133 | | - ret = v4l2_s_parm_cap(video_devdata(filp), cam->sensor, parm); |
|---|
| 1134 | | - mutex_unlock(&cam->lock); |
|---|
| 1135 | | - parm->parm.capture.readbuffers = cam->n_cap_bufs; |
|---|
| 1136 | | - return ret; |
|---|
| 939 | + return v4l2_s_parm_cap(video_devdata(filp), cam->sensor, parm); |
|---|
| 1137 | 940 | } |
|---|
| 1138 | 941 | |
|---|
| 1139 | 942 | static int viacam_enum_framesizes(struct file *filp, void *priv, |
|---|
| 1140 | 943 | struct v4l2_frmsizeenum *sizes) |
|---|
| 1141 | 944 | { |
|---|
| 945 | + unsigned int i; |
|---|
| 946 | + |
|---|
| 1142 | 947 | if (sizes->index != 0) |
|---|
| 948 | + return -EINVAL; |
|---|
| 949 | + for (i = 0; i < N_VIA_FMTS; i++) |
|---|
| 950 | + if (sizes->pixel_format == via_formats[i].pixelformat) |
|---|
| 951 | + break; |
|---|
| 952 | + if (i >= N_VIA_FMTS) |
|---|
| 1143 | 953 | return -EINVAL; |
|---|
| 1144 | 954 | sizes->type = V4L2_FRMSIZE_TYPE_CONTINUOUS; |
|---|
| 1145 | 955 | sizes->stepwise.min_width = QCIF_WIDTH; |
|---|
| .. | .. |
|---|
| 1153 | 963 | static int viacam_enum_frameintervals(struct file *filp, void *priv, |
|---|
| 1154 | 964 | struct v4l2_frmivalenum *interval) |
|---|
| 1155 | 965 | { |
|---|
| 1156 | | - struct via_camera *cam = priv; |
|---|
| 966 | + struct via_camera *cam = video_drvdata(filp); |
|---|
| 1157 | 967 | struct v4l2_subdev_frame_interval_enum fie = { |
|---|
| 1158 | 968 | .index = interval->index, |
|---|
| 1159 | 969 | .code = cam->mbus_code, |
|---|
| .. | .. |
|---|
| 1161 | 971 | .height = cam->sensor_format.height, |
|---|
| 1162 | 972 | .which = V4L2_SUBDEV_FORMAT_ACTIVE, |
|---|
| 1163 | 973 | }; |
|---|
| 974 | + unsigned int i; |
|---|
| 1164 | 975 | int ret; |
|---|
| 1165 | 976 | |
|---|
| 1166 | | - mutex_lock(&cam->lock); |
|---|
| 977 | + for (i = 0; i < N_VIA_FMTS; i++) |
|---|
| 978 | + if (interval->pixel_format == via_formats[i].pixelformat) |
|---|
| 979 | + break; |
|---|
| 980 | + if (i >= N_VIA_FMTS) |
|---|
| 981 | + return -EINVAL; |
|---|
| 982 | + if (interval->width < QCIF_WIDTH || interval->width > VGA_WIDTH || |
|---|
| 983 | + interval->height < QCIF_HEIGHT || interval->height > VGA_HEIGHT) |
|---|
| 984 | + return -EINVAL; |
|---|
| 1167 | 985 | ret = sensor_call(cam, pad, enum_frame_interval, NULL, &fie); |
|---|
| 1168 | | - mutex_unlock(&cam->lock); |
|---|
| 1169 | 986 | if (ret) |
|---|
| 1170 | 987 | return ret; |
|---|
| 1171 | 988 | interval->type = V4L2_FRMIVAL_TYPE_DISCRETE; |
|---|
| .. | .. |
|---|
| 1173 | 990 | return 0; |
|---|
| 1174 | 991 | } |
|---|
| 1175 | 992 | |
|---|
| 1176 | | - |
|---|
| 1177 | | - |
|---|
| 1178 | 993 | static const struct v4l2_ioctl_ops viacam_ioctl_ops = { |
|---|
| 1179 | 994 | .vidioc_enum_input = viacam_enum_input, |
|---|
| 1180 | 995 | .vidioc_g_input = viacam_g_input, |
|---|
| 1181 | 996 | .vidioc_s_input = viacam_s_input, |
|---|
| 1182 | | - .vidioc_s_std = viacam_s_std, |
|---|
| 1183 | | - .vidioc_g_std = viacam_g_std, |
|---|
| 1184 | 997 | .vidioc_enum_fmt_vid_cap = viacam_enum_fmt_vid_cap, |
|---|
| 1185 | 998 | .vidioc_try_fmt_vid_cap = viacam_try_fmt_vid_cap, |
|---|
| 1186 | 999 | .vidioc_g_fmt_vid_cap = viacam_g_fmt_vid_cap, |
|---|
| 1187 | 1000 | .vidioc_s_fmt_vid_cap = viacam_s_fmt_vid_cap, |
|---|
| 1188 | 1001 | .vidioc_querycap = viacam_querycap, |
|---|
| 1189 | | - .vidioc_reqbufs = viacam_reqbufs, |
|---|
| 1190 | | - .vidioc_querybuf = viacam_querybuf, |
|---|
| 1191 | | - .vidioc_qbuf = viacam_qbuf, |
|---|
| 1192 | | - .vidioc_dqbuf = viacam_dqbuf, |
|---|
| 1193 | | - .vidioc_streamon = viacam_streamon, |
|---|
| 1194 | | - .vidioc_streamoff = viacam_streamoff, |
|---|
| 1002 | + .vidioc_reqbufs = vb2_ioctl_reqbufs, |
|---|
| 1003 | + .vidioc_create_bufs = vb2_ioctl_create_bufs, |
|---|
| 1004 | + .vidioc_querybuf = vb2_ioctl_querybuf, |
|---|
| 1005 | + .vidioc_prepare_buf = vb2_ioctl_prepare_buf, |
|---|
| 1006 | + .vidioc_qbuf = vb2_ioctl_qbuf, |
|---|
| 1007 | + .vidioc_dqbuf = vb2_ioctl_dqbuf, |
|---|
| 1008 | + .vidioc_expbuf = vb2_ioctl_expbuf, |
|---|
| 1009 | + .vidioc_streamon = vb2_ioctl_streamon, |
|---|
| 1010 | + .vidioc_streamoff = vb2_ioctl_streamoff, |
|---|
| 1195 | 1011 | .vidioc_g_parm = viacam_g_parm, |
|---|
| 1196 | 1012 | .vidioc_s_parm = viacam_s_parm, |
|---|
| 1197 | 1013 | .vidioc_enum_framesizes = viacam_enum_framesizes, |
|---|
| 1198 | 1014 | .vidioc_enum_frameintervals = viacam_enum_frameintervals, |
|---|
| 1015 | + .vidioc_subscribe_event = v4l2_ctrl_subscribe_event, |
|---|
| 1016 | + .vidioc_unsubscribe_event = v4l2_event_unsubscribe, |
|---|
| 1199 | 1017 | }; |
|---|
| 1200 | 1018 | |
|---|
| 1201 | 1019 | /*----------------------------------------------------------------------------*/ |
|---|
| .. | .. |
|---|
| 1233 | 1051 | /* |
|---|
| 1234 | 1052 | * Make sure the sensor's power state is correct |
|---|
| 1235 | 1053 | */ |
|---|
| 1236 | | - if (cam->users > 0) |
|---|
| 1054 | + if (!list_empty(&cam->vdev.fh_list)) |
|---|
| 1237 | 1055 | via_sensor_power_up(cam); |
|---|
| 1238 | 1056 | else |
|---|
| 1239 | 1057 | via_sensor_power_down(cam); |
|---|
| .. | .. |
|---|
| 1267 | 1085 | static const struct video_device viacam_v4l_template = { |
|---|
| 1268 | 1086 | .name = "via-camera", |
|---|
| 1269 | 1087 | .minor = -1, |
|---|
| 1270 | | - .tvnorms = V4L2_STD_NTSC_M, |
|---|
| 1271 | 1088 | .fops = &viacam_fops, |
|---|
| 1272 | 1089 | .ioctl_ops = &viacam_ioctl_ops, |
|---|
| 1273 | 1090 | .release = video_device_release_empty, /* Check this */ |
|---|
| 1091 | + .device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_READWRITE | |
|---|
| 1092 | + V4L2_CAP_STREAMING, |
|---|
| 1274 | 1093 | }; |
|---|
| 1275 | 1094 | |
|---|
| 1276 | 1095 | /* |
|---|
| .. | .. |
|---|
| 1317 | 1136 | int ret; |
|---|
| 1318 | 1137 | struct i2c_adapter *sensor_adapter; |
|---|
| 1319 | 1138 | struct viafb_dev *viadev = pdev->dev.platform_data; |
|---|
| 1139 | + struct vb2_queue *vq; |
|---|
| 1320 | 1140 | struct i2c_board_info ov7670_info = { |
|---|
| 1321 | 1141 | .type = "ov7670", |
|---|
| 1322 | 1142 | .addr = 0x42 >> 1, |
|---|
| .. | .. |
|---|
| 1360 | 1180 | via_cam_info = cam; |
|---|
| 1361 | 1181 | cam->platdev = pdev; |
|---|
| 1362 | 1182 | cam->viadev = viadev; |
|---|
| 1363 | | - cam->users = 0; |
|---|
| 1364 | | - cam->owner = NULL; |
|---|
| 1365 | 1183 | cam->opstate = S_IDLE; |
|---|
| 1366 | 1184 | cam->user_format = cam->sensor_format = viacam_def_pix_format; |
|---|
| 1367 | 1185 | mutex_init(&cam->lock); |
|---|
| .. | .. |
|---|
| 1422 | 1240 | viacam_irq, IRQF_SHARED, "via-camera", cam); |
|---|
| 1423 | 1241 | if (ret) |
|---|
| 1424 | 1242 | goto out_power_down; |
|---|
| 1243 | + |
|---|
| 1244 | + vq = &cam->vq; |
|---|
| 1245 | + vq->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
|---|
| 1246 | + vq->io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF | VB2_READ; |
|---|
| 1247 | + vq->drv_priv = cam; |
|---|
| 1248 | + vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; |
|---|
| 1249 | + vq->buf_struct_size = sizeof(struct via_buffer); |
|---|
| 1250 | + vq->dev = cam->v4l2_dev.dev; |
|---|
| 1251 | + |
|---|
| 1252 | + vq->ops = &viacam_vb2_ops; |
|---|
| 1253 | + vq->mem_ops = &vb2_dma_sg_memops; |
|---|
| 1254 | + vq->lock = &cam->lock; |
|---|
| 1255 | + |
|---|
| 1256 | + ret = vb2_queue_init(vq); |
|---|
| 1425 | 1257 | /* |
|---|
| 1426 | 1258 | * Tell V4l2 that we exist. |
|---|
| 1427 | 1259 | */ |
|---|
| 1428 | 1260 | cam->vdev = viacam_v4l_template; |
|---|
| 1429 | 1261 | cam->vdev.v4l2_dev = &cam->v4l2_dev; |
|---|
| 1430 | | - ret = video_register_device(&cam->vdev, VFL_TYPE_GRABBER, -1); |
|---|
| 1262 | + cam->vdev.lock = &cam->lock; |
|---|
| 1263 | + cam->vdev.queue = vq; |
|---|
| 1264 | + video_set_drvdata(&cam->vdev, cam); |
|---|
| 1265 | + ret = video_register_device(&cam->vdev, VFL_TYPE_VIDEO, -1); |
|---|
| 1431 | 1266 | if (ret) |
|---|
| 1432 | 1267 | goto out_irq; |
|---|
| 1433 | | - video_set_drvdata(&cam->vdev, cam); |
|---|
| 1434 | 1268 | |
|---|
| 1435 | 1269 | #ifdef CONFIG_PM |
|---|
| 1436 | 1270 | /* |
|---|
| .. | .. |
|---|
| 1464 | 1298 | |
|---|
| 1465 | 1299 | video_unregister_device(&cam->vdev); |
|---|
| 1466 | 1300 | v4l2_device_unregister(&cam->v4l2_dev); |
|---|
| 1301 | +#ifdef CONFIG_PM |
|---|
| 1302 | + viafb_pm_unregister(&viacam_pm_hooks); |
|---|
| 1303 | +#endif |
|---|
| 1467 | 1304 | free_irq(viadev->pdev->irq, cam); |
|---|
| 1468 | 1305 | via_sensor_power_release(cam); |
|---|
| 1469 | 1306 | v4l2_ctrl_handler_free(&cam->ctrl_handler); |
|---|