/* * The companion CSI-2 receiver driver (rcar-csi2) is known * and we know it has one source pad (pad 0) and four sink * pads (pad 1-4). So to translate a pad on the remote * CSI-2 receiver to/from the VIN internal channel number simply * subtract/add one from the pad/channel number.
*/ #define rvin_group_csi_pad_to_channel(pad) ((pad) - 1) #define rvin_group_csi_channel_to_pad(channel) ((channel) + 1)
/* * Not all VINs are created equal, master VINs control the * routing for other VIN's. We can figure out which VIN is * master by looking at a VINs id.
*/ #define rvin_group_id_to_master(vin) ((vin) < 4 ? 0 : 4)
/* ----------------------------------------------------------------------------- * Gen3 Group Allocator
*/
/* FIXME: This should if we find a system that supports more * than one group for the whole system be replaced with a linked * list of groups. And eventually all of this should be replaced * with a global device allocator API. * * But for now this works as on all supported systems there will * be only one group for all instances.
*/
/* Count number of VINs in the system */
group->count = 0;
for_each_matching_node(np, vin->dev->driver->of_match_table) if (of_device_is_available(np))
group->count++;
vin_dbg(vin, "found %u enabled VIN's in DT", group->count);
group->link_setup = link_setup;
mdev->dev = vin->dev;
mdev->ops = ops;
match = of_match_node(vin->dev->driver->of_match_table,
vin->dev->of_node);
staticint rvin_group_get(struct rvin_dev *vin, int (*link_setup)(struct rvin_group *), conststruct media_device_ops *ops)
{ struct rvin_group *group; int ret;
/* Join or create a VIN group */
mutex_lock(&rvin_group_lock); if (rvin_group_data) {
group = rvin_group_data;
kref_get(&group->refcount);
} else {
group = kzalloc(sizeof(*group), GFP_KERNEL); if (!group) {
ret = -ENOMEM; goto err_group;
}
ret = rvin_group_init(group, vin, link_setup, ops); if (ret) {
kfree(group);
vin_err(vin, "Failed to initialize group\n"); goto err_group;
}
/* group lock should be held when calling this function. */ staticint rvin_group_entity_to_remote_id(struct rvin_group *group, struct media_entity *entity)
{ struct v4l2_subdev *sd; unsignedint i;
sd = media_entity_to_v4l2_subdev(entity);
for (i = 0; i < ARRAY_SIZE(group->remotes); i++) if (group->remotes[i].subdev == sd) return i;
ret = media_device_register(&vin->group->mdev); if (ret) return ret;
ret = v4l2_device_register_subdev_nodes(&vin->v4l2_dev); if (ret) {
vin_err(vin, "Failed to register subdev nodes\n"); return ret;
}
/* Register all video nodes for the group. */ for (i = 0; i < RCAR_VIN_NUM; i++) { if (vin->group->vin[i] &&
!video_is_registered(&vin->group->vin[i]->vdev)) {
ret = rvin_v4l2_register(vin->group->vin[i]); if (ret) return ret;
}
}
for (unsignedint i = 0; i < RCAR_VIN_NUM; i++) { struct rvin_dev *pvin = group->vin[i];
if (!pvin || pvin->parallel.asc != asc) continue;
pvin->parallel.source_pad = 0; for (unsignedint pad = 0; pad < subdev->entity.num_pads; pad++) if (subdev->entity.pads[pad].flags & MEDIA_PAD_FL_SOURCE)
pvin->parallel.source_pad = pad;
/* If not all VIN's are registered don't register the notifier. */ for (i = 0; i < RCAR_VIN_NUM; i++) { if (vin->group->vin[i]) {
count++;
vin_mask |= BIT(i);
}
}
if (vin->group->count != count) {
mutex_unlock(&vin->group->lock); return 0;
}
/* * Some subdevices may overlap but the parser function can handle it and * each subdevice will only be registered once with the group notifier.
*/ for (i = 0; i < RCAR_VIN_NUM; i++) { if (!(vin_mask & BIT(i))) continue;
/* Parse local subdevice. */
ret = rvin_parallel_parse_of(vin->group->vin[i]); if (ret) return ret;
/* Parse shared subdevices. */ for (id = 0; id < max_id; id++) { if (vin->group->remotes[id].asc) continue;
ret = rvin_group_parse_of(vin->group->vin[i], port, id); if (ret) return ret;
}
}
if (list_empty(&vin->group->notifier.waiting_list)) return 0;
vin->group->notifier.ops = &rvin_group_notify_ops;
ret = v4l2_async_nf_register(&vin->group->notifier); if (ret < 0) {
vin_err(vin, "Notifier registration failed\n");
v4l2_async_nf_cleanup(&vin->group->notifier); return ret;
}
/* * Link setup for the links between a VIN and a CSI-2 receiver is a bit * complex. The reason for this is that the register controlling routing * is not present in each VIN instance. There are special VINs which * control routing for themselves and other VINs. There are not many * different possible links combinations that can be enabled at the same * time, therefor all already enabled links which are controlled by a * master VIN need to be taken into account when making the decision * if a new link can be enabled or not. * * 1. Find out which VIN the link the user tries to enable is connected to. * 2. Lookup which master VIN controls the links for this VIN. * 3. Start with a bitmask with all bits set. * 4. For each previously enabled link from the master VIN bitwise AND its * route mask (see documentation for mask in struct rvin_group_route) * with the bitmask. * 5. Bitwise AND the mask for the link the user tries to enable to the bitmask. * 6. If the bitmask is not empty at this point the new link can be enabled * while keeping all previous links enabled. Update the CHSEL value of the * master VIN and inform the user that the link could be enabled. * * Please note that no link can be enabled if any VIN in the group is * currently open.
*/ staticint rvin_csi2_link_notify(struct media_link *link, u32 flags, unsignedint notification)
{ struct rvin_group *group = container_of(link->graph_obj.mdev, struct rvin_group, mdev); struct media_entity *entity; struct video_device *vdev; struct rvin_dev *vin; unsignedint i; int csi_id, ret;
ret = v4l2_pipeline_link_notify(link, flags, notification); if (ret) return ret;
/* Only care about link enablement for VIN nodes. */ if (!(flags & MEDIA_LNK_FL_ENABLED) ||
!is_media_entity_v4l2_video_device(link->sink->entity)) return 0;
/* * Don't allow link changes if any stream in the graph is active as * modifying the CHSEL register fields can disrupt running streams.
*/
media_device_for_each_entity(entity, &group->mdev) if (media_entity_is_streaming(entity)) return -EBUSY;
/* Find the master VIN that controls the routes. */
vdev = media_entity_to_video_device(link->sink->entity);
vin = container_of(vdev, struct rvin_dev, vdev);
/* * Make sure the source entity subdevice is registered as * a parallel input of one of the enabled VINs if it is not * one of the CSI-2 subdevices. * * No hardware configuration required for parallel inputs, * we can return here.
*/
sd = media_entity_to_v4l2_subdev(link->source->entity); for (i = 0; i < RCAR_VIN_NUM; i++) { if (group->vin[i] &&
group->vin[i]->parallel.subdev == sd) {
group->vin[i]->is_csi = false;
ret = 0; goto out;
}
}
vin_err(vin, "Subdevice %s not registered to any VIN\n",
link->source->entity->name);
ret = -ENODEV;
} else { conststruct rvin_group_route *route; unsignedint chsel = UINT_MAX; unsignedint master_id;
master_id = rvin_group_id_to_master(vin->id);
if (WARN_ON(!group->vin[master_id])) {
ret = -ENODEV; goto out;
}
/* Make sure group is connected to same CSI-2 */ for (i = master_id; i < master_id + 4; i++) { struct media_pad *csi_pad;
if (!group->vin[i]) continue;
/* Get remote CSI-2, if any. */
csi_pad = media_pad_remote_pad_first(
&group->vin[i]->vdev.entity.pads[0]); if (!csi_pad) continue;
if (csi_pad->entity != link->source->entity) {
vin_dbg(vin, "Already attached to %s\n",
csi_pad->entity->name);
ret = -EBUSY; goto out;
}
}
/* If the group also has links don't enable the link. */ for (unsignedint i = 0; i < ARRAY_SIZE(group->remotes); i++) { if (group->remotes[i].subdev) {
flags = 0; break;
}
}
/* Create links. */ for (unsignedint i = 0; i < RCAR_VIN_NUM; i++) { struct rvin_dev *vin = group->vin[i]; struct media_entity *source; struct media_entity *sink; int ret;
/* Nothing to do if there is no VIN or parallel subdev. */ if (!vin || !vin->parallel.subdev) continue;
ret = rvin_parallel_setup_links(group); if (ret) return ret;
/* Create all media device links between VINs and CSI-2's. */
mutex_lock(&group->lock); for (route = group->info->routes; route->chsel; route++) { /* Check that VIN' master is part of the group. */ if (!group->vin[route->master]) continue;
/* Check that CSI-2 is part of the group. */ if (!group->remotes[route->csi].subdev) continue;
for (id = route->master; id < route->master + 4; id++) { /* Check that VIN is part of the group. */ if (!group->vin[id]) continue;
ret = rvin_csi2_create_link(group, id, route); if (ret) goto out;
}
}
out:
mutex_unlock(&group->lock);
return ret;
}
staticint rvin_csi2_init(struct rvin_dev *vin)
{ int ret;
ret = rvin_group_get(vin, rvin_csi2_setup_links, &rvin_csi2_media_ops); if (ret) return ret;
ret = rvin_group_notifier_init(vin, 1, RVIN_CSI_MAX); if (ret)
rvin_group_put(vin);
/* * Restore group master CHSEL setting. * * This needs to be done by every VIN resuming not only the master * as we don't know if and in which order the master VINs will * be resumed.
*/ if (vin->info->model == RCAR_GEN3) { unsignedint master_id = rvin_group_id_to_master(vin->id); struct rvin_dev *master = vin->group->vin[master_id]; int ret;
if (WARN_ON(!master)) return -ENODEV;
ret = rvin_set_channel_routing(master, master->chsel); if (ret) return ret;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.