Commit 9f6a0c59 authored by Steve Longerbeam's avatar Steve Longerbeam Committed by Mauro Carvalho Chehab

media: staging/imx: remove static subdev arrays

For more complex OF graphs, there will be more async subdevices
registered. Remove the static subdev[IMX_MEDIA_MAX_SUBDEVS] array,
so that imx-media places no limits on the number of async subdevs
that can be added and registered.

There were two uses for 'struct imx_media_subdev'. First was to act
as the async subdev list to be passed to v4l2_async_notifier_register().

Second was to aid in inheriting subdev controls to the capture devices,
and this is done by creating a list of capture devices that can be reached
from a subdev's source pad. So 'struct imx_media_subdev' also contained
a static array of 'struct imx_media_pad' for placing the capture device
lists at each pad.

'struct imx_media_subdev' has been completely removed. Instead, at async
completion, allocate an array of 'struct imx_media_pad' and attach it to
the subdev's host_priv pointer, in order to support subdev controls
inheritance.

Likewise, remove static async_ptrs[IMX_MEDIA_MAX_SUBDEVS] array.
Instead, allocate a 'struct imx_media_async_subdev' when forming
the async list, and add it to an asd_list list_head in
imx_media_add_async_subdev(). At async completion, allocate the
asd pointer list and pull the asd's off asd_list for
v4l2_async_notifier_register().
Signed-off-by: default avatarSteve Longerbeam <steve_longerbeam@mentor.com>
Signed-off-by: default avatarHans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@s-opensource.com>
parent 4eef678d
......@@ -300,7 +300,7 @@ static int prp_link_validate(struct v4l2_subdev *sd,
{
struct imx_ic_priv *ic_priv = v4l2_get_subdevdata(sd);
struct prp_priv *priv = ic_priv->prp_priv;
struct imx_media_subdev *csi;
struct v4l2_subdev *csi;
int ret;
ret = v4l2_subdev_link_validate_default(sd, link,
......@@ -333,7 +333,7 @@ static int prp_link_validate(struct v4l2_subdev *sd,
}
if (csi) {
switch (csi->sd->grp_id) {
switch (csi->grp_id) {
case IMX_MEDIA_GRP_ID_CSI0:
priv->csi_id = 0;
break;
......
......@@ -138,7 +138,6 @@ static int csi_get_upstream_endpoint(struct csi_priv *priv,
struct v4l2_fwnode_endpoint *ep)
{
struct device_node *endpoint, *port;
struct imx_media_subdev *imxsd;
struct media_entity *src;
struct v4l2_subdev *sd;
struct media_pad *pad;
......@@ -154,10 +153,10 @@ static int csi_get_upstream_endpoint(struct csi_priv *priv,
* CSI-2 receiver if it is in the path, otherwise stay
* with video mux.
*/
imxsd = imx_media_find_upstream_subdev(priv->md, src,
sd = imx_media_find_upstream_subdev(priv->md, src,
IMX_MEDIA_GRP_ID_CSI2);
if (!IS_ERR(imxsd))
src = &imxsd->sd->entity;
if (!IS_ERR(sd))
src = &sd->entity;
}
/* get source pad of entity directly upstream from src */
......
This diff is collapsed.
......@@ -68,6 +68,8 @@ struct internal_link {
int remote_pad;
};
/* max pads per internal-sd */
#define MAX_INTERNAL_PADS 8
/* max links per internal-sd pad */
#define MAX_INTERNAL_LINKS 8
......@@ -77,7 +79,7 @@ struct internal_pad {
static const struct internal_subdev {
const struct internal_subdev_id *id;
struct internal_pad pad[IMX_MEDIA_MAX_PADS];
struct internal_pad pad[MAX_INTERNAL_PADS];
} int_subdev[num_isd] = {
[isd_csi0] = {
.id = &isd_id[isd_csi0],
......@@ -181,8 +183,8 @@ static const struct internal_subdev *find_intsd_by_grp_id(u32 grp_id)
return NULL;
}
static struct imx_media_subdev *find_sink(struct imx_media_dev *imxmd,
struct imx_media_subdev *src,
static struct v4l2_subdev *find_sink(struct imx_media_dev *imxmd,
struct v4l2_subdev *src,
const struct internal_link *link)
{
char sink_devname[32];
......@@ -194,20 +196,20 @@ static struct imx_media_subdev *find_sink(struct imx_media_dev *imxmd,
* a CSI, it has different struct ipu_client_platformdata which
* does not contain IPU id.
*/
if (sscanf(src->sd->name, "ipu%d", &ipu_id) != 1)
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_async_subdev(imxmd, NULL, sink_devname);
return imx_media_find_subdev_by_devname(imxmd, sink_devname);
}
static int create_ipu_internal_link(struct imx_media_dev *imxmd,
struct imx_media_subdev *src,
struct v4l2_subdev *src,
const struct internal_link *link)
{
struct imx_media_subdev *sink;
struct v4l2_subdev *sink;
int ret;
sink = find_sink(imxmd, src, link);
......@@ -215,11 +217,11 @@ static int create_ipu_internal_link(struct imx_media_dev *imxmd,
return -ENODEV;
v4l2_info(&imxmd->v4l2_dev, "%s:%d -> %s:%d\n",
src->sd->name, link->local_pad,
sink->sd->name, link->remote_pad);
src->name, link->local_pad,
sink->name, link->remote_pad);
ret = media_create_pad_link(&src->sd->entity, link->local_pad,
&sink->sd->entity, link->remote_pad, 0);
ret = media_create_pad_link(&src->entity, link->local_pad,
&sink->entity, link->remote_pad, 0);
if (ret)
v4l2_err(&imxmd->v4l2_dev,
"create_pad_link failed: %d\n", ret);
......@@ -228,16 +230,15 @@ static int create_ipu_internal_link(struct imx_media_dev *imxmd,
}
int imx_media_create_internal_links(struct imx_media_dev *imxmd,
struct imx_media_subdev *imxsd)
struct v4l2_subdev *sd)
{
struct v4l2_subdev *sd = imxsd->sd;
const struct internal_subdev *intsd;
const struct internal_pad *intpad;
const struct internal_link *link;
struct media_pad *pad;
int i, j, ret;
intsd = find_intsd_by_grp_id(imxsd->sd->grp_id);
intsd = find_intsd_by_grp_id(sd->grp_id);
if (!intsd)
return -ENODEV;
......@@ -255,7 +256,7 @@ int imx_media_create_internal_links(struct imx_media_dev *imxmd,
if (!link->remote)
break;
ret = create_ipu_internal_link(imxmd, imxsd, link);
ret = create_ipu_internal_link(imxmd, sd, link);
if (ret)
return ret;
}
......@@ -271,7 +272,6 @@ static int add_internal_subdev(struct imx_media_dev *imxmd,
{
struct imx_media_internal_sd_platformdata pdata;
struct platform_device_info pdevinfo = {0};
struct imx_media_subdev *imxsd;
struct platform_device *pdev;
pdata.grp_id = isd->id->grp_id;
......@@ -294,11 +294,7 @@ static int add_internal_subdev(struct imx_media_dev *imxmd,
if (IS_ERR(pdev))
return PTR_ERR(pdev);
imxsd = imx_media_add_async_subdev(imxmd, NULL, pdev);
if (IS_ERR(imxsd))
return PTR_ERR(imxsd);
return 0;
return imx_media_add_async_subdev(imxmd, NULL, pdev);
}
/* adds the internal subdevs in one ipu */
......@@ -353,13 +349,12 @@ int imx_media_add_internal_subdevs(struct imx_media_dev *imxmd)
void imx_media_remove_internal_subdevs(struct imx_media_dev *imxmd)
{
struct imx_media_subdev *imxsd;
int i;
struct imx_media_async_subdev *imxasd;
for (i = 0; i < imxmd->subdev_notifier.num_subdevs; i++) {
imxsd = &imxmd->subdev[i];
if (!imxsd->pdev)
list_for_each_entry(imxasd, &imxmd->asd_list, list) {
if (!imxasd->pdev)
continue;
platform_device_unregister(imxsd->pdev);
platform_device_unregister(imxasd->pdev);
}
}
......@@ -76,7 +76,6 @@ static int
of_parse_subdev(struct imx_media_dev *imxmd, struct device_node *sd_np,
bool is_csi_port)
{
struct imx_media_subdev *imxsd;
int i, num_ports, ret;
if (!of_device_is_available(sd_np)) {
......@@ -87,9 +86,8 @@ of_parse_subdev(struct imx_media_dev *imxmd, struct device_node *sd_np,
}
/* register this subdev with async notifier */
imxsd = imx_media_add_async_subdev(imxmd, of_fwnode_handle(sd_np),
ret = imx_media_add_async_subdev(imxmd, of_fwnode_handle(sd_np),
NULL);
ret = PTR_ERR_OR_ZERO(imxsd);
if (ret) {
if (ret == -EEXIST) {
/* already added, everything is fine */
......@@ -159,37 +157,35 @@ int imx_media_add_of_subdevs(struct imx_media_dev *imxmd,
}
/*
* Create a single media link to/from imxsd using a fwnode link.
* Create a single media link to/from sd using a fwnode link.
*
* NOTE: this function assumes an OF port node is equivalent to
* a media pad (port id equal to media pad index), and that an
* OF endpoint node is equivalent to a media link.
*/
static int create_of_link(struct imx_media_dev *imxmd,
struct imx_media_subdev *imxsd,
struct v4l2_subdev *sd,
struct v4l2_fwnode_link *link)
{
struct v4l2_subdev *sd = imxsd->sd;
struct imx_media_subdev *remote;
struct v4l2_subdev *src, *sink;
struct v4l2_subdev *remote, *src, *sink;
int src_pad, sink_pad;
if (link->local_port >= sd->entity.num_pads)
return -EINVAL;
remote = imx_media_find_async_subdev(imxmd, link->remote_node, NULL);
remote = imx_media_find_subdev_by_fwnode(imxmd, link->remote_node);
if (!remote)
return 0;
if (sd->entity.pads[link->local_port].flags & MEDIA_PAD_FL_SINK) {
src = remote->sd;
src = remote;
src_pad = link->remote_port;
sink = sd;
sink_pad = link->local_port;
} else {
src = sd;
src_pad = link->local_port;
sink = remote->sd;
sink = remote;
sink_pad = link->remote_port;
}
......@@ -206,12 +202,11 @@ static int create_of_link(struct imx_media_dev *imxmd,
}
/*
* Create media links to/from imxsd using its device-tree endpoints.
* Create media links to/from sd using its device-tree endpoints.
*/
int imx_media_create_of_links(struct imx_media_dev *imxmd,
struct imx_media_subdev *imxsd)
struct v4l2_subdev *sd)
{
struct v4l2_subdev *sd = imxsd->sd;
struct v4l2_fwnode_link link;
struct device_node *ep;
int ret;
......@@ -221,7 +216,7 @@ int imx_media_create_of_links(struct imx_media_dev *imxmd,
if (ret)
continue;
ret = create_of_link(imxmd, imxsd, &link);
ret = create_of_link(imxmd, sd, &link);
v4l2_fwnode_put_link(&link);
if (ret)
return ret;
......@@ -235,9 +230,9 @@ int imx_media_create_of_links(struct imx_media_dev *imxmd,
* using its device-tree endpoints.
*/
int imx_media_create_csi_of_links(struct imx_media_dev *imxmd,
struct imx_media_subdev *csi)
struct v4l2_subdev *csi)
{
struct device_node *csi_np = csi->sd->dev->of_node;
struct device_node *csi_np = csi->dev->of_node;
struct fwnode_handle *fwnode, *csi_ep;
struct v4l2_fwnode_link link;
struct device_node *ep;
......
......@@ -668,38 +668,35 @@ void imx_media_grp_id_to_sd_name(char *sd_name, int sz, u32 grp_id, int ipu_id)
}
EXPORT_SYMBOL_GPL(imx_media_grp_id_to_sd_name);
struct imx_media_subdev *
imx_media_find_subdev_by_sd(struct imx_media_dev *imxmd,
struct v4l2_subdev *sd)
struct v4l2_subdev *
imx_media_find_subdev_by_fwnode(struct imx_media_dev *imxmd,
struct fwnode_handle *fwnode)
{
struct imx_media_subdev *imxsd;
int i;
struct v4l2_subdev *sd;
for (i = 0; i < imxmd->num_subdevs; i++) {
imxsd = &imxmd->subdev[i];
if (sd == imxsd->sd)
return imxsd;
list_for_each_entry(sd, &imxmd->v4l2_dev.subdevs, list) {
if (sd->fwnode == fwnode)
return sd;
}
return ERR_PTR(-ENODEV);
return NULL;
}
EXPORT_SYMBOL_GPL(imx_media_find_subdev_by_sd);
EXPORT_SYMBOL_GPL(imx_media_find_subdev_by_fwnode);
struct imx_media_subdev *
imx_media_find_subdev_by_id(struct imx_media_dev *imxmd, u32 grp_id)
struct v4l2_subdev *
imx_media_find_subdev_by_devname(struct imx_media_dev *imxmd,
const char *devname)
{
struct imx_media_subdev *imxsd;
int i;
struct v4l2_subdev *sd;
for (i = 0; i < imxmd->num_subdevs; i++) {
imxsd = &imxmd->subdev[i];
if (imxsd->sd && imxsd->sd->grp_id == grp_id)
return imxsd;
list_for_each_entry(sd, &imxmd->v4l2_dev.subdevs, list) {
if (!strcmp(devname, dev_name(sd->dev)))
return sd;
}
return ERR_PTR(-ENODEV);
return NULL;
}
EXPORT_SYMBOL_GPL(imx_media_find_subdev_by_id);
EXPORT_SYMBOL_GPL(imx_media_find_subdev_by_devname);
/*
* Adds a video device to the master video device list. This is called by
......@@ -842,7 +839,7 @@ EXPORT_SYMBOL_GPL(imx_media_find_upstream_pad);
* the current pipeline.
* Must be called with mdev->graph_mutex held.
*/
struct imx_media_subdev *
struct v4l2_subdev *
imx_media_find_upstream_subdev(struct imx_media_dev *imxmd,
struct media_entity *start_entity,
u32 grp_id)
......@@ -853,7 +850,7 @@ imx_media_find_upstream_subdev(struct imx_media_dev *imxmd,
if (!sd)
return ERR_PTR(-ENODEV);
return imx_media_find_subdev_by_sd(imxmd, sd);
return sd;
}
EXPORT_SYMBOL_GPL(imx_media_find_upstream_subdev);
......
......@@ -11,6 +11,7 @@
#ifndef _IMX_MEDIA_H
#define _IMX_MEDIA_H
#include <linux/platform_device.h>
#include <media/v4l2-ctrls.h>
#include <media/v4l2-device.h>
#include <media/v4l2-fwnode.h>
......@@ -18,23 +19,8 @@
#include <media/videobuf2-dma-contig.h>
#include <video/imx-ipu-v3.h>
/*
* This is somewhat arbitrary, but we need at least:
* - 4 video devices per IPU
* - 3 IC subdevs per IPU
* - 1 VDIC subdev per IPU
* - 2 CSI subdevs per IPU
* - 1 mipi-csi2 receiver subdev
* - 2 video-mux subdevs
* - 2 camera sensor subdevs per IPU (1 parallel, 1 mipi-csi2)
*
*/
/* max video devices */
#define IMX_MEDIA_MAX_VDEVS 8
/* max subdevices */
#define IMX_MEDIA_MAX_SUBDEVS 32
/* max pads per subdev */
#define IMX_MEDIA_MAX_PADS 16
/*
* Pad definitions for the subdevs with multiple source or
......@@ -105,6 +91,7 @@ static inline struct imx_media_buffer *to_imx_media_vb(struct vb2_buffer *vb)
return container_of(vbuf, struct imx_media_buffer, vbuf);
}
/* to support control inheritance to video devices */
struct imx_media_pad {
/*
* list of video devices that can be reached from this pad,
......@@ -114,22 +101,34 @@ struct imx_media_pad {
int num_vdevs;
};
static inline struct imx_media_pad *
to_imx_media_pad(struct v4l2_subdev *sd, int pad_index)
{
struct imx_media_pad *imxpads = sd->host_priv;
return imxpads ? &imxpads[pad_index] : NULL;
}
struct imx_media_internal_sd_platformdata {
char sd_name[V4L2_SUBDEV_NAME_SIZE];
u32 grp_id;
int ipu_id;
};
struct imx_media_subdev {
struct v4l2_async_subdev asd;
struct v4l2_subdev *sd; /* set when bound */
struct imx_media_pad pad[IMX_MEDIA_MAX_PADS];
/* the platform device if this is an IPU-internal subdev */
struct imx_media_async_subdev {
struct v4l2_async_subdev asd;
/* the platform device of IPU-internal subdevs */
struct platform_device *pdev;
struct list_head list;
};
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 media_device md;
struct v4l2_device v4l2_dev;
......@@ -139,10 +138,6 @@ struct imx_media_dev {
struct mutex mutex; /* protect elements below */
/* master subdevice list */
struct imx_media_subdev subdev[IMX_MEDIA_MAX_SUBDEVS];
int num_subdevs;
/* master video device list */
struct imx_media_video_dev *vdev[IMX_MEDIA_MAX_VDEVS];
int num_vdevs;
......@@ -151,7 +146,7 @@ struct imx_media_dev {
struct ipu_soc *ipu[2];
/* for async subdev registration */
struct v4l2_async_subdev *async_ptrs[IMX_MEDIA_MAX_SUBDEVS];
struct list_head asd_list;
struct v4l2_async_notifier subdev_notifier;
};
......@@ -172,7 +167,6 @@ int imx_media_enum_mbus_format(u32 *code, u32 index, enum codespace_sel cs_sel,
const struct imx_media_pixfmt *
imx_media_find_ipu_format(u32 code, enum codespace_sel cs_sel);
int imx_media_enum_ipu_format(u32 *code, u32 index, enum codespace_sel cs_sel);
int imx_media_init_mbus_fmt(struct v4l2_mbus_framefmt *mbus,
u32 width, u32 height, u32 code, u32 field,
const struct imx_media_pixfmt **cc);
......@@ -186,30 +180,23 @@ int imx_media_mbus_fmt_to_ipu_image(struct ipu_image *image,
struct v4l2_mbus_framefmt *mbus);
int imx_media_ipu_image_to_mbus_fmt(struct v4l2_mbus_framefmt *mbus,
struct ipu_image *image);
struct imx_media_subdev *
imx_media_find_async_subdev(struct imx_media_dev *imxmd,
struct fwnode_handle *fwnode,
const char *devname);
struct imx_media_subdev *
imx_media_add_async_subdev(struct imx_media_dev *imxmd,
int imx_media_add_async_subdev(struct imx_media_dev *imxmd,
struct fwnode_handle *fwnode,
struct platform_device *pdev);
void imx_media_grp_id_to_sd_name(char *sd_name, int sz,
u32 grp_id, int ipu_id);
int imx_media_add_internal_subdevs(struct imx_media_dev *imxmd);
int imx_media_create_internal_links(struct imx_media_dev *imxmd,
struct imx_media_subdev *imxsd);
struct v4l2_subdev *sd);
void imx_media_remove_internal_subdevs(struct imx_media_dev *imxmd);
struct imx_media_subdev *
imx_media_find_subdev_by_sd(struct imx_media_dev *imxmd,
struct v4l2_subdev *sd);
struct imx_media_subdev *
imx_media_find_subdev_by_id(struct imx_media_dev *imxmd,
u32 grp_id);
struct v4l2_subdev *
imx_media_find_subdev_by_fwnode(struct imx_media_dev *imxmd,
struct fwnode_handle *fwnode);
struct v4l2_subdev *
imx_media_find_subdev_by_devname(struct imx_media_dev *imxmd,
const char *devname);
int imx_media_add_video_device(struct imx_media_dev *imxmd,
struct imx_media_video_dev *vdev);
int imx_media_find_mipi_csi2_channel(struct imx_media_dev *imxmd,
......@@ -218,7 +205,7 @@ struct media_pad *
imx_media_find_upstream_pad(struct imx_media_dev *imxmd,
struct media_entity *start_entity,
u32 grp_id);
struct imx_media_subdev *
struct v4l2_subdev *
imx_media_find_upstream_subdev(struct imx_media_dev *imxmd,
struct media_entity *start_entity,
u32 grp_id);
......@@ -253,9 +240,9 @@ void imx_media_fim_free(struct imx_media_fim *fim);
int imx_media_add_of_subdevs(struct imx_media_dev *dev,
struct device_node *np);
int imx_media_create_of_links(struct imx_media_dev *imxmd,
struct imx_media_subdev *imxsd);
struct v4l2_subdev *sd);
int imx_media_create_csi_of_links(struct imx_media_dev *imxmd,
struct imx_media_subdev *csi);
struct v4l2_subdev *csi);
/* imx-media-capture.c */
struct imx_media_video_dev *
......
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