Skip to content

Commit 621b08e

Browse files
slongerbeammchehab
authored andcommitted
media: staging/imx: remove static media link arrays
Remove the static list of media links that were formed at probe time. These links can instead be created after all registered async subdevices have been bound in imx_media_probe_complete(). The media links between subdevices that exist in the device tree, can be created post-async completion by using v4l2_fwnode_parse_link() for each endpoint node of that subdevice. Note this approach assumes device-tree ports are equivalent to media pads (pad index equals port id), and that device-tree endpoints are equivalent to media links between pads. Because links are no longer parsed by imx_media_of_parse(), its sole function is now only to add subdevices that it encounters by walking the OF graph to the async list, so the function has been renamed imx_media_add_of_subdevs(). Similarly, the media links between the IPU-internal subdevice pads (the CSI source pads, and all pads between the vdic, ic-prp, ic-prpenc, and ic-prpvf subdevices), can be created post-async completion by looping through the subdevice's media pads and using the const internal_subdev table. Because links are no longer parsed by imx_media_add_internal_subdevs(), this function no longer needs an array of CSI subdevs to form links from. In summary, the following functions, which were used to form a list of media links at probe time, are removed: imx_media_add_pad_link() add_internal_links() of_add_pad_link() replaced by these functions, called at probe time, which only populate the async subdev list: imx_media_add_of_subdevs() imx_media_add_internal_subdevs() and these functions, called at async completion, which create the media links: imx_media_create_of_links() imx_media_create_csi_of_links() imx_media_create_internal_links() Signed-off-by: Steve Longerbeam <[email protected]> Signed-off-by: Hans Verkuil <[email protected]> Signed-off-by: Mauro Carvalho Chehab <[email protected]>
1 parent bf3cfaa commit 621b08e

File tree

4 files changed

+281
-296
lines changed

4 files changed

+281
-296
lines changed

drivers/staging/media/imx/imx-media-dev.c

Lines changed: 24 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <linux/delay.h>
1212
#include <linux/fs.h>
1313
#include <linux/module.h>
14+
#include <linux/of_graph.h>
1415
#include <linux/of_platform.h>
1516
#include <linux/pinctrl/consumer.h>
1617
#include <linux/platform_device.h>
@@ -127,50 +128,6 @@ imx_media_add_async_subdev(struct imx_media_dev *imxmd,
127128
return imxsd;
128129
}
129130

