forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-10 37f49e37ab4cb5d0bc4c60eb5c6d4dd57db767bb
kernel/drivers/staging/media/imx/imx-ic-common.c
....@@ -1,15 +1,9 @@
1
+// SPDX-License-Identifier: GPL-2.0+
12 /*
23 * V4L2 Image Converter Subdev for Freescale i.MX5/6 SOC
34 *
45 * Copyright (c) 2014-2016 Mentor Graphics Inc.
5
- *
6
- * This program is free software; you can redistribute it and/or modify
7
- * it under the terms of the GNU General Public License as published by
8
- * the Free Software Foundation; either version 2 of the License, or
9
- * (at your option) any later version.
106 */
11
-#include <linux/module.h>
12
-#include <linux/platform_device.h>
137 #include <media/v4l2-device.h>
148 #include <media/v4l2-subdev.h>
159 #include "imx-media.h"
....@@ -24,34 +18,34 @@
2418 [IC_TASK_VIEWFINDER] = &imx_ic_prpencvf_ops,
2519 };
2620
27
-static int imx_ic_probe(struct platform_device *pdev)
21
+struct v4l2_subdev *imx_media_ic_register(struct v4l2_device *v4l2_dev,
22
+ struct device *ipu_dev,
23
+ struct ipu_soc *ipu,
24
+ u32 grp_id)
2825 {
29
- struct imx_media_internal_sd_platformdata *pdata;
3026 struct imx_ic_priv *priv;
3127 int ret;
3228
33
- priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
29
+ priv = devm_kzalloc(ipu_dev, sizeof(*priv), GFP_KERNEL);
3430 if (!priv)
35
- return -ENOMEM;
31
+ return ERR_PTR(-ENOMEM);
3632
37
- platform_set_drvdata(pdev, &priv->sd);
38
- priv->dev = &pdev->dev;
33
+ priv->ipu_dev = ipu_dev;
34
+ priv->ipu = ipu;
3935
40
- /* get our ipu_id, grp_id and IC task id */
41
- pdata = priv->dev->platform_data;
42
- priv->ipu_id = pdata->ipu_id;
43
- switch (pdata->grp_id) {
44
- case IMX_MEDIA_GRP_ID_IC_PRP:
36
+ /* get our IC task id */
37
+ switch (grp_id) {
38
+ case IMX_MEDIA_GRP_ID_IPU_IC_PRP:
4539 priv->task_id = IC_TASK_PRP;
4640 break;
47
- case IMX_MEDIA_GRP_ID_IC_PRPENC:
41
+ case IMX_MEDIA_GRP_ID_IPU_IC_PRPENC:
4842 priv->task_id = IC_TASK_ENCODER;
4943 break;
50
- case IMX_MEDIA_GRP_ID_IC_PRPVF:
44
+ case IMX_MEDIA_GRP_ID_IPU_IC_PRPVF:
5145 priv->task_id = IC_TASK_VIEWFINDER;
5246 break;
5347 default:
54
- return -EINVAL;
48
+ return ERR_PTR(-EINVAL);
5549 }
5650
5751 v4l2_subdev_init(&priv->sd, ic_ops[priv->task_id]->subdev_ops);
....@@ -59,55 +53,35 @@
5953 priv->sd.internal_ops = ic_ops[priv->task_id]->internal_ops;
6054 priv->sd.entity.ops = ic_ops[priv->task_id]->entity_ops;
6155 priv->sd.entity.function = MEDIA_ENT_F_PROC_VIDEO_SCALER;
62
- priv->sd.dev = &pdev->dev;
63
- priv->sd.owner = THIS_MODULE;
56
+ priv->sd.owner = ipu_dev->driver->owner;
6457 priv->sd.flags = V4L2_SUBDEV_FL_HAS_DEVNODE | V4L2_SUBDEV_FL_HAS_EVENTS;
65
- priv->sd.grp_id = pdata->grp_id;
66
- strncpy(priv->sd.name, pdata->sd_name, sizeof(priv->sd.name));
58
+ priv->sd.grp_id = grp_id;
59
+ imx_media_grp_id_to_sd_name(priv->sd.name, sizeof(priv->sd.name),
60
+ priv->sd.grp_id, ipu_get_num(ipu));
6761
6862 ret = ic_ops[priv->task_id]->init(priv);
6963 if (ret)
70
- return ret;
64
+ return ERR_PTR(ret);
7165
72
- ret = v4l2_async_register_subdev(&priv->sd);
73
- if (ret)
66
+ ret = v4l2_device_register_subdev(v4l2_dev, &priv->sd);
67
+ if (ret) {
7468 ic_ops[priv->task_id]->remove(priv);
69
+ return ERR_PTR(ret);
70
+ }
7571
76
- return ret;
72
+ return &priv->sd;
7773 }
7874
79
-static int imx_ic_remove(struct platform_device *pdev)
75
+int imx_media_ic_unregister(struct v4l2_subdev *sd)
8076 {
81
- struct v4l2_subdev *sd = platform_get_drvdata(pdev);
8277 struct imx_ic_priv *priv = container_of(sd, struct imx_ic_priv, sd);
8378
8479 v4l2_info(sd, "Removing\n");
8580
8681 ic_ops[priv->task_id]->remove(priv);
8782
88
- v4l2_async_unregister_subdev(sd);
83
+ v4l2_device_unregister_subdev(sd);
8984 media_entity_cleanup(&sd->entity);
9085
9186 return 0;
9287 }
93
-
94
-static const struct platform_device_id imx_ic_ids[] = {
95
- { .name = "imx-ipuv3-ic" },
96
- { },
97
-};
98
-MODULE_DEVICE_TABLE(platform, imx_ic_ids);
99
-
100
-static struct platform_driver imx_ic_driver = {
101
- .probe = imx_ic_probe,
102
- .remove = imx_ic_remove,
103
- .id_table = imx_ic_ids,
104
- .driver = {
105
- .name = "imx-ipuv3-ic",
106
- },
107
-};
108
-module_platform_driver(imx_ic_driver);
109
-
110
-MODULE_DESCRIPTION("i.MX IC subdev driver");
111
-MODULE_AUTHOR("Steve Longerbeam <steve_longerbeam@mentor.com>");
112
-MODULE_LICENSE("GPL");
113
-MODULE_ALIAS("platform:imx-ipuv3-ic");