Commit 0e63a5e4 authored by Steve Longerbeam's avatar Steve Longerbeam Committed by Mauro Carvalho Chehab

media: imx: Parse information from firmware without using callbacks

Instead of using the convenience functions
v4l2_async_notifier_parse_fwnode_endpoints*() or
v4l2_async_register_fwnode_subdev(), parse the input endpoints
and set up the async sub-devices without using callbacks. The drivers
know which ports it must parse and how to handle unconnected remotes,
so it makes the code simpler to transfer control of endpoint parsing
to the driver.
Signed-off-by: default avatarSteve Longerbeam <slongerbeam@gmail.com>
Signed-off-by: default avatarSakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab+huawei@kernel.org>
parent f4d7a681
...@@ -58,6 +58,8 @@ struct csi_priv { ...@@ -58,6 +58,8 @@ struct csi_priv {
struct ipu_soc *ipu; struct ipu_soc *ipu;
struct v4l2_subdev sd; struct v4l2_subdev sd;
struct media_pad pad[CSI_NUM_PADS]; struct media_pad pad[CSI_NUM_PADS];
struct v4l2_async_notifier notifier;
/* the video device at IDMAC output pad */ /* the video device at IDMAC output pad */
struct imx_media_video_dev *vdev; struct imx_media_video_dev *vdev;
struct imx_media_fim *fim; struct imx_media_fim *fim;
...@@ -1869,59 +1871,49 @@ static const struct v4l2_subdev_internal_ops csi_internal_ops = { ...@@ -1869,59 +1871,49 @@ static const struct v4l2_subdev_internal_ops csi_internal_ops = {
.unregistered = csi_unregistered, .unregistered = csi_unregistered,
}; };
static int imx_csi_parse_endpoint(struct device *dev,
struct v4l2_fwnode_endpoint *vep,
struct v4l2_async_subdev *asd)
{
return fwnode_device_is_available(asd->match.fwnode) ? 0 : -ENOTCONN;
}
static int imx_csi_async_register(struct csi_priv *priv) static int imx_csi_async_register(struct csi_priv *priv)
{ {
struct v4l2_async_notifier *notifier; struct v4l2_async_subdev *asd = NULL;
struct fwnode_handle *fwnode; struct fwnode_handle *ep;
unsigned int port; unsigned int port;
int ret; int ret;
notifier = kzalloc(sizeof(*notifier), GFP_KERNEL); v4l2_async_notifier_init(&priv->notifier);
if (!notifier)
return -ENOMEM;
v4l2_async_notifier_init(notifier);
fwnode = dev_fwnode(priv->dev);
/* get this CSI's port id */ /* get this CSI's port id */
ret = fwnode_property_read_u32(fwnode, "reg", &port); ret = fwnode_property_read_u32(dev_fwnode(priv->dev), "reg", &port);
if (ret < 0)
goto out_free;
ret = v4l2_async_notifier_parse_fwnode_endpoints_by_port(
priv->dev->parent, notifier, sizeof(struct v4l2_async_subdev),
port, imx_csi_parse_endpoint);
if (ret < 0) if (ret < 0)
goto out_cleanup; return ret;
ret = v4l2_async_subdev_notifier_register(&priv->sd, notifier);
if (ret < 0)
goto out_cleanup;
ret = v4l2_async_register_subdev(&priv->sd); ep = fwnode_graph_get_endpoint_by_id(dev_fwnode(priv->dev->parent),
if (ret < 0) port, 0,
goto out_unregister; FWNODE_GRAPH_ENDPOINT_NEXT);
if (ep) {
asd = kzalloc(sizeof(*asd), GFP_KERNEL);
if (!asd) {
fwnode_handle_put(ep);
return -ENOMEM;
}
priv->sd.subdev_notifier = notifier; ret = v4l2_async_notifier_add_fwnode_remote_subdev(
&priv->notifier, ep, asd);
return 0; fwnode_handle_put(ep);
out_unregister: if (ret) {
v4l2_async_notifier_unregister(notifier); kfree(asd);
out_cleanup: /* OK if asd already exists */
v4l2_async_notifier_cleanup(notifier); if (ret != -EEXIST)
out_free: return ret;
kfree(notifier); }
}
ret = v4l2_async_subdev_notifier_register(&priv->sd,
&priv->notifier);
if (ret)
return ret; return ret;
return v4l2_async_register_subdev(&priv->sd);
} }
static int imx_csi_probe(struct platform_device *pdev) static int imx_csi_probe(struct platform_device *pdev)
...@@ -2001,9 +1993,13 @@ static int imx_csi_probe(struct platform_device *pdev) ...@@ -2001,9 +1993,13 @@ static int imx_csi_probe(struct platform_device *pdev)
ret = imx_csi_async_register(priv); ret = imx_csi_async_register(priv);
if (ret) if (ret)
goto free; goto cleanup;
return 0; return 0;
cleanup:
v4l2_async_notifier_unregister(&priv->notifier);
v4l2_async_notifier_cleanup(&priv->notifier);
free: free:
v4l2_ctrl_handler_free(&priv->ctrl_hdlr); v4l2_ctrl_handler_free(&priv->ctrl_hdlr);
mutex_destroy(&priv->lock); mutex_destroy(&priv->lock);
...@@ -2017,6 +2013,8 @@ static int imx_csi_remove(struct platform_device *pdev) ...@@ -2017,6 +2013,8 @@ static int imx_csi_remove(struct platform_device *pdev)
v4l2_ctrl_handler_free(&priv->ctrl_hdlr); v4l2_ctrl_handler_free(&priv->ctrl_hdlr);
mutex_destroy(&priv->lock); mutex_destroy(&priv->lock);
v4l2_async_notifier_unregister(&priv->notifier);
v4l2_async_notifier_cleanup(&priv->notifier);
v4l2_async_unregister_subdev(sd); v4l2_async_unregister_subdev(sd);
media_entity_cleanup(&sd->entity); media_entity_cleanup(&sd->entity);
......
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
struct csi2_dev { struct csi2_dev {
struct device *dev; struct device *dev;
struct v4l2_subdev sd; struct v4l2_subdev sd;
struct v4l2_async_notifier notifier;
struct media_pad pad[CSI2_NUM_PADS]; struct media_pad pad[CSI2_NUM_PADS];
struct clk *dphy_clk; struct clk *dphy_clk;
struct clk *pllref_clk; struct clk *pllref_clk;
...@@ -530,34 +531,59 @@ static const struct v4l2_subdev_internal_ops csi2_internal_ops = { ...@@ -530,34 +531,59 @@ static const struct v4l2_subdev_internal_ops csi2_internal_ops = {
.registered = csi2_registered, .registered = csi2_registered,
}; };
static int csi2_parse_endpoint(struct device *dev, static int csi2_async_register(struct csi2_dev *csi2)
struct v4l2_fwnode_endpoint *vep,
struct v4l2_async_subdev *asd)
{ {
struct v4l2_subdev *sd = dev_get_drvdata(dev); struct v4l2_fwnode_endpoint vep = {
struct csi2_dev *csi2 = sd_to_dev(sd); .bus_type = V4L2_MBUS_CSI2_DPHY,
};
struct v4l2_async_subdev *asd = NULL;
struct fwnode_handle *ep;
int ret;
if (!fwnode_device_is_available(asd->match.fwnode)) { v4l2_async_notifier_init(&csi2->notifier);
v4l2_err(&csi2->sd, "remote is not available\n");
return -EINVAL;
}
if (vep->bus_type != V4L2_MBUS_CSI2_DPHY) { ep = fwnode_graph_get_endpoint_by_id(dev_fwnode(csi2->dev), 0, 0,
v4l2_err(&csi2->sd, "invalid bus type, must be MIPI CSI2\n"); FWNODE_GRAPH_ENDPOINT_NEXT);
return -EINVAL; if (!ep)
} return -ENOTCONN;
ret = v4l2_fwnode_endpoint_parse(ep, &vep);
if (ret)
goto err_parse;
csi2->bus = vep->bus.mipi_csi2; csi2->bus = vep.bus.mipi_csi2;
dev_dbg(csi2->dev, "data lanes: %d\n", csi2->bus.num_data_lanes); dev_dbg(csi2->dev, "data lanes: %d\n", csi2->bus.num_data_lanes);
dev_dbg(csi2->dev, "flags: 0x%08x\n", csi2->bus.flags); dev_dbg(csi2->dev, "flags: 0x%08x\n", csi2->bus.flags);
return 0; asd = kzalloc(sizeof(*asd), GFP_KERNEL);
if (!asd) {
ret = -ENOMEM;
goto err_parse;
}
ret = v4l2_async_notifier_add_fwnode_remote_subdev(
&csi2->notifier, ep, asd);
if (ret)
goto err_parse;
fwnode_handle_put(ep);
ret = v4l2_async_subdev_notifier_register(&csi2->sd,
&csi2->notifier);
if (ret)
return ret;
return v4l2_async_register_subdev(&csi2->sd);
err_parse:
fwnode_handle_put(ep);
kfree(asd);
return ret;
} }
static int csi2_probe(struct platform_device *pdev) static int csi2_probe(struct platform_device *pdev)
{ {
unsigned int sink_port = 0;
struct csi2_dev *csi2; struct csi2_dev *csi2;
struct resource *res; struct resource *res;
int i, ret; int i, ret;
...@@ -633,15 +659,15 @@ static int csi2_probe(struct platform_device *pdev) ...@@ -633,15 +659,15 @@ static int csi2_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, &csi2->sd); platform_set_drvdata(pdev, &csi2->sd);
ret = v4l2_async_register_fwnode_subdev( ret = csi2_async_register(csi2);
&csi2->sd, sizeof(struct v4l2_async_subdev),
&sink_port, 1, csi2_parse_endpoint);
if (ret) if (ret)
goto dphy_off; goto clean_notifier;
return 0; return 0;
dphy_off: clean_notifier:
v4l2_async_notifier_unregister(&csi2->notifier);
v4l2_async_notifier_cleanup(&csi2->notifier);
clk_disable_unprepare(csi2->dphy_clk); clk_disable_unprepare(csi2->dphy_clk);
pllref_off: pllref_off:
clk_disable_unprepare(csi2->pllref_clk); clk_disable_unprepare(csi2->pllref_clk);
...@@ -655,6 +681,8 @@ static int csi2_remove(struct platform_device *pdev) ...@@ -655,6 +681,8 @@ static int csi2_remove(struct platform_device *pdev)
struct v4l2_subdev *sd = platform_get_drvdata(pdev); struct v4l2_subdev *sd = platform_get_drvdata(pdev);
struct csi2_dev *csi2 = sd_to_dev(sd); struct csi2_dev *csi2 = sd_to_dev(sd);
v4l2_async_notifier_unregister(&csi2->notifier);
v4l2_async_notifier_cleanup(&csi2->notifier);
v4l2_async_unregister_subdev(sd); v4l2_async_unregister_subdev(sd);
clk_disable_unprepare(csi2->dphy_clk); clk_disable_unprepare(csi2->dphy_clk);
clk_disable_unprepare(csi2->pllref_clk); clk_disable_unprepare(csi2->pllref_clk);
......
...@@ -155,6 +155,7 @@ ...@@ -155,6 +155,7 @@
struct imx7_csi { struct imx7_csi {
struct device *dev; struct device *dev;
struct v4l2_subdev sd; struct v4l2_subdev sd;
struct v4l2_async_notifier notifier;
struct imx_media_video_dev *vdev; struct imx_media_video_dev *vdev;
struct imx_media_dev *imxmd; struct imx_media_dev *imxmd;
struct media_pad pad[IMX7_CSI_PADS_NUM]; struct media_pad pad[IMX7_CSI_PADS_NUM];
...@@ -1202,11 +1203,41 @@ static const struct v4l2_subdev_internal_ops imx7_csi_internal_ops = { ...@@ -1202,11 +1203,41 @@ static const struct v4l2_subdev_internal_ops imx7_csi_internal_ops = {
.unregistered = imx7_csi_unregistered, .unregistered = imx7_csi_unregistered,
}; };
static int imx7_csi_parse_endpoint(struct device *dev, static int imx7_csi_async_register(struct imx7_csi *csi)
struct v4l2_fwnode_endpoint *vep,
struct v4l2_async_subdev *asd)
{ {
return fwnode_device_is_available(asd->match.fwnode) ? 0 : -EINVAL; struct v4l2_async_subdev *asd = NULL;
struct fwnode_handle *ep;
int ret;
v4l2_async_notifier_init(&csi->notifier);
ep = fwnode_graph_get_endpoint_by_id(dev_fwnode(csi->dev), 0, 0,
FWNODE_GRAPH_ENDPOINT_NEXT);
if (ep) {
asd = kzalloc(sizeof(*asd), GFP_KERNEL);
if (!asd) {
fwnode_handle_put(ep);
return -ENOMEM;
}
ret = v4l2_async_notifier_add_fwnode_remote_subdev(
&csi->notifier, ep, asd);
fwnode_handle_put(ep);
if (ret) {
kfree(asd);
/* OK if asd already exists */
if (ret != -EEXIST)
return ret;
}
}
ret = v4l2_async_subdev_notifier_register(&csi->sd, &csi->notifier);
if (ret)
return ret;
return v4l2_async_register_subdev(&csi->sd);
} }
static int imx7_csi_probe(struct platform_device *pdev) static int imx7_csi_probe(struct platform_device *pdev)
...@@ -1289,19 +1320,21 @@ static int imx7_csi_probe(struct platform_device *pdev) ...@@ -1289,19 +1320,21 @@ static int imx7_csi_probe(struct platform_device *pdev)
if (ret < 0) if (ret < 0)
goto free; goto free;
ret = v4l2_async_register_fwnode_subdev(&csi->sd, ret = imx7_csi_async_register(csi);
sizeof(struct v4l2_async_subdev),
NULL, 0,
imx7_csi_parse_endpoint);
if (ret) if (ret)
goto free; goto subdev_notifier_cleanup;
return 0; return 0;
subdev_notifier_cleanup:
v4l2_async_notifier_unregister(&csi->notifier);
v4l2_async_notifier_cleanup(&csi->notifier);
free: free:
v4l2_ctrl_handler_free(&csi->ctrl_hdlr); v4l2_ctrl_handler_free(&csi->ctrl_hdlr);
cleanup: cleanup:
v4l2_async_notifier_unregister(&imxmd->notifier);
v4l2_async_notifier_cleanup(&imxmd->notifier); v4l2_async_notifier_cleanup(&imxmd->notifier);
v4l2_device_unregister(&imxmd->v4l2_dev); v4l2_device_unregister(&imxmd->v4l2_dev);
media_device_unregister(&imxmd->md); media_device_unregister(&imxmd->md);
...@@ -1326,6 +1359,8 @@ static int imx7_csi_remove(struct platform_device *pdev) ...@@ -1326,6 +1359,8 @@ static int imx7_csi_remove(struct platform_device *pdev)
v4l2_device_unregister(&imxmd->v4l2_dev); v4l2_device_unregister(&imxmd->v4l2_dev);
media_device_cleanup(&imxmd->md); media_device_cleanup(&imxmd->md);
v4l2_async_notifier_unregister(&csi->notifier);
v4l2_async_notifier_cleanup(&csi->notifier);
v4l2_async_unregister_subdev(sd); v4l2_async_unregister_subdev(sd);
v4l2_ctrl_handler_free(&csi->ctrl_hdlr); v4l2_ctrl_handler_free(&csi->ctrl_hdlr);
......
...@@ -221,6 +221,7 @@ struct csi_state { ...@@ -221,6 +221,7 @@ struct csi_state {
struct device *dev; struct device *dev;
struct media_pad pads[CSIS_PADS_NUM]; struct media_pad pads[CSIS_PADS_NUM];
struct v4l2_subdev mipi_sd; struct v4l2_subdev mipi_sd;
struct v4l2_async_notifier notifier;
struct v4l2_subdev *src_sd; struct v4l2_subdev *src_sd;
u8 index; u8 index;
...@@ -946,33 +947,11 @@ static int mipi_csis_parse_dt(struct platform_device *pdev, ...@@ -946,33 +947,11 @@ static int mipi_csis_parse_dt(struct platform_device *pdev,
static int mipi_csis_pm_resume(struct device *dev, bool runtime); static int mipi_csis_pm_resume(struct device *dev, bool runtime);
static int mipi_csis_parse_endpoint(struct device *dev,
struct v4l2_fwnode_endpoint *ep,
struct v4l2_async_subdev *asd)
{
struct v4l2_subdev *mipi_sd = dev_get_drvdata(dev);
struct csi_state *state = mipi_sd_to_csis_state(mipi_sd);
if (ep->bus_type != V4L2_MBUS_CSI2_DPHY) {
dev_err(dev, "invalid bus type, must be MIPI CSI2\n");
return -EINVAL;
}
state->bus = ep->bus.mipi_csi2;
dev_dbg(state->dev, "data lanes: %d\n", state->bus.num_data_lanes);
dev_dbg(state->dev, "flags: 0x%08x\n", state->bus.flags);
return 0;
}
static int mipi_csis_subdev_init(struct v4l2_subdev *mipi_sd, static int mipi_csis_subdev_init(struct v4l2_subdev *mipi_sd,
struct platform_device *pdev, struct platform_device *pdev,
const struct v4l2_subdev_ops *ops) const struct v4l2_subdev_ops *ops)
{ {
struct csi_state *state = mipi_sd_to_csis_state(mipi_sd); struct csi_state *state = mipi_sd_to_csis_state(mipi_sd);
unsigned int sink_port = 0;
int ret;
v4l2_subdev_init(mipi_sd, ops); v4l2_subdev_init(mipi_sd, ops);
mipi_sd->owner = THIS_MODULE; mipi_sd->owner = THIS_MODULE;
...@@ -994,17 +973,58 @@ static int mipi_csis_subdev_init(struct v4l2_subdev *mipi_sd, ...@@ -994,17 +973,58 @@ static int mipi_csis_subdev_init(struct v4l2_subdev *mipi_sd,
state->pads[CSIS_PAD_SINK].flags = MEDIA_PAD_FL_SINK; state->pads[CSIS_PAD_SINK].flags = MEDIA_PAD_FL_SINK;
state->pads[CSIS_PAD_SOURCE].flags = MEDIA_PAD_FL_SOURCE; state->pads[CSIS_PAD_SOURCE].flags = MEDIA_PAD_FL_SOURCE;
ret = media_entity_pads_init(&mipi_sd->entity, CSIS_PADS_NUM, return media_entity_pads_init(&mipi_sd->entity, CSIS_PADS_NUM,
state->pads); state->pads);
}
static int mipi_csis_async_register(struct csi_state *state)
{
struct v4l2_fwnode_endpoint vep = {
.bus_type = V4L2_MBUS_CSI2_DPHY,
};
struct v4l2_async_subdev *asd = NULL;
struct fwnode_handle *ep;
int ret;
v4l2_async_notifier_init(&state->notifier);
ep = fwnode_graph_get_endpoint_by_id(dev_fwnode(state->dev), 0, 0,
FWNODE_GRAPH_ENDPOINT_NEXT);
if (!ep)
return -ENOTCONN;
ret = v4l2_fwnode_endpoint_parse(ep, &vep);
if (ret)
goto err_parse;
state->bus = vep.bus.mipi_csi2;
dev_dbg(state->dev, "data lanes: %d\n", state->bus.num_data_lanes);
dev_dbg(state->dev, "flags: 0x%08x\n", state->bus.flags);
asd = kzalloc(sizeof(*asd), GFP_KERNEL);
if (!asd) {
ret = -ENOMEM;
goto err_parse;
}
ret = v4l2_async_notifier_add_fwnode_remote_subdev(
&state->notifier, ep, asd);
if (ret)
goto err_parse;
fwnode_handle_put(ep);
ret = v4l2_async_subdev_notifier_register(&state->mipi_sd,
&state->notifier);
if (ret) if (ret)
return ret; return ret;
ret = v4l2_async_register_fwnode_subdev(mipi_sd, return v4l2_async_register_subdev(&state->mipi_sd);
sizeof(struct v4l2_async_subdev),
&sink_port, 1, err_parse:
mipi_csis_parse_endpoint); fwnode_handle_put(ep);
if (ret < 0) kfree(asd);
dev_err(&pdev->dev, "async fwnode register failed: %d\n", ret);
return ret; return ret;
} }
...@@ -1092,6 +1112,12 @@ static int mipi_csis_probe(struct platform_device *pdev) ...@@ -1092,6 +1112,12 @@ static int mipi_csis_probe(struct platform_device *pdev)
if (ret < 0) if (ret < 0)
goto disable_clock; goto disable_clock;
ret = mipi_csis_async_register(state);
if (ret < 0) {
dev_err(&pdev->dev, "async register failed: %d\n", ret);
goto cleanup;
}
memcpy(state->events, mipi_csis_events, sizeof(state->events)); memcpy(state->events, mipi_csis_events, sizeof(state->events));
mipi_csis_debugfs_init(state); mipi_csis_debugfs_init(state);
...@@ -1110,7 +1136,10 @@ static int mipi_csis_probe(struct platform_device *pdev) ...@@ -1110,7 +1136,10 @@ static int mipi_csis_probe(struct platform_device *pdev)
unregister_all: unregister_all:
mipi_csis_debugfs_exit(state); mipi_csis_debugfs_exit(state);
cleanup:
media_entity_cleanup(&state->mipi_sd.entity); media_entity_cleanup(&state->mipi_sd.entity);
v4l2_async_notifier_unregister(&state->notifier);
v4l2_async_notifier_cleanup(&state->notifier);
v4l2_async_unregister_subdev(&state->mipi_sd); v4l2_async_unregister_subdev(&state->mipi_sd);
disable_clock: disable_clock:
mipi_csis_clk_disable(state); mipi_csis_clk_disable(state);
...@@ -1198,6 +1227,8 @@ static int mipi_csis_remove(struct platform_device *pdev) ...@@ -1198,6 +1227,8 @@ static int mipi_csis_remove(struct platform_device *pdev)
struct csi_state *state = mipi_sd_to_csis_state(mipi_sd); struct csi_state *state = mipi_sd_to_csis_state(mipi_sd);
mipi_csis_debugfs_exit(state); mipi_csis_debugfs_exit(state);
v4l2_async_notifier_unregister(&state->notifier);
v4l2_async_notifier_cleanup(&state->notifier);
v4l2_async_unregister_subdev(&state->mipi_sd); v4l2_async_unregister_subdev(&state->mipi_sd);
pm_runtime_disable(&pdev->dev); pm_runtime_disable(&pdev->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