130-
/*
131-
* Adds an imx-media link to a subdev pad's link list. This is called
132-
* during driver load when forming the links between subdevs.
133-
*
134-
* @pad: the local pad
135-
* @remote_node: the device node of the remote subdev
136-
* @remote_devname: the device name of the remote subdev
137-
* @local_pad: local pad index
138-
* @remote_pad: remote pad index
139-
*/
140-
int imx_media_add_pad_link(struct imx_media_dev *imxmd,
141-
struct imx_media_pad *pad,
142-
struct device_node *remote_node,
143-
const char *remote_devname,
144-
int local_pad, int remote_pad)
145-
{
146-
struct imx_media_link *link;
147-
int link_idx, ret = 0;
148-
149-
mutex_lock(&imxmd->mutex);
150-
151-
link_idx = pad->num_links;
152-
if (link_idx >= IMX_MEDIA_MAX_LINKS) {
153-
dev_err(imxmd->md.dev, "%s: too many links!\n", __func__);
154-
ret = -ENOSPC;
155-
goto out;
156-
}
157-
158-
link = &pad->link[link_idx];
159-
160-
link->remote_sd_node = remote_node;
161-
if (remote_devname)
162-
strncpy(link->remote_devname, remote_devname,
163-
sizeof(link->remote_devname));
164-
165-
link->local_pad = local_pad;
166-
link->remote_pad = remote_pad;
167-
168-
pad->num_links++;
169-
out:
170-
mutex_unlock(&imxmd->mutex);
171-
return ret;
172-
}
173-
174131
/*
175132
* get IPU from this CSI and add it to the list of IPUs
176133
* the media driver will control.
@@ -240,76 +197,38 @@ static int imx_media_subdev_bound(struct v4l2_async_notifier *notifier,
240197
}
241198

242199
/*
243-
* Create a single source->sink media link given a subdev and a single
244-
* link from one of its source pads. Called after all subdevs have
245-
* registered.
246-
*/
247-
static int imx_media_create_link(struct imx_media_dev *imxmd,
248-
struct imx_media_subdev *src,
249-
struct imx_media_link *link)
250-
{
251-
struct imx_media_subdev *sink;
252-
u16 source_pad, sink_pad;
253-
int ret;
254-
255-
sink = imx_media_find_async_subdev(imxmd, link->remote_sd_node,
256-
link->remote_devname);
257-
if (!sink) {
258-
v4l2_warn(&imxmd->v4l2_dev, "%s: no sink for %s:%d\n",
259-
__func__, src->sd->name, link->local_pad);
260-
return 0;
261-
}
262-
263-
source_pad = link->local_pad;
264-
sink_pad = link->remote_pad;
265-
266-
v4l2_info(&imxmd->v4l2_dev, "%s: %s:%d -> %s:%d\n", __func__,
267-
src->sd->name, source_pad, sink->sd->name, sink_pad);
268-
269-
ret = media_create_pad_link(&src->sd->entity, source_pad,
270-
&sink->sd->entity, sink_pad, 0);
271-
if (ret)
272-
v4l2_err(&imxmd->v4l2_dev,
273-
"create_pad_link failed: %d\n", ret);
274-
275-
return ret;
276-
}
277-
278-
/*
279-
* create the media links from all imx-media pads and their links.
200+
* create the media links from all pads and their links.
280201
* Called after all subdevs have registered.
281202
*/
282203
static int imx_media_create_links(struct imx_media_dev *imxmd)
283204
{
284205
struct imx_media_subdev *imxsd;
285-
struct imx_media_link *link;
286-
struct imx_media_pad *pad;
287-
int num_pads, i, j, k;
288-
int ret = 0;
206+
struct v4l2_subdev *sd;
207+
int i, ret;
289208

290209
for (i = 0; i < imxmd->num_subdevs; i++) {
291210
imxsd = &imxmd->subdev[i];
292-
num_pads = imxsd->num_sink_pads + imxsd->num_src_pads;
293-
294-
for (j = 0; j < num_pads; j++) {
295-
pad = &imxsd->pad[j];
296-
297-
/* only create the source->sink links */
298-
if (!(pad->pad.flags & MEDIA_PAD_FL_SOURCE))
299-
continue;
300-
301-
for (k = 0; k < pad->num_links; k++) {
302-
link = &pad->link[k];
211+
sd = imxsd->sd;
303212

304-
ret = imx_media_create_link(imxmd, imxsd, link);
305-
if (ret)
306-
goto out;
307-
}
213+
if (((sd->grp_id & IMX_MEDIA_GRP_ID_CSI) || imxsd->pdev)) {
214+
/* this is an internal subdev or a CSI */
215+
ret = imx_media_create_internal_links(imxmd, imxsd);
216+
if (ret)
217+
return ret;
218+
/*
219+
* the CSIs straddle between the external and the IPU
220+
* internal entities, so create the external links
221+
* to the CSI sink pads.
222+
*/
223+
if (sd->grp_id & IMX_MEDIA_GRP_ID_CSI)
224+
imx_media_create_csi_of_links(imxmd, imxsd);
225+
} else {
226+
/* this is an external fwnode subdev */
227+
imx_media_create_of_links(imxmd, imxsd);
308228
}
309229
}
310230

311-
out:
312-
return ret;
231+
return 0;
313232
}
314233

315234
/*
@@ -550,7 +469,6 @@ static int imx_media_probe(struct platform_device *pdev)
550469
{
551470
struct device *dev = &pdev->dev;
552471
struct device_node *node = dev->of_node;
553-
struct imx_media_subdev *csi[4] = {0};
554472
struct imx_media_dev *imxmd;
555473
int ret;
556474

@@ -581,14 +499,14 @@ static int imx_media_probe(struct platform_device *pdev)
581499

582500
dev_set_drvdata(imxmd->v4l2_dev.dev, imxmd);
583501

584-
ret = imx_media_of_parse(imxmd, &csi, node);
502+
ret = imx_media_add_of_subdevs(imxmd, node);
585503
if (ret) {
586504
v4l2_err(&imxmd->v4l2_dev,
587-
"imx_media_of_parse failed with %d\n", ret);
505+
"add_of_subdevs failed with %d\n", ret);
588506
goto unreg_dev;
589507
}
590508

591-
ret = imx_media_add_internal_subdevs(imxmd, csi);
509+
ret = imx_media_add_internal_subdevs(imxmd);
592510
if (ret) {
593511
v4l2_err(&imxmd->v4l2_dev,
594512
"add_internal_subdevs failed with %d\n", ret);

0 commit comments

Comments
 (0)