hc
2024-02-20 e636c8d336489bf3eed5878299e6cc045bbad077
kernel/drivers/media/platform/davinci/vpif_capture.c
....@@ -1,16 +1,7 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Copyright (C) 2009 Texas Instruments Inc
34 * Copyright (C) 2014 Lad, Prabhakar <prabhakar.csengg@gmail.com>
4
- *
5
- * This program is free software; you can redistribute it and/or modify
6
- * it under the terms of the GNU General Public License as published by
7
- * the Free Software Foundation; either version 2 of the License, or
8
- * (at your option) any later version.
9
- *
10
- * This program is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- * GNU General Public License for more details.
145 *
156 * TODO : add support for VBI & HBI data service
167 * add static buffer allocation
....@@ -947,15 +938,10 @@
947938 }
948939
949940 /* Fill in the information about format */
950
- if (ch->vpifparams.iface.if_type == VPIF_IF_RAW_BAYER) {
951
- fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
952
- strcpy(fmt->description, "Raw Mode -Bayer Pattern GrRBGb");
941
+ if (ch->vpifparams.iface.if_type == VPIF_IF_RAW_BAYER)
953942 fmt->pixelformat = V4L2_PIX_FMT_SBGGR8;
954
- } else {
955
- fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
956
- strcpy(fmt->description, "YCbCr4:2:2 Semi-Planar");
943
+ else
957944 fmt->pixelformat = V4L2_PIX_FMT_NV16;
958
- }
959945 return 0;
960946 }
961947
....@@ -986,7 +972,6 @@
986972 pixfmt->bytesperline = common->fmt.fmt.pix.width * 2;
987973 pixfmt->sizeimage = pixfmt->bytesperline * pixfmt->height;
988974 }
989
- pixfmt->priv = 0;
990975
991976 dev_dbg(vpif_dev, "%s: %d x %d; pitch=%d pixelformat=0x%08x, field=%d, size=%d\n", __func__,
992977 pixfmt->width, pixfmt->height,
....@@ -1092,12 +1077,10 @@
10921077 {
10931078 struct vpif_capture_config *config = vpif_dev->platform_data;
10941079
1095
- cap->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING;
1096
- cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
1097
- strlcpy(cap->driver, VPIF_DRIVER_NAME, sizeof(cap->driver));
1080
+ strscpy(cap->driver, VPIF_DRIVER_NAME, sizeof(cap->driver));
10981081 snprintf(cap->bus_info, sizeof(cap->bus_info), "platform:%s",
10991082 dev_name(vpif_dev));
1100
- strlcpy(cap->card, config->card_name, sizeof(cap->card));
1083
+ strscpy(cap->card, config->card_name, sizeof(cap->card));
11011084
11021085 return 0;
11031086 }
....@@ -1252,7 +1235,8 @@
12521235 } else {
12531236 std_info->l5 = std_info->vsize - (bt->vfrontporch - 1);
12541237 }
1255
- strncpy(std_info->name, "Custom timings BT656/1120", VPIF_MAX_NAME);
1238
+ strscpy(std_info->name, "Custom timings BT656/1120",
1239
+ sizeof(std_info->name));
12561240 std_info->width = bt->width;
12571241 std_info->height = bt->height;
12581242 std_info->frm_fmt = bt->interlaced ? 0 : 1;
....@@ -1382,6 +1366,14 @@
13821366 return err;
13831367 }
13841368
1369
+static inline void free_vpif_objs(void)
1370
+{
1371
+ int i;
1372
+
1373
+ for (i = 0; i < VPIF_CAPTURE_MAX_DEVICES; i++)
1374
+ kfree(vpif_obj.dev[i]);
1375
+}
1376
+
13851377 static int vpif_async_bound(struct v4l2_async_notifier *notifier,
13861378 struct v4l2_subdev *subdev,
13871379 struct v4l2_async_subdev *asd)
....@@ -1463,7 +1455,7 @@
14631455
14641456 /* Initialize the video_device structure */
14651457 vdev = &ch->video_dev;
1466
- strlcpy(vdev->name, VPIF_DRIVER_NAME, sizeof(vdev->name));
1458
+ strscpy(vdev->name, VPIF_DRIVER_NAME, sizeof(vdev->name));
14671459 vdev->release = video_device_release_empty;
14681460 vdev->fops = &vpif_fops;
14691461 vdev->ioctl_ops = &vpif_ioctl_ops;
....@@ -1471,9 +1463,10 @@
14711463 vdev->vfl_dir = VFL_DIR_RX;
14721464 vdev->queue = q;
14731465 vdev->lock = &common->lock;
1466
+ vdev->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING;
14741467 video_set_drvdata(&ch->video_dev, ch);
14751468 err = video_register_device(vdev,
1476
- VFL_TYPE_GRABBER, (j ? 1 : 0));
1469
+ VFL_TYPE_VIDEO, (j ? 1 : 0));
14771470 if (err)
14781471 goto probe_out;
14791472 }
....@@ -1489,8 +1482,6 @@
14891482 /* Unregister video device */
14901483 video_unregister_device(&ch->video_dev);
14911484 }
1492
- kfree(vpif_obj.sd);
1493
- v4l2_device_unregister(&vpif_obj.v4l2_dev);
14941485
14951486 return err;
14961487 }
....@@ -1509,11 +1500,13 @@
15091500 vpif_capture_get_pdata(struct platform_device *pdev)
15101501 {
15111502 struct device_node *endpoint = NULL;
1512
- struct v4l2_fwnode_endpoint bus_cfg;
1503
+ struct device_node *rem = NULL;
15131504 struct vpif_capture_config *pdata;
15141505 struct vpif_subdev_info *sdinfo;
15151506 struct vpif_capture_chan_config *chan;
15161507 unsigned int i;
1508
+
1509
+ v4l2_async_notifier_init(&vpif_obj.notifier);
15171510
15181511 /*
15191512 * DT boot: OF node from parent device contains
....@@ -1537,7 +1530,7 @@
15371530 return NULL;
15381531
15391532 for (i = 0; i < VPIF_CAPTURE_NUM_CHANNELS; i++) {
1540
- struct device_node *rem;
1533
+ struct v4l2_fwnode_endpoint bus_cfg = { .bus_type = 0 };
15411534 unsigned int flags;
15421535 int err;
15431536
....@@ -1546,6 +1539,13 @@
15461539 if (!endpoint)
15471540 break;
15481541
1542
+ rem = of_graph_get_remote_port_parent(endpoint);
1543
+ if (!rem) {
1544
+ dev_dbg(&pdev->dev, "Remote device at %pOF not found\n",
1545
+ endpoint);
1546
+ goto done;
1547
+ }
1548
+
15491549 sdinfo = &pdata->subdev_info[i];
15501550 chan = &pdata->chan_config[i];
15511551 chan->inputs = devm_kcalloc(&pdev->dev,
....@@ -1553,7 +1553,7 @@
15531553 sizeof(*chan->inputs),
15541554 GFP_KERNEL);
15551555 if (!chan->inputs)
1556
- return NULL;
1556
+ goto err_cleanup;
15571557
15581558 chan->input_count++;
15591559 chan->inputs[i].input.type = V4L2_INPUT_TYPE_CAMERA;
....@@ -1564,10 +1564,13 @@
15641564 &bus_cfg);
15651565 if (err) {
15661566 dev_err(&pdev->dev, "Could not parse the endpoint\n");
1567
+ of_node_put(rem);
15671568 goto done;
15681569 }
1570
+
15691571 dev_dbg(&pdev->dev, "Endpoint %pOF, bus_width = %d\n",
15701572 endpoint, bus_cfg.bus.parallel.bus_width);
1573
+
15711574 flags = bus_cfg.bus.parallel.flags;
15721575
15731576 if (flags & V4L2_MBUS_HSYNC_ACTIVE_HIGH)
....@@ -1576,39 +1579,32 @@
15761579 if (flags & V4L2_MBUS_VSYNC_ACTIVE_HIGH)
15771580 chan->vpif_if.vd_pol = 1;
15781581
1579
- rem = of_graph_get_remote_port_parent(endpoint);
1580
- if (!rem) {
1581
- dev_dbg(&pdev->dev, "Remote device at %pOF not found\n",
1582
- endpoint);
1583
- goto done;
1584
- }
1585
-
1586
- dev_dbg(&pdev->dev, "Remote device %s, %pOF found\n",
1587
- rem->name, rem);
1582
+ dev_dbg(&pdev->dev, "Remote device %pOF found\n", rem);
15881583 sdinfo->name = rem->full_name;
15891584
1590
- pdata->asd[i] = devm_kzalloc(&pdev->dev,
1591
- sizeof(struct v4l2_async_subdev),
1592
- GFP_KERNEL);
1593
- if (!pdata->asd[i]) {
1594
- of_node_put(rem);
1595
- pdata = NULL;
1596
- goto done;
1597
- }
1585
+ pdata->asd[i] = v4l2_async_notifier_add_fwnode_subdev(
1586
+ &vpif_obj.notifier, of_fwnode_handle(rem),
1587
+ sizeof(struct v4l2_async_subdev));
1588
+ if (IS_ERR(pdata->asd[i]))
1589
+ goto err_cleanup;
15981590
1599
- pdata->asd[i]->match_type = V4L2_ASYNC_MATCH_FWNODE;
1600
- pdata->asd[i]->match.fwnode = of_fwnode_handle(rem);
16011591 of_node_put(rem);
16021592 }
16031593
16041594 done:
1605
- if (pdata) {
1606
- pdata->asd_sizes[0] = i;
1607
- pdata->subdev_count = i;
1608
- pdata->card_name = "DA850/OMAP-L138 Video Capture";
1609
- }
1595
+ of_node_put(endpoint);
1596
+ pdata->asd_sizes[0] = i;
1597
+ pdata->subdev_count = i;
1598
+ pdata->card_name = "DA850/OMAP-L138 Video Capture";
16101599
16111600 return pdata;
1601
+
1602
+err_cleanup:
1603
+ of_node_put(rem);
1604
+ of_node_put(endpoint);
1605
+ v4l2_async_notifier_cleanup(&vpif_obj.notifier);
1606
+
1607
+ return NULL;
16121608 }
16131609
16141610 /**
....@@ -1633,23 +1629,18 @@
16331629 return -EINVAL;
16341630 }
16351631
1636
- if (!pdev->dev.platform_data) {
1637
- dev_warn(&pdev->dev, "Missing platform data. Giving up.\n");
1638
- return -EINVAL;
1639
- }
1640
-
16411632 vpif_dev = &pdev->dev;
16421633
16431634 err = initialize_vpif();
16441635 if (err) {
16451636 v4l2_err(vpif_dev->driver, "Error initializing vpif\n");
1646
- return err;
1637
+ goto cleanup;
16471638 }
16481639
16491640 err = v4l2_device_register(vpif_dev, &vpif_obj.v4l2_dev);
16501641 if (err) {
16511642 v4l2_err(vpif_dev->driver, "Error registering v4l2 device\n");
1652
- return err;
1643
+ goto vpif_free;
16531644 }
16541645
16551646 while ((res = platform_get_resource(pdev, IORESOURCE_IRQ, res_idx))) {
....@@ -1696,10 +1687,10 @@
16961687 "registered sub device %s\n",
16971688 subdevdata->name);
16981689 }
1699
- vpif_probe_complete();
1690
+ err = vpif_probe_complete();
1691
+ if (err)
1692
+ goto probe_subdev_out;
17001693 } else {
1701
- vpif_obj.notifier.subdevs = vpif_obj.config->asd;
1702
- vpif_obj.notifier.num_subdevs = vpif_obj.config->asd_sizes[0];
17031694 vpif_obj.notifier.ops = &vpif_async_ops;
17041695 err = v4l2_async_notifier_register(&vpif_obj.v4l2_dev,
17051696 &vpif_obj.notifier);
....@@ -1717,6 +1708,10 @@
17171708 kfree(vpif_obj.sd);
17181709 vpif_unregister:
17191710 v4l2_device_unregister(&vpif_obj.v4l2_dev);
1711
+vpif_free:
1712
+ free_vpif_objs();
1713
+cleanup:
1714
+ v4l2_async_notifier_cleanup(&vpif_obj.notifier);
17201715
17211716 return err;
17221717 }
....@@ -1732,6 +1727,8 @@
17321727 struct channel_obj *ch;
17331728 int i;
17341729
1730
+ v4l2_async_notifier_unregister(&vpif_obj.notifier);
1731
+ v4l2_async_notifier_cleanup(&vpif_obj.notifier);
17351732 v4l2_device_unregister(&vpif_obj.v4l2_dev);
17361733
17371734 kfree(vpif_obj.sd);