forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-04 1543e317f1da31b75942316931e8f491a8920811
kernel/drivers/media/platform/renesas-ceu.c
....@@ -189,8 +189,6 @@
189189
190190 /* async subdev notification helpers */
191191 struct v4l2_async_notifier notifier;
192
- /* pointers to "struct ceu_subdevice -> asd" */
193
- struct v4l2_async_subdev **asds;
194192
195193 /* vb2 queue, capture buffer list and active buffer pointer */
196194 struct vb2_queue vb2_vq;
....@@ -407,7 +405,7 @@
407405 /* Non-swapped planar image capture mode. */
408406 case V4L2_PIX_FMT_NV16:
409407 cdocr |= CEU_CDOCR_NO_DOWSAMPLE;
410
- /* fall-through */
408
+ fallthrough;
411409 case V4L2_PIX_FMT_NV12:
412410 if (mbus_fmt->swapped)
413411 camcr = mbus_fmt->fmt_order_swap;
....@@ -421,7 +419,7 @@
421419 /* Swapped planar image capture mode. */
422420 case V4L2_PIX_FMT_NV61:
423421 cdocr |= CEU_CDOCR_NO_DOWSAMPLE;
424
- /* fall-through */
422
+ fallthrough;
425423 case V4L2_PIX_FMT_NV21:
426424 if (mbus_fmt->swapped)
427425 camcr = mbus_fmt->fmt_order;
....@@ -1137,8 +1135,8 @@
11371135 {
11381136 struct ceu_device *ceudev = video_drvdata(file);
11391137
1140
- strlcpy(cap->card, "Renesas CEU", sizeof(cap->card));
1141
- strlcpy(cap->driver, DRIVER_NAME, sizeof(cap->driver));
1138
+ strscpy(cap->card, "Renesas CEU", sizeof(cap->card));
1139
+ strscpy(cap->driver, DRIVER_NAME, sizeof(cap->driver));
11421140 snprintf(cap->bus_info, sizeof(cap->bus_info),
11431141 "platform:renesas-ceu-%s", dev_name(ceudev->dev));
11441142
....@@ -1341,7 +1339,7 @@
13411339 static const struct v4l2_ioctl_ops ceu_ioctl_ops = {
13421340 .vidioc_querycap = ceu_querycap,
13431341
1344
- .vidioc_enum_fmt_vid_cap_mplane = ceu_enum_fmt_vid_cap,
1342
+ .vidioc_enum_fmt_vid_cap = ceu_enum_fmt_vid_cap,
13451343 .vidioc_try_fmt_vid_cap_mplane = ceu_try_fmt_vid_cap,
13461344 .vidioc_s_fmt_vid_cap_mplane = ceu_s_fmt_vid_cap,
13471345 .vidioc_g_fmt_vid_cap_mplane = ceu_g_fmt_vid_cap,
....@@ -1440,7 +1438,7 @@
14401438 return ret;
14411439
14421440 /* Register the video device. */
1443
- strlcpy(vdev->name, DRIVER_NAME, sizeof(vdev->name));
1441
+ strscpy(vdev->name, DRIVER_NAME, sizeof(vdev->name));
14441442 vdev->v4l2_dev = v4l2_dev;
14451443 vdev->lock = &ceudev->mlock;
14461444 vdev->queue = &ceudev->vb2_vq;
....@@ -1452,7 +1450,7 @@
14521450 V4L2_CAP_STREAMING;
14531451 video_set_drvdata(vdev, ceudev);
14541452
1455
- ret = video_register_device(vdev, VFL_TYPE_GRABBER, -1);
1453
+ ret = video_register_device(vdev, VFL_TYPE_VIDEO, -1);
14561454 if (ret < 0) {
14571455 v4l2_err(vdev->v4l2_dev,
14581456 "video_register_device failed: %d\n", ret);
....@@ -1482,15 +1480,6 @@
14821480 if (!ceudev->subdevs)
14831481 return -ENOMEM;
14841482
1485
- /*
1486
- * Reserve memory for 'n_sd' pointers to async_subdevices.
1487
- * ceudev->asds members will point to &ceu_subdev.asd
1488
- */
1489
- ceudev->asds = devm_kcalloc(ceudev->dev, n_sd,
1490
- sizeof(*ceudev->asds), GFP_KERNEL);
1491
- if (!ceudev->asds)
1492
- return -ENOMEM;
1493
-
14941483 ceudev->sd = NULL;
14951484 ceudev->sd_index = 0;
14961485 ceudev->num_sd = 0;
....@@ -1518,6 +1507,7 @@
15181507 return ret;
15191508
15201509 for (i = 0; i < pdata->num_subdevs; i++) {
1510
+
15211511 /* Setup the ceu subdevice and the async subdevice. */
15221512 async_sd = &pdata->subdevs[i];
15231513 ceu_sd = &ceudev->subdevs[i];
....@@ -1529,7 +1519,12 @@
15291519 ceu_sd->asd.match.i2c.adapter_id = async_sd->i2c_adapter_id;
15301520 ceu_sd->asd.match.i2c.address = async_sd->i2c_address;
15311521
1532
- ceudev->asds[i] = &ceu_sd->asd;
1522
+ ret = v4l2_async_notifier_add_subdev(&ceudev->notifier,
1523
+ &ceu_sd->asd);
1524
+ if (ret) {
1525
+ v4l2_async_notifier_cleanup(&ceudev->notifier);
1526
+ return ret;
1527
+ }
15331528 }
15341529
15351530 return pdata->num_subdevs;
....@@ -1541,9 +1536,8 @@
15411536 static int ceu_parse_dt(struct ceu_device *ceudev)
15421537 {
15431538 struct device_node *of = ceudev->dev->of_node;
1544
- struct v4l2_fwnode_endpoint fw_ep;
1539
+ struct device_node *ep, *remote;
15451540 struct ceu_subdev *ceu_sd;
1546
- struct device_node *ep;
15471541 unsigned int i;
15481542 int num_ep;
15491543 int ret;
....@@ -1557,45 +1551,55 @@
15571551 return ret;
15581552
15591553 for (i = 0; i < num_ep; i++) {
1554
+ struct v4l2_fwnode_endpoint fw_ep = {
1555
+ .bus_type = V4L2_MBUS_PARALLEL,
1556
+ .bus = {
1557
+ .parallel = {
1558
+ .flags = V4L2_MBUS_HSYNC_ACTIVE_HIGH |
1559
+ V4L2_MBUS_VSYNC_ACTIVE_HIGH,
1560
+ .bus_width = 8,
1561
+ },
1562
+ },
1563
+ };
1564
+
15601565 ep = of_graph_get_endpoint_by_regs(of, 0, i);
15611566 if (!ep) {
15621567 dev_err(ceudev->dev,
15631568 "No subdevice connected on endpoint %u.\n", i);
15641569 ret = -ENODEV;
1565
- goto error_put_node;
1570
+ goto error_cleanup;
15661571 }
15671572
15681573 ret = v4l2_fwnode_endpoint_parse(of_fwnode_handle(ep), &fw_ep);
15691574 if (ret) {
15701575 dev_err(ceudev->dev,
1571
- "Unable to parse endpoint #%u.\n", i);
1572
- goto error_put_node;
1573
- }
1574
-
1575
- if (fw_ep.bus_type != V4L2_MBUS_PARALLEL) {
1576
- dev_err(ceudev->dev,
1577
- "Only parallel input supported.\n");
1578
- ret = -EINVAL;
1579
- goto error_put_node;
1576
+ "Unable to parse endpoint #%u: %d.\n", i, ret);
1577
+ goto error_cleanup;
15801578 }
15811579
15821580 /* Setup the ceu subdevice and the async subdevice. */
15831581 ceu_sd = &ceudev->subdevs[i];
15841582 INIT_LIST_HEAD(&ceu_sd->asd.list);
15851583
1584
+ remote = of_graph_get_remote_port_parent(ep);
15861585 ceu_sd->mbus_flags = fw_ep.bus.parallel.flags;
15871586 ceu_sd->asd.match_type = V4L2_ASYNC_MATCH_FWNODE;
1588
- ceu_sd->asd.match.fwnode =
1589
- fwnode_graph_get_remote_port_parent(
1590
- of_fwnode_handle(ep));
1587
+ ceu_sd->asd.match.fwnode = of_fwnode_handle(remote);
15911588
1592
- ceudev->asds[i] = &ceu_sd->asd;
1589
+ ret = v4l2_async_notifier_add_subdev(&ceudev->notifier,
1590
+ &ceu_sd->asd);
1591
+ if (ret) {
1592
+ of_node_put(remote);
1593
+ goto error_cleanup;
1594
+ }
1595
+
15931596 of_node_put(ep);
15941597 }
15951598
15961599 return num_ep;
15971600
1598
-error_put_node:
1601
+error_cleanup:
1602
+ v4l2_async_notifier_cleanup(&ceudev->notifier);
15991603 of_node_put(ep);
16001604 return ret;
16011605 }
....@@ -1655,10 +1659,8 @@
16551659 }
16561660
16571661 ret = platform_get_irq(pdev, 0);
1658
- if (ret < 0) {
1659
- dev_err(dev, "Failed to get irq: %d\n", ret);
1662
+ if (ret < 0)
16601663 goto error_free_ceudev;
1661
- }
16621664 irq = ret;
16631665
16641666 ret = devm_request_irq(dev, irq, ceu_irq,
....@@ -1673,6 +1675,8 @@
16731675 ret = v4l2_device_register(dev, &ceudev->v4l2_dev);
16741676 if (ret)
16751677 goto error_pm_disable;
1678
+
1679
+ v4l2_async_notifier_init(&ceudev->notifier);
16761680
16771681 if (IS_ENABLED(CONFIG_OF) && dev->of_node) {
16781682 ceu_data = of_match_device(ceu_of_match, dev)->data;
....@@ -1693,18 +1697,18 @@
16931697 ceudev->irq_mask = ceu_data->irq_mask;
16941698
16951699 ceudev->notifier.v4l2_dev = &ceudev->v4l2_dev;
1696
- ceudev->notifier.subdevs = ceudev->asds;
1697
- ceudev->notifier.num_subdevs = num_subdevs;
16981700 ceudev->notifier.ops = &ceu_notify_ops;
16991701 ret = v4l2_async_notifier_register(&ceudev->v4l2_dev,
17001702 &ceudev->notifier);
17011703 if (ret)
1702
- goto error_v4l2_unregister;
1704
+ goto error_cleanup;
17031705
17041706 dev_info(dev, "Renesas Capture Engine Unit %s\n", dev_name(dev));
17051707
17061708 return 0;
17071709
1710
+error_cleanup:
1711
+ v4l2_async_notifier_cleanup(&ceudev->notifier);
17081712 error_v4l2_unregister:
17091713 v4l2_device_unregister(&ceudev->v4l2_dev);
17101714 error_pm_disable:
....@@ -1723,6 +1727,8 @@
17231727
17241728 v4l2_async_notifier_unregister(&ceudev->notifier);
17251729
1730
+ v4l2_async_notifier_cleanup(&ceudev->notifier);
1731
+
17261732 v4l2_device_unregister(&ceudev->v4l2_dev);
17271733
17281734 video_unregister_device(&ceudev->vdev);