Commit 6d01b7ff authored by Steve Longerbeam's avatar Steve Longerbeam Committed by Mauro Carvalho Chehab

media: staging/imx: Switch to sync registration for IPU subdevs

Because the IPU sub-devices VDIC and IC are not present in the
device-tree, platform devices were created for them instead. This
allowed these sub-devices to be added to the media device's async
notifier and registered asynchronously along with the other
sub-devices that do have a device-tree presence (CSI and devices
external to the IPU and SoC).

But that approach isn't really necessary. The IPU sub-devices don't
actually require a backing device (sd->dev is allowed to be NULL).
And that approach can't get around the fact that the IPU sub-devices
are not part of a device hierarchy, which makes it awkward to retrieve
the parent IPU of these devices.

By registering them synchronously, they can be registered from the CSI
async bound notifier, so the init function for them can be given the CSI
subdev, who's dev->parent is the IPU. That is a somewhat cleaner way
to retrieve the parent IPU.

So convert to synchronous registration for the VDIC and IC task
sub-devices, at the time a CSI sub-device is bound. There is no longer
a backing device for them (sd->dev is NULL), but that's ok. Also
set the VDIC/IC sub-device owner as the IPU, so that a reference can
be taken on the IPU module.

Since the VDIC and IC task drivers are no longer platform drivers,
they are now statically linked to imx-media module.
Signed-off-by: default avatarSteve Longerbeam <slongerbeam@gmail.com>
Signed-off-by: default avatarHans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab+samsung@kernel.org>
parent 411c5988
# SPDX-License-Identifier: GPL-2.0 # SPDX-License-Identifier: GPL-2.0
imx-media-objs := imx-media-dev.o imx-media-internal-sd.o imx-media-of.o imx-media-objs := imx-media-dev.o imx-media-internal-sd.o imx-media-of.o \
imx-ic-common.o imx-ic-prp.o imx-ic-prpencvf.o imx-media-vdic.o
imx-media-objs += imx-media-dev-common.o imx-media-objs += imx-media-dev-common.o
imx-media-common-objs := imx-media-utils.o imx-media-fim.o imx-media-common-objs := imx-media-utils.o imx-media-fim.o
imx-media-ic-objs := imx-ic-common.o imx-ic-prp.o imx-ic-prpencvf.o
obj-$(CONFIG_VIDEO_IMX_MEDIA) += imx-media.o obj-$(CONFIG_VIDEO_IMX_MEDIA) += imx-media.o
obj-$(CONFIG_VIDEO_IMX_MEDIA) += imx-media-common.o obj-$(CONFIG_VIDEO_IMX_MEDIA) += imx-media-common.o
obj-$(CONFIG_VIDEO_IMX_MEDIA) += imx-media-capture.o obj-$(CONFIG_VIDEO_IMX_MEDIA) += imx-media-capture.o
obj-$(CONFIG_VIDEO_IMX_MEDIA) += imx-media-vdic.o
obj-$(CONFIG_VIDEO_IMX_MEDIA) += imx-media-ic.o
obj-$(CONFIG_VIDEO_IMX_CSI) += imx-media-csi.o obj-$(CONFIG_VIDEO_IMX_CSI) += imx-media-csi.o
obj-$(CONFIG_VIDEO_IMX_CSI) += imx6-mipi-csi2.o obj-$(CONFIG_VIDEO_IMX_CSI) += imx6-mipi-csi2.o
......
...@@ -4,8 +4,6 @@ ...@@ -4,8 +4,6 @@
* *
* Copyright (c) 2014-2016 Mentor Graphics Inc. * Copyright (c) 2014-2016 Mentor Graphics Inc.
*/ */
#include <linux/module.h>
#include <linux/platform_device.h>
#include <media/v4l2-device.h> #include <media/v4l2-device.h>
#include <media/v4l2-subdev.h> #include <media/v4l2-subdev.h>
#include "imx-media.h" #include "imx-media.h"
...@@ -20,23 +18,25 @@ static struct imx_ic_ops *ic_ops[IC_NUM_OPS] = { ...@@ -20,23 +18,25 @@ static struct imx_ic_ops *ic_ops[IC_NUM_OPS] = {
[IC_TASK_VIEWFINDER] = &imx_ic_prpencvf_ops, [IC_TASK_VIEWFINDER] = &imx_ic_prpencvf_ops,
}; };
static int imx_ic_probe(struct platform_device *pdev) struct v4l2_subdev *imx_media_ic_register(struct imx_media_dev *imxmd,
struct device *ipu_dev,
struct ipu_soc *ipu,
u32 grp_id)
{ {
struct imx_media_ipu_internal_sd_pdata *pdata; struct v4l2_device *v4l2_dev = &imxmd->v4l2_dev;
struct imx_ic_priv *priv; struct imx_ic_priv *priv;
int ret; int ret;
priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); priv = devm_kzalloc(ipu_dev, sizeof(*priv), GFP_KERNEL);
if (!priv) if (!priv)
return -ENOMEM; return ERR_PTR(-ENOMEM);
platform_set_drvdata(pdev, &priv->sd); priv->ipu_dev = ipu_dev;
priv->dev = &pdev->dev; priv->ipu = ipu;
priv->md = imxmd;
/* get our ipu_id, grp_id and IC task id */ /* get our IC task id */
pdata = priv->dev->platform_data; switch (grp_id) {
priv->ipu_id = pdata->ipu_id;
switch (pdata->grp_id) {
case IMX_MEDIA_GRP_ID_IPU_IC_PRP: case IMX_MEDIA_GRP_ID_IPU_IC_PRP:
priv->task_id = IC_TASK_PRP; priv->task_id = IC_TASK_PRP;
break; break;
...@@ -47,7 +47,7 @@ static int imx_ic_probe(struct platform_device *pdev) ...@@ -47,7 +47,7 @@ static int imx_ic_probe(struct platform_device *pdev)
priv->task_id = IC_TASK_VIEWFINDER; priv->task_id = IC_TASK_VIEWFINDER;
break; break;
default: default:
return -EINVAL; return ERR_PTR(-EINVAL);
} }
v4l2_subdev_init(&priv->sd, ic_ops[priv->task_id]->subdev_ops); v4l2_subdev_init(&priv->sd, ic_ops[priv->task_id]->subdev_ops);
...@@ -55,55 +55,35 @@ static int imx_ic_probe(struct platform_device *pdev) ...@@ -55,55 +55,35 @@ static int imx_ic_probe(struct platform_device *pdev)
priv->sd.internal_ops = ic_ops[priv->task_id]->internal_ops; priv->sd.internal_ops = ic_ops[priv->task_id]->internal_ops;
priv->sd.entity.ops = ic_ops[priv->task_id]->entity_ops; priv->sd.entity.ops = ic_ops[priv->task_id]->entity_ops;
priv->sd.entity.function = MEDIA_ENT_F_PROC_VIDEO_SCALER; priv->sd.entity.function = MEDIA_ENT_F_PROC_VIDEO_SCALER;
priv->sd.dev = &pdev->dev; priv->sd.owner = ipu_dev->driver->owner;
priv->sd.owner = THIS_MODULE;
priv->sd.flags = V4L2_SUBDEV_FL_HAS_DEVNODE | V4L2_SUBDEV_FL_HAS_EVENTS; priv->sd.flags = V4L2_SUBDEV_FL_HAS_DEVNODE | V4L2_SUBDEV_FL_HAS_EVENTS;
priv->sd.grp_id = pdata->grp_id; priv->sd.grp_id = grp_id;
strscpy(priv->sd.name, pdata->sd_name, sizeof(priv->sd.name)); imx_media_grp_id_to_sd_name(priv->sd.name, sizeof(priv->sd.name),
priv->sd.grp_id, ipu_get_num(ipu));
ret = ic_ops[priv->task_id]->init(priv); ret = ic_ops[priv->task_id]->init(priv);
if (ret) if (ret)
return ret; return ERR_PTR(ret);
ret = v4l2_async_register_subdev(&priv->sd); ret = v4l2_device_register_subdev(v4l2_dev, &priv->sd);
if (ret) if (ret) {
ic_ops[priv->task_id]->remove(priv); ic_ops[priv->task_id]->remove(priv);
return ERR_PTR(ret);
}
return ret; return &priv->sd;
} }
static int imx_ic_remove(struct platform_device *pdev) int imx_media_ic_unregister(struct v4l2_subdev *sd)
{ {
struct v4l2_subdev *sd = platform_get_drvdata(pdev);
struct imx_ic_priv *priv = container_of(sd, struct imx_ic_priv, sd); struct imx_ic_priv *priv = container_of(sd, struct imx_ic_priv, sd);
v4l2_info(sd, "Removing\n"); v4l2_info(sd, "Removing\n");
ic_ops[priv->task_id]->remove(priv); ic_ops[priv->task_id]->remove(priv);
v4l2_async_unregister_subdev(sd); v4l2_device_unregister_subdev(sd);
media_entity_cleanup(&sd->entity); media_entity_cleanup(&sd->entity);
return 0; return 0;
} }
static const struct platform_device_id imx_ic_ids[] = {
{ .name = "imx-ipuv3-ic" },
{ },
};
MODULE_DEVICE_TABLE(platform, imx_ic_ids);
static struct platform_driver imx_ic_driver = {
.probe = imx_ic_probe,
.remove = imx_ic_remove,
.id_table = imx_ic_ids,
.driver = {
.name = "imx-ipuv3-ic",
},
};
module_platform_driver(imx_ic_driver);
MODULE_DESCRIPTION("i.MX IC subdev driver");
MODULE_AUTHOR("Steve Longerbeam <steve_longerbeam@mentor.com>");
MODULE_LICENSE("GPL");
MODULE_ALIAS("platform:imx-ipuv3-ic");
...@@ -35,16 +35,12 @@ ...@@ -35,16 +35,12 @@
#define S_ALIGN 1 /* multiple of 2 */ #define S_ALIGN 1 /* multiple of 2 */
struct prp_priv { struct prp_priv {
struct imx_media_dev *md;
struct imx_ic_priv *ic_priv; struct imx_ic_priv *ic_priv;
struct media_pad pad[PRP_NUM_PADS]; struct media_pad pad[PRP_NUM_PADS];
/* lock to protect all members below */ /* lock to protect all members below */
struct mutex lock; struct mutex lock;
/* IPU units we require */
struct ipu_soc *ipu;
struct v4l2_subdev *src_sd; struct v4l2_subdev *src_sd;
struct v4l2_subdev *sink_sd_prpenc; struct v4l2_subdev *sink_sd_prpenc;
struct v4l2_subdev *sink_sd_prpvf; struct v4l2_subdev *sink_sd_prpvf;
...@@ -62,7 +58,7 @@ static inline struct prp_priv *sd_to_priv(struct v4l2_subdev *sd) ...@@ -62,7 +58,7 @@ static inline struct prp_priv *sd_to_priv(struct v4l2_subdev *sd)
{ {
struct imx_ic_priv *ic_priv = v4l2_get_subdevdata(sd); struct imx_ic_priv *ic_priv = v4l2_get_subdevdata(sd);
return ic_priv->prp_priv; return ic_priv->task_priv;
} }
static int prp_start(struct prp_priv *priv) static int prp_start(struct prp_priv *priv)
...@@ -70,12 +66,10 @@ static int prp_start(struct prp_priv *priv) ...@@ -70,12 +66,10 @@ static int prp_start(struct prp_priv *priv)
struct imx_ic_priv *ic_priv = priv->ic_priv; struct imx_ic_priv *ic_priv = priv->ic_priv;
bool src_is_vdic; bool src_is_vdic;
priv->ipu = priv->md->ipu[ic_priv->ipu_id];
/* set IC to receive from CSI or VDI depending on source */ /* set IC to receive from CSI or VDI depending on source */
src_is_vdic = !!(priv->src_sd->grp_id & IMX_MEDIA_GRP_ID_IPU_VDIC); src_is_vdic = !!(priv->src_sd->grp_id & IMX_MEDIA_GRP_ID_IPU_VDIC);
ipu_set_ic_src_mux(priv->ipu, priv->csi_id, src_is_vdic); ipu_set_ic_src_mux(ic_priv->ipu, priv->csi_id, src_is_vdic);
return 0; return 0;
} }
...@@ -216,12 +210,12 @@ static int prp_link_setup(struct media_entity *entity, ...@@ -216,12 +210,12 @@ static int prp_link_setup(struct media_entity *entity,
{ {
struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity); struct v4l2_subdev *sd = media_entity_to_v4l2_subdev(entity);
struct imx_ic_priv *ic_priv = v4l2_get_subdevdata(sd); struct imx_ic_priv *ic_priv = v4l2_get_subdevdata(sd);
struct prp_priv *priv = ic_priv->prp_priv; struct prp_priv *priv = ic_priv->task_priv;
struct v4l2_subdev *remote_sd; struct v4l2_subdev *remote_sd;
int ret = 0; int ret = 0;
dev_dbg(ic_priv->dev, "link setup %s -> %s", remote->entity->name, dev_dbg(ic_priv->ipu_dev, "%s: link setup %s -> %s",
local->entity->name); ic_priv->sd.name, remote->entity->name, local->entity->name);
remote_sd = media_entity_to_v4l2_subdev(remote->entity); remote_sd = media_entity_to_v4l2_subdev(remote->entity);
...@@ -295,7 +289,7 @@ static int prp_link_validate(struct v4l2_subdev *sd, ...@@ -295,7 +289,7 @@ static int prp_link_validate(struct v4l2_subdev *sd,
struct v4l2_subdev_format *sink_fmt) struct v4l2_subdev_format *sink_fmt)
{ {
struct imx_ic_priv *ic_priv = v4l2_get_subdevdata(sd); struct imx_ic_priv *ic_priv = v4l2_get_subdevdata(sd);
struct prp_priv *priv = ic_priv->prp_priv; struct prp_priv *priv = ic_priv->task_priv;
struct v4l2_subdev *csi; struct v4l2_subdev *csi;
int ret; int ret;
...@@ -304,7 +298,7 @@ static int prp_link_validate(struct v4l2_subdev *sd, ...@@ -304,7 +298,7 @@ static int prp_link_validate(struct v4l2_subdev *sd,
if (ret) if (ret)
return ret; return ret;
csi = imx_media_find_upstream_subdev(priv->md, &ic_priv->sd.entity, csi = imx_media_find_upstream_subdev(ic_priv->md, &ic_priv->sd.entity,
IMX_MEDIA_GRP_ID_IPU_CSI); IMX_MEDIA_GRP_ID_IPU_CSI);
if (IS_ERR(csi)) if (IS_ERR(csi))
csi = NULL; csi = NULL;
...@@ -351,7 +345,7 @@ static int prp_link_validate(struct v4l2_subdev *sd, ...@@ -351,7 +345,7 @@ static int prp_link_validate(struct v4l2_subdev *sd,
static int prp_s_stream(struct v4l2_subdev *sd, int enable) static int prp_s_stream(struct v4l2_subdev *sd, int enable)
{ {
struct imx_ic_priv *ic_priv = v4l2_get_subdevdata(sd); struct imx_ic_priv *ic_priv = v4l2_get_subdevdata(sd);
struct prp_priv *priv = ic_priv->prp_priv; struct prp_priv *priv = ic_priv->task_priv;
int ret = 0; int ret = 0;
mutex_lock(&priv->lock); mutex_lock(&priv->lock);
...@@ -368,7 +362,8 @@ static int prp_s_stream(struct v4l2_subdev *sd, int enable) ...@@ -368,7 +362,8 @@ static int prp_s_stream(struct v4l2_subdev *sd, int enable)
if (priv->stream_count != !enable) if (priv->stream_count != !enable)
goto update_count; goto update_count;
dev_dbg(ic_priv->dev, "stream %s\n", enable ? "ON" : "OFF"); dev_dbg(ic_priv->ipu_dev, "%s: stream %s\n", sd->name,
enable ? "ON" : "OFF");
if (enable) if (enable)
ret = prp_start(priv); ret = prp_start(priv);
...@@ -440,9 +435,6 @@ static int prp_registered(struct v4l2_subdev *sd) ...@@ -440,9 +435,6 @@ static int prp_registered(struct v4l2_subdev *sd)
int i, ret; int i, ret;
u32 code; u32 code;
/* get media device */
priv->md = dev_get_drvdata(sd->v4l2_dev->dev);
for (i = 0; i < PRP_NUM_PADS; i++) { for (i = 0; i < PRP_NUM_PADS; i++) {
priv->pad[i].flags = (i == PRP_SINK_PAD) ? priv->pad[i].flags = (i == PRP_SINK_PAD) ?
MEDIA_PAD_FL_SINK : MEDIA_PAD_FL_SOURCE; MEDIA_PAD_FL_SINK : MEDIA_PAD_FL_SOURCE;
...@@ -494,12 +486,12 @@ static int prp_init(struct imx_ic_priv *ic_priv) ...@@ -494,12 +486,12 @@ static int prp_init(struct imx_ic_priv *ic_priv)
{ {
struct prp_priv *priv; struct prp_priv *priv;
priv = devm_kzalloc(ic_priv->dev, sizeof(*priv), GFP_KERNEL); priv = devm_kzalloc(ic_priv->ipu_dev, sizeof(*priv), GFP_KERNEL);
if (!priv) if (!priv)
return -ENOMEM; return -ENOMEM;
mutex_init(&priv->lock); mutex_init(&priv->lock);
ic_priv->prp_priv = priv; ic_priv->task_priv = priv;
priv->ic_priv = ic_priv; priv->ic_priv = ic_priv;
return 0; return 0;
...@@ -507,7 +499,7 @@ static int prp_init(struct imx_ic_priv *ic_priv) ...@@ -507,7 +499,7 @@ static int prp_init(struct imx_ic_priv *ic_priv)
static void prp_remove(struct imx_ic_priv *ic_priv) static void prp_remove(struct imx_ic_priv *ic_priv)
{ {
struct prp_priv *priv = ic_priv->prp_priv; struct prp_priv *priv = ic_priv->task_priv;
mutex_destroy(&priv->lock); mutex_destroy(&priv->lock);
} }
......
...@@ -50,7 +50,6 @@ ...@@ -50,7 +50,6 @@
#define S_ALIGN 1 /* multiple of 2 */ #define S_ALIGN 1 /* multiple of 2 */
struct prp_priv { struct prp_priv {
struct imx_media_dev *md;
struct imx_ic_priv *ic_priv; struct imx_ic_priv *ic_priv;
struct media_pad pad[PRPENCVF_NUM_PADS]; struct media_pad pad[PRPENCVF_NUM_PADS];
/* the video device at output pad */ /* the video device at output pad */
...@@ -60,7 +59,6 @@ struct prp_priv { ...@@ -60,7 +59,6 @@ struct prp_priv {
struct mutex lock; struct mutex lock;
/* IPU units we require */ /* IPU units we require */
struct ipu_soc *ipu;
struct ipu_ic *ic; struct ipu_ic *ic;
struct ipuv3_channel *out_ch; struct ipuv3_channel *out_ch;
struct ipuv3_channel *rot_in_ch; struct ipuv3_channel *rot_in_ch;
...@@ -156,9 +154,7 @@ static int prp_get_ipu_resources(struct prp_priv *priv) ...@@ -156,9 +154,7 @@ static int prp_get_ipu_resources(struct prp_priv *priv)
struct ipuv3_channel *out_ch, *rot_in_ch, *rot_out_ch; struct ipuv3_channel *out_ch, *rot_in_ch, *rot_out_ch;
int ret, task = ic_priv->task_id; int ret, task = ic_priv->task_id;
priv->ipu = priv->md->ipu[ic_priv->ipu_id]; ic = ipu_ic_get(ic_priv->ipu, task);
ic = ipu_ic_get(priv->ipu, task);
if (IS_ERR(ic)) { if (IS_ERR(ic)) {
v4l2_err(&ic_priv->sd, "failed to get IC\n"); v4l2_err(&ic_priv->sd, "failed to get IC\n");
ret = PTR_ERR(ic); ret = PTR_ERR(ic);
...@@ -166,7 +162,7 @@ static int prp_get_ipu_resources(struct prp_priv *priv) ...@@ -166,7 +162,7 @@ static int prp_get_ipu_resources(struct prp_priv *priv)
} }
priv->ic = ic; priv->ic = ic;
out_ch = ipu_idmac_get(priv->ipu, prp_channel[task].out_ch); out_ch = ipu_idmac_get(ic_priv->ipu, prp_channel[task].out_ch);
if (IS_ERR(out_ch)) { if (IS_ERR(out_ch)) {
v4l2_err(&ic_priv->sd, "could not get IDMAC channel %u\n", v4l2_err(&ic_priv->sd, "could not get IDMAC channel %u\n",
prp_channel[task].out_ch); prp_channel[task].out_ch);
...@@ -175,7 +171,7 @@ static int prp_get_ipu_resources(struct prp_priv *priv) ...@@ -175,7 +171,7 @@ static int prp_get_ipu_resources(struct prp_priv *priv)
} }
priv->out_ch = out_ch; priv->out_ch = out_ch;
rot_in_ch = ipu_idmac_get(priv->ipu, prp_channel[task].rot_in_ch); rot_in_ch = ipu_idmac_get(ic_priv->ipu, prp_channel[task].rot_in_ch);
if (IS_ERR(rot_in_ch)) { if (IS_ERR(rot_in_ch)) {
v4l2_err(&ic_priv->sd, "could not get IDMAC channel %u\n", v4l2_err(&ic_priv->sd, "could not get IDMAC channel %u\n",
prp_channel[task].rot_in_ch); prp_channel[task].rot_in_ch);
...@@ -184,7 +180,7 @@ static int prp_get_ipu_resources(struct prp_priv *priv) ...@@ -184,7 +180,7 @@ static int prp_get_ipu_resources(struct prp_priv *priv)
} }
priv->rot_in_ch = rot_in_ch; priv->rot_in_ch = rot_in_ch;
rot_out_ch = ipu_idmac_get(priv->ipu, prp_channel[task].rot_out_ch); rot_out_ch = ipu_idmac_get(ic_priv->ipu, prp_channel[task].rot_out_ch);
if (IS_ERR(rot_out_ch)) { if (IS_ERR(rot_out_ch)) {
v4l2_err(&ic_priv->sd, "could not get IDMAC channel %u\n", v4l2_err(&ic_priv->sd, "could not get IDMAC channel %u\n",
prp_channel[task].rot_out_ch); prp_channel[task].rot_out_ch);
...@@ -464,13 +460,13 @@ static int prp_setup_rotation(struct prp_priv *priv) ...@@ -464,13 +460,13 @@ static int prp_setup_rotation(struct prp_priv *priv)
incc = priv->cc[PRPENCVF_SINK_PAD]; incc = priv->cc[PRPENCVF_SINK_PAD];
outcc = vdev->cc; outcc = vdev->cc;
ret = imx_media_alloc_dma_buf(priv->md, &priv->rot_buf[0], ret = imx_media_alloc_dma_buf(ic_priv->md, &priv->rot_buf[0],
outfmt->sizeimage); outfmt->sizeimage);
if (ret) { if (ret) {
v4l2_err(&ic_priv->sd, "failed to alloc rot_buf[0], %d\n", ret); v4l2_err(&ic_priv->sd, "failed to alloc rot_buf[0], %d\n", ret);
return ret; return ret;
} }
ret = imx_media_alloc_dma_buf(priv->md, &priv->rot_buf[1], ret = imx_media_alloc_dma_buf(ic_priv->md, &priv->rot_buf[1],
outfmt->sizeimage); outfmt->sizeimage);
if (ret) { if (ret) {
v4l2_err(&ic_priv->sd, "failed to alloc rot_buf[1], %d\n", ret); v4l2_err(&ic_priv->sd, "failed to alloc rot_buf[1], %d\n", ret);
...@@ -543,14 +539,16 @@ static int prp_setup_rotation(struct prp_priv *priv) ...@@ -543,14 +539,16 @@ static int prp_setup_rotation(struct prp_priv *priv)
unsetup_vb2: unsetup_vb2:
prp_unsetup_vb2_buf(priv, VB2_BUF_STATE_QUEUED); prp_unsetup_vb2_buf(priv, VB2_BUF_STATE_QUEUED);
free_rot1: free_rot1:
imx_media_free_dma_buf(priv->md, &priv->rot_buf[1]); imx_media_free_dma_buf(ic_priv->md, &priv->rot_buf[1]);
free_rot0: free_rot0:
imx_media_free_dma_buf(priv->md, &priv->rot_buf[0]); imx_media_free_dma_buf(ic_priv->md, &priv->rot_buf[0]);
return ret; return ret;
} }
static void prp_unsetup_rotation(struct prp_priv *priv) static void prp_unsetup_rotation(struct prp_priv *priv)
{ {
struct imx_ic_priv *ic_priv = priv->ic_priv;
ipu_ic_task_disable(priv->ic); ipu_ic_task_disable(priv->ic);
ipu_idmac_disable_channel(priv->out_ch); ipu_idmac_disable_channel(priv->out_ch);
...@@ -561,8 +559,8 @@ static void prp_unsetup_rotation(struct prp_priv *priv) ...@@ -561,8 +559,8 @@ static void prp_unsetup_rotation(struct prp_priv *priv)
ipu_ic_disable(priv->ic); ipu_ic_disable(priv->ic);
imx_media_free_dma_buf(priv->md, &priv->rot_buf[0]); imx_media_free_dma_buf(ic_priv->md, &priv->rot_buf[0]);
imx_media_free_dma_buf(priv->md, &priv->rot_buf[1]); imx_media_free_dma_buf(ic_priv->md, &priv->rot_buf[1]);
} }
static int prp_setup_norotation(struct prp_priv *priv) static int prp_setup_norotation(struct prp_priv *priv)
...@@ -602,7 +600,7 @@ static int prp_setup_norotation(struct prp_priv *priv) ...@@ -602,7 +600,7 @@ static int prp_setup_norotation(struct prp_priv *priv)
ipu_cpmem_dump(priv->out_ch); ipu_cpmem_dump(priv->out_ch);
ipu_ic_dump(priv->ic); ipu_ic_dump(priv->ic);
ipu_dump(priv->ipu); ipu_dump(ic_priv->ipu);
ipu_ic_enable(priv->ic); ipu_ic_enable(priv->ic);
...@@ -654,7 +652,7 @@ static int prp_start(struct prp_priv *priv) ...@@ -654,7 +652,7 @@ static int prp_start(struct prp_priv *priv)
outfmt = &vdev->fmt.fmt.pix; outfmt = &vdev->fmt.fmt.pix;
ret = imx_media_alloc_dma_buf(priv->md, &priv->underrun_buf, ret = imx_media_alloc_dma_buf(ic_priv->md, &priv->underrun_buf,
outfmt->sizeimage); outfmt->sizeimage);
if (ret) if (ret)
goto out_put_ipu; goto out_put_ipu;
...@@ -674,10 +672,10 @@ static int prp_start(struct prp_priv *priv) ...@@ -674,10 +672,10 @@ static int prp_start(struct prp_priv *priv)
if (ret) if (ret)
goto out_free_underrun; goto out_free_underrun;
priv->nfb4eof_irq = ipu_idmac_channel_irq(priv->ipu, priv->nfb4eof_irq = ipu_idmac_channel_irq(ic_priv->ipu,
priv->out_ch, priv->out_ch,
IPU_IRQ_NFB4EOF); IPU_IRQ_NFB4EOF);
ret = devm_request_irq(ic_priv->dev, priv->nfb4eof_irq, ret = devm_request_irq(ic_priv->ipu_dev, priv->nfb4eof_irq,
prp_nfb4eof_interrupt, 0, prp_nfb4eof_interrupt, 0,
"imx-ic-prp-nfb4eof", priv); "imx-ic-prp-nfb4eof", priv);
if (ret) { if (ret) {
...@@ -688,12 +686,12 @@ static int prp_start(struct prp_priv *priv) ...@@ -688,12 +686,12 @@ static int prp_start(struct prp_priv *priv)
if (ipu_rot_mode_is_irt(priv->rot_mode)) if (ipu_rot_mode_is_irt(priv->rot_mode))
priv->eof_irq = ipu_idmac_channel_irq( priv->eof_irq = ipu_idmac_channel_irq(
priv->ipu, priv->rot_out_ch, IPU_IRQ_EOF); ic_priv->ipu, priv->rot_out_ch, IPU_IRQ_EOF);
else else
priv->eof_irq = ipu_idmac_channel_irq( priv->eof_irq = ipu_idmac_channel_irq(
priv->ipu, priv->out_ch, IPU_IRQ_EOF); ic_priv->ipu, priv->out_ch, IPU_IRQ_EOF);
ret = devm_request_irq(ic_priv->dev, priv->eof_irq, ret = devm_request_irq(ic_priv->ipu_dev, priv->eof_irq,
prp_eof_interrupt, 0, prp_eof_interrupt, 0,
"imx-ic-prp-eof", priv); "imx-ic-prp-eof", priv);
if (ret) { if (ret) {
...@@ -718,13 +716,13 @@ static int prp_start(struct prp_priv *priv) ...@@ -718,13 +716,13 @@ static int prp_start(struct prp_priv *priv)
return 0; return 0;
out_free_eof_irq: out_free_eof_irq:
devm_free_irq(ic_priv->dev, priv->eof_irq, priv); devm_free_irq(ic_priv->ipu_dev, priv->eof_irq, priv);
out_free_nfb4eof_irq: out_free_nfb4eof_irq:
devm_free_irq(ic_priv->dev, priv->nfb4eof_irq, priv); devm_free_irq(ic_priv->ipu_dev, priv->nfb4eof_irq, priv);
out_unsetup: out_unsetup:
prp_unsetup(priv, VB2_BUF_STATE_QUEUED); prp_unsetup(priv, VB2_BUF_STATE_QUEUED);
out_free_underrun: out_free_underrun:
imx_media_free_dma_buf(priv->md, &priv->underrun_buf); imx_media_free_dma_buf(ic_priv->md, &priv->underrun_buf);
out_put_ipu: out_put_ipu:
prp_put_ipu_resources(priv); prp_put_ipu_resources(priv);
return ret; return ret;
...@@ -756,12 +754,12 @@ static void prp_stop(struct prp_priv *priv) ...@@ -756,12 +754,12 @@ static void prp_stop(struct prp_priv *priv)
v4l2_warn(&ic_priv->sd, v4l2_warn(&ic_priv->sd,
"upstream stream off failed: %d\n", ret); "upstream stream off failed: %d\n", ret);
devm_free_irq(ic_priv->dev, priv->eof_irq, priv); devm_free_irq(ic_priv->ipu_dev, priv->eof_irq, priv);
devm_free_irq(ic_priv->dev, priv->nfb4eof_irq, priv); devm_free_irq(ic_priv->ipu_dev, priv->nfb4eof_irq, priv);
prp_unsetup(priv, VB2_BUF_STATE_ERROR); prp_unsetup(priv, VB2_BUF_STATE_ERROR);
imx_media_free_dma_buf(priv->md, &priv->underrun_buf); imx_media_free_dma_buf(ic_priv->md, &priv->underrun_buf);
/* cancel the EOF timeout timer */ /* cancel the EOF timeout timer */
del_timer_sync(&priv->eof_timeout_timer); del_timer_sync(&priv->eof_timeout_timer);
...@@ -1011,8 +1009,8 @@ static int prp_link_setup(struct media_entity *entity, ...@@ -1011,8 +1009,8 @@ static int prp_link_setup(struct media_entity *entity,
struct v4l2_subdev *remote_sd; struct v4l2_subdev *remote_sd;
int ret = 0; int ret = 0;
dev_dbg(ic_priv->dev, "link setup %s -> %s", remote->entity->name, dev_dbg(ic_priv->ipu_dev, "%s: link setup %s -> %s",
local->entity->name); ic_priv->sd.name, remote->entity->name, local->entity->name);
mutex_lock(&priv->lock); mutex_lock(&priv->lock);
...@@ -1178,7 +1176,8 @@ static int prp_s_stream(struct v4l2_subdev *sd, int enable) ...@@ -1178,7 +1176,8 @@ static int prp_s_stream(struct v4l2_subdev *sd, int enable)
if (priv->stream_count != !enable) if (priv->stream_count != !enable)
goto update_count; goto update_count;
dev_dbg(ic_priv->dev, "stream %s\n", enable ? "ON" : "OFF"); dev_dbg(ic_priv->ipu_dev, "%s: stream %s\n", sd->name,
enable ? "ON" : "OFF");
if (enable) if (enable)
ret = prp_start(priv); ret = prp_start(priv);
...@@ -1238,12 +1237,10 @@ static int prp_s_frame_interval(struct v4l2_subdev *sd, ...@@ -1238,12 +1237,10 @@ static int prp_s_frame_interval(struct v4l2_subdev *sd,
static int prp_registered(struct v4l2_subdev *sd) static int prp_registered(struct v4l2_subdev *sd)
{ {
struct prp_priv *priv = sd_to_priv(sd); struct prp_priv *priv = sd_to_priv(sd);
struct imx_ic_priv *ic_priv = priv->ic_priv;
int i, ret; int i, ret;
u32 code; u32 code;
/* get media device */
priv->md = dev_get_drvdata(sd->v4l2_dev->dev);
for (i = 0; i < PRPENCVF_NUM_PADS; i++) { for (i = 0; i < PRPENCVF_NUM_PADS; i++) {
priv->pad[i].flags = (i == PRPENCVF_SINK_PAD) ? priv->pad[i].flags = (i == PRPENCVF_SINK_PAD) ?
MEDIA_PAD_FL_SINK : MEDIA_PAD_FL_SOURCE; MEDIA_PAD_FL_SINK : MEDIA_PAD_FL_SOURCE;
...@@ -1270,7 +1267,7 @@ static int prp_registered(struct v4l2_subdev *sd) ...@@ -1270,7 +1267,7 @@ static int prp_registered(struct v4l2_subdev *sd)
if (ret) if (ret)
return ret; return ret;
ret = imx_media_add_video_device(priv->md, priv->vdev); ret = imx_media_add_video_device(ic_priv->md, priv->vdev);
if (ret) if (ret)
goto unreg; goto unreg;
...@@ -1325,7 +1322,7 @@ static int prp_init(struct imx_ic_priv *ic_priv) ...@@ -1325,7 +1322,7 @@ static int prp_init(struct imx_ic_priv *ic_priv)
{ {
struct prp_priv *priv; struct prp_priv *priv;
priv = devm_kzalloc(ic_priv->dev, sizeof(*priv), GFP_KERNEL); priv = devm_kzalloc(ic_priv->ipu_dev, sizeof(*priv), GFP_KERNEL);
if (!priv) if (!priv)
return -ENOMEM; return -ENOMEM;
...@@ -1335,7 +1332,8 @@ static int prp_init(struct imx_ic_priv *ic_priv) ...@@ -1335,7 +1332,8 @@ static int prp_init(struct imx_ic_priv *ic_priv)
spin_lock_init(&priv->irqlock); spin_lock_init(&priv->irqlock);
timer_setup(&priv->eof_timeout_timer, prp_eof_timeout, 0); timer_setup(&priv->eof_timeout_timer, prp_eof_timeout, 0);
priv->vdev = imx_media_capture_device_init(&ic_priv->sd, priv->vdev = imx_media_capture_device_init(ic_priv->ipu_dev,
&ic_priv->sd,
PRPENCVF_SRC_PAD); PRPENCVF_SRC_PAD);
if (IS_ERR(priv->vdev)) if (IS_ERR(priv->vdev))
return PTR_ERR(priv->vdev); return PTR_ERR(priv->vdev);
......
...@@ -10,11 +10,11 @@ ...@@ -10,11 +10,11 @@
#include <media/v4l2-subdev.h> #include <media/v4l2-subdev.h>
struct imx_ic_priv { struct imx_ic_priv {
struct device *dev; struct device *ipu_dev;
struct ipu_soc *ipu;
struct imx_media_dev *md;
struct v4l2_subdev sd; struct v4l2_subdev sd;
int ipu_id;
int task_id; int task_id;
void *prp_priv;
void *task_priv; void *task_priv;
}; };
...@@ -29,6 +29,5 @@ struct imx_ic_ops { ...@@ -29,6 +29,5 @@ struct imx_ic_ops {
extern struct imx_ic_ops imx_ic_prp_ops; extern struct imx_ic_ops imx_ic_prp_ops;
extern struct imx_ic_ops imx_ic_prpencvf_ops; extern struct imx_ic_ops imx_ic_prpencvf_ops;
extern struct imx_ic_ops imx_ic_pp_ops;
#endif #endif
...@@ -798,18 +798,19 @@ void imx_media_capture_device_unregister(struct imx_media_video_dev *vdev) ...@@ -798,18 +798,19 @@ void imx_media_capture_device_unregister(struct imx_media_video_dev *vdev)
EXPORT_SYMBOL_GPL(imx_media_capture_device_unregister); EXPORT_SYMBOL_GPL(imx_media_capture_device_unregister);
struct imx_media_video_dev * struct imx_media_video_dev *
imx_media_capture_device_init(struct v4l2_subdev *src_sd, int pad) imx_media_capture_device_init(struct device *dev, struct v4l2_subdev *src_sd,
int pad)
{ {
struct capture_priv *priv; struct capture_priv *priv;
struct video_device *vfd; struct video_device *vfd;
priv = devm_kzalloc(src_sd->dev, sizeof(*priv), GFP_KERNEL); priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
if (!priv) if (!priv)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
priv->src_sd = src_sd; priv->src_sd = src_sd;
priv->src_sd_pad = pad; priv->src_sd_pad = pad;
priv->dev = src_sd->dev; priv->dev = dev;
mutex_init(&priv->mutex); mutex_init(&priv->mutex);
spin_lock_init(&priv->q_lock); spin_lock_init(&priv->q_lock);
......
...@@ -1983,7 +1983,7 @@ static int imx_csi_probe(struct platform_device *pdev) ...@@ -1983,7 +1983,7 @@ static int imx_csi_probe(struct platform_device *pdev)
imx_media_grp_id_to_sd_name(priv->sd.name, sizeof(priv->sd.name), imx_media_grp_id_to_sd_name(priv->sd.name, sizeof(priv->sd.name),
priv->sd.grp_id, ipu_get_num(priv->ipu)); priv->sd.grp_id, ipu_get_num(priv->ipu));
priv->vdev = imx_media_capture_device_init(&priv->sd, priv->vdev = imx_media_capture_device_init(priv->sd.dev, &priv->sd,
CSI_SRC_PAD_IDMAC); CSI_SRC_PAD_IDMAC);
if (IS_ERR(priv->vdev)) if (IS_ERR(priv->vdev))
return PTR_ERR(priv->vdev); return PTR_ERR(priv->vdev);
......
...@@ -28,111 +28,24 @@ static inline struct imx_media_dev *notifier2dev(struct v4l2_async_notifier *n) ...@@ -28,111 +28,24 @@ static inline struct imx_media_dev *notifier2dev(struct v4l2_async_notifier *n)
return container_of(n, struct imx_media_dev, notifier); return container_of(n, struct imx_media_dev, notifier);
} }
/*
* Adds a subdev to the root notifier's async subdev list. If fwnode is
* non-NULL, adds the async as a V4L2_ASYNC_MATCH_FWNODE match type,
* otherwise as a V4L2_ASYNC_MATCH_DEVNAME match type using the dev_name
* of the given platform_device. This is called during driver load when
* forming the async subdev list.
*/
int imx_media_add_async_subdev(struct imx_media_dev *imxmd,
struct fwnode_handle *fwnode,
struct platform_device *pdev)
{
struct device_node *np = to_of_node(fwnode);
struct imx_media_async_subdev *imxasd;
struct v4l2_async_subdev *asd;
const char *devname = NULL;
int ret;
if (fwnode) {
asd = v4l2_async_notifier_add_fwnode_subdev(&imxmd->notifier,
fwnode,
sizeof(*imxasd));
} else {
devname = dev_name(&pdev->dev);
asd = v4l2_async_notifier_add_devname_subdev(&imxmd->notifier,
devname,
sizeof(*imxasd));
}
if (IS_ERR(asd)) {
ret = PTR_ERR(asd);
if (ret == -EEXIST) {
if (np)
dev_dbg(imxmd->md.dev, "%s: already added %pOFn\n",
__func__, np);
else
dev_dbg(imxmd->md.dev, "%s: already added %s\n",
__func__, devname);
}
return ret;
}
imxasd = to_imx_media_asd(asd);
if (devname)
imxasd->pdev = pdev;
if (np)
dev_dbg(imxmd->md.dev, "%s: added %pOFn, match type FWNODE\n",
__func__, np);
else
dev_dbg(imxmd->md.dev, "%s: added %s, match type DEVNAME\n",
__func__, devname);
return 0;
}
/*
* get IPU from this CSI and add it to the list of IPUs
* the media driver will control.
*/
static int imx_media_get_ipu(struct imx_media_dev *imxmd,
struct v4l2_subdev *csi_sd)
{
struct ipu_soc *ipu;
int ipu_id;
ipu = dev_get_drvdata(csi_sd->dev->parent);
if (!ipu) {
v4l2_err(&imxmd->v4l2_dev,
"CSI %s has no parent IPU!\n", csi_sd->name);
return -ENODEV;
}
ipu_id = ipu_get_num(ipu);
if (ipu_id > 1) {
v4l2_err(&imxmd->v4l2_dev, "invalid IPU id %d!\n", ipu_id);
return -ENODEV;
}
if (!imxmd->ipu[ipu_id])
imxmd->ipu[ipu_id] = ipu;
return 0;
}
/* async subdev bound notifier */ /* async subdev bound notifier */
int imx_media_subdev_bound(struct v4l2_async_notifier *notifier, int imx_media_subdev_bound(struct v4l2_async_notifier *notifier,
struct v4l2_subdev *sd, struct v4l2_subdev *sd,
struct v4l2_async_subdev *asd) struct v4l2_async_subdev *asd)
{ {
struct imx_media_dev *imxmd = notifier2dev(notifier); struct imx_media_dev *imxmd = notifier2dev(notifier);
int ret = 0; int ret;
mutex_lock(&imxmd->mutex);
if (sd->grp_id & IMX_MEDIA_GRP_ID_IPU_CSI) { if (sd->grp_id & IMX_MEDIA_GRP_ID_IPU_CSI) {
ret = imx_media_get_ipu(imxmd, sd); /* register the IPU internal subdevs */
ret = imx_media_register_ipu_internal_subdevs(imxmd, sd);
if (ret) if (ret)
goto out; return ret;
} }
v4l2_info(&imxmd->v4l2_dev, "subdev %s bound\n", sd->name); v4l2_info(&imxmd->v4l2_dev, "subdev %s bound\n", sd->name);
out:
mutex_unlock(&imxmd->mutex); return 0;
return ret;
} }
/* /*
...@@ -143,7 +56,6 @@ static int imx_media_create_links(struct v4l2_async_notifier *notifier) ...@@ -143,7 +56,6 @@ static int imx_media_create_links(struct v4l2_async_notifier *notifier)
{ {
struct imx_media_dev *imxmd = notifier2dev(notifier); struct imx_media_dev *imxmd = notifier2dev(notifier);
struct v4l2_subdev *sd; struct v4l2_subdev *sd;
int ret;
list_for_each_entry(sd, &imxmd->v4l2_dev.subdevs, list) { list_for_each_entry(sd, &imxmd->v4l2_dev.subdevs, list) {
switch (sd->grp_id) { switch (sd->grp_id) {
...@@ -151,22 +63,15 @@ static int imx_media_create_links(struct v4l2_async_notifier *notifier) ...@@ -151,22 +63,15 @@ static int imx_media_create_links(struct v4l2_async_notifier *notifier)
case IMX_MEDIA_GRP_ID_IPU_IC_PRP: case IMX_MEDIA_GRP_ID_IPU_IC_PRP:
case IMX_MEDIA_GRP_ID_IPU_IC_PRPENC: case IMX_MEDIA_GRP_ID_IPU_IC_PRPENC:
case IMX_MEDIA_GRP_ID_IPU_IC_PRPVF: case IMX_MEDIA_GRP_ID_IPU_IC_PRPVF:
case IMX_MEDIA_GRP_ID_IPU_CSI0:
case IMX_MEDIA_GRP_ID_IPU_CSI1:
ret = imx_media_create_ipu_internal_links(imxmd, sd);
if (ret)
return ret;
/* /*
* the CSIs straddle between the external and the IPU * links have already been created for the
* internal entities, so create the external links * sync-registered subdevs.
* to the CSI sink pads.
*/ */
if (sd->grp_id & IMX_MEDIA_GRP_ID_IPU_CSI)
imx_media_create_csi_of_links(imxmd, sd);
break; break;
case IMX_MEDIA_GRP_ID_IPU_CSI0:
case IMX_MEDIA_GRP_ID_IPU_CSI1:
case IMX_MEDIA_GRP_ID_CSI: case IMX_MEDIA_GRP_ID_CSI:
imx_media_create_csi_of_links(imxmd, sd); imx_media_create_csi_of_links(imxmd, sd);
break; break;
default: default:
/* /*
...@@ -476,12 +381,10 @@ static int imx_media_probe(struct platform_device *pdev) ...@@ -476,12 +381,10 @@ static int imx_media_probe(struct platform_device *pdev)
ret = imx_media_dev_notifier_register(imxmd); ret = imx_media_dev_notifier_register(imxmd);
if (ret) if (ret)
goto del_int; goto cleanup;
return 0; return 0;
del_int:
imx_media_remove_ipu_internal_subdevs(imxmd);
cleanup: cleanup:
v4l2_async_notifier_cleanup(&imxmd->notifier); v4l2_async_notifier_cleanup(&imxmd->notifier);
v4l2_device_unregister(&imxmd->v4l2_dev); v4l2_device_unregister(&imxmd->v4l2_dev);
...@@ -498,7 +401,7 @@ static int imx_media_remove(struct platform_device *pdev) ...@@ -498,7 +401,7 @@ static int imx_media_remove(struct platform_device *pdev)
v4l2_info(&imxmd->v4l2_dev, "Removing imx-media\n"); v4l2_info(&imxmd->v4l2_dev, "Removing imx-media\n");
v4l2_async_notifier_unregister(&imxmd->notifier); v4l2_async_notifier_unregister(&imxmd->notifier);
imx_media_remove_ipu_internal_subdevs(imxmd); imx_media_unregister_ipu_internal_subdevs(imxmd);
v4l2_async_notifier_cleanup(&imxmd->notifier); v4l2_async_notifier_cleanup(&imxmd->notifier);
media_device_unregister(&imxmd->md); media_device_unregister(&imxmd->md);
v4l2_device_unregister(&imxmd->v4l2_dev); v4l2_device_unregister(&imxmd->v4l2_dev);
......
...@@ -9,208 +9,138 @@ ...@@ -9,208 +9,138 @@
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include "imx-media.h" #include "imx-media.h"
enum isd_enum { /* max pads per internal-sd */
isd_csi0 = 0, #define MAX_INTERNAL_PADS 8
isd_csi1, /* max links per internal-sd pad */
isd_vdic, #define MAX_INTERNAL_LINKS 8
isd_ic_prp,
isd_ic_prpenc,
isd_ic_prpvf,
num_isd,
};
static const struct internal_subdev_id {
enum isd_enum index;
const char *name;
u32 grp_id;
} isd_id[num_isd] = {
[isd_csi0] = {
.index = isd_csi0,
.grp_id = IMX_MEDIA_GRP_ID_IPU_CSI0,
.name = "imx-ipuv3-csi",
},
[isd_csi1] = {
.index = isd_csi1,
.grp_id = IMX_MEDIA_GRP_ID_IPU_CSI1,
.name = "imx-ipuv3-csi",
},
[isd_vdic] = {
.index = isd_vdic,
.grp_id = IMX_MEDIA_GRP_ID_IPU_VDIC,
.name = "imx-ipuv3-vdic",
},
[isd_ic_prp] = {
.index = isd_ic_prp,
.grp_id = IMX_MEDIA_GRP_ID_IPU_IC_PRP,
.name = "imx-ipuv3-ic",
},
[isd_ic_prpenc] = {
.index = isd_ic_prpenc,
.grp_id = IMX_MEDIA_GRP_ID_IPU_IC_PRPENC,
.name = "imx-ipuv3-ic",
},
[isd_ic_prpvf] = {
.index = isd_ic_prpvf,
.grp_id = IMX_MEDIA_GRP_ID_IPU_IC_PRPVF,
.name = "imx-ipuv3-ic",
},
};
struct internal_subdev; struct internal_subdev;
struct internal_link { struct internal_link {
const struct internal_subdev *remote; int remote;
int local_pad; int local_pad;
int remote_pad; int remote_pad;
}; };
/* max pads per internal-sd */
#define MAX_INTERNAL_PADS 8
/* max links per internal-sd pad */
#define MAX_INTERNAL_LINKS 8
struct internal_pad { struct internal_pad {
int num_links;
struct internal_link link[MAX_INTERNAL_LINKS]; struct internal_link link[MAX_INTERNAL_LINKS];
}; };
static const struct internal_subdev { struct internal_subdev {
const struct internal_subdev_id *id; u32 grp_id;
struct internal_pad pad[MAX_INTERNAL_PADS]; struct internal_pad pad[MAX_INTERNAL_PADS];
} int_subdev[num_isd] = {
[isd_csi0] = { struct v4l2_subdev * (*sync_register)(struct imx_media_dev *imxmd,
.id = &isd_id[isd_csi0], struct device *ipu_dev,
struct ipu_soc *ipu,
u32 grp_id);
int (*sync_unregister)(struct v4l2_subdev *sd);
};
static const struct internal_subdev int_subdev[NUM_IPU_SUBDEVS] = {
[IPU_CSI0] = {
.grp_id = IMX_MEDIA_GRP_ID_IPU_CSI0,
.pad[CSI_SRC_PAD_DIRECT] = { .pad[CSI_SRC_PAD_DIRECT] = {
.num_links = 2,
.link = { .link = {
{ {
.local_pad = CSI_SRC_PAD_DIRECT, .local_pad = CSI_SRC_PAD_DIRECT,
.remote = &int_subdev[isd_ic_prp], .remote = IPU_IC_PRP,
.remote_pad = PRP_SINK_PAD, .remote_pad = PRP_SINK_PAD,
}, { }, {
.local_pad = CSI_SRC_PAD_DIRECT, .local_pad = CSI_SRC_PAD_DIRECT,
.remote = &int_subdev[isd_vdic], .remote = IPU_VDIC,
.remote_pad = VDIC_SINK_PAD_DIRECT, .remote_pad = VDIC_SINK_PAD_DIRECT,
}, },
}, },
}, },
}, },
[isd_csi1] = { [IPU_CSI1] = {
.id = &isd_id[isd_csi1], .grp_id = IMX_MEDIA_GRP_ID_IPU_CSI1,
.pad[CSI_SRC_PAD_DIRECT] = { .pad[CSI_SRC_PAD_DIRECT] = {
.num_links = 2,
.link = { .link = {
{ {
.local_pad = CSI_SRC_PAD_DIRECT, .local_pad = CSI_SRC_PAD_DIRECT,
.remote = &int_subdev[isd_ic_prp], .remote = IPU_IC_PRP,
.remote_pad = PRP_SINK_PAD, .remote_pad = PRP_SINK_PAD,
}, { }, {
.local_pad = CSI_SRC_PAD_DIRECT, .local_pad = CSI_SRC_PAD_DIRECT,
.remote = &int_subdev[isd_vdic], .remote = IPU_VDIC,
.remote_pad = VDIC_SINK_PAD_DIRECT, .remote_pad = VDIC_SINK_PAD_DIRECT,
}, },
}, },
}, },
}, },
[isd_vdic] = { [IPU_VDIC] = {
.id = &isd_id[isd_vdic], .grp_id = IMX_MEDIA_GRP_ID_IPU_VDIC,
.sync_register = imx_media_vdic_register,
.sync_unregister = imx_media_vdic_unregister,
.pad[VDIC_SRC_PAD_DIRECT] = { .pad[VDIC_SRC_PAD_DIRECT] = {
.num_links = 1,
.link = { .link = {
{ {
.local_pad = VDIC_SRC_PAD_DIRECT, .local_pad = VDIC_SRC_PAD_DIRECT,
.remote = &int_subdev[isd_ic_prp], .remote = IPU_IC_PRP,
.remote_pad = PRP_SINK_PAD, .remote_pad = PRP_SINK_PAD,
}, },
}, },
}, },
}, },
[isd_ic_prp] = { [IPU_IC_PRP] = {
.id = &isd_id[isd_ic_prp], .grp_id = IMX_MEDIA_GRP_ID_IPU_IC_PRP,
.sync_register = imx_media_ic_register,
.sync_unregister = imx_media_ic_unregister,
.pad[PRP_SRC_PAD_PRPENC] = { .pad[PRP_SRC_PAD_PRPENC] = {
.num_links = 1,
.link = { .link = {
{ {
.local_pad = PRP_SRC_PAD_PRPENC, .local_pad = PRP_SRC_PAD_PRPENC,
.remote = &int_subdev[isd_ic_prpenc], .remote = IPU_IC_PRPENC,
.remote_pad = 0, .remote_pad = PRPENCVF_SINK_PAD,
}, },
}, },
}, },
.pad[PRP_SRC_PAD_PRPVF] = { .pad[PRP_SRC_PAD_PRPVF] = {
.num_links = 1,
.link = { .link = {
{ {
.local_pad = PRP_SRC_PAD_PRPVF, .local_pad = PRP_SRC_PAD_PRPVF,
.remote = &int_subdev[isd_ic_prpvf], .remote = IPU_IC_PRPVF,
.remote_pad = 0, .remote_pad = PRPENCVF_SINK_PAD,
}, },
}, },
}, },
}, },
[isd_ic_prpenc] = { [IPU_IC_PRPENC] = {
.id = &isd_id[isd_ic_prpenc], .grp_id = IMX_MEDIA_GRP_ID_IPU_IC_PRPENC,
.sync_register = imx_media_ic_register,
.sync_unregister = imx_media_ic_unregister,
}, },
[isd_ic_prpvf] = { [IPU_IC_PRPVF] = {
.id = &isd_id[isd_ic_prpvf], .grp_id = IMX_MEDIA_GRP_ID_IPU_IC_PRPVF,
.sync_register = imx_media_ic_register,
.sync_unregister = imx_media_ic_unregister,
}, },
}; };
/* form a device name given an internal subdev and ipu id */ static int create_internal_link(struct imx_media_dev *imxmd,
static inline void isd_to_devname(char *devname, int sz,
const struct internal_subdev *isd,
int ipu_id)
{
int pdev_id = ipu_id * num_isd + isd->id->index;
snprintf(devname, sz, "%s.%d", isd->id->name, pdev_id);
}
static const struct internal_subdev *find_intsd_by_grp_id(u32 grp_id)
{
enum isd_enum i;
for (i = 0; i < num_isd; i++) {
const struct internal_subdev *isd = &int_subdev[i];
if (isd->id->grp_id == grp_id)
return isd;
}
return NULL;
}
static struct v4l2_subdev *find_sink(struct imx_media_dev *imxmd,
struct v4l2_subdev *src, struct v4l2_subdev *src,
struct v4l2_subdev *sink,
const struct internal_link *link) const struct internal_link *link)
{ {
char sink_devname[32];
int ipu_id;
/*
* retrieve IPU id from subdev name, note: can't get this from
* struct imx_media_ipu_internal_sd_pdata because if src is
* a CSI, it has different struct ipu_client_platformdata which
* does not contain IPU id.
*/
if (sscanf(src->name, "ipu%d", &ipu_id) != 1)
return NULL;
isd_to_devname(sink_devname, sizeof(sink_devname),
link->remote, ipu_id - 1);
return imx_media_find_subdev_by_devname(imxmd, sink_devname);
}
static int create_ipu_internal_link(struct imx_media_dev *imxmd,
struct v4l2_subdev *src,
const struct internal_link *link)
{
struct v4l2_subdev *sink;
int ret; int ret;
sink = find_sink(imxmd, src, link); /* skip if this link already created */
if (!sink) if (media_entity_find_link(&src->entity.pads[link->local_pad],
return -ENODEV; &sink->entity.pads[link->remote_pad]))
return 0;
v4l2_info(&imxmd->v4l2_dev, "%s:%d -> %s:%d\n", v4l2_info(&imxmd->v4l2_dev, "%s:%d -> %s:%d\n",
src->name, link->local_pad, src->name, link->local_pad,
...@@ -219,25 +149,21 @@ static int create_ipu_internal_link(struct imx_media_dev *imxmd, ...@@ -219,25 +149,21 @@ static int create_ipu_internal_link(struct imx_media_dev *imxmd,
ret = media_create_pad_link(&src->entity, link->local_pad, ret = media_create_pad_link(&src->entity, link->local_pad,
&sink->entity, link->remote_pad, 0); &sink->entity, link->remote_pad, 0);
if (ret) if (ret)
v4l2_err(&imxmd->v4l2_dev, v4l2_err(&imxmd->v4l2_dev, "%s failed: %d\n", __func__, ret);
"create_pad_link failed: %d\n", ret);
return ret; return ret;
} }
int imx_media_create_ipu_internal_links(struct imx_media_dev *imxmd, static int create_ipu_internal_links(struct imx_media_dev *imxmd,
struct v4l2_subdev *sd) const struct internal_subdev *intsd,
struct v4l2_subdev *sd,
int ipu_id)
{ {
const struct internal_subdev *intsd;
const struct internal_pad *intpad; const struct internal_pad *intpad;
const struct internal_link *link; const struct internal_link *link;
struct media_pad *pad; struct media_pad *pad;
int i, j, ret; int i, j, ret;
intsd = find_intsd_by_grp_id(sd->grp_id);
if (!intsd)
return -ENODEV;
/* create the source->sink links */ /* create the source->sink links */
for (i = 0; i < sd->entity.num_pads; i++) { for (i = 0; i < sd->entity.num_pads; i++) {
intpad = &intsd->pad[i]; intpad = &intsd->pad[i];
...@@ -246,13 +172,13 @@ int imx_media_create_ipu_internal_links(struct imx_media_dev *imxmd, ...@@ -246,13 +172,13 @@ int imx_media_create_ipu_internal_links(struct imx_media_dev *imxmd,
if (!(pad->flags & MEDIA_PAD_FL_SOURCE)) if (!(pad->flags & MEDIA_PAD_FL_SOURCE))
continue; continue;
for (j = 0; ; j++) { for (j = 0; j < intpad->num_links; j++) {
link = &intpad->link[j]; struct v4l2_subdev *sink;
if (!link->remote) link = &intpad->link[j];
break; sink = imxmd->sync_sd[ipu_id][link->remote];
ret = create_ipu_internal_link(imxmd, sd, link); ret = create_internal_link(imxmd, sd, sink, link);
if (ret) if (ret)
return ret; return ret;
} }
...@@ -261,85 +187,115 @@ int imx_media_create_ipu_internal_links(struct imx_media_dev *imxmd, ...@@ -261,85 +187,115 @@ int imx_media_create_ipu_internal_links(struct imx_media_dev *imxmd,
return 0; return 0;
} }
/* register an internal subdev as a platform device */ int imx_media_register_ipu_internal_subdevs(struct imx_media_dev *imxmd,
static int add_internal_subdev(struct imx_media_dev *imxmd, struct v4l2_subdev *csi)
const struct internal_subdev *isd,
int ipu_id)
{ {
struct imx_media_ipu_internal_sd_pdata pdata; struct device *ipu_dev = csi->dev->parent;
struct platform_device_info pdevinfo = {}; const struct internal_subdev *intsd;
struct platform_device *pdev; struct v4l2_subdev *sd;
struct ipu_soc *ipu;
int i, ipu_id, ret;
pdata.grp_id = isd->id->grp_id; ipu = dev_get_drvdata(ipu_dev);
if (!ipu) {
v4l2_err(&imxmd->v4l2_dev, "invalid IPU device!\n");
return -ENODEV;
}
/* the id of IPU this subdev will control */ ipu_id = ipu_get_num(ipu);
pdata.ipu_id = ipu_id; if (ipu_id > 1) {
v4l2_err(&imxmd->v4l2_dev, "invalid IPU id %d!\n", ipu_id);
return -ENODEV;
}
/* create subdev name */ mutex_lock(&imxmd->mutex);
imx_media_grp_id_to_sd_name(pdata.sd_name, sizeof(pdata.sd_name),
pdata.grp_id, ipu_id);
pdevinfo.name = isd->id->name; /* register the synchronous subdevs */
pdevinfo.id = ipu_id * num_isd + isd->id->index; for (i = 0; i < NUM_IPU_SUBDEVS; i++) {
pdevinfo.parent = imxmd->md.dev; intsd = &int_subdev[i];
pdevinfo.data = &pdata;
pdevinfo.size_data = sizeof(pdata);
pdevinfo.dma_mask = DMA_BIT_MASK(32);
pdev = platform_device_register_full(&pdevinfo); sd = imxmd->sync_sd[ipu_id][i];
if (IS_ERR(pdev))
return PTR_ERR(pdev);
return imx_media_add_async_subdev(imxmd, NULL, pdev); /*
} * skip if this sync subdev already registered or its
* not a sync subdev (one of the CSIs)
*/
if (sd || !intsd->sync_register)
continue;
/* adds the internal subdevs in one ipu */ mutex_unlock(&imxmd->mutex);
int imx_media_add_ipu_internal_subdevs(struct imx_media_dev *imxmd, sd = intsd->sync_register(imxmd, ipu_dev, ipu, intsd->grp_id);
int ipu_id) mutex_lock(&imxmd->mutex);
{ if (IS_ERR(sd)) {
enum isd_enum i; ret = PTR_ERR(sd);
int ret; goto err_unwind;
}
for (i = 0; i < num_isd; i++) { imxmd->sync_sd[ipu_id][i] = sd;
const struct internal_subdev *isd = &int_subdev[i]; }
/* /*
* the CSIs are represented in the device-tree, so those * all the sync subdevs are registered, create the media links
* devices are already added to the async subdev list by * between them.
* of_parse_subdev().
*/ */
switch (isd->id->grp_id) { for (i = 0; i < NUM_IPU_SUBDEVS; i++) {
case IMX_MEDIA_GRP_ID_IPU_CSI0: intsd = &int_subdev[i];
case IMX_MEDIA_GRP_ID_IPU_CSI1:
ret = 0; if (intsd->grp_id == csi->grp_id) {
break; sd = csi;
default: } else {
ret = add_internal_subdev(imxmd, isd, ipu_id); sd = imxmd->sync_sd[ipu_id][i];
break; if (!sd)
continue;
} }
if (ret) ret = create_ipu_internal_links(imxmd, intsd, sd, ipu_id);
goto remove; if (ret) {
mutex_unlock(&imxmd->mutex);
imx_media_unregister_ipu_internal_subdevs(imxmd);
return ret;
}
} }
mutex_unlock(&imxmd->mutex);
return 0; return 0;
remove: err_unwind:
imx_media_remove_ipu_internal_subdevs(imxmd); while (--i >= 0) {
intsd = &int_subdev[i];
sd = imxmd->sync_sd[ipu_id][i];
if (!sd || !intsd->sync_unregister)
continue;
mutex_unlock(&imxmd->mutex);
intsd->sync_unregister(sd);
mutex_lock(&imxmd->mutex);
}
mutex_unlock(&imxmd->mutex);
return ret; return ret;
} }
void imx_media_remove_ipu_internal_subdevs(struct imx_media_dev *imxmd) void imx_media_unregister_ipu_internal_subdevs(struct imx_media_dev *imxmd)
{ {
struct imx_media_async_subdev *imxasd; const struct internal_subdev *intsd;
struct v4l2_async_subdev *asd; struct v4l2_subdev *sd;
int i, j;
mutex_lock(&imxmd->mutex);
list_for_each_entry(asd, &imxmd->notifier.asd_list, asd_list) { for (i = 0; i < 2; i++) {
imxasd = to_imx_media_asd(asd); for (j = 0; j < NUM_IPU_SUBDEVS; j++) {
intsd = &int_subdev[j];
sd = imxmd->sync_sd[i][j];
if (!imxasd->pdev) if (!sd || !intsd->sync_unregister)
continue; continue;
platform_device_unregister(imxasd->pdev); mutex_unlock(&imxmd->mutex);
intsd->sync_unregister(sd);
mutex_lock(&imxmd->mutex);
} }
}
mutex_unlock(&imxmd->mutex);
} }
...@@ -19,6 +19,9 @@ ...@@ -19,6 +19,9 @@
int imx_media_of_add_csi(struct imx_media_dev *imxmd, int imx_media_of_add_csi(struct imx_media_dev *imxmd,
struct device_node *csi_np) struct device_node *csi_np)
{ {
struct v4l2_async_subdev *asd;
int ret = 0;
if (!of_device_is_available(csi_np)) { if (!of_device_is_available(csi_np)) {
dev_dbg(imxmd->md.dev, "%s: %pOFn not enabled\n", __func__, dev_dbg(imxmd->md.dev, "%s: %pOFn not enabled\n", __func__,
csi_np); csi_np);
...@@ -26,18 +29,25 @@ int imx_media_of_add_csi(struct imx_media_dev *imxmd, ...@@ -26,18 +29,25 @@ int imx_media_of_add_csi(struct imx_media_dev *imxmd,
} }
/* add CSI fwnode to async notifier */ /* add CSI fwnode to async notifier */
return imx_media_add_async_subdev(imxmd, of_fwnode_handle(csi_np), asd = v4l2_async_notifier_add_fwnode_subdev(&imxmd->notifier,
NULL); of_fwnode_handle(csi_np),
sizeof(*asd));
if (IS_ERR(asd)) {
ret = PTR_ERR(asd);
if (ret == -EEXIST)
dev_dbg(imxmd->md.dev, "%s: already added %pOFn\n",
__func__, csi_np);
}
return ret;
} }
EXPORT_SYMBOL_GPL(imx_media_of_add_csi); EXPORT_SYMBOL_GPL(imx_media_of_add_csi);
int imx_media_add_of_subdevs(struct imx_media_dev *imxmd, int imx_media_add_of_subdevs(struct imx_media_dev *imxmd,
struct device_node *np) struct device_node *np)
{ {
bool ipu_found[2] = {false, false};
struct device_node *csi_np; struct device_node *csi_np;
int i, ret; int i, ret;
u32 ipu_id;
for (i = 0; ; i++) { for (i = 0; ; i++) {
csi_np = of_parse_phandle(np, "ports", i); csi_np = of_parse_phandle(np, "ports", i);
...@@ -55,31 +65,11 @@ int imx_media_add_of_subdevs(struct imx_media_dev *imxmd, ...@@ -55,31 +65,11 @@ int imx_media_add_of_subdevs(struct imx_media_dev *imxmd,
/* other error, can't continue */ /* other error, can't continue */
goto err_out; goto err_out;
} }
ret = of_alias_get_id(csi_np->parent, "ipu");
if (ret < 0)
goto err_out;
if (ret > 1) {
ret = -EINVAL;
goto err_out;
}
ipu_id = ret;
if (!ipu_found[ipu_id]) {
ret = imx_media_add_ipu_internal_subdevs(imxmd,
ipu_id);
if (ret)
goto err_out;
}
ipu_found[ipu_id] = true;
} }
return 0; return 0;
err_out: err_out:
imx_media_remove_ipu_internal_subdevs(imxmd);
of_node_put(csi_np); of_node_put(csi_np);
return ret; return ret;
} }
......
...@@ -4,13 +4,6 @@ ...@@ -4,13 +4,6 @@
* *
* Copyright (c) 2017 Mentor Graphics Inc. * Copyright (c) 2017 Mentor Graphics Inc.
*/ */
#include <linux/delay.h>
#include <linux/interrupt.h>
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/sched.h>
#include <linux/slab.h>
#include <linux/timer.h>
#include <media/v4l2-ctrls.h> #include <media/v4l2-ctrls.h>
#include <media/v4l2-device.h> #include <media/v4l2-device.h>
#include <media/v4l2-ioctl.h> #include <media/v4l2-ioctl.h>
...@@ -65,12 +58,12 @@ struct vdic_pipeline_ops { ...@@ -65,12 +58,12 @@ struct vdic_pipeline_ops {
#define S_ALIGN 1 /* multiple of 2 */ #define S_ALIGN 1 /* multiple of 2 */
struct vdic_priv { struct vdic_priv {
struct device *dev; struct device *ipu_dev;
struct ipu_soc *ipu; struct ipu_soc *ipu;
struct imx_media_dev *md; struct imx_media_dev *md;
struct v4l2_subdev sd; struct v4l2_subdev sd;
struct media_pad pad[VDIC_NUM_PADS]; struct media_pad pad[VDIC_NUM_PADS];
int ipu_id;
/* lock to protect all members below */ /* lock to protect all members below */
struct mutex lock; struct mutex lock;
...@@ -145,8 +138,6 @@ static int vdic_get_ipu_resources(struct vdic_priv *priv) ...@@ -145,8 +138,6 @@ static int vdic_get_ipu_resources(struct vdic_priv *priv)
struct ipuv3_channel *ch; struct ipuv3_channel *ch;
struct ipu_vdi *vdi; struct ipu_vdi *vdi;
priv->ipu = priv->md->ipu[priv->ipu_id];
vdi = ipu_vdi_get(priv->ipu); vdi = ipu_vdi_get(priv->ipu);
if (IS_ERR(vdi)) { if (IS_ERR(vdi)) {
v4l2_err(&priv->sd, "failed to get VDIC\n"); v4l2_err(&priv->sd, "failed to get VDIC\n");
...@@ -511,7 +502,8 @@ static int vdic_s_stream(struct v4l2_subdev *sd, int enable) ...@@ -511,7 +502,8 @@ static int vdic_s_stream(struct v4l2_subdev *sd, int enable)
if (priv->stream_count != !enable) if (priv->stream_count != !enable)
goto update_count; goto update_count;
dev_dbg(priv->dev, "stream %s\n", enable ? "ON" : "OFF"); dev_dbg(priv->ipu_dev, "%s: stream %s\n", sd->name,
enable ? "ON" : "OFF");
if (enable) if (enable)
ret = vdic_start(priv); ret = vdic_start(priv);
...@@ -686,8 +678,8 @@ static int vdic_link_setup(struct media_entity *entity, ...@@ -686,8 +678,8 @@ static int vdic_link_setup(struct media_entity *entity,
struct v4l2_subdev *remote_sd; struct v4l2_subdev *remote_sd;
int ret = 0; int ret = 0;
dev_dbg(priv->dev, "link setup %s -> %s", remote->entity->name, dev_dbg(priv->ipu_dev, "%s: link setup %s -> %s",
local->entity->name); sd->name, remote->entity->name, local->entity->name);
mutex_lock(&priv->lock); mutex_lock(&priv->lock);
...@@ -860,9 +852,6 @@ static int vdic_registered(struct v4l2_subdev *sd) ...@@ -860,9 +852,6 @@ static int vdic_registered(struct v4l2_subdev *sd)
int i, ret; int i, ret;
u32 code; u32 code;
/* get media device */
priv->md = dev_get_drvdata(sd->v4l2_dev->dev);
for (i = 0; i < VDIC_NUM_PADS; i++) { for (i = 0; i < VDIC_NUM_PADS; i++) {
priv->pad[i].flags = (i == VDIC_SRC_PAD_DIRECT) ? priv->pad[i].flags = (i == VDIC_SRC_PAD_DIRECT) ?
MEDIA_PAD_FL_SOURCE : MEDIA_PAD_FL_SINK; MEDIA_PAD_FL_SOURCE : MEDIA_PAD_FL_SINK;
...@@ -934,77 +923,55 @@ static const struct v4l2_subdev_internal_ops vdic_internal_ops = { ...@@ -934,77 +923,55 @@ static const struct v4l2_subdev_internal_ops vdic_internal_ops = {
.unregistered = vdic_unregistered, .unregistered = vdic_unregistered,
}; };
static int imx_vdic_probe(struct platform_device *pdev) struct v4l2_subdev *imx_media_vdic_register(struct imx_media_dev *imxmd,
struct device *ipu_dev,
struct ipu_soc *ipu,
u32 grp_id)
{ {
struct imx_media_ipu_internal_sd_pdata *pdata; struct v4l2_device *v4l2_dev = &imxmd->v4l2_dev;
struct vdic_priv *priv; struct vdic_priv *priv;
int ret; int ret;
priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); priv = devm_kzalloc(ipu_dev, sizeof(*priv), GFP_KERNEL);
if (!priv) if (!priv)
return -ENOMEM; return ERR_PTR(-ENOMEM);
platform_set_drvdata(pdev, &priv->sd); priv->ipu_dev = ipu_dev;
priv->dev = &pdev->dev; priv->ipu = ipu;
priv->md = imxmd;
pdata = priv->dev->platform_data;
priv->ipu_id = pdata->ipu_id;
v4l2_subdev_init(&priv->sd, &vdic_subdev_ops); v4l2_subdev_init(&priv->sd, &vdic_subdev_ops);
v4l2_set_subdevdata(&priv->sd, priv); v4l2_set_subdevdata(&priv->sd, priv);
priv->sd.internal_ops = &vdic_internal_ops; priv->sd.internal_ops = &vdic_internal_ops;
priv->sd.entity.ops = &vdic_entity_ops; priv->sd.entity.ops = &vdic_entity_ops;
priv->sd.entity.function = MEDIA_ENT_F_PROC_VIDEO_PIXEL_FORMATTER; priv->sd.entity.function = MEDIA_ENT_F_PROC_VIDEO_PIXEL_FORMATTER;
priv->sd.dev = &pdev->dev; priv->sd.owner = ipu_dev->driver->owner;
priv->sd.owner = THIS_MODULE;
priv->sd.flags = V4L2_SUBDEV_FL_HAS_DEVNODE; priv->sd.flags = V4L2_SUBDEV_FL_HAS_DEVNODE;
/* get our group id */ priv->sd.grp_id = grp_id;
priv->sd.grp_id = pdata->grp_id; imx_media_grp_id_to_sd_name(priv->sd.name, sizeof(priv->sd.name),
strscpy(priv->sd.name, pdata->sd_name, sizeof(priv->sd.name)); priv->sd.grp_id, ipu_get_num(ipu));
mutex_init(&priv->lock); mutex_init(&priv->lock);
ret = v4l2_async_register_subdev(&priv->sd); ret = v4l2_device_register_subdev(v4l2_dev, &priv->sd);
if (ret) if (ret)
goto free; goto free;
return 0; return &priv->sd;
free: free:
mutex_destroy(&priv->lock); mutex_destroy(&priv->lock);
return ret; return ERR_PTR(ret);
} }
static int imx_vdic_remove(struct platform_device *pdev) int imx_media_vdic_unregister(struct v4l2_subdev *sd)
{ {
struct v4l2_subdev *sd = platform_get_drvdata(pdev);
struct vdic_priv *priv = v4l2_get_subdevdata(sd); struct vdic_priv *priv = v4l2_get_subdevdata(sd);
v4l2_info(sd, "Removing\n"); v4l2_info(sd, "Removing\n");
v4l2_async_unregister_subdev(sd); v4l2_device_unregister_subdev(sd);
mutex_destroy(&priv->lock); mutex_destroy(&priv->lock);
media_entity_cleanup(&sd->entity); media_entity_cleanup(&sd->entity);
return 0; return 0;
} }
static const struct platform_device_id imx_vdic_ids[] = {
{ .name = "imx-ipuv3-vdic" },
{ },
};
MODULE_DEVICE_TABLE(platform, imx_vdic_ids);
static struct platform_driver imx_vdic_driver = {
.probe = imx_vdic_probe,
.remove = imx_vdic_remove,
.id_table = imx_vdic_ids,
.driver = {
.name = "imx-ipuv3-vdic",
},
};
module_platform_driver(imx_vdic_driver);
MODULE_DESCRIPTION("i.MX VDIC subdev driver");
MODULE_AUTHOR("Steve Longerbeam <steve_longerbeam@mentor.com>");
MODULE_LICENSE("GPL");
MODULE_ALIAS("platform:imx-ipuv3-vdic");
...@@ -15,6 +15,19 @@ ...@@ -15,6 +15,19 @@
#include <media/videobuf2-dma-contig.h> #include <media/videobuf2-dma-contig.h>
#include <video/imx-ipu-v3.h> #include <video/imx-ipu-v3.h>
/*
* Enumeration of the IPU internal sub-devices
*/
enum {
IPU_CSI0 = 0,
IPU_CSI1,
IPU_VDIC,
IPU_IC_PRP,
IPU_IC_PRPENC,
IPU_IC_PRPVF,
NUM_IPU_SUBDEVS,
};
/* /*
* Pad definitions for the subdevs with multiple source or * Pad definitions for the subdevs with multiple source or
* sink pads * sink pads
...@@ -111,25 +124,6 @@ struct imx_media_pad_vdev { ...@@ -111,25 +124,6 @@ struct imx_media_pad_vdev {
struct list_head list; struct list_head list;
}; };
struct imx_media_ipu_internal_sd_pdata {
char sd_name[V4L2_SUBDEV_NAME_SIZE];
u32 grp_id;
int ipu_id;
};
struct imx_media_async_subdev {
/* the base asd - must be first in this struct */
struct v4l2_async_subdev asd;
/* the platform device of IPU-internal subdevs */
struct platform_device *pdev;
};
static inline struct imx_media_async_subdev *
to_imx_media_asd(struct v4l2_async_subdev *asd)
{
return container_of(asd, struct imx_media_async_subdev, asd);
}
struct imx_media_dev { struct imx_media_dev {
struct media_device md; struct media_device md;
struct v4l2_device v4l2_dev; struct v4l2_device v4l2_dev;
...@@ -142,11 +136,11 @@ struct imx_media_dev { ...@@ -142,11 +136,11 @@ struct imx_media_dev {
/* master video device list */ /* master video device list */
struct list_head vdev_list; struct list_head vdev_list;
/* IPUs this media driver control, valid after subdevs bound */
struct ipu_soc *ipu[2];
/* for async subdev registration */ /* for async subdev registration */
struct v4l2_async_notifier notifier; struct v4l2_async_notifier notifier;
/* the IPU internal subdev's registered synchronously */
struct v4l2_subdev *sync_sd[2][NUM_IPU_SUBDEVS];
}; };
enum codespace_sel { enum codespace_sel {
...@@ -221,10 +215,6 @@ int imx_media_pipeline_set_stream(struct imx_media_dev *imxmd, ...@@ -221,10 +215,6 @@ int imx_media_pipeline_set_stream(struct imx_media_dev *imxmd,
bool on); bool on);
/* imx-media-dev.c */ /* imx-media-dev.c */
int imx_media_add_async_subdev(struct imx_media_dev *imxmd,
struct fwnode_handle *fwnode,
struct platform_device *pdev);
int imx_media_subdev_bound(struct v4l2_async_notifier *notifier, int imx_media_subdev_bound(struct v4l2_async_notifier *notifier,
struct v4l2_subdev *sd, struct v4l2_subdev *sd,
struct v4l2_async_subdev *asd); struct v4l2_async_subdev *asd);
...@@ -248,11 +238,9 @@ struct imx_media_fim *imx_media_fim_init(struct v4l2_subdev *sd); ...@@ -248,11 +238,9 @@ struct imx_media_fim *imx_media_fim_init(struct v4l2_subdev *sd);
void imx_media_fim_free(struct imx_media_fim *fim); void imx_media_fim_free(struct imx_media_fim *fim);
/* imx-media-internal-sd.c */ /* imx-media-internal-sd.c */
int imx_media_add_ipu_internal_subdevs(struct imx_media_dev *imxmd, int imx_media_register_ipu_internal_subdevs(struct imx_media_dev *imxmd,
int ipu_id); struct v4l2_subdev *csi);
int imx_media_create_ipu_internal_links(struct imx_media_dev *imxmd, void imx_media_unregister_ipu_internal_subdevs(struct imx_media_dev *imxmd);
struct v4l2_subdev *sd);
void imx_media_remove_ipu_internal_subdevs(struct imx_media_dev *imxmd);
/* imx-media-of.c */ /* imx-media-of.c */
int imx_media_add_of_subdevs(struct imx_media_dev *dev, int imx_media_add_of_subdevs(struct imx_media_dev *dev,
...@@ -264,9 +252,24 @@ int imx_media_create_csi_of_links(struct imx_media_dev *imxmd, ...@@ -264,9 +252,24 @@ int imx_media_create_csi_of_links(struct imx_media_dev *imxmd,
int imx_media_of_add_csi(struct imx_media_dev *imxmd, int imx_media_of_add_csi(struct imx_media_dev *imxmd,
struct device_node *csi_np); struct device_node *csi_np);
/* imx-media-vdic.c */
struct v4l2_subdev *imx_media_vdic_register(struct imx_media_dev *imxmd,
struct device *ipu_dev,
struct ipu_soc *ipu,
u32 grp_id);
int imx_media_vdic_unregister(struct v4l2_subdev *sd);
/* imx-ic-common.c */
struct v4l2_subdev *imx_media_ic_register(struct imx_media_dev *imxmd,
struct device *ipu_dev,
struct ipu_soc *ipu,
u32 grp_id);
int imx_media_ic_unregister(struct v4l2_subdev *sd);
/* imx-media-capture.c */ /* imx-media-capture.c */
struct imx_media_video_dev * struct imx_media_video_dev *
imx_media_capture_device_init(struct v4l2_subdev *src_sd, int pad); imx_media_capture_device_init(struct device *dev, struct v4l2_subdev *src_sd,
int pad);
void imx_media_capture_device_remove(struct imx_media_video_dev *vdev); void imx_media_capture_device_remove(struct imx_media_video_dev *vdev);
int imx_media_capture_device_register(struct imx_media_video_dev *vdev); int imx_media_capture_device_register(struct imx_media_video_dev *vdev);
void imx_media_capture_device_unregister(struct imx_media_video_dev *vdev); void imx_media_capture_device_unregister(struct imx_media_video_dev *vdev);
......
...@@ -1292,7 +1292,8 @@ static int imx7_csi_probe(struct platform_device *pdev) ...@@ -1292,7 +1292,8 @@ static int imx7_csi_probe(struct platform_device *pdev)
csi->sd.grp_id = IMX_MEDIA_GRP_ID_CSI; csi->sd.grp_id = IMX_MEDIA_GRP_ID_CSI;
snprintf(csi->sd.name, sizeof(csi->sd.name), "csi"); snprintf(csi->sd.name, sizeof(csi->sd.name), "csi");
csi->vdev = imx_media_capture_device_init(&csi->sd, IMX7_CSI_PAD_SRC); csi->vdev = imx_media_capture_device_init(csi->sd.dev, &csi->sd,
IMX7_CSI_PAD_SRC);
if (IS_ERR(csi->vdev)) if (IS_ERR(csi->vdev))
return PTR_ERR(csi->vdev); return PTR_ERR(csi->vdev);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment