1 // SPDX-License-Identifier: GPL-2.0+
3 * Driver for Renesas R-Car VIN
5 * Copyright (C) 2016 Renesas Electronics Corp.
6 * Copyright (C) 2011-2013 Renesas Solutions Corp.
7 * Copyright (C) 2013 Cogent Embedded, Inc., <source@cogentembedded.com>
8 * Copyright (C) 2008 Magnus Damm
10 * Based on the soc-camera rcar_vin driver
13 #include <linux/module.h>
15 #include <linux/of_device.h>
16 #include <linux/of_graph.h>
17 #include <linux/platform_device.h>
18 #include <linux/pm_runtime.h>
19 #include <linux/slab.h>
20 #include <linux/sys_soc.h>
22 #include <media/v4l2-async.h>
23 #include <media/v4l2-fwnode.h>
24 #include <media/v4l2-mc.h>
29 * The companion CSI-2 receiver driver (rcar-csi2) is known
30 * and we know it has one source pad (pad 0) and four sink
31 * pads (pad 1-4). So to translate a pad on the remote
32 * CSI-2 receiver to/from the VIN internal channel number simply
33 * subtract/add one from the pad/channel number.
35 #define rvin_group_csi_pad_to_channel(pad) ((pad) - 1)
36 #define rvin_group_csi_channel_to_pad(channel) ((channel) + 1)
39 * Not all VINs are created equal, master VINs control the
40 * routing for other VIN's. We can figure out which VIN is
41 * master by looking at a VINs id.
43 #define rvin_group_id_to_master(vin) ((vin) < 4 ? 0 : 4)
45 #define v4l2_dev_to_vin(d) container_of(d, struct rvin_dev, v4l2_dev)
47 /* -----------------------------------------------------------------------------
48 * Media Controller link notification
51 /* group lock should be held when calling this function. */
52 static int rvin_group_entity_to_csi_id(struct rvin_group *group,
53 struct media_entity *entity)
55 struct v4l2_subdev *sd;
58 sd = media_entity_to_v4l2_subdev(entity);
60 for (i = 0; i < RVIN_CSI_MAX; i++)
61 if (group->csi[i].subdev == sd)
67 static unsigned int rvin_group_get_mask(struct rvin_dev *vin,
68 enum rvin_csi_id csi_id,
69 unsigned char channel)
71 const struct rvin_group_route *route;
72 unsigned int mask = 0;
74 for (route = vin->info->routes; route->mask; route++) {
75 if (route->vin == vin->id &&
76 route->csi == csi_id &&
77 route->channel == channel) {
79 "Adding route: vin: %d csi: %d channel: %d\n",
80 route->vin, route->csi, route->channel);
89 * Link setup for the links between a VIN and a CSI-2 receiver is a bit
90 * complex. The reason for this is that the register controlling routing
91 * is not present in each VIN instance. There are special VINs which
92 * control routing for themselves and other VINs. There are not many
93 * different possible links combinations that can be enabled at the same
94 * time, therefor all already enabled links which are controlled by a
95 * master VIN need to be taken into account when making the decision
96 * if a new link can be enabled or not.
98 * 1. Find out which VIN the link the user tries to enable is connected to.
99 * 2. Lookup which master VIN controls the links for this VIN.
100 * 3. Start with a bitmask with all bits set.
101 * 4. For each previously enabled link from the master VIN bitwise AND its
102 * route mask (see documentation for mask in struct rvin_group_route)
104 * 5. Bitwise AND the mask for the link the user tries to enable to the bitmask.
105 * 6. If the bitmask is not empty at this point the new link can be enabled
106 * while keeping all previous links enabled. Update the CHSEL value of the
107 * master VIN and inform the user that the link could be enabled.
109 * Please note that no link can be enabled if any VIN in the group is
112 static int rvin_group_link_notify(struct media_link *link, u32 flags,
113 unsigned int notification)
115 struct rvin_group *group = container_of(link->graph_obj.mdev,
116 struct rvin_group, mdev);
117 unsigned int master_id, channel, mask_new, i;
118 unsigned int mask = ~0;
119 struct media_entity *entity;
120 struct video_device *vdev;
121 struct media_pad *csi_pad;
122 struct rvin_dev *vin = NULL;
125 ret = v4l2_pipeline_link_notify(link, flags, notification);
129 /* Only care about link enablement for VIN nodes. */
130 if (!(flags & MEDIA_LNK_FL_ENABLED) ||
131 !is_media_entity_v4l2_video_device(link->sink->entity))
135 * Don't allow link changes if any entity in the graph is
136 * streaming, modifying the CHSEL register fields can disrupt
139 media_device_for_each_entity(entity, &group->mdev)
140 if (entity->stream_count)
143 mutex_lock(&group->lock);
145 /* Find the master VIN that controls the routes. */
146 vdev = media_entity_to_video_device(link->sink->entity);
147 vin = container_of(vdev, struct rvin_dev, vdev);
148 master_id = rvin_group_id_to_master(vin->id);
150 if (WARN_ON(!group->vin[master_id])) {
155 /* Build a mask for already enabled links. */
156 for (i = master_id; i < master_id + 4; i++) {
160 /* Get remote CSI-2, if any. */
161 csi_pad = media_entity_remote_pad(
162 &group->vin[i]->vdev.entity.pads[0]);
166 csi_id = rvin_group_entity_to_csi_id(group, csi_pad->entity);
167 channel = rvin_group_csi_pad_to_channel(csi_pad->index);
169 mask &= rvin_group_get_mask(group->vin[i], csi_id, channel);
172 /* Add the new link to the existing mask and check if it works. */
173 csi_id = rvin_group_entity_to_csi_id(group, link->source->entity);
175 if (csi_id == -ENODEV) {
176 struct v4l2_subdev *sd;
179 * Make sure the source entity subdevice is registered as
180 * a parallel input of one of the enabled VINs if it is not
181 * one of the CSI-2 subdevices.
183 * No hardware configuration required for parallel inputs,
184 * we can return here.
186 sd = media_entity_to_v4l2_subdev(link->source->entity);
187 for (i = 0; i < RCAR_VIN_NUM; i++) {
188 if (group->vin[i] && group->vin[i]->parallel &&
189 group->vin[i]->parallel->subdev == sd) {
190 group->vin[i]->is_csi = false;
196 vin_err(vin, "Subdevice %s not registered to any VIN\n",
197 link->source->entity->name);
202 channel = rvin_group_csi_pad_to_channel(link->source->index);
203 mask_new = mask & rvin_group_get_mask(vin, csi_id, channel);
204 vin_dbg(vin, "Try link change mask: 0x%x new: 0x%x\n", mask, mask_new);
211 /* New valid CHSEL found, set the new value. */
212 ret = rvin_set_channel_routing(group->vin[master_id], __ffs(mask_new));
219 mutex_unlock(&group->lock);
224 static const struct media_device_ops rvin_media_ops = {
225 .link_notify = rvin_group_link_notify,
228 /* -----------------------------------------------------------------------------
229 * Gen3 CSI2 Group Allocator
232 /* FIXME: This should if we find a system that supports more
233 * than one group for the whole system be replaced with a linked
234 * list of groups. And eventually all of this should be replaced
235 * with a global device allocator API.
237 * But for now this works as on all supported systems there will
238 * be only one group for all instances.
241 static DEFINE_MUTEX(rvin_group_lock);
242 static struct rvin_group *rvin_group_data;
244 static void rvin_group_cleanup(struct rvin_group *group)
246 media_device_cleanup(&group->mdev);
247 mutex_destroy(&group->lock);
250 static int rvin_group_init(struct rvin_group *group, struct rvin_dev *vin)
252 struct media_device *mdev = &group->mdev;
253 const struct of_device_id *match;
254 struct device_node *np;
256 mutex_init(&group->lock);
258 /* Count number of VINs in the system */
260 for_each_matching_node(np, vin->dev->driver->of_match_table)
261 if (of_device_is_available(np))
264 vin_dbg(vin, "found %u enabled VIN's in DT", group->count);
266 mdev->dev = vin->dev;
267 mdev->ops = &rvin_media_ops;
269 match = of_match_node(vin->dev->driver->of_match_table,
272 strscpy(mdev->driver_name, KBUILD_MODNAME, sizeof(mdev->driver_name));
273 strscpy(mdev->model, match->compatible, sizeof(mdev->model));
274 snprintf(mdev->bus_info, sizeof(mdev->bus_info), "platform:%s",
275 dev_name(mdev->dev));
277 media_device_init(mdev);
282 static void rvin_group_release(struct kref *kref)
284 struct rvin_group *group =
285 container_of(kref, struct rvin_group, refcount);
287 mutex_lock(&rvin_group_lock);
289 rvin_group_data = NULL;
291 rvin_group_cleanup(group);
295 mutex_unlock(&rvin_group_lock);
298 static int rvin_group_get(struct rvin_dev *vin)
300 struct rvin_group *group;
304 /* Make sure VIN id is present and sane */
305 ret = of_property_read_u32(vin->dev->of_node, "renesas,id", &id);
307 vin_err(vin, "%pOF: No renesas,id property found\n",
312 if (id >= RCAR_VIN_NUM) {
313 vin_err(vin, "%pOF: Invalid renesas,id '%u'\n",
314 vin->dev->of_node, id);
318 /* Join or create a VIN group */
319 mutex_lock(&rvin_group_lock);
320 if (rvin_group_data) {
321 group = rvin_group_data;
322 kref_get(&group->refcount);
324 group = kzalloc(sizeof(*group), GFP_KERNEL);
330 ret = rvin_group_init(group, vin);
333 vin_err(vin, "Failed to initialize group\n");
337 kref_init(&group->refcount);
339 rvin_group_data = group;
341 mutex_unlock(&rvin_group_lock);
343 /* Add VIN to group */
344 mutex_lock(&group->lock);
346 if (group->vin[id]) {
347 vin_err(vin, "Duplicate renesas,id property value %u\n", id);
348 mutex_unlock(&group->lock);
349 kref_put(&group->refcount, rvin_group_release);
353 group->vin[id] = vin;
357 vin->v4l2_dev.mdev = &group->mdev;
359 mutex_unlock(&group->lock);
363 mutex_unlock(&rvin_group_lock);
367 static void rvin_group_put(struct rvin_dev *vin)
369 struct rvin_group *group = vin->group;
371 mutex_lock(&group->lock);
374 vin->v4l2_dev.mdev = NULL;
376 if (WARN_ON(group->vin[vin->id] != vin))
379 group->vin[vin->id] = NULL;
381 mutex_unlock(&group->lock);
383 kref_put(&group->refcount, rvin_group_release);
386 /* -----------------------------------------------------------------------------
390 static int rvin_s_ctrl(struct v4l2_ctrl *ctrl)
392 struct rvin_dev *vin =
393 container_of(ctrl->handler, struct rvin_dev, ctrl_handler);
396 case V4L2_CID_ALPHA_COMPONENT:
397 rvin_set_alpha(vin, ctrl->val);
404 static const struct v4l2_ctrl_ops rvin_ctrl_ops = {
405 .s_ctrl = rvin_s_ctrl,
408 /* -----------------------------------------------------------------------------
412 static int rvin_find_pad(struct v4l2_subdev *sd, int direction)
416 if (sd->entity.num_pads <= 1)
419 for (pad = 0; pad < sd->entity.num_pads; pad++)
420 if (sd->entity.pads[pad].flags & direction)
426 /* -----------------------------------------------------------------------------
427 * Parallel async notifier
430 /* The vin lock should be held when calling the subdevice attach and detach */
431 static int rvin_parallel_subdevice_attach(struct rvin_dev *vin,
432 struct v4l2_subdev *subdev)
434 struct v4l2_subdev_mbus_code_enum code = {
435 .which = V4L2_SUBDEV_FORMAT_ACTIVE,
439 /* Find source and sink pad of remote subdevice */
440 ret = rvin_find_pad(subdev, MEDIA_PAD_FL_SOURCE);
443 vin->parallel->source_pad = ret;
445 ret = rvin_find_pad(subdev, MEDIA_PAD_FL_SINK);
446 vin->parallel->sink_pad = ret < 0 ? 0 : ret;
448 if (vin->info->use_mc) {
449 vin->parallel->subdev = subdev;
453 /* Find compatible subdevices mbus format */
456 code.pad = vin->parallel->source_pad;
457 while (!vin->mbus_code &&
458 !v4l2_subdev_call(subdev, pad, enum_mbus_code, NULL, &code)) {
461 case MEDIA_BUS_FMT_YUYV8_1X16:
462 case MEDIA_BUS_FMT_UYVY8_1X16:
463 case MEDIA_BUS_FMT_UYVY8_2X8:
464 case MEDIA_BUS_FMT_UYVY10_2X10:
465 case MEDIA_BUS_FMT_RGB888_1X24:
466 vin->mbus_code = code.code;
467 vin_dbg(vin, "Found media bus format for %s: %d\n",
468 subdev->name, vin->mbus_code);
475 if (!vin->mbus_code) {
476 vin_err(vin, "Unsupported media bus format for %s\n",
482 ret = v4l2_subdev_call(subdev, video, g_tvnorms, &vin->vdev.tvnorms);
483 if (ret < 0 && ret != -ENOIOCTLCMD && ret != -ENODEV)
487 vin->std = V4L2_STD_UNKNOWN;
488 ret = v4l2_subdev_call(subdev, video, g_std, &vin->std);
489 if (ret < 0 && ret != -ENOIOCTLCMD)
492 /* Add the controls */
493 ret = v4l2_ctrl_handler_init(&vin->ctrl_handler, 16);
497 v4l2_ctrl_new_std(&vin->ctrl_handler, &rvin_ctrl_ops,
498 V4L2_CID_ALPHA_COMPONENT, 0, 255, 1, 255);
500 if (vin->ctrl_handler.error) {
501 ret = vin->ctrl_handler.error;
502 v4l2_ctrl_handler_free(&vin->ctrl_handler);
506 ret = v4l2_ctrl_add_handler(&vin->ctrl_handler, subdev->ctrl_handler,
509 v4l2_ctrl_handler_free(&vin->ctrl_handler);
513 vin->vdev.ctrl_handler = &vin->ctrl_handler;
515 vin->parallel->subdev = subdev;
520 static void rvin_parallel_subdevice_detach(struct rvin_dev *vin)
522 rvin_v4l2_unregister(vin);
523 vin->parallel->subdev = NULL;
525 if (!vin->info->use_mc) {
526 v4l2_ctrl_handler_free(&vin->ctrl_handler);
527 vin->vdev.ctrl_handler = NULL;
531 static int rvin_parallel_notify_complete(struct v4l2_async_notifier *notifier)
533 struct rvin_dev *vin = v4l2_dev_to_vin(notifier->v4l2_dev);
534 struct media_entity *source;
535 struct media_entity *sink;
538 ret = v4l2_device_register_subdev_nodes(&vin->v4l2_dev);
540 vin_err(vin, "Failed to register subdev nodes\n");
544 if (!video_is_registered(&vin->vdev)) {
545 ret = rvin_v4l2_register(vin);
550 if (!vin->info->use_mc)
553 /* If we're running with media-controller, link the subdevs. */
554 source = &vin->parallel->subdev->entity;
555 sink = &vin->vdev.entity;
557 ret = media_create_pad_link(source, vin->parallel->source_pad,
558 sink, vin->parallel->sink_pad, 0);
560 vin_err(vin, "Error adding link from %s to %s: %d\n",
561 source->name, sink->name, ret);
566 static void rvin_parallel_notify_unbind(struct v4l2_async_notifier *notifier,
567 struct v4l2_subdev *subdev,
568 struct v4l2_async_subdev *asd)
570 struct rvin_dev *vin = v4l2_dev_to_vin(notifier->v4l2_dev);
572 vin_dbg(vin, "unbind parallel subdev %s\n", subdev->name);
574 mutex_lock(&vin->lock);
575 rvin_parallel_subdevice_detach(vin);
576 mutex_unlock(&vin->lock);
579 static int rvin_parallel_notify_bound(struct v4l2_async_notifier *notifier,
580 struct v4l2_subdev *subdev,
581 struct v4l2_async_subdev *asd)
583 struct rvin_dev *vin = v4l2_dev_to_vin(notifier->v4l2_dev);
586 mutex_lock(&vin->lock);
587 ret = rvin_parallel_subdevice_attach(vin, subdev);
588 mutex_unlock(&vin->lock);
592 v4l2_set_subdev_hostdata(subdev, vin);
594 vin_dbg(vin, "bound subdev %s source pad: %u sink pad: %u\n",
595 subdev->name, vin->parallel->source_pad,
596 vin->parallel->sink_pad);
601 static const struct v4l2_async_notifier_operations rvin_parallel_notify_ops = {
602 .bound = rvin_parallel_notify_bound,
603 .unbind = rvin_parallel_notify_unbind,
604 .complete = rvin_parallel_notify_complete,
607 static int rvin_parallel_parse_v4l2(struct device *dev,
608 struct v4l2_fwnode_endpoint *vep,
609 struct v4l2_async_subdev *asd)
611 struct rvin_dev *vin = dev_get_drvdata(dev);
612 struct rvin_parallel_entity *rvpe =
613 container_of(asd, struct rvin_parallel_entity, asd);
615 if (vep->base.port || vep->base.id)
618 vin->parallel = rvpe;
619 vin->parallel->mbus_type = vep->bus_type;
621 switch (vin->parallel->mbus_type) {
622 case V4L2_MBUS_PARALLEL:
623 case V4L2_MBUS_BT656:
624 vin_dbg(vin, "Found %s media bus\n",
625 vin->parallel->mbus_type == V4L2_MBUS_PARALLEL ?
626 "PARALLEL" : "BT656");
627 vin->parallel->bus = vep->bus.parallel;
630 vin_err(vin, "Unknown media bus type\n");
637 static int rvin_parallel_init(struct rvin_dev *vin)
641 v4l2_async_notifier_init(&vin->notifier);
643 ret = v4l2_async_notifier_parse_fwnode_endpoints_by_port(
644 vin->dev, &vin->notifier, sizeof(struct rvin_parallel_entity),
645 0, rvin_parallel_parse_v4l2);
649 /* If using mc, it's fine not to have any input registered. */
651 return vin->info->use_mc ? 0 : -ENODEV;
653 vin_dbg(vin, "Found parallel subdevice %pOF\n",
654 to_of_node(vin->parallel->asd.match.fwnode));
656 vin->notifier.ops = &rvin_parallel_notify_ops;
657 ret = v4l2_async_notifier_register(&vin->v4l2_dev, &vin->notifier);
659 vin_err(vin, "Notifier registration failed\n");
660 v4l2_async_notifier_cleanup(&vin->notifier);
667 /* -----------------------------------------------------------------------------
668 * Group async notifier
671 static int rvin_group_notify_complete(struct v4l2_async_notifier *notifier)
673 struct rvin_dev *vin = v4l2_dev_to_vin(notifier->v4l2_dev);
674 const struct rvin_group_route *route;
678 ret = media_device_register(&vin->group->mdev);
682 ret = v4l2_device_register_subdev_nodes(&vin->v4l2_dev);
684 vin_err(vin, "Failed to register subdev nodes\n");
688 /* Register all video nodes for the group. */
689 for (i = 0; i < RCAR_VIN_NUM; i++) {
690 if (vin->group->vin[i] &&
691 !video_is_registered(&vin->group->vin[i]->vdev)) {
692 ret = rvin_v4l2_register(vin->group->vin[i]);
698 /* Create all media device links between VINs and CSI-2's. */
699 mutex_lock(&vin->group->lock);
700 for (route = vin->info->routes; route->mask; route++) {
701 struct media_pad *source_pad, *sink_pad;
702 struct media_entity *source, *sink;
703 unsigned int source_idx;
705 /* Check that VIN is part of the group. */
706 if (!vin->group->vin[route->vin])
709 /* Check that VIN' master is part of the group. */
710 if (!vin->group->vin[rvin_group_id_to_master(route->vin)])
713 /* Check that CSI-2 is part of the group. */
714 if (!vin->group->csi[route->csi].subdev)
717 source = &vin->group->csi[route->csi].subdev->entity;
718 source_idx = rvin_group_csi_channel_to_pad(route->channel);
719 source_pad = &source->pads[source_idx];
721 sink = &vin->group->vin[route->vin]->vdev.entity;
722 sink_pad = &sink->pads[0];
724 /* Skip if link already exists. */
725 if (media_entity_find_link(source_pad, sink_pad))
728 ret = media_create_pad_link(source, source_idx, sink, 0, 0);
730 vin_err(vin, "Error adding link from %s to %s\n",
731 source->name, sink->name);
735 mutex_unlock(&vin->group->lock);
740 static void rvin_group_notify_unbind(struct v4l2_async_notifier *notifier,
741 struct v4l2_subdev *subdev,
742 struct v4l2_async_subdev *asd)
744 struct rvin_dev *vin = v4l2_dev_to_vin(notifier->v4l2_dev);
747 for (i = 0; i < RCAR_VIN_NUM; i++)
748 if (vin->group->vin[i])
749 rvin_v4l2_unregister(vin->group->vin[i]);
751 mutex_lock(&vin->group->lock);
753 for (i = 0; i < RVIN_CSI_MAX; i++) {
754 if (vin->group->csi[i].fwnode != asd->match.fwnode)
756 vin->group->csi[i].subdev = NULL;
757 vin_dbg(vin, "Unbind CSI-2 %s from slot %u\n", subdev->name, i);
761 mutex_unlock(&vin->group->lock);
763 media_device_unregister(&vin->group->mdev);
766 static int rvin_group_notify_bound(struct v4l2_async_notifier *notifier,
767 struct v4l2_subdev *subdev,
768 struct v4l2_async_subdev *asd)
770 struct rvin_dev *vin = v4l2_dev_to_vin(notifier->v4l2_dev);
773 mutex_lock(&vin->group->lock);
775 for (i = 0; i < RVIN_CSI_MAX; i++) {
776 if (vin->group->csi[i].fwnode != asd->match.fwnode)
778 vin->group->csi[i].subdev = subdev;
779 vin_dbg(vin, "Bound CSI-2 %s to slot %u\n", subdev->name, i);
783 mutex_unlock(&vin->group->lock);
788 static const struct v4l2_async_notifier_operations rvin_group_notify_ops = {
789 .bound = rvin_group_notify_bound,
790 .unbind = rvin_group_notify_unbind,
791 .complete = rvin_group_notify_complete,
794 static int rvin_mc_parse_of_endpoint(struct device *dev,
795 struct v4l2_fwnode_endpoint *vep,
796 struct v4l2_async_subdev *asd)
798 struct rvin_dev *vin = dev_get_drvdata(dev);
801 if (vep->base.port != 1 || vep->base.id >= RVIN_CSI_MAX)
804 if (!of_device_is_available(to_of_node(asd->match.fwnode))) {
805 vin_dbg(vin, "OF device %pOF disabled, ignoring\n",
806 to_of_node(asd->match.fwnode));
810 mutex_lock(&vin->group->lock);
812 if (vin->group->csi[vep->base.id].fwnode) {
813 vin_dbg(vin, "OF device %pOF already handled\n",
814 to_of_node(asd->match.fwnode));
819 vin->group->csi[vep->base.id].fwnode = asd->match.fwnode;
821 vin_dbg(vin, "Add group OF device %pOF to slot %u\n",
822 to_of_node(asd->match.fwnode), vep->base.id);
824 mutex_unlock(&vin->group->lock);
829 static int rvin_mc_parse_of_graph(struct rvin_dev *vin)
831 unsigned int count = 0, vin_mask = 0;
835 mutex_lock(&vin->group->lock);
837 /* If not all VIN's are registered don't register the notifier. */
838 for (i = 0; i < RCAR_VIN_NUM; i++) {
839 if (vin->group->vin[i]) {
845 if (vin->group->count != count) {
846 mutex_unlock(&vin->group->lock);
850 mutex_unlock(&vin->group->lock);
852 v4l2_async_notifier_init(&vin->group->notifier);
855 * Have all VIN's look for CSI-2 subdevices. Some subdevices will
856 * overlap but the parser function can handle it, so each subdevice
857 * will only be registered once with the group notifier.
859 for (i = 0; i < RCAR_VIN_NUM; i++) {
860 if (!(vin_mask & BIT(i)))
863 ret = v4l2_async_notifier_parse_fwnode_endpoints_by_port(
864 vin->group->vin[i]->dev, &vin->group->notifier,
865 sizeof(struct v4l2_async_subdev), 1,
866 rvin_mc_parse_of_endpoint);
871 if (list_empty(&vin->group->notifier.asd_list))
874 vin->group->notifier.ops = &rvin_group_notify_ops;
875 ret = v4l2_async_notifier_register(&vin->v4l2_dev,
876 &vin->group->notifier);
878 vin_err(vin, "Notifier registration failed\n");
879 v4l2_async_notifier_cleanup(&vin->group->notifier);
886 static int rvin_mc_init(struct rvin_dev *vin)
890 vin->pad.flags = MEDIA_PAD_FL_SINK;
891 ret = media_entity_pads_init(&vin->vdev.entity, 1, &vin->pad);
895 ret = rvin_group_get(vin);
899 ret = rvin_mc_parse_of_graph(vin);
903 ret = v4l2_ctrl_handler_init(&vin->ctrl_handler, 1);
907 v4l2_ctrl_new_std(&vin->ctrl_handler, &rvin_ctrl_ops,
908 V4L2_CID_ALPHA_COMPONENT, 0, 255, 1, 255);
910 if (vin->ctrl_handler.error) {
911 ret = vin->ctrl_handler.error;
912 v4l2_ctrl_handler_free(&vin->ctrl_handler);
916 vin->vdev.ctrl_handler = &vin->ctrl_handler;
921 /* -----------------------------------------------------------------------------
925 static int __maybe_unused rvin_suspend(struct device *dev)
927 struct rvin_dev *vin = dev_get_drvdata(dev);
929 if (vin->state != RUNNING)
932 rvin_stop_streaming(vin);
934 vin->state = SUSPENDED;
939 static int __maybe_unused rvin_resume(struct device *dev)
941 struct rvin_dev *vin = dev_get_drvdata(dev);
943 if (vin->state != SUSPENDED)
947 * Restore group master CHSEL setting.
949 * This needs to be done by every VIN resuming not only the master
950 * as we don't know if and in which order the master VINs will
953 if (vin->info->use_mc) {
954 unsigned int master_id = rvin_group_id_to_master(vin->id);
955 struct rvin_dev *master = vin->group->vin[master_id];
958 if (WARN_ON(!master))
961 ret = rvin_set_channel_routing(master, master->chsel);
966 return rvin_start_streaming(vin);
969 /* -----------------------------------------------------------------------------
970 * Platform Device Driver
973 static const struct rvin_info rcar_info_h1 = {
980 static const struct rvin_info rcar_info_m1 = {
987 static const struct rvin_info rcar_info_gen2 = {
994 static const struct rvin_group_route rcar_info_r8a774e1_routes[] = {
995 { .csi = RVIN_CSI40, .channel = 0, .vin = 0, .mask = BIT(0) | BIT(3) },
996 { .csi = RVIN_CSI20, .channel = 0, .vin = 0, .mask = BIT(1) | BIT(4) },
997 { .csi = RVIN_CSI40, .channel = 1, .vin = 0, .mask = BIT(2) },
998 { .csi = RVIN_CSI20, .channel = 0, .vin = 1, .mask = BIT(0) },
999 { .csi = RVIN_CSI40, .channel = 1, .vin = 1, .mask = BIT(1) | BIT(3) },
1000 { .csi = RVIN_CSI40, .channel = 0, .vin = 1, .mask = BIT(2) },
1001 { .csi = RVIN_CSI20, .channel = 1, .vin = 1, .mask = BIT(4) },
1002 { .csi = RVIN_CSI20, .channel = 1, .vin = 2, .mask = BIT(0) },
1003 { .csi = RVIN_CSI40, .channel = 0, .vin = 2, .mask = BIT(1) },
1004 { .csi = RVIN_CSI20, .channel = 0, .vin = 2, .mask = BIT(2) },
1005 { .csi = RVIN_CSI40, .channel = 2, .vin = 2, .mask = BIT(3) },
1006 { .csi = RVIN_CSI20, .channel = 2, .vin = 2, .mask = BIT(4) },
1007 { .csi = RVIN_CSI40, .channel = 1, .vin = 3, .mask = BIT(0) },
1008 { .csi = RVIN_CSI20, .channel = 1, .vin = 3, .mask = BIT(1) | BIT(2) },
1009 { .csi = RVIN_CSI40, .channel = 3, .vin = 3, .mask = BIT(3) },
1010 { .csi = RVIN_CSI20, .channel = 3, .vin = 3, .mask = BIT(4) },
1011 { .csi = RVIN_CSI20, .channel = 0, .vin = 4, .mask = BIT(1) | BIT(4) },
1012 { .csi = RVIN_CSI20, .channel = 0, .vin = 5, .mask = BIT(0) },
1013 { .csi = RVIN_CSI20, .channel = 1, .vin = 5, .mask = BIT(4) },
1014 { .csi = RVIN_CSI20, .channel = 1, .vin = 6, .mask = BIT(0) },
1015 { .csi = RVIN_CSI20, .channel = 0, .vin = 6, .mask = BIT(2) },
1016 { .csi = RVIN_CSI20, .channel = 2, .vin = 6, .mask = BIT(4) },
1017 { .csi = RVIN_CSI20, .channel = 1, .vin = 7, .mask = BIT(1) | BIT(2) },
1018 { .csi = RVIN_CSI20, .channel = 3, .vin = 7, .mask = BIT(4) },
1022 static const struct rvin_info rcar_info_r8a774e1 = {
1027 .routes = rcar_info_r8a774e1_routes,
1030 static const struct rvin_group_route rcar_info_r8a7795_routes[] = {
1031 { .csi = RVIN_CSI40, .channel = 0, .vin = 0, .mask = BIT(0) | BIT(3) },
1032 { .csi = RVIN_CSI20, .channel = 0, .vin = 0, .mask = BIT(1) | BIT(4) },
1033 { .csi = RVIN_CSI40, .channel = 1, .vin = 0, .mask = BIT(2) },
1034 { .csi = RVIN_CSI20, .channel = 0, .vin = 1, .mask = BIT(0) },
1035 { .csi = RVIN_CSI40, .channel = 1, .vin = 1, .mask = BIT(1) | BIT(3) },
1036 { .csi = RVIN_CSI40, .channel = 0, .vin = 1, .mask = BIT(2) },
1037 { .csi = RVIN_CSI20, .channel = 1, .vin = 1, .mask = BIT(4) },
1038 { .csi = RVIN_CSI20, .channel = 1, .vin = 2, .mask = BIT(0) },
1039 { .csi = RVIN_CSI40, .channel = 0, .vin = 2, .mask = BIT(1) },
1040 { .csi = RVIN_CSI20, .channel = 0, .vin = 2, .mask = BIT(2) },
1041 { .csi = RVIN_CSI40, .channel = 2, .vin = 2, .mask = BIT(3) },
1042 { .csi = RVIN_CSI20, .channel = 2, .vin = 2, .mask = BIT(4) },
1043 { .csi = RVIN_CSI40, .channel = 1, .vin = 3, .mask = BIT(0) },
1044 { .csi = RVIN_CSI20, .channel = 1, .vin = 3, .mask = BIT(1) | BIT(2) },
1045 { .csi = RVIN_CSI40, .channel = 3, .vin = 3, .mask = BIT(3) },
1046 { .csi = RVIN_CSI20, .channel = 3, .vin = 3, .mask = BIT(4) },
1047 { .csi = RVIN_CSI41, .channel = 0, .vin = 4, .mask = BIT(0) | BIT(3) },
1048 { .csi = RVIN_CSI20, .channel = 0, .vin = 4, .mask = BIT(1) | BIT(4) },
1049 { .csi = RVIN_CSI41, .channel = 1, .vin = 4, .mask = BIT(2) },
1050 { .csi = RVIN_CSI20, .channel = 0, .vin = 5, .mask = BIT(0) },
1051 { .csi = RVIN_CSI41, .channel = 1, .vin = 5, .mask = BIT(1) | BIT(3) },
1052 { .csi = RVIN_CSI41, .channel = 0, .vin = 5, .mask = BIT(2) },
1053 { .csi = RVIN_CSI20, .channel = 1, .vin = 5, .mask = BIT(4) },
1054 { .csi = RVIN_CSI20, .channel = 1, .vin = 6, .mask = BIT(0) },
1055 { .csi = RVIN_CSI41, .channel = 0, .vin = 6, .mask = BIT(1) },
1056 { .csi = RVIN_CSI20, .channel = 0, .vin = 6, .mask = BIT(2) },
1057 { .csi = RVIN_CSI41, .channel = 2, .vin = 6, .mask = BIT(3) },
1058 { .csi = RVIN_CSI20, .channel = 2, .vin = 6, .mask = BIT(4) },
1059 { .csi = RVIN_CSI41, .channel = 1, .vin = 7, .mask = BIT(0) },
1060 { .csi = RVIN_CSI20, .channel = 1, .vin = 7, .mask = BIT(1) | BIT(2) },
1061 { .csi = RVIN_CSI41, .channel = 3, .vin = 7, .mask = BIT(3) },
1062 { .csi = RVIN_CSI20, .channel = 3, .vin = 7, .mask = BIT(4) },
1066 static const struct rvin_info rcar_info_r8a7795 = {
1072 .routes = rcar_info_r8a7795_routes,
1075 static const struct rvin_group_route rcar_info_r8a7795es1_routes[] = {
1076 { .csi = RVIN_CSI40, .channel = 0, .vin = 0, .mask = BIT(0) | BIT(3) },
1077 { .csi = RVIN_CSI20, .channel = 0, .vin = 0, .mask = BIT(1) | BIT(4) },
1078 { .csi = RVIN_CSI21, .channel = 0, .vin = 0, .mask = BIT(2) | BIT(5) },
1079 { .csi = RVIN_CSI20, .channel = 0, .vin = 1, .mask = BIT(0) },
1080 { .csi = RVIN_CSI21, .channel = 0, .vin = 1, .mask = BIT(1) },
1081 { .csi = RVIN_CSI40, .channel = 0, .vin = 1, .mask = BIT(2) },
1082 { .csi = RVIN_CSI40, .channel = 1, .vin = 1, .mask = BIT(3) },
1083 { .csi = RVIN_CSI20, .channel = 1, .vin = 1, .mask = BIT(4) },
1084 { .csi = RVIN_CSI21, .channel = 1, .vin = 1, .mask = BIT(5) },
1085 { .csi = RVIN_CSI21, .channel = 0, .vin = 2, .mask = BIT(0) },
1086 { .csi = RVIN_CSI40, .channel = 0, .vin = 2, .mask = BIT(1) },
1087 { .csi = RVIN_CSI20, .channel = 0, .vin = 2, .mask = BIT(2) },
1088 { .csi = RVIN_CSI40, .channel = 2, .vin = 2, .mask = BIT(3) },
1089 { .csi = RVIN_CSI20, .channel = 2, .vin = 2, .mask = BIT(4) },
1090 { .csi = RVIN_CSI21, .channel = 2, .vin = 2, .mask = BIT(5) },
1091 { .csi = RVIN_CSI40, .channel = 1, .vin = 3, .mask = BIT(0) },
1092 { .csi = RVIN_CSI20, .channel = 1, .vin = 3, .mask = BIT(1) },
1093 { .csi = RVIN_CSI21, .channel = 1, .vin = 3, .mask = BIT(2) },
1094 { .csi = RVIN_CSI40, .channel = 3, .vin = 3, .mask = BIT(3) },
1095 { .csi = RVIN_CSI20, .channel = 3, .vin = 3, .mask = BIT(4) },
1096 { .csi = RVIN_CSI21, .channel = 3, .vin = 3, .mask = BIT(5) },
1097 { .csi = RVIN_CSI41, .channel = 0, .vin = 4, .mask = BIT(0) | BIT(3) },
1098 { .csi = RVIN_CSI20, .channel = 0, .vin = 4, .mask = BIT(1) | BIT(4) },
1099 { .csi = RVIN_CSI21, .channel = 0, .vin = 4, .mask = BIT(2) | BIT(5) },
1100 { .csi = RVIN_CSI20, .channel = 0, .vin = 5, .mask = BIT(0) },
1101 { .csi = RVIN_CSI21, .channel = 0, .vin = 5, .mask = BIT(1) },
1102 { .csi = RVIN_CSI41, .channel = 0, .vin = 5, .mask = BIT(2) },
1103 { .csi = RVIN_CSI41, .channel = 1, .vin = 5, .mask = BIT(3) },
1104 { .csi = RVIN_CSI20, .channel = 1, .vin = 5, .mask = BIT(4) },
1105 { .csi = RVIN_CSI21, .channel = 1, .vin = 5, .mask = BIT(5) },
1106 { .csi = RVIN_CSI21, .channel = 0, .vin = 6, .mask = BIT(0) },
1107 { .csi = RVIN_CSI41, .channel = 0, .vin = 6, .mask = BIT(1) },
1108 { .csi = RVIN_CSI20, .channel = 0, .vin = 6, .mask = BIT(2) },
1109 { .csi = RVIN_CSI41, .channel = 2, .vin = 6, .mask = BIT(3) },
1110 { .csi = RVIN_CSI20, .channel = 2, .vin = 6, .mask = BIT(4) },
1111 { .csi = RVIN_CSI21, .channel = 2, .vin = 6, .mask = BIT(5) },
1112 { .csi = RVIN_CSI41, .channel = 1, .vin = 7, .mask = BIT(0) },
1113 { .csi = RVIN_CSI20, .channel = 1, .vin = 7, .mask = BIT(1) },
1114 { .csi = RVIN_CSI21, .channel = 1, .vin = 7, .mask = BIT(2) },
1115 { .csi = RVIN_CSI41, .channel = 3, .vin = 7, .mask = BIT(3) },
1116 { .csi = RVIN_CSI20, .channel = 3, .vin = 7, .mask = BIT(4) },
1117 { .csi = RVIN_CSI21, .channel = 3, .vin = 7, .mask = BIT(5) },
1121 static const struct rvin_info rcar_info_r8a7795es1 = {
1126 .routes = rcar_info_r8a7795es1_routes,
1129 static const struct rvin_group_route rcar_info_r8a7796_routes[] = {
1130 { .csi = RVIN_CSI40, .channel = 0, .vin = 0, .mask = BIT(0) | BIT(3) },
1131 { .csi = RVIN_CSI20, .channel = 0, .vin = 0, .mask = BIT(1) | BIT(4) },
1132 { .csi = RVIN_CSI20, .channel = 0, .vin = 1, .mask = BIT(0) },
1133 { .csi = RVIN_CSI40, .channel = 0, .vin = 1, .mask = BIT(2) },
1134 { .csi = RVIN_CSI40, .channel = 1, .vin = 1, .mask = BIT(3) },
1135 { .csi = RVIN_CSI20, .channel = 1, .vin = 1, .mask = BIT(4) },
1136 { .csi = RVIN_CSI40, .channel = 0, .vin = 2, .mask = BIT(1) },
1137 { .csi = RVIN_CSI20, .channel = 0, .vin = 2, .mask = BIT(2) },
1138 { .csi = RVIN_CSI40, .channel = 2, .vin = 2, .mask = BIT(3) },
1139 { .csi = RVIN_CSI20, .channel = 2, .vin = 2, .mask = BIT(4) },
1140 { .csi = RVIN_CSI40, .channel = 1, .vin = 3, .mask = BIT(0) },
1141 { .csi = RVIN_CSI20, .channel = 1, .vin = 3, .mask = BIT(1) },
1142 { .csi = RVIN_CSI40, .channel = 3, .vin = 3, .mask = BIT(3) },
1143 { .csi = RVIN_CSI20, .channel = 3, .vin = 3, .mask = BIT(4) },
1144 { .csi = RVIN_CSI40, .channel = 0, .vin = 4, .mask = BIT(0) | BIT(3) },
1145 { .csi = RVIN_CSI20, .channel = 0, .vin = 4, .mask = BIT(1) | BIT(4) },
1146 { .csi = RVIN_CSI20, .channel = 0, .vin = 5, .mask = BIT(0) },
1147 { .csi = RVIN_CSI40, .channel = 0, .vin = 5, .mask = BIT(2) },
1148 { .csi = RVIN_CSI40, .channel = 1, .vin = 5, .mask = BIT(3) },
1149 { .csi = RVIN_CSI20, .channel = 1, .vin = 5, .mask = BIT(4) },
1150 { .csi = RVIN_CSI40, .channel = 0, .vin = 6, .mask = BIT(1) },
1151 { .csi = RVIN_CSI20, .channel = 0, .vin = 6, .mask = BIT(2) },
1152 { .csi = RVIN_CSI40, .channel = 2, .vin = 6, .mask = BIT(3) },
1153 { .csi = RVIN_CSI20, .channel = 2, .vin = 6, .mask = BIT(4) },
1154 { .csi = RVIN_CSI40, .channel = 1, .vin = 7, .mask = BIT(0) },
1155 { .csi = RVIN_CSI20, .channel = 1, .vin = 7, .mask = BIT(1) },
1156 { .csi = RVIN_CSI40, .channel = 3, .vin = 7, .mask = BIT(3) },
1157 { .csi = RVIN_CSI20, .channel = 3, .vin = 7, .mask = BIT(4) },
1161 static const struct rvin_info rcar_info_r8a7796 = {
1167 .routes = rcar_info_r8a7796_routes,
1170 static const struct rvin_group_route rcar_info_r8a77965_routes[] = {
1171 { .csi = RVIN_CSI40, .channel = 0, .vin = 0, .mask = BIT(0) | BIT(3) },
1172 { .csi = RVIN_CSI20, .channel = 0, .vin = 0, .mask = BIT(1) | BIT(4) },
1173 { .csi = RVIN_CSI40, .channel = 1, .vin = 0, .mask = BIT(2) },
1174 { .csi = RVIN_CSI20, .channel = 0, .vin = 1, .mask = BIT(0) },
1175 { .csi = RVIN_CSI40, .channel = 1, .vin = 1, .mask = BIT(1) | BIT(3) },
1176 { .csi = RVIN_CSI40, .channel = 0, .vin = 1, .mask = BIT(2) },
1177 { .csi = RVIN_CSI20, .channel = 1, .vin = 1, .mask = BIT(4) },
1178 { .csi = RVIN_CSI20, .channel = 1, .vin = 2, .mask = BIT(0) },
1179 { .csi = RVIN_CSI40, .channel = 0, .vin = 2, .mask = BIT(1) },
1180 { .csi = RVIN_CSI20, .channel = 0, .vin = 2, .mask = BIT(2) },
1181 { .csi = RVIN_CSI40, .channel = 2, .vin = 2, .mask = BIT(3) },
1182 { .csi = RVIN_CSI20, .channel = 2, .vin = 2, .mask = BIT(4) },
1183 { .csi = RVIN_CSI40, .channel = 1, .vin = 3, .mask = BIT(0) },
1184 { .csi = RVIN_CSI20, .channel = 1, .vin = 3, .mask = BIT(1) | BIT(2) },
1185 { .csi = RVIN_CSI40, .channel = 3, .vin = 3, .mask = BIT(3) },
1186 { .csi = RVIN_CSI20, .channel = 3, .vin = 3, .mask = BIT(4) },
1187 { .csi = RVIN_CSI40, .channel = 0, .vin = 4, .mask = BIT(0) | BIT(3) },
1188 { .csi = RVIN_CSI20, .channel = 0, .vin = 4, .mask = BIT(1) | BIT(4) },
1189 { .csi = RVIN_CSI40, .channel = 1, .vin = 4, .mask = BIT(2) },
1190 { .csi = RVIN_CSI20, .channel = 0, .vin = 5, .mask = BIT(0) },
1191 { .csi = RVIN_CSI40, .channel = 1, .vin = 5, .mask = BIT(1) | BIT(3) },
1192 { .csi = RVIN_CSI40, .channel = 0, .vin = 5, .mask = BIT(2) },
1193 { .csi = RVIN_CSI20, .channel = 1, .vin = 5, .mask = BIT(4) },
1194 { .csi = RVIN_CSI20, .channel = 1, .vin = 6, .mask = BIT(0) },
1195 { .csi = RVIN_CSI40, .channel = 0, .vin = 6, .mask = BIT(1) },
1196 { .csi = RVIN_CSI20, .channel = 0, .vin = 6, .mask = BIT(2) },
1197 { .csi = RVIN_CSI40, .channel = 2, .vin = 6, .mask = BIT(3) },
1198 { .csi = RVIN_CSI20, .channel = 2, .vin = 6, .mask = BIT(4) },
1199 { .csi = RVIN_CSI40, .channel = 1, .vin = 7, .mask = BIT(0) },
1200 { .csi = RVIN_CSI20, .channel = 1, .vin = 7, .mask = BIT(1) | BIT(2) },
1201 { .csi = RVIN_CSI40, .channel = 3, .vin = 7, .mask = BIT(3) },
1202 { .csi = RVIN_CSI20, .channel = 3, .vin = 7, .mask = BIT(4) },
1206 static const struct rvin_info rcar_info_r8a77965 = {
1212 .routes = rcar_info_r8a77965_routes,
1215 static const struct rvin_group_route rcar_info_r8a77970_routes[] = {
1216 { .csi = RVIN_CSI40, .channel = 0, .vin = 0, .mask = BIT(0) | BIT(3) },
1217 { .csi = RVIN_CSI40, .channel = 0, .vin = 1, .mask = BIT(2) },
1218 { .csi = RVIN_CSI40, .channel = 1, .vin = 1, .mask = BIT(3) },
1219 { .csi = RVIN_CSI40, .channel = 0, .vin = 2, .mask = BIT(1) },
1220 { .csi = RVIN_CSI40, .channel = 2, .vin = 2, .mask = BIT(3) },
1221 { .csi = RVIN_CSI40, .channel = 1, .vin = 3, .mask = BIT(0) },
1222 { .csi = RVIN_CSI40, .channel = 3, .vin = 3, .mask = BIT(3) },
1226 static const struct rvin_info rcar_info_r8a77970 = {
1231 .routes = rcar_info_r8a77970_routes,
1234 static const struct rvin_group_route rcar_info_r8a77980_routes[] = {
1235 { .csi = RVIN_CSI40, .channel = 0, .vin = 0, .mask = BIT(0) | BIT(3) },
1236 { .csi = RVIN_CSI40, .channel = 1, .vin = 0, .mask = BIT(2) },
1237 { .csi = RVIN_CSI40, .channel = 0, .vin = 1, .mask = BIT(2) },
1238 { .csi = RVIN_CSI40, .channel = 1, .vin = 1, .mask = BIT(1) | BIT(3) },
1239 { .csi = RVIN_CSI40, .channel = 0, .vin = 2, .mask = BIT(1) },
1240 { .csi = RVIN_CSI40, .channel = 2, .vin = 2, .mask = BIT(3) },
1241 { .csi = RVIN_CSI40, .channel = 1, .vin = 3, .mask = BIT(0) },
1242 { .csi = RVIN_CSI40, .channel = 3, .vin = 3, .mask = BIT(3) },
1243 { .csi = RVIN_CSI41, .channel = 0, .vin = 4, .mask = BIT(0) | BIT(3) },
1244 { .csi = RVIN_CSI41, .channel = 1, .vin = 4, .mask = BIT(2) },
1245 { .csi = RVIN_CSI41, .channel = 0, .vin = 5, .mask = BIT(2) },
1246 { .csi = RVIN_CSI41, .channel = 1, .vin = 5, .mask = BIT(1) | BIT(3) },
1247 { .csi = RVIN_CSI41, .channel = 0, .vin = 6, .mask = BIT(1) },
1248 { .csi = RVIN_CSI41, .channel = 2, .vin = 6, .mask = BIT(3) },
1249 { .csi = RVIN_CSI41, .channel = 1, .vin = 7, .mask = BIT(0) },
1250 { .csi = RVIN_CSI41, .channel = 3, .vin = 7, .mask = BIT(3) },
1254 static const struct rvin_info rcar_info_r8a77980 = {
1260 .routes = rcar_info_r8a77980_routes,
1263 static const struct rvin_group_route rcar_info_r8a77990_routes[] = {
1264 { .csi = RVIN_CSI40, .channel = 0, .vin = 4, .mask = BIT(0) | BIT(3) },
1265 { .csi = RVIN_CSI40, .channel = 0, .vin = 5, .mask = BIT(2) },
1266 { .csi = RVIN_CSI40, .channel = 1, .vin = 4, .mask = BIT(2) },
1267 { .csi = RVIN_CSI40, .channel = 1, .vin = 5, .mask = BIT(1) | BIT(3) },
1271 static const struct rvin_info rcar_info_r8a77990 = {
1277 .routes = rcar_info_r8a77990_routes,
1280 static const struct rvin_group_route rcar_info_r8a77995_routes[] = {
1284 static const struct rvin_info rcar_info_r8a77995 = {
1290 .routes = rcar_info_r8a77995_routes,
1293 static const struct of_device_id rvin_of_id_table[] = {
1295 .compatible = "renesas,vin-r8a774a1",
1296 .data = &rcar_info_r8a7796,
1299 .compatible = "renesas,vin-r8a774b1",
1300 .data = &rcar_info_r8a77965,
1303 .compatible = "renesas,vin-r8a774c0",
1304 .data = &rcar_info_r8a77990,
1307 .compatible = "renesas,vin-r8a774e1",
1308 .data = &rcar_info_r8a774e1,
1311 .compatible = "renesas,vin-r8a7778",
1312 .data = &rcar_info_m1,
1315 .compatible = "renesas,vin-r8a7779",
1316 .data = &rcar_info_h1,
1319 .compatible = "renesas,rcar-gen2-vin",
1320 .data = &rcar_info_gen2,
1323 .compatible = "renesas,vin-r8a7795",
1324 .data = &rcar_info_r8a7795,
1327 .compatible = "renesas,vin-r8a7796",
1328 .data = &rcar_info_r8a7796,
1331 .compatible = "renesas,vin-r8a77965",
1332 .data = &rcar_info_r8a77965,
1335 .compatible = "renesas,vin-r8a77970",
1336 .data = &rcar_info_r8a77970,
1339 .compatible = "renesas,vin-r8a77980",
1340 .data = &rcar_info_r8a77980,
1343 .compatible = "renesas,vin-r8a77990",
1344 .data = &rcar_info_r8a77990,
1347 .compatible = "renesas,vin-r8a77995",
1348 .data = &rcar_info_r8a77995,
1352 MODULE_DEVICE_TABLE(of, rvin_of_id_table);
1354 static const struct soc_device_attribute r8a7795es1[] = {
1356 .soc_id = "r8a7795", .revision = "ES1.*",
1357 .data = &rcar_info_r8a7795es1,
1362 static int rcar_vin_probe(struct platform_device *pdev)
1364 const struct soc_device_attribute *attr;
1365 struct rvin_dev *vin;
1368 vin = devm_kzalloc(&pdev->dev, sizeof(*vin), GFP_KERNEL);
1372 vin->dev = &pdev->dev;
1373 vin->info = of_device_get_match_data(&pdev->dev);
1377 * Special care is needed on r8a7795 ES1.x since it
1378 * uses different routing than r8a7795 ES2.0.
1380 attr = soc_device_match(r8a7795es1);
1382 vin->info = attr->data;
1384 vin->base = devm_platform_ioremap_resource(pdev, 0);
1385 if (IS_ERR(vin->base))
1386 return PTR_ERR(vin->base);
1388 irq = platform_get_irq(pdev, 0);
1392 ret = rvin_dma_register(vin, irq);
1396 platform_set_drvdata(pdev, vin);
1398 if (vin->info->use_mc) {
1399 ret = rvin_mc_init(vin);
1401 goto error_dma_unregister;
1404 ret = rvin_parallel_init(vin);
1406 goto error_group_unregister;
1408 pm_suspend_ignore_children(&pdev->dev, true);
1409 pm_runtime_enable(&pdev->dev);
1413 error_group_unregister:
1414 v4l2_ctrl_handler_free(&vin->ctrl_handler);
1416 if (vin->info->use_mc) {
1417 mutex_lock(&vin->group->lock);
1418 if (&vin->v4l2_dev == vin->group->notifier.v4l2_dev) {
1419 v4l2_async_notifier_unregister(&vin->group->notifier);
1420 v4l2_async_notifier_cleanup(&vin->group->notifier);
1422 mutex_unlock(&vin->group->lock);
1423 rvin_group_put(vin);
1426 error_dma_unregister:
1427 rvin_dma_unregister(vin);
1432 static int rcar_vin_remove(struct platform_device *pdev)
1434 struct rvin_dev *vin = platform_get_drvdata(pdev);
1436 pm_runtime_disable(&pdev->dev);
1438 rvin_v4l2_unregister(vin);
1440 v4l2_async_notifier_unregister(&vin->notifier);
1441 v4l2_async_notifier_cleanup(&vin->notifier);
1443 if (vin->info->use_mc) {
1444 v4l2_async_notifier_unregister(&vin->group->notifier);
1445 v4l2_async_notifier_cleanup(&vin->group->notifier);
1446 rvin_group_put(vin);
1449 v4l2_ctrl_handler_free(&vin->ctrl_handler);
1451 rvin_dma_unregister(vin);
1456 static SIMPLE_DEV_PM_OPS(rvin_pm_ops, rvin_suspend, rvin_resume);
1458 static struct platform_driver rcar_vin_driver = {
1462 .of_match_table = rvin_of_id_table,
1464 .probe = rcar_vin_probe,
1465 .remove = rcar_vin_remove,
1468 module_platform_driver(rcar_vin_driver);
1470 MODULE_AUTHOR("Niklas Söderlund <niklas.soderlund@ragnatech.se>");
1471 MODULE_DESCRIPTION("Renesas R-Car VIN camera host driver");
1472 MODULE_LICENSE("GPL");