forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-03 2f7c68cb55ecb7331f2381deb497c27155f32faf
kernel/drivers/media/usb/cx231xx/cx231xx-417.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 *
34 * Support for a cx23417 mpeg encoder via cx231xx host port.
....@@ -8,16 +9,6 @@
89 * - CX23885/7/8 support
910 *
1011 * Includes parts from the ivtv driver( http://ivtv.sourceforge.net/),
11
- *
12
- * This program is free software; you can redistribute it and/or modify
13
- * it under the terms of the GNU General Public License as published by
14
- * the Free Software Foundation; either version 2 of the License, or
15
- * (at your option) any later version.
16
- *
17
- * This program is distributed in the hope that it will be useful,
18
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
- * GNU General Public License for more details.
2112 */
2213
2314 #include "cx231xx.h"
....@@ -68,10 +59,6 @@
6859 #define MCI_MODE_REGISTER_WRITE 0x100
6960 #define MCI_MODE_MEMORY_READ 0x000
7061 #define MCI_MODE_MEMORY_WRITE 0x4000
71
-
72
-static unsigned int mpegbufs = 8;
73
-module_param(mpegbufs, int, 0644);
74
-MODULE_PARM_DESC(mpegbufs, "number of mpeg buffers, range 2-32");
7562
7663 static unsigned int mpeglines = 128;
7764 module_param(mpeglines, int, 0644);
....@@ -1060,6 +1047,7 @@
10601047 p_current_fw = p_fw;
10611048 vfree(p_current_fw);
10621049 p_current_fw = NULL;
1050
+ vfree(p_buffer);
10631051 uninitGPIO(dev);
10641052 release_firmware(firmware);
10651053 dprintk(1, "Firmware upload successful.\n");
....@@ -1086,16 +1074,6 @@
10861074 return retval;
10871075 }
10881076 return 0;
1089
-}
1090
-
1091
-static void cx231xx_417_check_encoder(struct cx231xx *dev)
1092
-{
1093
- u32 status, seq;
1094
-
1095
- status = 0;
1096
- seq = 0;
1097
- cx231xx_api_cmd(dev, CX2341X_ENC_GET_SEQ_END, 0, 2, &status, &seq);
1098
- dprintk(1, "%s() status = %d, seq = %d\n", __func__, status, seq);
10991077 }
11001078
11011079 static void cx231xx_codec_settings(struct cx231xx *dev)
....@@ -1235,40 +1213,25 @@
12351213
12361214 /* ------------------------------------------------------------------ */
12371215
1238
-static int bb_buf_setup(struct videobuf_queue *q,
1239
- unsigned int *count, unsigned int *size)
1216
+static int queue_setup(struct vb2_queue *vq,
1217
+ unsigned int *nbuffers, unsigned int *nplanes,
1218
+ unsigned int sizes[], struct device *alloc_devs[])
12401219 {
1241
- struct cx231xx_fh *fh = q->priv_data;
1220
+ struct cx231xx *dev = vb2_get_drv_priv(vq);
1221
+ unsigned int size = mpeglinesize * mpeglines;
12421222
1243
- fh->dev->ts1.ts_packet_size = mpeglinesize;
1244
- fh->dev->ts1.ts_packet_count = mpeglines;
1223
+ dev->ts1.ts_packet_size = mpeglinesize;
1224
+ dev->ts1.ts_packet_count = mpeglines;
12451225
1246
- *size = fh->dev->ts1.ts_packet_size * fh->dev->ts1.ts_packet_count;
1247
- *count = mpegbufs;
1226
+ if (vq->num_buffers + *nbuffers < CX231XX_MIN_BUF)
1227
+ *nbuffers = CX231XX_MIN_BUF - vq->num_buffers;
1228
+
1229
+ if (*nplanes)
1230
+ return sizes[0] < size ? -EINVAL : 0;
1231
+ *nplanes = 1;
1232
+ sizes[0] = mpeglinesize * mpeglines;
12481233
12491234 return 0;
1250
-}
1251
-
1252
-static void free_buffer(struct videobuf_queue *vq, struct cx231xx_buffer *buf)
1253
-{
1254
- struct cx231xx_fh *fh = vq->priv_data;
1255
- struct cx231xx *dev = fh->dev;
1256
- unsigned long flags = 0;
1257
-
1258
- BUG_ON(in_interrupt());
1259
-
1260
- spin_lock_irqsave(&dev->video_mode.slock, flags);
1261
- if (dev->USE_ISO) {
1262
- if (dev->video_mode.isoc_ctl.buf == buf)
1263
- dev->video_mode.isoc_ctl.buf = NULL;
1264
- } else {
1265
- if (dev->video_mode.bulk_ctl.buf == buf)
1266
- dev->video_mode.bulk_ctl.buf = NULL;
1267
- }
1268
- spin_unlock_irqrestore(&dev->video_mode.slock, flags);
1269
- videobuf_waiton(vq, &buf->vb, 0, 0);
1270
- videobuf_vmalloc_free(&buf->vb);
1271
- buf->vb.state = VIDEOBUF_NEEDS_INIT;
12721235 }
12731236
12741237 static void buffer_copy(struct cx231xx *dev, char *data, int len, struct urb *urb,
....@@ -1284,13 +1247,13 @@
12841247 return;
12851248
12861249 buf = list_entry(dma_q->active.next,
1287
- struct cx231xx_buffer, vb.queue);
1250
+ struct cx231xx_buffer, list);
12881251 dev->video_mode.isoc_ctl.buf = buf;
12891252 dma_q->mpeg_buffer_done = 1;
12901253 }
12911254 /* Fill buffer */
12921255 buf = dev->video_mode.isoc_ctl.buf;
1293
- vbuf = videobuf_to_vmalloc(&buf->vb);
1256
+ vbuf = vb2_plane_vaddr(&buf->vb.vb2_buf, 0);
12941257
12951258 if ((dma_q->mpeg_buffer_completed+len) <
12961259 mpeglines*mpeglinesize) {
....@@ -1314,11 +1277,10 @@
13141277 memcpy(vbuf+dma_q->mpeg_buffer_completed,
13151278 data, tail_data);
13161279
1317
- buf->vb.state = VIDEOBUF_DONE;
1318
- buf->vb.field_count++;
1319
- v4l2_get_timestamp(&buf->vb.ts);
1320
- list_del(&buf->vb.queue);
1321
- wake_up(&buf->vb.done);
1280
+ buf->vb.vb2_buf.timestamp = ktime_get_ns();
1281
+ buf->vb.sequence = dma_q->sequence++;
1282
+ list_del(&buf->list);
1283
+ vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_DONE);
13221284 dma_q->mpeg_buffer_completed = 0;
13231285
13241286 if (len - tail_data > 0) {
....@@ -1339,17 +1301,15 @@
13391301 if (list_empty(&dma_q->active))
13401302 return;
13411303
1342
- buf = list_entry(dma_q->active.next,
1343
- struct cx231xx_buffer, vb.queue);
1304
+ buf = list_entry(dma_q->active.next, struct cx231xx_buffer, list);
13441305
13451306 /* Fill buffer */
1346
- vbuf = videobuf_to_vmalloc(&buf->vb);
1307
+ vbuf = vb2_plane_vaddr(&buf->vb.vb2_buf, 0);
13471308 memcpy(vbuf, data, len);
1348
- buf->vb.state = VIDEOBUF_DONE;
1349
- buf->vb.field_count++;
1350
- v4l2_get_timestamp(&buf->vb.ts);
1351
- list_del(&buf->vb.queue);
1352
- wake_up(&buf->vb.done);
1309
+ buf->vb.sequence = dma_q->sequence++;
1310
+ buf->vb.vb2_buf.timestamp = ktime_get_ns();
1311
+ list_del(&buf->list);
1312
+ vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_DONE);
13531313 }
13541314
13551315 static int cx231xx_isoc_copy(struct cx231xx *dev, struct urb *urb)
....@@ -1402,129 +1362,148 @@
14021362 return 0;
14031363 }
14041364
1405
-static int bb_buf_prepare(struct videobuf_queue *q,
1406
- struct videobuf_buffer *vb, enum v4l2_field field)
1365
+static void buffer_queue(struct vb2_buffer *vb)
14071366 {
1408
- struct cx231xx_fh *fh = q->priv_data;
14091367 struct cx231xx_buffer *buf =
1410
- container_of(vb, struct cx231xx_buffer, vb);
1411
- struct cx231xx *dev = fh->dev;
1412
- int rc = 0, urb_init = 0;
1413
- int size = fh->dev->ts1.ts_packet_size * fh->dev->ts1.ts_packet_count;
1368
+ container_of(vb, struct cx231xx_buffer, vb.vb2_buf);
1369
+ struct cx231xx *dev = vb2_get_drv_priv(vb->vb2_queue);
1370
+ struct cx231xx_dmaqueue *vidq = &dev->video_mode.vidq;
1371
+ unsigned long flags;
14141372
1415
- if (0 != buf->vb.baddr && buf->vb.bsize < size)
1416
- return -EINVAL;
1417
- buf->vb.width = fh->dev->ts1.ts_packet_size;
1418
- buf->vb.height = fh->dev->ts1.ts_packet_count;
1419
- buf->vb.size = size;
1420
- buf->vb.field = field;
1373
+ spin_lock_irqsave(&dev->video_mode.slock, flags);
1374
+ list_add_tail(&buf->list, &vidq->active);
1375
+ spin_unlock_irqrestore(&dev->video_mode.slock, flags);
1376
+}
14211377
1422
- if (VIDEOBUF_NEEDS_INIT == buf->vb.state) {
1423
- rc = videobuf_iolock(q, &buf->vb, NULL);
1424
- if (rc < 0)
1425
- goto fail;
1378
+static void return_all_buffers(struct cx231xx *dev,
1379
+ enum vb2_buffer_state state)
1380
+{
1381
+ struct cx231xx_dmaqueue *vidq = &dev->video_mode.vidq;
1382
+ struct cx231xx_buffer *buf, *node;
1383
+ unsigned long flags;
1384
+
1385
+ spin_lock_irqsave(&dev->video_mode.slock, flags);
1386
+ list_for_each_entry_safe(buf, node, &vidq->active, list) {
1387
+ vb2_buffer_done(&buf->vb.vb2_buf, state);
1388
+ list_del(&buf->list);
14261389 }
1390
+ spin_unlock_irqrestore(&dev->video_mode.slock, flags);
1391
+}
14271392
1428
- if (dev->USE_ISO) {
1429
- if (!dev->video_mode.isoc_ctl.num_bufs)
1430
- urb_init = 1;
1431
- } else {
1432
- if (!dev->video_mode.bulk_ctl.num_bufs)
1433
- urb_init = 1;
1434
- }
1435
- dev_dbg(dev->dev,
1436
- "urb_init=%d dev->video_mode.max_pkt_size=%d\n",
1437
- urb_init, dev->video_mode.max_pkt_size);
1393
+static int start_streaming(struct vb2_queue *vq, unsigned int count)
1394
+{
1395
+ struct cx231xx *dev = vb2_get_drv_priv(vq);
1396
+ struct cx231xx_dmaqueue *vidq = &dev->video_mode.vidq;
1397
+ int ret = 0;
1398
+
1399
+ vidq->sequence = 0;
14381400 dev->mode_tv = 1;
14391401
1440
- if (urb_init) {
1441
- rc = cx231xx_set_mode(dev, CX231XX_DIGITAL_MODE);
1442
- rc = cx231xx_unmute_audio(dev);
1443
- if (dev->USE_ISO) {
1444
- cx231xx_set_alt_setting(dev, INDEX_TS1, 4);
1445
- rc = cx231xx_init_isoc(dev, mpeglines,
1446
- mpegbufs,
1447
- dev->ts1_mode.max_pkt_size,
1448
- cx231xx_isoc_copy);
1449
- } else {
1450
- cx231xx_set_alt_setting(dev, INDEX_TS1, 0);
1451
- rc = cx231xx_init_bulk(dev, mpeglines,
1452
- mpegbufs,
1453
- dev->ts1_mode.max_pkt_size,
1454
- cx231xx_bulk_copy);
1455
- }
1456
- if (rc < 0)
1457
- goto fail;
1458
- }
1402
+ cx231xx_set_alt_setting(dev, INDEX_VANC, 1);
1403
+ cx231xx_set_gpio_value(dev, 2, 0);
14591404
1460
- buf->vb.state = VIDEOBUF_PREPARED;
1461
- return 0;
1405
+ cx231xx_initialize_codec(dev);
14621406
1463
-fail:
1464
- free_buffer(q, buf);
1465
- return rc;
1407
+ cx231xx_start_TS1(dev);
1408
+
1409
+ cx231xx_set_alt_setting(dev, INDEX_TS1, 0);
1410
+ cx231xx_set_mode(dev, CX231XX_DIGITAL_MODE);
1411
+ if (dev->USE_ISO)
1412
+ ret = cx231xx_init_isoc(dev, CX231XX_NUM_PACKETS,
1413
+ CX231XX_NUM_BUFS,
1414
+ dev->ts1_mode.max_pkt_size,
1415
+ cx231xx_isoc_copy);
1416
+ else
1417
+ ret = cx231xx_init_bulk(dev, 320, 5,
1418
+ dev->ts1_mode.max_pkt_size,
1419
+ cx231xx_bulk_copy);
1420
+ if (ret)
1421
+ return_all_buffers(dev, VB2_BUF_STATE_QUEUED);
1422
+
1423
+ call_all(dev, video, s_stream, 1);
1424
+ return ret;
14661425 }
14671426
1468
-static void bb_buf_queue(struct videobuf_queue *q,
1469
- struct videobuf_buffer *vb)
1427
+static void stop_streaming(struct vb2_queue *vq)
14701428 {
1471
- struct cx231xx_fh *fh = q->priv_data;
1429
+ struct cx231xx *dev = vb2_get_drv_priv(vq);
1430
+ unsigned long flags;
14721431
1473
- struct cx231xx_buffer *buf =
1474
- container_of(vb, struct cx231xx_buffer, vb);
1475
- struct cx231xx *dev = fh->dev;
1476
- struct cx231xx_dmaqueue *vidq = &dev->video_mode.vidq;
1432
+ call_all(dev, video, s_stream, 0);
14771433
1478
- buf->vb.state = VIDEOBUF_QUEUED;
1479
- list_add_tail(&buf->vb.queue, &vidq->active);
1434
+ cx231xx_stop_TS1(dev);
14801435
1436
+ /* do this before setting alternate! */
1437
+ if (dev->USE_ISO)
1438
+ cx231xx_uninit_isoc(dev);
1439
+ else
1440
+ cx231xx_uninit_bulk(dev);
1441
+ cx231xx_set_mode(dev, CX231XX_SUSPEND);
1442
+
1443
+ cx231xx_api_cmd(dev, CX2341X_ENC_STOP_CAPTURE, 3, 0,
1444
+ CX231xx_END_NOW, CX231xx_MPEG_CAPTURE,
1445
+ CX231xx_RAW_BITS_NONE);
1446
+
1447
+ spin_lock_irqsave(&dev->video_mode.slock, flags);
1448
+ if (dev->USE_ISO)
1449
+ dev->video_mode.isoc_ctl.buf = NULL;
1450
+ else
1451
+ dev->video_mode.bulk_ctl.buf = NULL;
1452
+ spin_unlock_irqrestore(&dev->video_mode.slock, flags);
1453
+ return_all_buffers(dev, VB2_BUF_STATE_ERROR);
14811454 }
14821455
1483
-static void bb_buf_release(struct videobuf_queue *q,
1484
- struct videobuf_buffer *vb)
1485
-{
1486
- struct cx231xx_buffer *buf =
1487
- container_of(vb, struct cx231xx_buffer, vb);
1488
- /*struct cx231xx_fh *fh = q->priv_data;*/
1489
- /*struct cx231xx *dev = (struct cx231xx *)fh->dev;*/
1490
-
1491
- free_buffer(q, buf);
1492
-}
1493
-
1494
-static const struct videobuf_queue_ops cx231xx_qops = {
1495
- .buf_setup = bb_buf_setup,
1496
- .buf_prepare = bb_buf_prepare,
1497
- .buf_queue = bb_buf_queue,
1498
- .buf_release = bb_buf_release,
1456
+static struct vb2_ops cx231xx_video_qops = {
1457
+ .queue_setup = queue_setup,
1458
+ .buf_queue = buffer_queue,
1459
+ .start_streaming = start_streaming,
1460
+ .stop_streaming = stop_streaming,
1461
+ .wait_prepare = vb2_ops_wait_prepare,
1462
+ .wait_finish = vb2_ops_wait_finish,
14991463 };
15001464
15011465 /* ------------------------------------------------------------------ */
15021466
1503
-static int vidioc_cropcap(struct file *file, void *priv,
1504
- struct v4l2_cropcap *cc)
1467
+static int vidioc_g_pixelaspect(struct file *file, void *priv,
1468
+ int type, struct v4l2_fract *f)
15051469 {
1506
- struct cx231xx_fh *fh = priv;
1507
- struct cx231xx *dev = fh->dev;
1470
+ struct cx231xx *dev = video_drvdata(file);
15081471 bool is_50hz = dev->encodernorm.id & V4L2_STD_625_50;
15091472
1510
- if (cc->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1473
+ if (type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
15111474 return -EINVAL;
15121475
1513
- cc->bounds.left = 0;
1514
- cc->bounds.top = 0;
1515
- cc->bounds.width = dev->ts1.width;
1516
- cc->bounds.height = dev->ts1.height;
1517
- cc->defrect = cc->bounds;
1518
- cc->pixelaspect.numerator = is_50hz ? 54 : 11;
1519
- cc->pixelaspect.denominator = is_50hz ? 59 : 10;
1476
+ f->numerator = is_50hz ? 54 : 11;
1477
+ f->denominator = is_50hz ? 59 : 10;
15201478
1479
+ return 0;
1480
+}
1481
+
1482
+static int vidioc_g_selection(struct file *file, void *priv,
1483
+ struct v4l2_selection *s)
1484
+{
1485
+ struct cx231xx *dev = video_drvdata(file);
1486
+
1487
+ if (s->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1488
+ return -EINVAL;
1489
+
1490
+ switch (s->target) {
1491
+ case V4L2_SEL_TGT_CROP_BOUNDS:
1492
+ case V4L2_SEL_TGT_CROP_DEFAULT:
1493
+ s->r.left = 0;
1494
+ s->r.top = 0;
1495
+ s->r.width = dev->ts1.width;
1496
+ s->r.height = dev->ts1.height;
1497
+ break;
1498
+ default:
1499
+ return -EINVAL;
1500
+ }
15211501 return 0;
15221502 }
15231503
15241504 static int vidioc_g_std(struct file *file, void *fh0, v4l2_std_id *norm)
15251505 {
1526
- struct cx231xx_fh *fh = file->private_data;
1527
- struct cx231xx *dev = fh->dev;
1506
+ struct cx231xx *dev = video_drvdata(file);
15281507
15291508 *norm = dev->encodernorm.id;
15301509 return 0;
....@@ -1532,8 +1511,7 @@
15321511
15331512 static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id id)
15341513 {
1535
- struct cx231xx_fh *fh = file->private_data;
1536
- struct cx231xx *dev = fh->dev;
1514
+ struct cx231xx *dev = video_drvdata(file);
15371515 unsigned int i;
15381516
15391517 for (i = 0; i < ARRAY_SIZE(cx231xx_tvnorms); i++)
....@@ -1565,8 +1543,7 @@
15651543 static int vidioc_s_ctrl(struct file *file, void *priv,
15661544 struct v4l2_control *ctl)
15671545 {
1568
- struct cx231xx_fh *fh = file->private_data;
1569
- struct cx231xx *dev = fh->dev;
1546
+ struct cx231xx *dev = video_drvdata(file);
15701547 struct v4l2_subdev *sd;
15711548
15721549 dprintk(3, "enter vidioc_s_ctrl()\n");
....@@ -1583,7 +1560,6 @@
15831560 if (f->index != 0)
15841561 return -EINVAL;
15851562
1586
- strlcpy(f->description, "MPEG", sizeof(f->description));
15871563 f->pixelformat = V4L2_PIX_FMT_MPEG;
15881564
15891565 return 0;
....@@ -1592,8 +1568,7 @@
15921568 static int vidioc_g_fmt_vid_cap(struct file *file, void *priv,
15931569 struct v4l2_format *f)
15941570 {
1595
- struct cx231xx_fh *fh = file->private_data;
1596
- struct cx231xx *dev = fh->dev;
1571
+ struct cx231xx *dev = video_drvdata(file);
15971572
15981573 dprintk(3, "enter vidioc_g_fmt_vid_cap()\n");
15991574 f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG;
....@@ -1612,8 +1587,7 @@
16121587 static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
16131588 struct v4l2_format *f)
16141589 {
1615
- struct cx231xx_fh *fh = file->private_data;
1616
- struct cx231xx *dev = fh->dev;
1590
+ struct cx231xx *dev = video_drvdata(file);
16171591
16181592 dprintk(3, "enter vidioc_try_fmt_vid_cap()\n");
16191593 f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG;
....@@ -1627,230 +1601,21 @@
16271601 return 0;
16281602 }
16291603
1630
-static int vidioc_reqbufs(struct file *file, void *priv,
1631
- struct v4l2_requestbuffers *p)
1632
-{
1633
- struct cx231xx_fh *fh = file->private_data;
1634
-
1635
- return videobuf_reqbufs(&fh->vidq, p);
1636
-}
1637
-
1638
-static int vidioc_querybuf(struct file *file, void *priv,
1639
- struct v4l2_buffer *p)
1640
-{
1641
- struct cx231xx_fh *fh = file->private_data;
1642
-
1643
- return videobuf_querybuf(&fh->vidq, p);
1644
-}
1645
-
1646
-static int vidioc_qbuf(struct file *file, void *priv,
1647
- struct v4l2_buffer *p)
1648
-{
1649
- struct cx231xx_fh *fh = file->private_data;
1650
-
1651
- return videobuf_qbuf(&fh->vidq, p);
1652
-}
1653
-
1654
-static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *b)
1655
-{
1656
- struct cx231xx_fh *fh = priv;
1657
-
1658
- return videobuf_dqbuf(&fh->vidq, b, file->f_flags & O_NONBLOCK);
1659
-}
1660
-
1661
-
1662
-static int vidioc_streamon(struct file *file, void *priv,
1663
- enum v4l2_buf_type i)
1664
-{
1665
- struct cx231xx_fh *fh = file->private_data;
1666
- struct cx231xx *dev = fh->dev;
1667
-
1668
- dprintk(3, "enter vidioc_streamon()\n");
1669
- cx231xx_set_alt_setting(dev, INDEX_TS1, 0);
1670
- cx231xx_set_mode(dev, CX231XX_DIGITAL_MODE);
1671
- if (dev->USE_ISO)
1672
- cx231xx_init_isoc(dev, CX231XX_NUM_PACKETS,
1673
- CX231XX_NUM_BUFS,
1674
- dev->video_mode.max_pkt_size,
1675
- cx231xx_isoc_copy);
1676
- else {
1677
- cx231xx_init_bulk(dev, 320,
1678
- 5,
1679
- dev->ts1_mode.max_pkt_size,
1680
- cx231xx_bulk_copy);
1681
- }
1682
- dprintk(3, "exit vidioc_streamon()\n");
1683
- return videobuf_streamon(&fh->vidq);
1684
-}
1685
-
1686
-static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
1687
-{
1688
- struct cx231xx_fh *fh = file->private_data;
1689
-
1690
- return videobuf_streamoff(&fh->vidq);
1691
-}
1692
-
16931604 static int vidioc_log_status(struct file *file, void *priv)
16941605 {
1695
- struct cx231xx_fh *fh = priv;
1696
- struct cx231xx *dev = fh->dev;
1606
+ struct cx231xx *dev = video_drvdata(file);
16971607
16981608 call_all(dev, core, log_status);
16991609 return v4l2_ctrl_log_status(file, priv);
17001610 }
17011611
1702
-static int mpeg_open(struct file *file)
1703
-{
1704
- struct video_device *vdev = video_devdata(file);
1705
- struct cx231xx *dev = video_drvdata(file);
1706
- struct cx231xx_fh *fh;
1707
-
1708
- dprintk(2, "%s()\n", __func__);
1709
-
1710
- if (mutex_lock_interruptible(&dev->lock))
1711
- return -ERESTARTSYS;
1712
-
1713
- /* allocate + initialize per filehandle data */
1714
- fh = kzalloc(sizeof(*fh), GFP_KERNEL);
1715
- if (NULL == fh) {
1716
- mutex_unlock(&dev->lock);
1717
- return -ENOMEM;
1718
- }
1719
-
1720
- file->private_data = fh;
1721
- v4l2_fh_init(&fh->fh, vdev);
1722
- fh->dev = dev;
1723
-
1724
-
1725
- videobuf_queue_vmalloc_init(&fh->vidq, &cx231xx_qops,
1726
- NULL, &dev->video_mode.slock,
1727
- V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_INTERLACED,
1728
- sizeof(struct cx231xx_buffer), fh, &dev->lock);
1729
-/*
1730
- videobuf_queue_sg_init(&fh->vidq, &cx231xx_qops,
1731
- dev->dev, &dev->ts1.slock,
1732
- V4L2_BUF_TYPE_VIDEO_CAPTURE,
1733
- V4L2_FIELD_INTERLACED,
1734
- sizeof(struct cx231xx_buffer),
1735
- fh, &dev->lock);
1736
-*/
1737
-
1738
- cx231xx_set_alt_setting(dev, INDEX_VANC, 1);
1739
- cx231xx_set_gpio_value(dev, 2, 0);
1740
-
1741
- cx231xx_initialize_codec(dev);
1742
-
1743
- mutex_unlock(&dev->lock);
1744
- v4l2_fh_add(&fh->fh);
1745
- cx231xx_start_TS1(dev);
1746
-
1747
- return 0;
1748
-}
1749
-
1750
-static int mpeg_release(struct file *file)
1751
-{
1752
- struct cx231xx_fh *fh = file->private_data;
1753
- struct cx231xx *dev = fh->dev;
1754
-
1755
- dprintk(3, "mpeg_release()! dev=0x%p\n", dev);
1756
-
1757
- mutex_lock(&dev->lock);
1758
-
1759
- cx231xx_stop_TS1(dev);
1760
-
1761
- /* do this before setting alternate! */
1762
- if (dev->USE_ISO)
1763
- cx231xx_uninit_isoc(dev);
1764
- else
1765
- cx231xx_uninit_bulk(dev);
1766
- cx231xx_set_mode(dev, CX231XX_SUSPEND);
1767
-
1768
- cx231xx_api_cmd(fh->dev, CX2341X_ENC_STOP_CAPTURE, 3, 0,
1769
- CX231xx_END_NOW, CX231xx_MPEG_CAPTURE,
1770
- CX231xx_RAW_BITS_NONE);
1771
-
1772
- /* FIXME: Review this crap */
1773
- /* Shut device down on last close */
1774
- if (atomic_cmpxchg(&fh->v4l_reading, 1, 0) == 1) {
1775
- if (atomic_dec_return(&dev->v4l_reader_count) == 0) {
1776
- /* stop mpeg capture */
1777
-
1778
- msleep(500);
1779
- cx231xx_417_check_encoder(dev);
1780
-
1781
- }
1782
- }
1783
-
1784
- if (fh->vidq.streaming)
1785
- videobuf_streamoff(&fh->vidq);
1786
- if (fh->vidq.reading)
1787
- videobuf_read_stop(&fh->vidq);
1788
-
1789
- videobuf_mmap_free(&fh->vidq);
1790
- v4l2_fh_del(&fh->fh);
1791
- v4l2_fh_exit(&fh->fh);
1792
- kfree(fh);
1793
- mutex_unlock(&dev->lock);
1794
- return 0;
1795
-}
1796
-
1797
-static ssize_t mpeg_read(struct file *file, char __user *data,
1798
- size_t count, loff_t *ppos)
1799
-{
1800
- struct cx231xx_fh *fh = file->private_data;
1801
- struct cx231xx *dev = fh->dev;
1802
-
1803
- /* Deal w/ A/V decoder * and mpeg encoder sync issues. */
1804
- /* Start mpeg encoder on first read. */
1805
- if (atomic_cmpxchg(&fh->v4l_reading, 0, 1) == 0) {
1806
- if (atomic_inc_return(&dev->v4l_reader_count) == 1) {
1807
- if (cx231xx_initialize_codec(dev) < 0)
1808
- return -EINVAL;
1809
- }
1810
- }
1811
-
1812
- return videobuf_read_stream(&fh->vidq, data, count, ppos, 0,
1813
- file->f_flags & O_NONBLOCK);
1814
-}
1815
-
1816
-static __poll_t mpeg_poll(struct file *file,
1817
- struct poll_table_struct *wait)
1818
-{
1819
- __poll_t req_events = poll_requested_events(wait);
1820
- struct cx231xx_fh *fh = file->private_data;
1821
- struct cx231xx *dev = fh->dev;
1822
- __poll_t res = 0;
1823
-
1824
- if (v4l2_event_pending(&fh->fh))
1825
- res |= EPOLLPRI;
1826
- else
1827
- poll_wait(file, &fh->fh.wait, wait);
1828
-
1829
- if (!(req_events & (EPOLLIN | EPOLLRDNORM)))
1830
- return res;
1831
-
1832
- mutex_lock(&dev->lock);
1833
- res |= videobuf_poll_stream(file, &fh->vidq, wait);
1834
- mutex_unlock(&dev->lock);
1835
- return res;
1836
-}
1837
-
1838
-static int mpeg_mmap(struct file *file, struct vm_area_struct *vma)
1839
-{
1840
- struct cx231xx_fh *fh = file->private_data;
1841
-
1842
- dprintk(2, "%s()\n", __func__);
1843
-
1844
- return videobuf_mmap_mapper(&fh->vidq, vma);
1845
-}
1846
-
18471612 static const struct v4l2_file_operations mpeg_fops = {
18481613 .owner = THIS_MODULE,
1849
- .open = mpeg_open,
1850
- .release = mpeg_release,
1851
- .read = mpeg_read,
1852
- .poll = mpeg_poll,
1853
- .mmap = mpeg_mmap,
1614
+ .open = v4l2_fh_open,
1615
+ .release = vb2_fop_release,
1616
+ .read = vb2_fop_read,
1617
+ .poll = vb2_fop_poll,
1618
+ .mmap = vb2_fop_mmap,
18541619 .unlocked_ioctl = video_ioctl2,
18551620 };
18561621
....@@ -1865,18 +1630,19 @@
18651630 .vidioc_g_input = cx231xx_g_input,
18661631 .vidioc_s_input = cx231xx_s_input,
18671632 .vidioc_s_ctrl = vidioc_s_ctrl,
1868
- .vidioc_cropcap = vidioc_cropcap,
1633
+ .vidioc_g_pixelaspect = vidioc_g_pixelaspect,
1634
+ .vidioc_g_selection = vidioc_g_selection,
18691635 .vidioc_querycap = cx231xx_querycap,
18701636 .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
18711637 .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
18721638 .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap,
18731639 .vidioc_s_fmt_vid_cap = vidioc_try_fmt_vid_cap,
1874
- .vidioc_reqbufs = vidioc_reqbufs,
1875
- .vidioc_querybuf = vidioc_querybuf,
1876
- .vidioc_qbuf = vidioc_qbuf,
1877
- .vidioc_dqbuf = vidioc_dqbuf,
1878
- .vidioc_streamon = vidioc_streamon,
1879
- .vidioc_streamoff = vidioc_streamoff,
1640
+ .vidioc_reqbufs = vb2_ioctl_reqbufs,
1641
+ .vidioc_querybuf = vb2_ioctl_querybuf,
1642
+ .vidioc_qbuf = vb2_ioctl_qbuf,
1643
+ .vidioc_dqbuf = vb2_ioctl_dqbuf,
1644
+ .vidioc_streamon = vb2_ioctl_streamon,
1645
+ .vidioc_streamoff = vb2_ioctl_streamoff,
18801646 .vidioc_log_status = vidioc_log_status,
18811647 #ifdef CONFIG_VIDEO_ADV_DEBUG
18821648 .vidioc_g_register = cx231xx_g_register,
....@@ -1968,8 +1734,9 @@
19681734 int cx231xx_417_register(struct cx231xx *dev)
19691735 {
19701736 /* FIXME: Port1 hardcoded here */
1971
- int err = -ENODEV;
1737
+ int err;
19721738 struct cx231xx_tsport *tsport = &dev->ts1;
1739
+ struct vb2_queue *q;
19731740
19741741 dprintk(1, "%s()\n", __func__);
19751742
....@@ -1992,7 +1759,7 @@
19921759 dev->mpeg_ctrl_handler.ops = &cx231xx_ops;
19931760 if (dev->sd_cx25840)
19941761 v4l2_ctrl_add_handler(&dev->mpeg_ctrl_handler.hdl,
1995
- dev->sd_cx25840->ctrl_handler, NULL);
1762
+ dev->sd_cx25840->ctrl_handler, NULL, false);
19961763 if (dev->mpeg_ctrl_handler.hdl.error) {
19971764 err = dev->mpeg_ctrl_handler.hdl.error;
19981765 dprintk(3, "%s: can't add cx25840 controls\n", dev->name);
....@@ -2007,8 +1774,23 @@
20071774 /* Allocate and initialize V4L video device */
20081775 cx231xx_video_dev_init(dev, dev->udev,
20091776 &dev->v4l_device, &cx231xx_mpeg_template, "mpeg");
1777
+ q = &dev->mpegq;
1778
+ q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1779
+ q->io_modes = VB2_USERPTR | VB2_MMAP | VB2_DMABUF | VB2_READ;
1780
+ q->drv_priv = dev;
1781
+ q->buf_struct_size = sizeof(struct cx231xx_buffer);
1782
+ q->ops = &cx231xx_video_qops;
1783
+ q->mem_ops = &vb2_vmalloc_memops;
1784
+ q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
1785
+ q->min_buffers_needed = 1;
1786
+ q->lock = &dev->lock;
1787
+ err = vb2_queue_init(q);
1788
+ if (err)
1789
+ return err;
1790
+ dev->v4l_device.queue = q;
1791
+
20101792 err = video_register_device(&dev->v4l_device,
2011
- VFL_TYPE_GRABBER, -1);
1793
+ VFL_TYPE_VIDEO, -1);
20121794 if (err < 0) {
20131795 dprintk(3, "%s: can't register mpeg device\n", dev->name);
20141796 v4l2_ctrl_handler_free(&dev->mpeg_ctrl_handler.hdl);