Linux 4.14.51
[linux/fpc-iii.git] / drivers / media / platform / vsp1 / vsp1_drv.c
blobeed9516e25e1d59fa89f10d89f2301f601d4a27a
1 /*
2 * vsp1_drv.c -- R-Car VSP1 Driver
4 * Copyright (C) 2013-2015 Renesas Electronics Corporation
6 * Contact: Laurent Pinchart (laurent.pinchart@ideasonboard.com)
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
14 #include <linux/clk.h>
15 #include <linux/delay.h>
16 #include <linux/device.h>
17 #include <linux/interrupt.h>
18 #include <linux/module.h>
19 #include <linux/of.h>
20 #include <linux/of_device.h>
21 #include <linux/platform_device.h>
22 #include <linux/pm_runtime.h>
23 #include <linux/videodev2.h>
25 #include <media/rcar-fcp.h>
26 #include <media/v4l2-subdev.h>
28 #include "vsp1.h"
29 #include "vsp1_bru.h"
30 #include "vsp1_clu.h"
31 #include "vsp1_dl.h"
32 #include "vsp1_drm.h"
33 #include "vsp1_hgo.h"
34 #include "vsp1_hgt.h"
35 #include "vsp1_hsit.h"
36 #include "vsp1_lif.h"
37 #include "vsp1_lut.h"
38 #include "vsp1_pipe.h"
39 #include "vsp1_rwpf.h"
40 #include "vsp1_sru.h"
41 #include "vsp1_uds.h"
42 #include "vsp1_video.h"
44 /* -----------------------------------------------------------------------------
45 * Interrupt Handling
48 static irqreturn_t vsp1_irq_handler(int irq, void *data)
50 u32 mask = VI6_WFP_IRQ_STA_DFE | VI6_WFP_IRQ_STA_FRE;
51 struct vsp1_device *vsp1 = data;
52 irqreturn_t ret = IRQ_NONE;
53 unsigned int i;
54 u32 status;
56 for (i = 0; i < vsp1->info->wpf_count; ++i) {
57 struct vsp1_rwpf *wpf = vsp1->wpf[i];
59 if (wpf == NULL)
60 continue;
62 status = vsp1_read(vsp1, VI6_WPF_IRQ_STA(i));
63 vsp1_write(vsp1, VI6_WPF_IRQ_STA(i), ~status & mask);
65 if (status & VI6_WFP_IRQ_STA_DFE) {
66 vsp1_pipeline_frame_end(wpf->pipe);
67 ret = IRQ_HANDLED;
71 return ret;
74 /* -----------------------------------------------------------------------------
75 * Entities
79 * vsp1_create_sink_links - Create links from all sources to the given sink
81 * This function creates media links from all valid sources to the given sink
82 * pad. Links that would be invalid according to the VSP1 hardware capabilities
83 * are skipped. Those include all links
85 * - from a UDS to a UDS (UDS entities can't be chained)
86 * - from an entity to itself (no loops are allowed)
88 * Furthermore, the BRS can't be connected to histogram generators, but no
89 * special check is currently needed as all VSP instances that include a BRS
90 * have no histogram generator.
92 static int vsp1_create_sink_links(struct vsp1_device *vsp1,
93 struct vsp1_entity *sink)
95 struct media_entity *entity = &sink->subdev.entity;
96 struct vsp1_entity *source;
97 unsigned int pad;
98 int ret;
100 list_for_each_entry(source, &vsp1->entities, list_dev) {
101 u32 flags;
103 if (source->type == sink->type)
104 continue;
106 if (source->type == VSP1_ENTITY_HGO ||
107 source->type == VSP1_ENTITY_HGT ||
108 source->type == VSP1_ENTITY_LIF ||
109 source->type == VSP1_ENTITY_WPF)
110 continue;
112 flags = source->type == VSP1_ENTITY_RPF &&
113 sink->type == VSP1_ENTITY_WPF &&
114 source->index == sink->index
115 ? MEDIA_LNK_FL_ENABLED : 0;
117 for (pad = 0; pad < entity->num_pads; ++pad) {
118 if (!(entity->pads[pad].flags & MEDIA_PAD_FL_SINK))
119 continue;
121 ret = media_create_pad_link(&source->subdev.entity,
122 source->source_pad,
123 entity, pad, flags);
124 if (ret < 0)
125 return ret;
127 if (flags & MEDIA_LNK_FL_ENABLED)
128 source->sink = sink;
132 return 0;
135 static int vsp1_uapi_create_links(struct vsp1_device *vsp1)
137 struct vsp1_entity *entity;
138 unsigned int i;
139 int ret;
141 list_for_each_entry(entity, &vsp1->entities, list_dev) {
142 if (entity->type == VSP1_ENTITY_LIF ||
143 entity->type == VSP1_ENTITY_RPF)
144 continue;
146 ret = vsp1_create_sink_links(vsp1, entity);
147 if (ret < 0)
148 return ret;
151 if (vsp1->hgo) {
152 ret = media_create_pad_link(&vsp1->hgo->histo.entity.subdev.entity,
153 HISTO_PAD_SOURCE,
154 &vsp1->hgo->histo.video.entity, 0,
155 MEDIA_LNK_FL_ENABLED |
156 MEDIA_LNK_FL_IMMUTABLE);
157 if (ret < 0)
158 return ret;
161 if (vsp1->hgt) {
162 ret = media_create_pad_link(&vsp1->hgt->histo.entity.subdev.entity,
163 HISTO_PAD_SOURCE,
164 &vsp1->hgt->histo.video.entity, 0,
165 MEDIA_LNK_FL_ENABLED |
166 MEDIA_LNK_FL_IMMUTABLE);
167 if (ret < 0)
168 return ret;
171 for (i = 0; i < vsp1->info->lif_count; ++i) {
172 if (!vsp1->lif[i])
173 continue;
175 ret = media_create_pad_link(&vsp1->wpf[i]->entity.subdev.entity,
176 RWPF_PAD_SOURCE,
177 &vsp1->lif[i]->entity.subdev.entity,
178 LIF_PAD_SINK, 0);
179 if (ret < 0)
180 return ret;
183 for (i = 0; i < vsp1->info->rpf_count; ++i) {
184 struct vsp1_rwpf *rpf = vsp1->rpf[i];
186 ret = media_create_pad_link(&rpf->video->video.entity, 0,
187 &rpf->entity.subdev.entity,
188 RWPF_PAD_SINK,
189 MEDIA_LNK_FL_ENABLED |
190 MEDIA_LNK_FL_IMMUTABLE);
191 if (ret < 0)
192 return ret;
195 for (i = 0; i < vsp1->info->wpf_count; ++i) {
197 * Connect the video device to the WPF. All connections are
198 * immutable.
200 struct vsp1_rwpf *wpf = vsp1->wpf[i];
202 ret = media_create_pad_link(&wpf->entity.subdev.entity,
203 RWPF_PAD_SOURCE,
204 &wpf->video->video.entity, 0,
205 MEDIA_LNK_FL_IMMUTABLE |
206 MEDIA_LNK_FL_ENABLED);
207 if (ret < 0)
208 return ret;
211 return 0;
214 static void vsp1_destroy_entities(struct vsp1_device *vsp1)
216 struct vsp1_entity *entity, *_entity;
217 struct vsp1_video *video, *_video;
219 list_for_each_entry_safe(entity, _entity, &vsp1->entities, list_dev) {
220 list_del(&entity->list_dev);
221 vsp1_entity_destroy(entity);
224 list_for_each_entry_safe(video, _video, &vsp1->videos, list) {
225 list_del(&video->list);
226 vsp1_video_cleanup(video);
229 v4l2_device_unregister(&vsp1->v4l2_dev);
230 if (vsp1->info->uapi)
231 media_device_unregister(&vsp1->media_dev);
232 media_device_cleanup(&vsp1->media_dev);
234 if (!vsp1->info->uapi)
235 vsp1_drm_cleanup(vsp1);
238 static int vsp1_create_entities(struct vsp1_device *vsp1)
240 struct media_device *mdev = &vsp1->media_dev;
241 struct v4l2_device *vdev = &vsp1->v4l2_dev;
242 struct vsp1_entity *entity;
243 unsigned int i;
244 int ret;
246 mdev->dev = vsp1->dev;
247 mdev->hw_revision = vsp1->version;
248 strlcpy(mdev->model, vsp1->info->model, sizeof(mdev->model));
249 snprintf(mdev->bus_info, sizeof(mdev->bus_info), "platform:%s",
250 dev_name(mdev->dev));
251 media_device_init(mdev);
253 vsp1->media_ops.link_setup = vsp1_entity_link_setup;
255 * Don't perform link validation when the userspace API is disabled as
256 * the pipeline is configured internally by the driver in that case, and
257 * its configuration can thus be trusted.
259 if (vsp1->info->uapi)
260 vsp1->media_ops.link_validate = v4l2_subdev_link_validate;
262 vdev->mdev = mdev;
263 ret = v4l2_device_register(vsp1->dev, vdev);
264 if (ret < 0) {
265 dev_err(vsp1->dev, "V4L2 device registration failed (%d)\n",
266 ret);
267 goto done;
270 /* Instantiate all the entities. */
271 if (vsp1->info->features & VSP1_HAS_BRS) {
272 vsp1->brs = vsp1_bru_create(vsp1, VSP1_ENTITY_BRS);
273 if (IS_ERR(vsp1->brs)) {
274 ret = PTR_ERR(vsp1->brs);
275 goto done;
278 list_add_tail(&vsp1->brs->entity.list_dev, &vsp1->entities);
281 if (vsp1->info->features & VSP1_HAS_BRU) {
282 vsp1->bru = vsp1_bru_create(vsp1, VSP1_ENTITY_BRU);
283 if (IS_ERR(vsp1->bru)) {
284 ret = PTR_ERR(vsp1->bru);
285 goto done;
288 list_add_tail(&vsp1->bru->entity.list_dev, &vsp1->entities);
291 if (vsp1->info->features & VSP1_HAS_CLU) {
292 vsp1->clu = vsp1_clu_create(vsp1);
293 if (IS_ERR(vsp1->clu)) {
294 ret = PTR_ERR(vsp1->clu);
295 goto done;
298 list_add_tail(&vsp1->clu->entity.list_dev, &vsp1->entities);
301 vsp1->hsi = vsp1_hsit_create(vsp1, true);
302 if (IS_ERR(vsp1->hsi)) {
303 ret = PTR_ERR(vsp1->hsi);
304 goto done;
307 list_add_tail(&vsp1->hsi->entity.list_dev, &vsp1->entities);
309 vsp1->hst = vsp1_hsit_create(vsp1, false);
310 if (IS_ERR(vsp1->hst)) {
311 ret = PTR_ERR(vsp1->hst);
312 goto done;
315 list_add_tail(&vsp1->hst->entity.list_dev, &vsp1->entities);
317 if (vsp1->info->features & VSP1_HAS_HGO && vsp1->info->uapi) {
318 vsp1->hgo = vsp1_hgo_create(vsp1);
319 if (IS_ERR(vsp1->hgo)) {
320 ret = PTR_ERR(vsp1->hgo);
321 goto done;
324 list_add_tail(&vsp1->hgo->histo.entity.list_dev,
325 &vsp1->entities);
328 if (vsp1->info->features & VSP1_HAS_HGT && vsp1->info->uapi) {
329 vsp1->hgt = vsp1_hgt_create(vsp1);
330 if (IS_ERR(vsp1->hgt)) {
331 ret = PTR_ERR(vsp1->hgt);
332 goto done;
335 list_add_tail(&vsp1->hgt->histo.entity.list_dev,
336 &vsp1->entities);
340 * The LIFs are only supported when used in conjunction with the DU, in
341 * which case the userspace API is disabled. If the userspace API is
342 * enabled skip the LIFs, even when present.
344 if (!vsp1->info->uapi) {
345 for (i = 0; i < vsp1->info->lif_count; ++i) {
346 struct vsp1_lif *lif;
348 lif = vsp1_lif_create(vsp1, i);
349 if (IS_ERR(lif)) {
350 ret = PTR_ERR(lif);
351 goto done;
354 vsp1->lif[i] = lif;
355 list_add_tail(&lif->entity.list_dev, &vsp1->entities);
359 if (vsp1->info->features & VSP1_HAS_LUT) {
360 vsp1->lut = vsp1_lut_create(vsp1);
361 if (IS_ERR(vsp1->lut)) {
362 ret = PTR_ERR(vsp1->lut);
363 goto done;
366 list_add_tail(&vsp1->lut->entity.list_dev, &vsp1->entities);
369 for (i = 0; i < vsp1->info->rpf_count; ++i) {
370 struct vsp1_rwpf *rpf;
372 rpf = vsp1_rpf_create(vsp1, i);
373 if (IS_ERR(rpf)) {
374 ret = PTR_ERR(rpf);
375 goto done;
378 vsp1->rpf[i] = rpf;
379 list_add_tail(&rpf->entity.list_dev, &vsp1->entities);
381 if (vsp1->info->uapi) {
382 struct vsp1_video *video = vsp1_video_create(vsp1, rpf);
384 if (IS_ERR(video)) {
385 ret = PTR_ERR(video);
386 goto done;
389 list_add_tail(&video->list, &vsp1->videos);
393 if (vsp1->info->features & VSP1_HAS_SRU) {
394 vsp1->sru = vsp1_sru_create(vsp1);
395 if (IS_ERR(vsp1->sru)) {
396 ret = PTR_ERR(vsp1->sru);
397 goto done;
400 list_add_tail(&vsp1->sru->entity.list_dev, &vsp1->entities);
403 for (i = 0; i < vsp1->info->uds_count; ++i) {
404 struct vsp1_uds *uds;
406 uds = vsp1_uds_create(vsp1, i);
407 if (IS_ERR(uds)) {
408 ret = PTR_ERR(uds);
409 goto done;
412 vsp1->uds[i] = uds;
413 list_add_tail(&uds->entity.list_dev, &vsp1->entities);
416 for (i = 0; i < vsp1->info->wpf_count; ++i) {
417 struct vsp1_rwpf *wpf;
419 wpf = vsp1_wpf_create(vsp1, i);
420 if (IS_ERR(wpf)) {
421 ret = PTR_ERR(wpf);
422 goto done;
425 vsp1->wpf[i] = wpf;
426 list_add_tail(&wpf->entity.list_dev, &vsp1->entities);
428 if (vsp1->info->uapi) {
429 struct vsp1_video *video = vsp1_video_create(vsp1, wpf);
431 if (IS_ERR(video)) {
432 ret = PTR_ERR(video);
433 goto done;
436 list_add_tail(&video->list, &vsp1->videos);
440 /* Register all subdevs. */
441 list_for_each_entry(entity, &vsp1->entities, list_dev) {
442 ret = v4l2_device_register_subdev(&vsp1->v4l2_dev,
443 &entity->subdev);
444 if (ret < 0)
445 goto done;
449 * Create links and register subdev nodes if the userspace API is
450 * enabled or initialize the DRM pipeline otherwise.
452 if (vsp1->info->uapi) {
453 ret = vsp1_uapi_create_links(vsp1);
454 if (ret < 0)
455 goto done;
457 ret = v4l2_device_register_subdev_nodes(&vsp1->v4l2_dev);
458 if (ret < 0)
459 goto done;
461 ret = media_device_register(mdev);
462 } else {
463 ret = vsp1_drm_init(vsp1);
466 done:
467 if (ret < 0)
468 vsp1_destroy_entities(vsp1);
470 return ret;
473 int vsp1_reset_wpf(struct vsp1_device *vsp1, unsigned int index)
475 unsigned int timeout;
476 u32 status;
478 status = vsp1_read(vsp1, VI6_STATUS);
479 if (!(status & VI6_STATUS_SYS_ACT(index)))
480 return 0;
482 vsp1_write(vsp1, VI6_SRESET, VI6_SRESET_SRTS(index));
483 for (timeout = 10; timeout > 0; --timeout) {
484 status = vsp1_read(vsp1, VI6_STATUS);
485 if (!(status & VI6_STATUS_SYS_ACT(index)))
486 break;
488 usleep_range(1000, 2000);
491 if (!timeout) {
492 dev_err(vsp1->dev, "failed to reset wpf.%u\n", index);
493 return -ETIMEDOUT;
496 return 0;
499 static int vsp1_device_init(struct vsp1_device *vsp1)
501 unsigned int i;
502 int ret;
504 /* Reset any channel that might be running. */
505 for (i = 0; i < vsp1->info->wpf_count; ++i) {
506 ret = vsp1_reset_wpf(vsp1, i);
507 if (ret < 0)
508 return ret;
511 vsp1_write(vsp1, VI6_CLK_DCSWT, (8 << VI6_CLK_DCSWT_CSTPW_SHIFT) |
512 (8 << VI6_CLK_DCSWT_CSTRW_SHIFT));
514 for (i = 0; i < vsp1->info->rpf_count; ++i)
515 vsp1_write(vsp1, VI6_DPR_RPF_ROUTE(i), VI6_DPR_NODE_UNUSED);
517 for (i = 0; i < vsp1->info->uds_count; ++i)
518 vsp1_write(vsp1, VI6_DPR_UDS_ROUTE(i), VI6_DPR_NODE_UNUSED);
520 vsp1_write(vsp1, VI6_DPR_SRU_ROUTE, VI6_DPR_NODE_UNUSED);
521 vsp1_write(vsp1, VI6_DPR_LUT_ROUTE, VI6_DPR_NODE_UNUSED);
522 vsp1_write(vsp1, VI6_DPR_CLU_ROUTE, VI6_DPR_NODE_UNUSED);
523 vsp1_write(vsp1, VI6_DPR_HST_ROUTE, VI6_DPR_NODE_UNUSED);
524 vsp1_write(vsp1, VI6_DPR_HSI_ROUTE, VI6_DPR_NODE_UNUSED);
525 vsp1_write(vsp1, VI6_DPR_BRU_ROUTE, VI6_DPR_NODE_UNUSED);
527 if (vsp1->info->features & VSP1_HAS_BRS)
528 vsp1_write(vsp1, VI6_DPR_ILV_BRS_ROUTE, VI6_DPR_NODE_UNUSED);
530 vsp1_write(vsp1, VI6_DPR_HGO_SMPPT, (7 << VI6_DPR_SMPPT_TGW_SHIFT) |
531 (VI6_DPR_NODE_UNUSED << VI6_DPR_SMPPT_PT_SHIFT));
532 vsp1_write(vsp1, VI6_DPR_HGT_SMPPT, (7 << VI6_DPR_SMPPT_TGW_SHIFT) |
533 (VI6_DPR_NODE_UNUSED << VI6_DPR_SMPPT_PT_SHIFT));
535 vsp1_dlm_setup(vsp1);
537 return 0;
541 * vsp1_device_get - Acquire the VSP1 device
543 * Make sure the device is not suspended and initialize it if needed.
545 * Return 0 on success or a negative error code otherwise.
547 int vsp1_device_get(struct vsp1_device *vsp1)
549 int ret;
551 ret = pm_runtime_get_sync(vsp1->dev);
552 return ret < 0 ? ret : 0;
556 * vsp1_device_put - Release the VSP1 device
558 * Decrement the VSP1 reference count and cleanup the device if the last
559 * reference is released.
561 void vsp1_device_put(struct vsp1_device *vsp1)
563 pm_runtime_put_sync(vsp1->dev);
566 /* -----------------------------------------------------------------------------
567 * Power Management
570 static int __maybe_unused vsp1_pm_suspend(struct device *dev)
572 struct vsp1_device *vsp1 = dev_get_drvdata(dev);
575 * When used as part of a display pipeline, the VSP is stopped and
576 * restarted explicitly by the DU.
578 if (!vsp1->drm)
579 vsp1_pipelines_suspend(vsp1);
581 pm_runtime_force_suspend(vsp1->dev);
583 return 0;
586 static int __maybe_unused vsp1_pm_resume(struct device *dev)
588 struct vsp1_device *vsp1 = dev_get_drvdata(dev);
590 pm_runtime_force_resume(vsp1->dev);
593 * When used as part of a display pipeline, the VSP is stopped and
594 * restarted explicitly by the DU.
596 if (!vsp1->drm)
597 vsp1_pipelines_resume(vsp1);
599 return 0;
602 static int __maybe_unused vsp1_pm_runtime_suspend(struct device *dev)
604 struct vsp1_device *vsp1 = dev_get_drvdata(dev);
606 rcar_fcp_disable(vsp1->fcp);
608 return 0;
611 static int __maybe_unused vsp1_pm_runtime_resume(struct device *dev)
613 struct vsp1_device *vsp1 = dev_get_drvdata(dev);
614 int ret;
616 if (vsp1->info) {
617 ret = vsp1_device_init(vsp1);
618 if (ret < 0)
619 return ret;
622 return rcar_fcp_enable(vsp1->fcp);
625 static const struct dev_pm_ops vsp1_pm_ops = {
626 SET_SYSTEM_SLEEP_PM_OPS(vsp1_pm_suspend, vsp1_pm_resume)
627 SET_RUNTIME_PM_OPS(vsp1_pm_runtime_suspend, vsp1_pm_runtime_resume, NULL)
630 /* -----------------------------------------------------------------------------
631 * Platform Driver
634 static const struct vsp1_device_info vsp1_device_infos[] = {
636 .version = VI6_IP_VERSION_MODEL_VSPS_H2,
637 .model = "VSP1-S",
638 .gen = 2,
639 .features = VSP1_HAS_BRU | VSP1_HAS_CLU | VSP1_HAS_HGO
640 | VSP1_HAS_HGT | VSP1_HAS_LUT | VSP1_HAS_SRU
641 | VSP1_HAS_WPF_VFLIP,
642 .rpf_count = 5,
643 .uds_count = 3,
644 .wpf_count = 4,
645 .num_bru_inputs = 4,
646 .uapi = true,
647 }, {
648 .version = VI6_IP_VERSION_MODEL_VSPR_H2,
649 .model = "VSP1-R",
650 .gen = 2,
651 .features = VSP1_HAS_BRU | VSP1_HAS_SRU | VSP1_HAS_WPF_VFLIP,
652 .rpf_count = 5,
653 .uds_count = 3,
654 .wpf_count = 4,
655 .num_bru_inputs = 4,
656 .uapi = true,
657 }, {
658 .version = VI6_IP_VERSION_MODEL_VSPD_GEN2,
659 .model = "VSP1-D",
660 .gen = 2,
661 .features = VSP1_HAS_BRU | VSP1_HAS_HGO | VSP1_HAS_LUT,
662 .lif_count = 1,
663 .rpf_count = 4,
664 .uds_count = 1,
665 .wpf_count = 1,
666 .num_bru_inputs = 4,
667 .uapi = true,
668 }, {
669 .version = VI6_IP_VERSION_MODEL_VSPS_M2,
670 .model = "VSP1-S",
671 .gen = 2,
672 .features = VSP1_HAS_BRU | VSP1_HAS_CLU | VSP1_HAS_HGO
673 | VSP1_HAS_HGT | VSP1_HAS_LUT | VSP1_HAS_SRU
674 | VSP1_HAS_WPF_VFLIP,
675 .rpf_count = 5,
676 .uds_count = 1,
677 .wpf_count = 4,
678 .num_bru_inputs = 4,
679 .uapi = true,
680 }, {
681 .version = VI6_IP_VERSION_MODEL_VSPS_V2H,
682 .model = "VSP1V-S",
683 .gen = 2,
684 .features = VSP1_HAS_BRU | VSP1_HAS_CLU | VSP1_HAS_LUT
685 | VSP1_HAS_SRU | VSP1_HAS_WPF_VFLIP,
686 .rpf_count = 4,
687 .uds_count = 1,
688 .wpf_count = 4,
689 .num_bru_inputs = 4,
690 .uapi = true,
691 }, {
692 .version = VI6_IP_VERSION_MODEL_VSPD_V2H,
693 .model = "VSP1V-D",
694 .gen = 2,
695 .features = VSP1_HAS_BRU | VSP1_HAS_CLU | VSP1_HAS_LUT,
696 .lif_count = 1,
697 .rpf_count = 4,
698 .uds_count = 1,
699 .wpf_count = 1,
700 .num_bru_inputs = 4,
701 .uapi = true,
702 }, {
703 .version = VI6_IP_VERSION_MODEL_VSPI_GEN3,
704 .model = "VSP2-I",
705 .gen = 3,
706 .features = VSP1_HAS_CLU | VSP1_HAS_HGO | VSP1_HAS_HGT
707 | VSP1_HAS_LUT | VSP1_HAS_SRU | VSP1_HAS_WPF_HFLIP
708 | VSP1_HAS_WPF_VFLIP,
709 .rpf_count = 1,
710 .uds_count = 1,
711 .wpf_count = 1,
712 .uapi = true,
713 }, {
714 .version = VI6_IP_VERSION_MODEL_VSPBD_GEN3,
715 .model = "VSP2-BD",
716 .gen = 3,
717 .features = VSP1_HAS_BRU | VSP1_HAS_WPF_VFLIP,
718 .rpf_count = 5,
719 .wpf_count = 1,
720 .num_bru_inputs = 5,
721 .uapi = true,
722 }, {
723 .version = VI6_IP_VERSION_MODEL_VSPBC_GEN3,
724 .model = "VSP2-BC",
725 .gen = 3,
726 .features = VSP1_HAS_BRU | VSP1_HAS_CLU | VSP1_HAS_HGO
727 | VSP1_HAS_LUT | VSP1_HAS_WPF_VFLIP,
728 .rpf_count = 5,
729 .wpf_count = 1,
730 .num_bru_inputs = 5,
731 .uapi = true,
732 }, {
733 .version = VI6_IP_VERSION_MODEL_VSPBS_GEN3,
734 .model = "VSP2-BS",
735 .gen = 3,
736 .features = VSP1_HAS_BRS | VSP1_HAS_WPF_VFLIP,
737 .rpf_count = 2,
738 .wpf_count = 1,
739 .uapi = true,
740 }, {
741 .version = VI6_IP_VERSION_MODEL_VSPD_GEN3,
742 .model = "VSP2-D",
743 .gen = 3,
744 .features = VSP1_HAS_BRU | VSP1_HAS_WPF_VFLIP,
745 .lif_count = 1,
746 .rpf_count = 5,
747 .wpf_count = 2,
748 .num_bru_inputs = 5,
749 }, {
750 .version = VI6_IP_VERSION_MODEL_VSPD_V3,
751 .model = "VSP2-D",
752 .gen = 3,
753 .features = VSP1_HAS_BRS | VSP1_HAS_BRU,
754 .lif_count = 1,
755 .rpf_count = 5,
756 .wpf_count = 1,
757 .num_bru_inputs = 5,
758 }, {
759 .version = VI6_IP_VERSION_MODEL_VSPDL_GEN3,
760 .model = "VSP2-DL",
761 .gen = 3,
762 .features = VSP1_HAS_BRS | VSP1_HAS_BRU,
763 .lif_count = 2,
764 .rpf_count = 5,
765 .wpf_count = 2,
766 .num_bru_inputs = 5,
770 static int vsp1_probe(struct platform_device *pdev)
772 struct vsp1_device *vsp1;
773 struct device_node *fcp_node;
774 struct resource *irq;
775 struct resource *io;
776 unsigned int i;
777 int ret;
779 vsp1 = devm_kzalloc(&pdev->dev, sizeof(*vsp1), GFP_KERNEL);
780 if (vsp1 == NULL)
781 return -ENOMEM;
783 vsp1->dev = &pdev->dev;
784 INIT_LIST_HEAD(&vsp1->entities);
785 INIT_LIST_HEAD(&vsp1->videos);
787 platform_set_drvdata(pdev, vsp1);
789 /* I/O and IRQ resources (clock managed by the clock PM domain) */
790 io = platform_get_resource(pdev, IORESOURCE_MEM, 0);
791 vsp1->mmio = devm_ioremap_resource(&pdev->dev, io);
792 if (IS_ERR(vsp1->mmio))
793 return PTR_ERR(vsp1->mmio);
795 irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
796 if (!irq) {
797 dev_err(&pdev->dev, "missing IRQ\n");
798 return -EINVAL;
801 ret = devm_request_irq(&pdev->dev, irq->start, vsp1_irq_handler,
802 IRQF_SHARED, dev_name(&pdev->dev), vsp1);
803 if (ret < 0) {
804 dev_err(&pdev->dev, "failed to request IRQ\n");
805 return ret;
808 /* FCP (optional) */
809 fcp_node = of_parse_phandle(pdev->dev.of_node, "renesas,fcp", 0);
810 if (fcp_node) {
811 vsp1->fcp = rcar_fcp_get(fcp_node);
812 of_node_put(fcp_node);
813 if (IS_ERR(vsp1->fcp)) {
814 dev_dbg(&pdev->dev, "FCP not found (%ld)\n",
815 PTR_ERR(vsp1->fcp));
816 return PTR_ERR(vsp1->fcp);
820 * When the FCP is present, it handles all bus master accesses
821 * for the VSP and must thus be used in place of the VSP device
822 * to map DMA buffers.
824 vsp1->bus_master = rcar_fcp_get_device(vsp1->fcp);
825 } else {
826 vsp1->bus_master = vsp1->dev;
829 /* Configure device parameters based on the version register. */
830 pm_runtime_enable(&pdev->dev);
832 ret = pm_runtime_get_sync(&pdev->dev);
833 if (ret < 0)
834 goto done;
836 vsp1->version = vsp1_read(vsp1, VI6_IP_VERSION);
837 pm_runtime_put_sync(&pdev->dev);
839 for (i = 0; i < ARRAY_SIZE(vsp1_device_infos); ++i) {
840 if ((vsp1->version & VI6_IP_VERSION_MODEL_MASK) ==
841 vsp1_device_infos[i].version) {
842 vsp1->info = &vsp1_device_infos[i];
843 break;
847 if (!vsp1->info) {
848 dev_err(&pdev->dev, "unsupported IP version 0x%08x\n",
849 vsp1->version);
850 ret = -ENXIO;
851 goto done;
854 dev_dbg(&pdev->dev, "IP version 0x%08x\n", vsp1->version);
856 /* Instanciate entities */
857 ret = vsp1_create_entities(vsp1);
858 if (ret < 0) {
859 dev_err(&pdev->dev, "failed to create entities\n");
860 goto done;
863 done:
864 if (ret)
865 pm_runtime_disable(&pdev->dev);
867 return ret;
870 static int vsp1_remove(struct platform_device *pdev)
872 struct vsp1_device *vsp1 = platform_get_drvdata(pdev);
874 vsp1_destroy_entities(vsp1);
875 rcar_fcp_put(vsp1->fcp);
877 pm_runtime_disable(&pdev->dev);
879 return 0;
882 static const struct of_device_id vsp1_of_match[] = {
883 { .compatible = "renesas,vsp1" },
884 { .compatible = "renesas,vsp2" },
885 { },
887 MODULE_DEVICE_TABLE(of, vsp1_of_match);
889 static struct platform_driver vsp1_platform_driver = {
890 .probe = vsp1_probe,
891 .remove = vsp1_remove,
892 .driver = {
893 .name = "vsp1",
894 .pm = &vsp1_pm_ops,
895 .of_match_table = vsp1_of_match,
899 module_platform_driver(vsp1_platform_driver);
901 MODULE_ALIAS("vsp1");
902 MODULE_AUTHOR("Laurent Pinchart <laurent.pinchart@ideasonboard.com>");
903 MODULE_DESCRIPTION("Renesas VSP1 Driver");
904 MODULE_LICENSE("GPL");