Lines Matching +full:gop +full:- +full:port +full:- +full:id

1 // SPDX-License-Identifier: GPL-2.0-or-later
4 * Support for a cx23417 mpeg encoder via cx23885 host port.
9 * - CX23885/7/8 support
15 #include "cx23885-ioctl.h"
25 #include <media/v4l2-common.h>
26 #include <media/v4l2-ioctl.h>
27 #include <media/drv-intf/cx2341x.h>
30 #define CX23885_FIRM_IMAGE_NAME "v4l-cx23885-enc.fw"
34 MODULE_PARM_DESC(mpegbufs, "number of mpeg buffers, range 2-32");
37 MODULE_PARM_DESC(mpeglines, "number of lines in an MPEG buffer, range 2-32");
41 "number of bytes in each line of an MPEG buffer, range 512-1024");
55 .name = "NTSC-M",
56 .id = V4L2_STD_NTSC_M,
58 .name = "NTSC-JP",
59 .id = V4L2_STD_NTSC_M_JP,
61 .name = "PAL-BG",
62 .id = V4L2_STD_PAL_BG,
64 .name = "PAL-DK",
65 .id = V4L2_STD_PAL_DK,
67 .name = "PAL-I",
68 .id = V4L2_STD_PAL_I,
70 .name = "PAL-M",
71 .id = V4L2_STD_PAL_M,
73 .name = "PAL-N",
74 .id = V4L2_STD_PAL_N,
76 .name = "PAL-Nc",
77 .id = V4L2_STD_PAL_Nc,
79 .name = "PAL-60",
80 .id = V4L2_STD_PAL_60,
82 .name = "SECAM-L",
83 .id = V4L2_STD_SECAM_L,
85 .name = "SECAM-DK",
86 .id = V4L2_STD_SECAM_DK,
90 /* ------------------------------------------------------------------ */
105 CX23885_END_AT_GOP, /* stop at the end of gop, generate irq */
163 CX23885_NOTIFICATION_NO_MAILBOX = -1,
194 /* defines below are from ivtv-driver.h */
210 bits 31-16
211 +-----------+
213 +-----------+
215 +-------+-------+-------+-------+-------+-------+-------+-------+
217 +-------+-------+-------+-------+-------+-------+-------+-------+
219 +-------+-------+-------+-------+-------+-------+-------+-------+
221 +-------+-------+-------+-------+-------+-------+-------+-------+
253 bits 31-6 bits 5-4 bit 3 bits 2-1 Bit 0
254 +--------+-------------+--------+--------------+------------+
256 +--------+-------------+--------+--------------+------------+
304 return -1; in mc417_wait_ready()
409 /* switch the DAT0-7 GPIO[10:3] to input mode */ in mc417_register_read()
417 * Transition 0x5000 -> 0x9000 correct (RD/RDY -> WR/RDY)? in mc417_register_read()
418 * Should it be 0x9000 -> 0xF000 (also why is RDY being set, its in mc417_register_read()
567 /* switch the DAT0-7 GPIO[10:3] to input mode */ in mc417_memory_read()
654 /* ------------------------------------------------------------------ */
761 mc417_memory_read(dev, dev->cx23417_mailbox - 4, &value); in cx23885_mbox_func()
765 return -1; in cx23885_mbox_func()
771 mc417_memory_read(dev, dev->cx23417_mailbox, &flag); in cx23885_mbox_func()
775 return -1; in cx23885_mbox_func()
779 mc417_memory_write(dev, dev->cx23417_mailbox, flag); in cx23885_mbox_func()
783 mc417_memory_write(dev, dev->cx23417_mailbox + 1, command); in cx23885_mbox_func()
784 mc417_memory_write(dev, dev->cx23417_mailbox + 3, in cx23885_mbox_func()
787 mc417_memory_write(dev, dev->cx23417_mailbox + 4 + i, data[i]); in cx23885_mbox_func()
791 mc417_memory_write(dev, dev->cx23417_mailbox + 4 + i, 0); in cx23885_mbox_func()
794 mc417_memory_write(dev, dev->cx23417_mailbox, flag); in cx23885_mbox_func()
799 mc417_memory_read(dev, dev->cx23417_mailbox, &flag); in cx23885_mbox_func()
804 return -1; in cx23885_mbox_func()
811 mc417_memory_read(dev, dev->cx23417_mailbox + 4 + i, data + i); in cx23885_mbox_func()
815 mc417_memory_read(dev, dev->cx23417_mailbox + 2, &retval); in cx23885_mbox_func()
819 mc417_memory_write(dev, dev->cx23417_mailbox, flag); in cx23885_mbox_func()
881 return -1; in cx23885_find_mailbox()
917 return -1; in cx23885_load_firmware()
921 &dev->pci->dev); in cx23885_load_firmware()
927 return -1; in cx23885_load_firmware()
930 if (firmware->size != CX23885_FIRM_IMAGE_SIZE) { in cx23885_load_firmware()
932 firmware->size, CX23885_FIRM_IMAGE_SIZE); in cx23885_load_firmware()
934 return -1; in cx23885_load_firmware()
937 if (0 != memcmp(firmware->data, magic, 8)) { in cx23885_load_firmware()
940 return -1; in cx23885_load_firmware()
945 dataptr = (u32 *)firmware->data; in cx23885_load_firmware()
946 for (i = 0; i < (firmware->size >> 2); i++) { in cx23885_load_firmware()
952 return -1; in cx23885_load_firmware()
959 for (i--; i >= 0; i--) { in cx23885_load_firmware()
963 return -1; in cx23885_load_firmware()
965 checksum -= ~value; in cx23885_load_firmware()
970 return -1; in cx23885_load_firmware()
1012 if (dev->encodernorm.id & V4L2_STD_525_60) in cx23885_codec_settings()
1013 dev->ts1.height = 480; in cx23885_codec_settings()
1015 dev->ts1.height = 576; in cx23885_codec_settings()
1019 dev->ts1.height, dev->ts1.width); in cx23885_codec_settings()
1021 dev->cxhdl.width = dev->ts1.width; in cx23885_codec_settings()
1022 dev->cxhdl.height = dev->ts1.height; in cx23885_codec_settings()
1023 dev->cxhdl.is_50hz = in cx23885_codec_settings()
1024 (dev->encodernorm.id & V4L2_STD_625_50) != 0; in cx23885_codec_settings()
1026 cx2341x_handler_setup(&dev->cxhdl); in cx23885_codec_settings()
1052 return -1; in cx23885_initialize_codec()
1054 dev->cx23417_mailbox = retval; in cx23885_initialize_codec()
1058 return -1; in cx23885_initialize_codec()
1064 return -1; in cx23885_initialize_codec()
1121 /* ------------------------------------------------------------------ */
1127 struct cx23885_dev *dev = q->drv_priv; in queue_setup()
1129 dev->ts1.ts_packet_size = mpeglinesize; in queue_setup()
1130 dev->ts1.ts_packet_count = mpeglines; in queue_setup()
1140 struct cx23885_dev *dev = vb->vb2_queue->drv_priv; in buffer_prepare()
1144 return cx23885_buf_prepare(buf, &dev->ts1); in buffer_prepare()
1150 struct cx23885_dev *dev = vb->vb2_queue->drv_priv; in buffer_finish()
1160 struct cx23885_dev *dev = vb->vb2_queue->drv_priv; in buffer_queue()
1164 cx23885_buf_queue(&dev->ts1, buf); in buffer_queue()
1169 struct cx23885_dev *dev = q->drv_priv; in cx23885_start_streaming()
1170 struct cx23885_dmaqueue *dmaq = &dev->ts1.mpegq; in cx23885_start_streaming()
1176 struct cx23885_buffer *buf = list_entry(dmaq->active.next, in cx23885_start_streaming()
1179 cx23885_start_dma(&dev->ts1, dmaq, buf); in cx23885_start_streaming()
1182 spin_lock_irqsave(&dev->slock, flags); in cx23885_start_streaming()
1183 while (!list_empty(&dmaq->active)) { in cx23885_start_streaming()
1184 struct cx23885_buffer *buf = list_entry(dmaq->active.next, in cx23885_start_streaming()
1187 list_del(&buf->queue); in cx23885_start_streaming()
1188 vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_QUEUED); in cx23885_start_streaming()
1190 spin_unlock_irqrestore(&dev->slock, flags); in cx23885_start_streaming()
1196 struct cx23885_dev *dev = q->drv_priv; in cx23885_stop_streaming()
1205 cx23885_cancel_buffers(&dev->ts1); in cx23885_stop_streaming()
1219 /* ------------------------------------------------------------------ */
1221 static int vidioc_g_std(struct file *file, void *priv, v4l2_std_id *id) in vidioc_g_std() argument
1225 *id = dev->tvnorm; in vidioc_g_std()
1229 static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id id) in vidioc_s_std() argument
1236 if (id & cx23885_tvnorms[i].id) in vidioc_s_std()
1239 return -EINVAL; in vidioc_s_std()
1241 ret = cx23885_set_tvnorm(dev, id); in vidioc_s_std()
1243 dev->encodernorm = cx23885_tvnorms[i]; in vidioc_s_std()
1270 if (dev->tuner_type == TUNER_ABSENT) in vidioc_g_tuner()
1271 return -EINVAL; in vidioc_g_tuner()
1272 if (0 != t->index) in vidioc_g_tuner()
1273 return -EINVAL; in vidioc_g_tuner()
1274 strscpy(t->name, "Television", sizeof(t->name)); in vidioc_g_tuner()
1277 dprintk(1, "VIDIOC_G_TUNER: tuner type %d\n", t->type); in vidioc_g_tuner()
1287 if (dev->tuner_type == TUNER_ABSENT) in vidioc_s_tuner()
1288 return -EINVAL; in vidioc_s_tuner()
1301 if (dev->tuner_type == TUNER_ABSENT) in vidioc_g_frequency()
1302 return -EINVAL; in vidioc_g_frequency()
1303 f->type = V4L2_TUNER_ANALOG_TV; in vidioc_g_frequency()
1304 f->frequency = dev->freq; in vidioc_g_frequency()
1321 struct cx23885_tsport *tsport = &dev->ts1; in vidioc_querycap()
1323 strscpy(cap->driver, dev->name, sizeof(cap->driver)); in vidioc_querycap()
1324 strscpy(cap->card, cx23885_boards[tsport->dev->board].name, in vidioc_querycap()
1325 sizeof(cap->card)); in vidioc_querycap()
1326 sprintf(cap->bus_info, "PCIe:%s", pci_name(dev->pci)); in vidioc_querycap()
1327 cap->capabilities = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_READWRITE | in vidioc_querycap()
1330 if (dev->tuner_type != TUNER_ABSENT) in vidioc_querycap()
1331 cap->capabilities |= V4L2_CAP_TUNER; in vidioc_querycap()
1339 if (f->index != 0) in vidioc_enum_fmt_vid_cap()
1340 return -EINVAL; in vidioc_enum_fmt_vid_cap()
1342 f->pixelformat = V4L2_PIX_FMT_MPEG; in vidioc_enum_fmt_vid_cap()
1352 f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG; in vidioc_g_fmt_vid_cap()
1353 f->fmt.pix.bytesperline = 0; in vidioc_g_fmt_vid_cap()
1354 f->fmt.pix.sizeimage = in vidioc_g_fmt_vid_cap()
1355 dev->ts1.ts_packet_size * dev->ts1.ts_packet_count; in vidioc_g_fmt_vid_cap()
1356 f->fmt.pix.colorspace = 0; in vidioc_g_fmt_vid_cap()
1357 f->fmt.pix.width = dev->ts1.width; in vidioc_g_fmt_vid_cap()
1358 f->fmt.pix.height = dev->ts1.height; in vidioc_g_fmt_vid_cap()
1359 f->fmt.pix.field = V4L2_FIELD_INTERLACED; in vidioc_g_fmt_vid_cap()
1361 dev->ts1.width, dev->ts1.height); in vidioc_g_fmt_vid_cap()
1370 f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG; in vidioc_try_fmt_vid_cap()
1371 f->fmt.pix.bytesperline = 0; in vidioc_try_fmt_vid_cap()
1372 f->fmt.pix.sizeimage = in vidioc_try_fmt_vid_cap()
1373 dev->ts1.ts_packet_size * dev->ts1.ts_packet_count; in vidioc_try_fmt_vid_cap()
1374 f->fmt.pix.colorspace = 0; in vidioc_try_fmt_vid_cap()
1375 f->fmt.pix.field = V4L2_FIELD_INTERLACED; in vidioc_try_fmt_vid_cap()
1377 dev->ts1.width, dev->ts1.height); in vidioc_try_fmt_vid_cap()
1386 f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG; in vidioc_s_fmt_vid_cap()
1387 f->fmt.pix.bytesperline = 0; in vidioc_s_fmt_vid_cap()
1388 f->fmt.pix.sizeimage = in vidioc_s_fmt_vid_cap()
1389 dev->ts1.ts_packet_size * dev->ts1.ts_packet_count; in vidioc_s_fmt_vid_cap()
1390 f->fmt.pix.colorspace = 0; in vidioc_s_fmt_vid_cap()
1391 f->fmt.pix.field = V4L2_FIELD_INTERLACED; in vidioc_s_fmt_vid_cap()
1393 f->fmt.pix.width, f->fmt.pix.height, f->fmt.pix.field); in vidioc_s_fmt_vid_cap()
1402 snprintf(name, sizeof(name), "%s/2", dev->name); in vidioc_log_status()
1404 v4l2_ctrl_handler_log_status(&dev->cxhdl.hdl, name); in vidioc_log_status()
1459 if (dev->v4l_device) { in cx23885_417_unregister()
1460 if (video_is_registered(dev->v4l_device)) in cx23885_417_unregister()
1461 video_unregister_device(dev->v4l_device); in cx23885_417_unregister()
1463 video_device_release(dev->v4l_device); in cx23885_417_unregister()
1464 v4l2_ctrl_handler_free(&dev->cxhdl.hdl); in cx23885_417_unregister()
1465 dev->v4l_device = NULL; in cx23885_417_unregister()
1476 struct cx23885_dev *dev = tsport->dev; in cx23885_video_dev_alloc()
1484 snprintf(vfd->name, sizeof(vfd->name), "%s (%s)", in cx23885_video_dev_alloc()
1485 cx23885_boards[tsport->dev->board].name, type); in cx23885_video_dev_alloc()
1486 vfd->v4l2_dev = &dev->v4l2_dev; in cx23885_video_dev_alloc()
1487 vfd->release = video_device_release; in cx23885_video_dev_alloc()
1494 int err = -ENODEV; in cx23885_417_register()
1495 struct cx23885_tsport *tsport = &dev->ts1; in cx23885_417_register()
1500 if (cx23885_boards[dev->board].portb != CX23885_MPEG_ENCODER) in cx23885_417_register()
1504 dev->encodernorm = cx23885_tvnorms[0]; in cx23885_417_register()
1506 if (dev->encodernorm.id & V4L2_STD_525_60) in cx23885_417_register()
1507 tsport->height = 480; in cx23885_417_register()
1509 tsport->height = 576; in cx23885_417_register()
1511 tsport->width = 720; in cx23885_417_register()
1512 dev->cxhdl.port = CX2341X_PORT_SERIAL; in cx23885_417_register()
1513 err = cx2341x_handler_init(&dev->cxhdl, 50); in cx23885_417_register()
1516 dev->cxhdl.priv = dev; in cx23885_417_register()
1517 dev->cxhdl.func = cx23885_api_func; in cx23885_417_register()
1518 cx2341x_handler_set_50hz(&dev->cxhdl, tsport->height == 576); in cx23885_417_register()
1519 v4l2_ctrl_add_handler(&dev->ctrl_handler, &dev->cxhdl.hdl, NULL, false); in cx23885_417_register()
1522 dev->v4l_device = cx23885_video_dev_alloc(tsport, in cx23885_417_register()
1523 dev->pci, &cx23885_mpeg_template, "mpeg"); in cx23885_417_register()
1524 q = &dev->vb2_mpegq; in cx23885_417_register()
1525 q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; in cx23885_417_register()
1526 q->io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF | VB2_READ; in cx23885_417_register()
1527 q->gfp_flags = GFP_DMA32; in cx23885_417_register()
1528 q->min_queued_buffers = 2; in cx23885_417_register()
1529 q->drv_priv = dev; in cx23885_417_register()
1530 q->buf_struct_size = sizeof(struct cx23885_buffer); in cx23885_417_register()
1531 q->ops = &cx23885_qops; in cx23885_417_register()
1532 q->mem_ops = &vb2_dma_sg_memops; in cx23885_417_register()
1533 q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; in cx23885_417_register()
1534 q->lock = &dev->lock; in cx23885_417_register()
1535 q->dev = &dev->pci->dev; in cx23885_417_register()
1540 video_set_drvdata(dev->v4l_device, dev); in cx23885_417_register()
1541 dev->v4l_device->lock = &dev->lock; in cx23885_417_register()
1542 dev->v4l_device->queue = q; in cx23885_417_register()
1543 dev->v4l_device->device_caps = V4L2_CAP_VIDEO_CAPTURE | in cx23885_417_register()
1545 if (dev->tuner_type != TUNER_ABSENT) in cx23885_417_register()
1546 dev->v4l_device->device_caps |= V4L2_CAP_TUNER; in cx23885_417_register()
1547 err = video_register_device(dev->v4l_device, in cx23885_417_register()
1548 VFL_TYPE_VIDEO, -1); in cx23885_417_register()
1550 pr_info("%s: can't register mpeg device\n", dev->name); in cx23885_417_register()
1555 dev->name, video_device_node_name(dev->v4l_device)); in cx23885_417_register()