Lines Matching refs:voutdev

43 static void return_all_buffers(struct mgb4_vout_dev *voutdev,
49 spin_lock_irqsave(&voutdev->qlock, flags);
50 list_for_each_entry_safe(buf, node, &voutdev->buf_list, list) {
54 spin_unlock_irqrestore(&voutdev->qlock, flags);
61 struct mgb4_vout_dev *voutdev = vb2_get_drv_priv(q);
69 if (test_bit(0, &voutdev->mgbdev->io_reconfig))
72 size = (voutdev->width + voutdev->padding) * voutdev->height * 4;
94 struct mgb4_vout_dev *voutdev = vb2_get_drv_priv(vb->vb2_queue);
95 struct device *dev = &voutdev->mgbdev->pdev->dev;
98 size = (voutdev->width + voutdev->padding) * voutdev->height * 4;
125 struct mgb4_vout_dev *voutdev = vb2_get_drv_priv(vq);
126 struct mgb4_dev *mgbdev = voutdev->mgbdev;
127 int irq = xdma_get_user_irq(mgbdev->xdev, voutdev->config->irq);
130 cancel_work_sync(&voutdev->dma_work);
131 mgb4_mask_reg(&mgbdev->video, voutdev->config->regs.config, 0x2, 0x0);
132 return_all_buffers(voutdev, VB2_BUF_STATE_ERROR);
137 struct mgb4_vout_dev *voutdev = vb2_get_drv_priv(vq);
138 struct mgb4_dev *mgbdev = voutdev->mgbdev;
142 const struct mgb4_vout_config *config = voutdev->config;
152 return_all_buffers(voutdev, VB2_BUF_STATE_QUEUED);
156 buf = list_first_entry(&voutdev->buf_list, struct mgb4_frame_buffer,
158 list_del_init(voutdev->buf_list.next);
207 struct mgb4_vout_dev *voutdev = video_drvdata(file);
210 f->fmt.pix.width = voutdev->width;
211 f->fmt.pix.height = voutdev->height;
214 f->fmt.pix.bytesperline = (f->fmt.pix.width + voutdev->padding) * 4;
222 struct mgb4_vout_dev *voutdev = video_drvdata(file);
225 f->fmt.pix.width = voutdev->width;
226 f->fmt.pix.height = voutdev->height;
238 struct mgb4_vout_dev *voutdev = video_drvdata(file);
239 struct mgb4_regs *video = &voutdev->mgbdev->video;
241 if (vb2_is_busy(&voutdev->queue))
246 voutdev->padding = (f->fmt.pix.bytesperline - (f->fmt.pix.width * 4)) / 4;
247 mgb4_write_reg(video, voutdev->config->regs.padding, voutdev->padding);
297 struct mgb4_vout_dev *voutdev = video_drvdata(file);
298 struct mgb4_regs *video = &voutdev->mgbdev->video;
299 struct device *dev = &voutdev->mgbdev->pdev->dev;
304 config = mgb4_read_reg(video, voutdev->config->regs.config);
305 if ((config & 0xc) >> 2 != voutdev->config->id + MGB4_VIN_DEVICES) {
310 mutex_lock(&voutdev->lock);
319 resolution = mgb4_read_reg(video, voutdev->config->regs.resolution);
320 voutdev->width = resolution >> 16;
321 voutdev->height = resolution & 0xFFFF;
324 mutex_unlock(&voutdev->lock);
340 struct mgb4_vout_dev *voutdev = container_of(work, struct mgb4_vout_dev,
342 struct device *dev = &voutdev->mgbdev->pdev->dev;
343 struct mgb4_regs *video = &voutdev->mgbdev->video;
349 spin_lock_irqsave(&voutdev->qlock, flags);
350 if (!list_empty(&voutdev->buf_list)) {
351 buf = list_first_entry(&voutdev->buf_list,
353 list_del_init(voutdev->buf_list.next);
355 spin_unlock_irqrestore(&voutdev->qlock, flags);
360 addr = mgb4_read_reg(video, voutdev->config->regs.address);
367 rv = mgb4_dma_transfer(voutdev->mgbdev, voutdev->config->dma_channel,
380 struct mgb4_vout_dev *voutdev = (struct mgb4_vout_dev *)ctx;
381 struct mgb4_regs *video = &voutdev->mgbdev->video;
383 schedule_work(&voutdev->dma_work);
385 mgb4_write_reg(video, 0xB4, 1U << voutdev->config->irq);
390 static int ser_init(struct mgb4_vout_dev *voutdev, int id)
394 struct mgb4_i2c_client *ser = &voutdev->ser;
395 struct device *dev = &voutdev->mgbdev->pdev->dev;
397 if (MGB4_IS_GMSL(voutdev->mgbdev))
400 rv = mgb4_i2c_init(ser, voutdev->mgbdev->i2c_adap, info, 8);
419 static void fpga_init(struct mgb4_vout_dev *voutdev)
421 struct mgb4_regs *video = &voutdev->mgbdev->video;
422 const struct mgb4_vout_regs *regs = &voutdev->config->regs;
432 voutdev->freq = mgb4_cmt_set_vout_freq(voutdev, 70000 >> 1) << 1;
435 (voutdev->config->id + MGB4_VIN_DEVICES) << 2 | 1 << 4);
439 static void debugfs_init(struct mgb4_vout_dev *voutdev)
441 struct mgb4_regs *video = &voutdev->mgbdev->video;
443 voutdev->debugfs = debugfs_create_dir(voutdev->vdev.name,
444 voutdev->mgbdev->debugfs);
445 if (!voutdev->debugfs)
448 voutdev->regs[0].name = "CONFIG";
449 voutdev->regs[0].offset = voutdev->config->regs.config;
450 voutdev->regs[1].name = "STATUS";
451 voutdev->regs[1].offset = voutdev->config->regs.status;
452 voutdev->regs[2].name = "RESOLUTION";
453 voutdev->regs[2].offset = voutdev->config->regs.resolution;
454 voutdev->regs[3].name = "VIDEO_PARAMS_1";
455 voutdev->regs[3].offset = voutdev->config->regs.hsync;
456 voutdev->regs[4].name = "VIDEO_PARAMS_2";
457 voutdev->regs[4].offset = voutdev->config->regs.vsync;
458 voutdev->regs[5].name = "FRAME_PERIOD";
459 voutdev->regs[5].offset = voutdev->config->regs.frame_period;
460 voutdev->regs[6].name = "PADDING";
461 voutdev->regs[6].offset = voutdev->config->regs.padding;
463 voutdev->regset.base = video->membase;
464 voutdev->regset.regs = voutdev->regs;
465 voutdev->regset.nregs = ARRAY_SIZE(voutdev->regs);
467 debugfs_create_regset32("registers", 0444, voutdev->debugfs,
468 &voutdev->regset);
476 struct mgb4_vout_dev *voutdev;
480 voutdev = kzalloc(sizeof(*voutdev), GFP_KERNEL);
481 if (!voutdev)
484 voutdev->mgbdev = mgbdev;
485 voutdev->config = &vout_cfg[id];
488 INIT_LIST_HEAD(&voutdev->buf_list);
489 spin_lock_init(&voutdev->qlock);
492 INIT_WORK(&voutdev->dma_work, dma_transfer);
495 irq = xdma_get_user_irq(mgbdev->xdev, voutdev->config->irq);
496 rv = request_irq(irq, handler, 0, "mgb4-vout", voutdev);
503 fpga_init(voutdev);
506 rv = ser_init(voutdev, id);
511 rv = v4l2_device_register(dev, &voutdev->v4l2dev);
517 mutex_init(&voutdev->lock);
519 voutdev->queue.type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
520 voutdev->queue.io_modes = VB2_MMAP | VB2_DMABUF | VB2_WRITE;
521 voutdev->queue.buf_struct_size = sizeof(struct mgb4_frame_buffer);
522 voutdev->queue.ops = &queue_ops;
523 voutdev->queue.mem_ops = &vb2_dma_sg_memops;
524 voutdev->queue.gfp_flags = GFP_DMA32;
525 voutdev->queue.timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
526 voutdev->queue.min_queued_buffers = 2;
527 voutdev->queue.drv_priv = voutdev;
528 voutdev->queue.lock = &voutdev->lock;
529 voutdev->queue.dev = dev;
530 rv = vb2_queue_init(&voutdev->queue);
536 snprintf(voutdev->vdev.name, sizeof(voutdev->vdev.name), "mgb4-out%d",
538 voutdev->vdev.device_caps = V4L2_CAP_VIDEO_OUTPUT | V4L2_CAP_READWRITE
540 voutdev->vdev.vfl_dir = VFL_DIR_TX;
541 voutdev->vdev.fops = &video_fops;
542 voutdev->vdev.ioctl_ops = &video_ioctl_ops;
543 voutdev->vdev.release = video_device_release_empty;
544 voutdev->vdev.v4l2_dev = &voutdev->v4l2dev;
545 voutdev->vdev.lock = &voutdev->lock;
546 voutdev->vdev.queue = &voutdev->queue;
547 video_set_drvdata(&voutdev->vdev, voutdev);
549 rv = video_register_device(&voutdev->vdev, VFL_TYPE_VIDEO, -1);
558 rv = device_add_groups(&voutdev->vdev.dev, groups);
565 debugfs_init(voutdev);
568 return voutdev;
571 video_unregister_device(&voutdev->vdev);
573 v4l2_device_unregister(&voutdev->v4l2dev);
575 free_irq(irq, voutdev);
577 kfree(voutdev);
582 void mgb4_vout_free(struct mgb4_vout_dev *voutdev)
585 int irq = xdma_get_user_irq(voutdev->mgbdev->xdev, voutdev->config->irq);
587 free_irq(irq, voutdev);
590 debugfs_remove_recursive(voutdev->debugfs);
593 groups = MGB4_IS_GMSL(voutdev->mgbdev)
595 device_remove_groups(&voutdev->vdev.dev, groups);
597 mgb4_i2c_free(&voutdev->ser);
598 video_unregister_device(&voutdev->vdev);
599 v4l2_device_unregister(&voutdev->v4l2dev);
601 kfree(voutdev);