mirror of
https://github.com/patjak/facetimehd.git
synced 2026-04-09 19:10:01 +02:00
fthd/v4l2: A bunch of trivial codestyle fixes
Signed-off-by: Patrik Jakobsson <patrik.r.jakobsson@gmail.com>
This commit is contained in:
161
fthd_v4l2.c
161
fthd_v4l2.c
@@ -73,7 +73,7 @@ static void fthd_buffer_cleanup(struct vb2_buffer *vb)
|
||||
int i;
|
||||
|
||||
pr_debug("%p\n", vb);
|
||||
for(i = 0; i < FTHD_BUFFERS; i++) {
|
||||
for (i = 0; i < FTHD_BUFFERS; i++) {
|
||||
if (dev_priv->h2t_bufs[i].vb == vb) {
|
||||
ctx = dev_priv->h2t_bufs + i;
|
||||
break;
|
||||
@@ -85,7 +85,7 @@ static void fthd_buffer_cleanup(struct vb2_buffer *vb)
|
||||
ctx->state = BUF_FREE;
|
||||
ctx->vb = NULL;
|
||||
isp_mem_destroy(ctx->dma_desc_obj);
|
||||
for(i = 0; i < dev_priv->fmt.planes; i++) {
|
||||
for (i = 0; i < dev_priv->fmt.planes; i++) {
|
||||
iommu_free(dev_priv, ctx->plane[i]);
|
||||
ctx->plane[i] = NULL;
|
||||
}
|
||||
@@ -97,8 +97,10 @@ static int fthd_send_h2t_buffer(struct fthd_private *dev_priv, struct h2t_buf_ct
|
||||
u32 entry;
|
||||
int ret;
|
||||
|
||||
pr_debug("sending buffer %p size %ld, ctx %p\n", ctx->vb, sizeof(ctx->dma_desc_list), ctx);
|
||||
FTHD_S2_MEMCPY_TOIO(ctx->dma_desc_obj->offset, &ctx->dma_desc_list, sizeof(ctx->dma_desc_list));
|
||||
pr_debug("sending buffer %p size %ld, ctx %p\n",
|
||||
ctx->vb, sizeof(ctx->dma_desc_list), ctx);
|
||||
FTHD_S2_MEMCPY_TOIO(ctx->dma_desc_obj->offset, &ctx->dma_desc_list,
|
||||
sizeof(ctx->dma_desc_list));
|
||||
ret = fthd_channel_ringbuf_send(dev_priv, dev_priv->channel_buf_h2t,
|
||||
ctx->dma_desc_obj->offset, 0x180, 0x30000000, &entry);
|
||||
|
||||
@@ -106,6 +108,7 @@ static int fthd_send_h2t_buffer(struct fthd_private *dev_priv, struct h2t_buf_ct
|
||||
pr_err("%s: fthd_channel_ringbuf_send: %d\n", __FUNCTION__, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
return fthd_channel_wait_ready(dev_priv, dev_priv->channel_buf_h2t, entry, 2000);
|
||||
}
|
||||
|
||||
@@ -117,11 +120,11 @@ static void fthd_buffer_queue(struct vb2_buffer *vb)
|
||||
|
||||
int i;
|
||||
pr_debug("vb = %p\n", vb);
|
||||
for(i = 0; i < FTHD_BUFFERS; i++) {
|
||||
for (i = 0; i < FTHD_BUFFERS; i++) {
|
||||
if (dev_priv->h2t_bufs[i].vb == vb) {
|
||||
ctx = dev_priv->h2t_bufs + i;
|
||||
break;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
if (!ctx)
|
||||
@@ -137,14 +140,17 @@ static void fthd_buffer_queue(struct vb2_buffer *vb)
|
||||
list->field0 = 1;
|
||||
ctx->state = BUF_HW_QUEUED;
|
||||
wmb();
|
||||
pr_debug("%d: field0: %d, count %d, pool %d, addr0 0x%08x, addr1 0x%08x tag 0x%08llx vb = %p\n", i, list->field0,
|
||||
list->desc[i].count, list->desc[i].pool, list->desc[i].addr0, list->desc[i].addr1, list->desc[i].tag, ctx->vb);
|
||||
pr_debug("%d: field0: %d, count %d, pool %d, addr0 0x%08x, addr1 0x%08x tag 0x%08llx vb = %p\n",
|
||||
i, list->field0, list->desc[i].count,
|
||||
list->desc[i].pool, list->desc[i].addr0,
|
||||
list->desc[i].addr1, list->desc[i].tag, ctx->vb);
|
||||
|
||||
if (fthd_send_h2t_buffer(dev_priv, ctx)) {
|
||||
vb2_buffer_done(vb, VB2_BUF_STATE_ERROR);
|
||||
ctx->state = BUF_ALLOC;
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -157,9 +163,10 @@ static int fthd_buffer_prepare(struct vb2_buffer *vb)
|
||||
int i;
|
||||
|
||||
pr_debug("%p\n", vb);
|
||||
for(i = 0; i < FTHD_BUFFERS; i++) {
|
||||
for (i = 0; i < FTHD_BUFFERS; i++) {
|
||||
if (dev_priv->h2t_bufs[i].state == BUF_FREE ||
|
||||
(dev_priv->h2t_bufs[i].state == BUF_ALLOC && dev_priv->h2t_bufs[i].vb == vb)) {
|
||||
(dev_priv->h2t_bufs[i].state == BUF_ALLOC &&
|
||||
dev_priv->h2t_bufs[i].vb == vb)) {
|
||||
ctx = dev_priv->h2t_bufs + i;
|
||||
break;
|
||||
}
|
||||
@@ -170,18 +177,20 @@ static int fthd_buffer_prepare(struct vb2_buffer *vb)
|
||||
|
||||
if (ctx->state == BUF_FREE) {
|
||||
pr_debug("allocating new entry\n");
|
||||
ctx->dma_desc_obj = isp_mem_create(dev_priv, FTHD_MEM_BUFFER, 0x180);
|
||||
ctx->dma_desc_obj = isp_mem_create(dev_priv, FTHD_MEM_BUFFER,
|
||||
0x180);
|
||||
if (!ctx->dma_desc_obj)
|
||||
return -ENOMEM;
|
||||
|
||||
ctx->vb = vb;
|
||||
ctx->state = BUF_ALLOC;
|
||||
|
||||
for(i = 0; i < dev_priv->fmt.planes; i++) {
|
||||
sgtable = vb2_dma_sg_plane_desc(vb, i);
|
||||
ctx->plane[i] = iommu_allocate_sgtable(dev_priv, sgtable);
|
||||
if(!ctx->plane[i])
|
||||
return -ENOMEM;
|
||||
for (i = 0; i < dev_priv->fmt.planes; i++) {
|
||||
sgtable = vb2_dma_sg_plane_desc(vb, i);
|
||||
ctx->plane[i] = iommu_allocate_sgtable(dev_priv, sgtable);
|
||||
|
||||
if(!ctx->plane[i])
|
||||
return -ENOMEM;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -203,6 +212,7 @@ static int fthd_buffer_prepare(struct vb2_buffer *vb)
|
||||
|
||||
dma_list->desc[0].tag = (u64)ctx;
|
||||
init_waitqueue_head(&ctx->wq);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -214,12 +224,15 @@ void fthd_buffer_return_handler(struct fthd_private *dev_priv, u32 offset, int s
|
||||
|
||||
FTHD_S2_MEMCPY_FROMIO(&list, offset, sizeof(list));
|
||||
|
||||
for(i = 0; i < list.count; i++) {
|
||||
for (i = 0; i < list.count; i++) {
|
||||
ctx = (struct h2t_buf_ctx *)list.desc[i].tag;
|
||||
pr_debug("%d: field0: %d, count %d, pool %d, addr0 0x%08x, addr1 0x%08x tag 0x%08llx vb = %p, ctx = %p\n", i, list.field0,
|
||||
list.desc[i].count, list.desc[i].pool, list.desc[i].addr0, list.desc[i].addr1, list.desc[i].tag, ctx->vb, ctx);
|
||||
pr_debug("%d: field0: %d, count %d, pool %d, addr0 0x%08x, addr1 0x%08x tag 0x%08llx vb = %p, ctx = %p\n",
|
||||
i, list.field0, list.desc[i].count, list.desc[i].pool,
|
||||
list.desc[i].addr0, list.desc[i].addr1,
|
||||
list.desc[i].tag, ctx->vb, ctx);
|
||||
|
||||
if (ctx->state == BUF_HW_QUEUED || ctx->state == BUF_DRV_QUEUED) {
|
||||
if (ctx->state == BUF_HW_QUEUED ||
|
||||
ctx->state == BUF_DRV_QUEUED) {
|
||||
ctx->state = BUF_ALLOC;
|
||||
vb2_buffer_done(ctx->vb, VB2_BUF_STATE_DONE);
|
||||
}
|
||||
@@ -238,7 +251,7 @@ static int fthd_start_streaming(struct vb2_queue *vq, unsigned int count)
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
for(i = 0; i < FTHD_BUFFERS && count; i++, count--) {
|
||||
for (i = 0; i < FTHD_BUFFERS && count; i++, count--) {
|
||||
ctx = dev_priv->h2t_bufs + i;
|
||||
if (ctx->state != BUF_DRV_QUEUED)
|
||||
continue;
|
||||
@@ -247,8 +260,9 @@ static int fthd_start_streaming(struct vb2_queue *vq, unsigned int count)
|
||||
vb2_buffer_done(ctx->vb, VB2_BUF_STATE_ERROR);
|
||||
ctx->state = BUF_ALLOC;
|
||||
}
|
||||
ctx->state = BUF_HW_QUEUED;
|
||||
ctx->state = BUF_HW_QUEUED;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -264,37 +278,38 @@ static void fthd_stop_streaming(struct vb2_queue *vq)
|
||||
vb2_wait_for_all_buffers(vq);
|
||||
pr_debug("done\n");
|
||||
} else {
|
||||
/* Firmware doesn't respond. */
|
||||
for(i = 0; i < FTHD_BUFFERS;i++) {
|
||||
ctx = dev_priv->h2t_bufs + i;
|
||||
if (ctx->state == BUF_DRV_QUEUED || ctx->state == BUF_HW_QUEUED) {
|
||||
vb2_buffer_done(ctx->vb, VB2_BUF_STATE_DONE);
|
||||
ctx->vb = NULL;
|
||||
ctx->state = BUF_ALLOC;
|
||||
/* Firmware doesn't respond. */
|
||||
for (i = 0; i < FTHD_BUFFERS;i++) {
|
||||
ctx = dev_priv->h2t_bufs + i;
|
||||
if (ctx->state == BUF_DRV_QUEUED ||
|
||||
ctx->state == BUF_HW_QUEUED) {
|
||||
vb2_buffer_done(ctx->vb, VB2_BUF_STATE_DONE);
|
||||
ctx->vb = NULL;
|
||||
ctx->state = BUF_ALLOC;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static struct vb2_ops vb2_queue_ops = {
|
||||
.queue_setup = fthd_buffer_queue_setup,
|
||||
.buf_prepare = fthd_buffer_prepare,
|
||||
.buf_cleanup = fthd_buffer_cleanup,
|
||||
.start_streaming = fthd_start_streaming,
|
||||
.stop_streaming = fthd_stop_streaming,
|
||||
.buf_queue = fthd_buffer_queue,
|
||||
.wait_prepare = vb2_ops_wait_prepare,
|
||||
.wait_finish = vb2_ops_wait_finish,
|
||||
.queue_setup = fthd_buffer_queue_setup,
|
||||
.buf_prepare = fthd_buffer_prepare,
|
||||
.buf_cleanup = fthd_buffer_cleanup,
|
||||
.start_streaming = fthd_start_streaming,
|
||||
.stop_streaming = fthd_stop_streaming,
|
||||
.buf_queue = fthd_buffer_queue,
|
||||
.wait_prepare = vb2_ops_wait_prepare,
|
||||
.wait_finish = vb2_ops_wait_finish,
|
||||
};
|
||||
|
||||
static struct v4l2_file_operations fthd_vdev_fops = {
|
||||
.owner = THIS_MODULE,
|
||||
.open = v4l2_fh_open,
|
||||
.owner = THIS_MODULE,
|
||||
.open = v4l2_fh_open,
|
||||
|
||||
.read = vb2_fop_read,
|
||||
.release = vb2_fop_release,
|
||||
.poll = vb2_fop_poll,
|
||||
.mmap = vb2_fop_mmap,
|
||||
.release = vb2_fop_release,
|
||||
.poll = vb2_fop_poll,
|
||||
.mmap = vb2_fop_mmap,
|
||||
.unlocked_ioctl = video_ioctl2
|
||||
};
|
||||
|
||||
@@ -315,6 +330,7 @@ static int fthd_v4l2_ioctl_enum_input(struct file *filp, void *priv,
|
||||
static int fthd_v4l2_ioctl_g_input(struct file *filp, void *priv, unsigned int *i)
|
||||
{
|
||||
*i = 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -322,6 +338,7 @@ static int fthd_v4l2_ioctl_s_input(struct file *filp, void *priv, unsigned int i
|
||||
{
|
||||
if (i != 0)
|
||||
return -EINVAL;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -374,7 +391,6 @@ static int fthd_v4l2_ioctl_enum_fmt_vid_cap(struct file *filp, void *priv,
|
||||
static int fthd_v4l2_adjust_format(struct fthd_private *dev_priv,
|
||||
struct v4l2_pix_format *pix)
|
||||
{
|
||||
|
||||
if (pix->pixelformat != V4L2_PIX_FMT_YUYV &&
|
||||
pix->pixelformat != V4L2_PIX_FMT_YVYU)
|
||||
pix->pixelformat = V4L2_PIX_FMT_YUYV;
|
||||
@@ -415,7 +431,8 @@ static int fthd_v4l2_ioctl_try_fmt_vid_cap(struct file *filp, void *_priv,
|
||||
{
|
||||
struct fthd_private *dev_priv = video_drvdata(filp);
|
||||
|
||||
pr_debug("%s: %dx%d\n", __FUNCTION__, fmt->fmt.pix.width, fmt->fmt.pix.height);
|
||||
pr_debug("%s: %dx%d\n", __FUNCTION__, fmt->fmt.pix.width,
|
||||
fmt->fmt.pix.height);
|
||||
|
||||
if (fmt->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
|
||||
return -EINVAL;
|
||||
@@ -472,7 +489,7 @@ static int fthd_v4l2_ioctl_s_fmt_vid_cap(struct file *filp, void *priv,
|
||||
|
||||
|
||||
static int fthd_v4l2_ioctl_g_parm(struct file *filp, void *priv,
|
||||
struct v4l2_streamparm *parm)
|
||||
struct v4l2_streamparm *parm)
|
||||
{
|
||||
struct fthd_private *priv_dev = video_drvdata(filp);
|
||||
struct v4l2_fract timeperframe = {
|
||||
@@ -486,6 +503,7 @@ static int fthd_v4l2_ioctl_g_parm(struct file *filp, void *priv,
|
||||
parm->parm.capture.readbuffers = FTHD_BUFFERS;
|
||||
parm->parm.capture.capability = V4L2_CAP_TIMEPERFRAME;
|
||||
parm->parm.capture.timeperframe = timeperframe;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -501,7 +519,7 @@ static int fthd_v4l2_ioctl_s_parm(struct file *filp, void *priv,
|
||||
|
||||
timeperframe = &parm->parm.capture.timeperframe;
|
||||
|
||||
if(timeperframe->denominator == 0) {
|
||||
if (timeperframe->denominator == 0) {
|
||||
timeperframe->numerator = 20;
|
||||
timeperframe->denominator = 1000;
|
||||
}
|
||||
@@ -529,11 +547,12 @@ static int fthd_v4l2_ioctl_enum_framesizes(struct file *filp, void *priv,
|
||||
sizes->stepwise.max_height = FTHD_MAX_HEIGHT;
|
||||
sizes->stepwise.step_width = 8;
|
||||
sizes->stepwise.step_height = 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int fthd_v4l2_ioctl_enum_frameintervals(struct file *filp, void *priv,
|
||||
struct v4l2_frmivalenum *interval)
|
||||
struct v4l2_frmivalenum *interval)
|
||||
{
|
||||
pr_debug("%s\n", __FUNCTION__);
|
||||
|
||||
@@ -557,6 +576,7 @@ static int fthd_v4l2_ioctl_enum_frameintervals(struct file *filp, void *priv,
|
||||
interval->stepwise.min.denominator = 1000;
|
||||
interval->stepwise.max.numerator = 500;
|
||||
interval->stepwise.max.denominator = 1000;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -572,28 +592,27 @@ static int fthd_v4l2_ioctl_subscribe_event(struct v4l2_fh *fh,
|
||||
}
|
||||
|
||||
static struct v4l2_ioctl_ops fthd_ioctl_ops = {
|
||||
.vidioc_enum_input = fthd_v4l2_ioctl_enum_input,
|
||||
.vidioc_g_input = fthd_v4l2_ioctl_g_input,
|
||||
.vidioc_s_input = fthd_v4l2_ioctl_s_input,
|
||||
.vidioc_enum_input = fthd_v4l2_ioctl_enum_input,
|
||||
.vidioc_g_input = fthd_v4l2_ioctl_g_input,
|
||||
.vidioc_s_input = fthd_v4l2_ioctl_s_input,
|
||||
.vidioc_enum_fmt_vid_cap = fthd_v4l2_ioctl_enum_fmt_vid_cap,
|
||||
.vidioc_try_fmt_vid_cap = fthd_v4l2_ioctl_try_fmt_vid_cap,
|
||||
.vidioc_try_fmt_vid_cap = fthd_v4l2_ioctl_try_fmt_vid_cap,
|
||||
|
||||
.vidioc_g_fmt_vid_cap = fthd_v4l2_ioctl_g_fmt_vid_cap,
|
||||
.vidioc_s_fmt_vid_cap = fthd_v4l2_ioctl_s_fmt_vid_cap,
|
||||
.vidioc_querycap = fthd_v4l2_ioctl_querycap,
|
||||
.vidioc_g_fmt_vid_cap = fthd_v4l2_ioctl_g_fmt_vid_cap,
|
||||
.vidioc_s_fmt_vid_cap = fthd_v4l2_ioctl_s_fmt_vid_cap,
|
||||
.vidioc_querycap = fthd_v4l2_ioctl_querycap,
|
||||
|
||||
.vidioc_reqbufs = vb2_ioctl_reqbufs,
|
||||
.vidioc_create_bufs = vb2_ioctl_create_bufs,
|
||||
.vidioc_querybuf = vb2_ioctl_querybuf,
|
||||
.vidioc_qbuf = vb2_ioctl_qbuf,
|
||||
.vidioc_dqbuf = vb2_ioctl_dqbuf,
|
||||
.vidioc_expbuf = vb2_ioctl_expbuf,
|
||||
.vidioc_streamon = vb2_ioctl_streamon,
|
||||
.vidioc_streamoff = vb2_ioctl_streamoff,
|
||||
|
||||
.vidioc_reqbufs = vb2_ioctl_reqbufs,
|
||||
.vidioc_create_bufs = vb2_ioctl_create_bufs,
|
||||
.vidioc_querybuf = vb2_ioctl_querybuf,
|
||||
.vidioc_qbuf = vb2_ioctl_qbuf,
|
||||
.vidioc_dqbuf = vb2_ioctl_dqbuf,
|
||||
.vidioc_expbuf = vb2_ioctl_expbuf,
|
||||
.vidioc_streamon = vb2_ioctl_streamon,
|
||||
.vidioc_streamoff = vb2_ioctl_streamoff,
|
||||
|
||||
.vidioc_g_parm = fthd_v4l2_ioctl_g_parm,
|
||||
.vidioc_s_parm = fthd_v4l2_ioctl_s_parm,
|
||||
.vidioc_g_parm = fthd_v4l2_ioctl_g_parm,
|
||||
.vidioc_s_parm = fthd_v4l2_ioctl_s_parm,
|
||||
.vidioc_enum_framesizes = fthd_v4l2_ioctl_enum_framesizes,
|
||||
.vidioc_enum_frameintervals = fthd_v4l2_ioctl_enum_frameintervals,
|
||||
|
||||
@@ -604,6 +623,7 @@ static struct v4l2_ioctl_ops fthd_ioctl_ops = {
|
||||
static int fthd_g_volatile_ctrl(struct v4l2_ctrl *ctrl)
|
||||
{
|
||||
pr_debug("id = %x\n", ctrl->id);
|
||||
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
@@ -635,6 +655,7 @@ static int fthd_s_ctrl(struct v4l2_ctrl *ctrl)
|
||||
|
||||
}
|
||||
pr_debug("ret = %d\n", ret);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -669,7 +690,7 @@ int fthd_v4l2_register(struct fthd_private *dev_priv)
|
||||
q->drv_priv = dev_priv;
|
||||
q->ops = &vb2_queue_ops;
|
||||
q->mem_ops = &vb2_dma_sg_memops;
|
||||
q->buf_struct_size = 0;//sizeof(struct vpif_cap_buffer);
|
||||
q->buf_struct_size = 0; /* sizeof(struct vpif_cap_buffer); */
|
||||
q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
|
||||
q->min_buffers_needed = 1;
|
||||
q->lock = &dev_priv->vb2_queue_lock;
|
||||
@@ -695,7 +716,9 @@ int fthd_v4l2_register(struct fthd_private *dev_priv)
|
||||
v4l2_ctrl_handler_free(&dev_priv->v4l2_ctrl_handler);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
dev_priv->alloc_ctx = vb2_dma_sg_init_ctx(&dev_priv->pdev->dev);
|
||||
|
||||
vdev->v4l2_dev = v4l2_dev;
|
||||
strcpy(vdev->name, "Apple Facetime HD"); // XXX: Length?
|
||||
vdev->vfl_dir = VFL_DIR_RX;
|
||||
@@ -705,11 +728,13 @@ int fthd_v4l2_register(struct fthd_private *dev_priv)
|
||||
vdev->release = video_device_release;
|
||||
vdev->ctrl_handler = &dev_priv->v4l2_ctrl_handler;
|
||||
video_set_drvdata(vdev, dev_priv);
|
||||
|
||||
ret = video_register_device(vdev, VFL_TYPE_GRABBER, -1);
|
||||
if (ret) {
|
||||
video_device_release(vdev);
|
||||
goto fail_vdev;
|
||||
}
|
||||
|
||||
dev_priv->fmt.fmt.sizeimage = 1280 * 720 * 2;
|
||||
dev_priv->fmt.fmt.pixelformat = V4L2_PIX_FMT_YUYV;
|
||||
dev_priv->fmt.fmt.width = 1280;
|
||||
@@ -719,10 +744,12 @@ int fthd_v4l2_register(struct fthd_private *dev_priv)
|
||||
fthd_v4l2_adjust_format(dev_priv, &dev_priv->fmt.fmt);
|
||||
|
||||
return 0;
|
||||
|
||||
fail_vdev:
|
||||
v4l2_ctrl_handler_free(&dev_priv->v4l2_ctrl_handler);
|
||||
fail:
|
||||
v4l2_device_unregister(&dev_priv->v4l2_dev);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user