]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/media/platform/vsp1/vsp1_drv.c
da43e3f35610962755f67507ce84ff228dd1f498
[karo-tx-linux.git] / drivers / media / platform / vsp1 / vsp1_drv.c
1 /*
2  * vsp1_drv.c  --  R-Car VSP1 Driver
3  *
4  * Copyright (C) 2013-2015 Renesas Electronics Corporation
5  *
6  * Contact: Laurent Pinchart (laurent.pinchart@ideasonboard.com)
7  *
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.
12  */
13
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/videodev2.h>
23
24 #include <media/v4l2-subdev.h>
25
26 #include "vsp1.h"
27 #include "vsp1_bru.h"
28 #include "vsp1_dl.h"
29 #include "vsp1_drm.h"
30 #include "vsp1_hsit.h"
31 #include "vsp1_lif.h"
32 #include "vsp1_lut.h"
33 #include "vsp1_rwpf.h"
34 #include "vsp1_sru.h"
35 #include "vsp1_uds.h"
36 #include "vsp1_video.h"
37
38 /* -----------------------------------------------------------------------------
39  * Interrupt Handling
40  */
41
42 static irqreturn_t vsp1_irq_handler(int irq, void *data)
43 {
44         u32 mask = VI6_WFP_IRQ_STA_DFE | VI6_WFP_IRQ_STA_FRE;
45         struct vsp1_device *vsp1 = data;
46         irqreturn_t ret = IRQ_NONE;
47         unsigned int i;
48         u32 status;
49
50         for (i = 0; i < vsp1->info->wpf_count; ++i) {
51                 struct vsp1_rwpf *wpf = vsp1->wpf[i];
52                 struct vsp1_pipeline *pipe;
53
54                 if (wpf == NULL)
55                         continue;
56
57                 pipe = to_vsp1_pipeline(&wpf->entity.subdev.entity);
58                 status = vsp1_read(vsp1, VI6_WPF_IRQ_STA(i));
59                 vsp1_write(vsp1, VI6_WPF_IRQ_STA(i), ~status & mask);
60
61                 if (status & VI6_WFP_IRQ_STA_FRE) {
62                         vsp1_pipeline_frame_end(pipe);
63                         ret = IRQ_HANDLED;
64                 }
65         }
66
67         status = vsp1_read(vsp1, VI6_DISP_IRQ_STA);
68         vsp1_write(vsp1, VI6_DISP_IRQ_STA, ~status & VI6_DISP_IRQ_STA_DST);
69
70         if (status & VI6_DISP_IRQ_STA_DST) {
71                 struct vsp1_rwpf *wpf = vsp1->wpf[0];
72                 struct vsp1_pipeline *pipe;
73
74                 if (wpf) {
75                         pipe = to_vsp1_pipeline(&wpf->entity.subdev.entity);
76                         vsp1_pipeline_display_start(pipe);
77                 }
78
79                 ret = IRQ_HANDLED;
80         }
81
82         return ret;
83 }
84
85 /* -----------------------------------------------------------------------------
86  * Entities
87  */
88
89 /*
90  * vsp1_create_sink_links - Create links from all sources to the given sink
91  *
92  * This function creates media links from all valid sources to the given sink
93  * pad. Links that would be invalid according to the VSP1 hardware capabilities
94  * are skipped. Those include all links
95  *
96  * - from a UDS to a UDS (UDS entities can't be chained)
97  * - from an entity to itself (no loops are allowed)
98  */
99 static int vsp1_create_sink_links(struct vsp1_device *vsp1,
100                                   struct vsp1_entity *sink)
101 {
102         struct media_entity *entity = &sink->subdev.entity;
103         struct vsp1_entity *source;
104         unsigned int pad;
105         int ret;
106
107         list_for_each_entry(source, &vsp1->entities, list_dev) {
108                 u32 flags;
109
110                 if (source->type == sink->type)
111                         continue;
112
113                 if (source->type == VSP1_ENTITY_LIF ||
114                     source->type == VSP1_ENTITY_WPF)
115                         continue;
116
117                 flags = source->type == VSP1_ENTITY_RPF &&
118                         sink->type == VSP1_ENTITY_WPF &&
119                         source->index == sink->index
120                       ? MEDIA_LNK_FL_ENABLED : 0;
121
122                 for (pad = 0; pad < entity->num_pads; ++pad) {
123                         if (!(entity->pads[pad].flags & MEDIA_PAD_FL_SINK))
124                                 continue;
125
126                         ret = media_create_pad_link(&source->subdev.entity,
127                                                        source->source_pad,
128                                                        entity, pad, flags);
129                         if (ret < 0)
130                                 return ret;
131
132                         if (flags & MEDIA_LNK_FL_ENABLED)
133                                 source->sink = entity;
134                 }
135         }
136
137         return 0;
138 }
139
140 static int vsp1_uapi_create_links(struct vsp1_device *vsp1)
141 {
142         struct vsp1_entity *entity;
143         unsigned int i;
144         int ret;
145
146         list_for_each_entry(entity, &vsp1->entities, list_dev) {
147                 if (entity->type == VSP1_ENTITY_LIF ||
148                     entity->type == VSP1_ENTITY_RPF)
149                         continue;
150
151                 ret = vsp1_create_sink_links(vsp1, entity);
152                 if (ret < 0)
153                         return ret;
154         }
155
156         if (vsp1->info->features & VSP1_HAS_LIF) {
157                 ret = media_create_pad_link(&vsp1->wpf[0]->entity.subdev.entity,
158                                             RWPF_PAD_SOURCE,
159                                             &vsp1->lif->entity.subdev.entity,
160                                             LIF_PAD_SINK, 0);
161                 if (ret < 0)
162                         return ret;
163         }
164
165         for (i = 0; i < vsp1->info->rpf_count; ++i) {
166                 struct vsp1_rwpf *rpf = vsp1->rpf[i];
167
168                 ret = media_create_pad_link(&rpf->video->video.entity, 0,
169                                             &rpf->entity.subdev.entity,
170                                             RWPF_PAD_SINK,
171                                             MEDIA_LNK_FL_ENABLED |
172                                             MEDIA_LNK_FL_IMMUTABLE);
173                 if (ret < 0)
174                         return ret;
175         }
176
177         for (i = 0; i < vsp1->info->wpf_count; ++i) {
178                 /* Connect the video device to the WPF. All connections are
179                  * immutable except for the WPF0 source link if a LIF is
180                  * present.
181                  */
182                 struct vsp1_rwpf *wpf = vsp1->wpf[i];
183                 unsigned int flags = MEDIA_LNK_FL_ENABLED;
184
185                 if (!(vsp1->info->features & VSP1_HAS_LIF) || i != 0)
186                         flags |= MEDIA_LNK_FL_IMMUTABLE;
187
188                 ret = media_create_pad_link(&wpf->entity.subdev.entity,
189                                             RWPF_PAD_SOURCE,
190                                             &wpf->video->video.entity, 0,
191                                             flags);
192                 if (ret < 0)
193                         return ret;
194         }
195
196         return 0;
197 }
198
199 static void vsp1_destroy_entities(struct vsp1_device *vsp1)
200 {
201         struct vsp1_entity *entity, *_entity;
202         struct vsp1_video *video, *_video;
203
204         list_for_each_entry_safe(entity, _entity, &vsp1->entities, list_dev) {
205                 list_del(&entity->list_dev);
206                 vsp1_entity_destroy(entity);
207         }
208
209         list_for_each_entry_safe(video, _video, &vsp1->videos, list) {
210                 list_del(&video->list);
211                 vsp1_video_cleanup(video);
212         }
213
214         v4l2_device_unregister(&vsp1->v4l2_dev);
215         media_device_unregister(&vsp1->media_dev);
216         media_device_cleanup(&vsp1->media_dev);
217
218         if (!vsp1->info->uapi)
219                 vsp1_drm_cleanup(vsp1);
220 }
221
222 static int vsp1_create_entities(struct vsp1_device *vsp1)
223 {
224         struct media_device *mdev = &vsp1->media_dev;
225         struct v4l2_device *vdev = &vsp1->v4l2_dev;
226         struct vsp1_entity *entity;
227         unsigned int i;
228         int ret;
229
230         mdev->dev = vsp1->dev;
231         strlcpy(mdev->model, "VSP1", sizeof(mdev->model));
232         snprintf(mdev->bus_info, sizeof(mdev->bus_info), "platform:%s",
233                  dev_name(mdev->dev));
234         media_device_init(mdev);
235
236         vsp1->media_ops.link_setup = vsp1_entity_link_setup;
237         /* Don't perform link validation when the userspace API is disabled as
238          * the pipeline is configured internally by the driver in that case, and
239          * its configuration can thus be trusted.
240          */
241         if (vsp1->info->uapi)
242                 vsp1->media_ops.link_validate = v4l2_subdev_link_validate;
243
244         vdev->mdev = mdev;
245         ret = v4l2_device_register(vsp1->dev, vdev);
246         if (ret < 0) {
247                 dev_err(vsp1->dev, "V4L2 device registration failed (%d)\n",
248                         ret);
249                 goto done;
250         }
251
252         /* Instantiate all the entities. */
253         if (vsp1->info->features & VSP1_HAS_BRU) {
254                 vsp1->bru = vsp1_bru_create(vsp1);
255                 if (IS_ERR(vsp1->bru)) {
256                         ret = PTR_ERR(vsp1->bru);
257                         goto done;
258                 }
259
260                 list_add_tail(&vsp1->bru->entity.list_dev, &vsp1->entities);
261         }
262
263         vsp1->hsi = vsp1_hsit_create(vsp1, true);
264         if (IS_ERR(vsp1->hsi)) {
265                 ret = PTR_ERR(vsp1->hsi);
266                 goto done;
267         }
268
269         list_add_tail(&vsp1->hsi->entity.list_dev, &vsp1->entities);
270
271         vsp1->hst = vsp1_hsit_create(vsp1, false);
272         if (IS_ERR(vsp1->hst)) {
273                 ret = PTR_ERR(vsp1->hst);
274                 goto done;
275         }
276
277         list_add_tail(&vsp1->hst->entity.list_dev, &vsp1->entities);
278
279         if (vsp1->info->features & VSP1_HAS_LIF) {
280                 vsp1->lif = vsp1_lif_create(vsp1);
281                 if (IS_ERR(vsp1->lif)) {
282                         ret = PTR_ERR(vsp1->lif);
283                         goto done;
284                 }
285
286                 list_add_tail(&vsp1->lif->entity.list_dev, &vsp1->entities);
287         }
288
289         if (vsp1->info->features & VSP1_HAS_LUT) {
290                 vsp1->lut = vsp1_lut_create(vsp1);
291                 if (IS_ERR(vsp1->lut)) {
292                         ret = PTR_ERR(vsp1->lut);
293                         goto done;
294                 }
295
296                 list_add_tail(&vsp1->lut->entity.list_dev, &vsp1->entities);
297         }
298
299         for (i = 0; i < vsp1->info->rpf_count; ++i) {
300                 struct vsp1_rwpf *rpf;
301
302                 rpf = vsp1_rpf_create(vsp1, i);
303                 if (IS_ERR(rpf)) {
304                         ret = PTR_ERR(rpf);
305                         goto done;
306                 }
307
308                 vsp1->rpf[i] = rpf;
309                 list_add_tail(&rpf->entity.list_dev, &vsp1->entities);
310
311                 if (vsp1->info->uapi) {
312                         struct vsp1_video *video = vsp1_video_create(vsp1, rpf);
313
314                         if (IS_ERR(video)) {
315                                 ret = PTR_ERR(video);
316                                 goto done;
317                         }
318
319                         list_add_tail(&video->list, &vsp1->videos);
320                 }
321         }
322
323         if (vsp1->info->features & VSP1_HAS_SRU) {
324                 vsp1->sru = vsp1_sru_create(vsp1);
325                 if (IS_ERR(vsp1->sru)) {
326                         ret = PTR_ERR(vsp1->sru);
327                         goto done;
328                 }
329
330                 list_add_tail(&vsp1->sru->entity.list_dev, &vsp1->entities);
331         }
332
333         for (i = 0; i < vsp1->info->uds_count; ++i) {
334                 struct vsp1_uds *uds;
335
336                 uds = vsp1_uds_create(vsp1, i);
337                 if (IS_ERR(uds)) {
338                         ret = PTR_ERR(uds);
339                         goto done;
340                 }
341
342                 vsp1->uds[i] = uds;
343                 list_add_tail(&uds->entity.list_dev, &vsp1->entities);
344         }
345
346         for (i = 0; i < vsp1->info->wpf_count; ++i) {
347                 struct vsp1_rwpf *wpf;
348
349                 wpf = vsp1_wpf_create(vsp1, i);
350                 if (IS_ERR(wpf)) {
351                         ret = PTR_ERR(wpf);
352                         goto done;
353                 }
354
355                 vsp1->wpf[i] = wpf;
356                 list_add_tail(&wpf->entity.list_dev, &vsp1->entities);
357
358                 if (vsp1->info->uapi) {
359                         struct vsp1_video *video = vsp1_video_create(vsp1, wpf);
360
361                         if (IS_ERR(video)) {
362                                 ret = PTR_ERR(video);
363                                 goto done;
364                         }
365
366                         list_add_tail(&video->list, &vsp1->videos);
367                         wpf->entity.sink = &video->video.entity;
368                 }
369         }
370
371         /* Register all subdevs. */
372         list_for_each_entry(entity, &vsp1->entities, list_dev) {
373                 ret = v4l2_device_register_subdev(&vsp1->v4l2_dev,
374                                                   &entity->subdev);
375                 if (ret < 0)
376                         goto done;
377         }
378
379         /* Create links. */
380         if (vsp1->info->uapi)
381                 ret = vsp1_uapi_create_links(vsp1);
382         else
383                 ret = vsp1_drm_create_links(vsp1);
384         if (ret < 0)
385                 goto done;
386
387         /* Register subdev nodes if the userspace API is enabled or initialize
388          * the DRM pipeline otherwise.
389          */
390         if (vsp1->info->uapi) {
391                 vsp1->use_dl = false;
392                 ret = v4l2_device_register_subdev_nodes(&vsp1->v4l2_dev);
393         } else {
394                 vsp1->use_dl = true;
395                 ret = vsp1_drm_init(vsp1);
396         }
397         if (ret < 0)
398                 goto done;
399
400         ret = media_device_register(mdev);
401
402 done:
403         if (ret < 0)
404                 vsp1_destroy_entities(vsp1);
405
406         return ret;
407 }
408
409 int vsp1_reset_wpf(struct vsp1_device *vsp1, unsigned int index)
410 {
411         unsigned int timeout;
412         u32 status;
413
414         status = vsp1_read(vsp1, VI6_STATUS);
415         if (!(status & VI6_STATUS_SYS_ACT(index)))
416                 return 0;
417
418         vsp1_write(vsp1, VI6_SRESET, VI6_SRESET_SRTS(index));
419         for (timeout = 10; timeout > 0; --timeout) {
420                 status = vsp1_read(vsp1, VI6_STATUS);
421                 if (!(status & VI6_STATUS_SYS_ACT(index)))
422                         break;
423
424                 usleep_range(1000, 2000);
425         }
426
427         if (!timeout) {
428                 dev_err(vsp1->dev, "failed to reset wpf.%u\n", index);
429                 return -ETIMEDOUT;
430         }
431
432         return 0;
433 }
434
435 static int vsp1_device_init(struct vsp1_device *vsp1)
436 {
437         unsigned int i;
438         int ret;
439
440         /* Reset any channel that might be running. */
441         for (i = 0; i < vsp1->info->wpf_count; ++i) {
442                 ret = vsp1_reset_wpf(vsp1, i);
443                 if (ret < 0)
444                         return ret;
445         }
446
447         vsp1_write(vsp1, VI6_CLK_DCSWT, (8 << VI6_CLK_DCSWT_CSTPW_SHIFT) |
448                    (8 << VI6_CLK_DCSWT_CSTRW_SHIFT));
449
450         for (i = 0; i < vsp1->info->rpf_count; ++i)
451                 vsp1_write(vsp1, VI6_DPR_RPF_ROUTE(i), VI6_DPR_NODE_UNUSED);
452
453         for (i = 0; i < vsp1->info->uds_count; ++i)
454                 vsp1_write(vsp1, VI6_DPR_UDS_ROUTE(i), VI6_DPR_NODE_UNUSED);
455
456         vsp1_write(vsp1, VI6_DPR_SRU_ROUTE, VI6_DPR_NODE_UNUSED);
457         vsp1_write(vsp1, VI6_DPR_LUT_ROUTE, VI6_DPR_NODE_UNUSED);
458         vsp1_write(vsp1, VI6_DPR_CLU_ROUTE, VI6_DPR_NODE_UNUSED);
459         vsp1_write(vsp1, VI6_DPR_HST_ROUTE, VI6_DPR_NODE_UNUSED);
460         vsp1_write(vsp1, VI6_DPR_HSI_ROUTE, VI6_DPR_NODE_UNUSED);
461         vsp1_write(vsp1, VI6_DPR_BRU_ROUTE, VI6_DPR_NODE_UNUSED);
462
463         vsp1_write(vsp1, VI6_DPR_HGO_SMPPT, (7 << VI6_DPR_SMPPT_TGW_SHIFT) |
464                    (VI6_DPR_NODE_UNUSED << VI6_DPR_SMPPT_PT_SHIFT));
465         vsp1_write(vsp1, VI6_DPR_HGT_SMPPT, (7 << VI6_DPR_SMPPT_TGW_SHIFT) |
466                    (VI6_DPR_NODE_UNUSED << VI6_DPR_SMPPT_PT_SHIFT));
467
468         if (vsp1->use_dl)
469                 vsp1_dl_setup(vsp1);
470
471         return 0;
472 }
473
474 /*
475  * vsp1_device_get - Acquire the VSP1 device
476  *
477  * Increment the VSP1 reference count and initialize the device if the first
478  * reference is taken.
479  *
480  * Return 0 on success or a negative error code otherwise.
481  */
482 int vsp1_device_get(struct vsp1_device *vsp1)
483 {
484         int ret = 0;
485
486         mutex_lock(&vsp1->lock);
487         if (vsp1->ref_count > 0)
488                 goto done;
489
490         ret = clk_prepare_enable(vsp1->clock);
491         if (ret < 0)
492                 goto done;
493
494         ret = vsp1_device_init(vsp1);
495         if (ret < 0) {
496                 clk_disable_unprepare(vsp1->clock);
497                 goto done;
498         }
499
500 done:
501         if (!ret)
502                 vsp1->ref_count++;
503
504         mutex_unlock(&vsp1->lock);
505         return ret;
506 }
507
508 /*
509  * vsp1_device_put - Release the VSP1 device
510  *
511  * Decrement the VSP1 reference count and cleanup the device if the last
512  * reference is released.
513  */
514 void vsp1_device_put(struct vsp1_device *vsp1)
515 {
516         mutex_lock(&vsp1->lock);
517
518         if (--vsp1->ref_count == 0)
519                 clk_disable_unprepare(vsp1->clock);
520
521         mutex_unlock(&vsp1->lock);
522 }
523
524 /* -----------------------------------------------------------------------------
525  * Power Management
526  */
527
528 #ifdef CONFIG_PM_SLEEP
529 static int vsp1_pm_suspend(struct device *dev)
530 {
531         struct vsp1_device *vsp1 = dev_get_drvdata(dev);
532
533         WARN_ON(mutex_is_locked(&vsp1->lock));
534
535         if (vsp1->ref_count == 0)
536                 return 0;
537
538         vsp1_pipelines_suspend(vsp1);
539
540         clk_disable_unprepare(vsp1->clock);
541
542         return 0;
543 }
544
545 static int vsp1_pm_resume(struct device *dev)
546 {
547         struct vsp1_device *vsp1 = dev_get_drvdata(dev);
548
549         WARN_ON(mutex_is_locked(&vsp1->lock));
550
551         if (vsp1->ref_count == 0)
552                 return 0;
553
554         clk_prepare_enable(vsp1->clock);
555
556         vsp1_pipelines_resume(vsp1);
557
558         return 0;
559 }
560 #endif
561
562 static const struct dev_pm_ops vsp1_pm_ops = {
563         SET_SYSTEM_SLEEP_PM_OPS(vsp1_pm_suspend, vsp1_pm_resume)
564 };
565
566 /* -----------------------------------------------------------------------------
567  * Platform Driver
568  */
569
570 static const struct vsp1_device_info vsp1_device_infos[] = {
571         {
572                 .version = VI6_IP_VERSION_MODEL_VSPS_H2,
573                 .features = VSP1_HAS_BRU | VSP1_HAS_LUT | VSP1_HAS_SRU,
574                 .rpf_count = 5,
575                 .uds_count = 3,
576                 .wpf_count = 4,
577                 .num_bru_inputs = 4,
578                 .uapi = true,
579         }, {
580                 .version = VI6_IP_VERSION_MODEL_VSPR_H2,
581                 .features = VSP1_HAS_BRU | VSP1_HAS_SRU,
582                 .rpf_count = 5,
583                 .uds_count = 1,
584                 .wpf_count = 4,
585                 .num_bru_inputs = 4,
586                 .uapi = true,
587         }, {
588                 .version = VI6_IP_VERSION_MODEL_VSPD_GEN2,
589                 .features = VSP1_HAS_BRU | VSP1_HAS_LIF | VSP1_HAS_LUT,
590                 .rpf_count = 4,
591                 .uds_count = 1,
592                 .wpf_count = 4,
593                 .num_bru_inputs = 4,
594                 .uapi = true,
595         }, {
596                 .version = VI6_IP_VERSION_MODEL_VSPS_M2,
597                 .features = VSP1_HAS_BRU | VSP1_HAS_LUT | VSP1_HAS_SRU,
598                 .rpf_count = 5,
599                 .uds_count = 3,
600                 .wpf_count = 4,
601                 .num_bru_inputs = 4,
602                 .uapi = true,
603         }, {
604                 .version = VI6_IP_VERSION_MODEL_VSPI_GEN3,
605                 .features = VSP1_HAS_LUT | VSP1_HAS_SRU,
606                 .rpf_count = 1,
607                 .uds_count = 1,
608                 .wpf_count = 1,
609                 .uapi = true,
610         }, {
611                 .version = VI6_IP_VERSION_MODEL_VSPBD_GEN3,
612                 .features = VSP1_HAS_BRU,
613                 .rpf_count = 5,
614                 .wpf_count = 1,
615                 .num_bru_inputs = 5,
616                 .uapi = true,
617         }, {
618                 .version = VI6_IP_VERSION_MODEL_VSPBC_GEN3,
619                 .features = VSP1_HAS_BRU | VSP1_HAS_LUT,
620                 .rpf_count = 5,
621                 .wpf_count = 1,
622                 .num_bru_inputs = 5,
623                 .uapi = true,
624         }, {
625                 .version = VI6_IP_VERSION_MODEL_VSPD_GEN3,
626                 .features = VSP1_HAS_BRU | VSP1_HAS_LIF,
627                 .rpf_count = 5,
628                 .wpf_count = 2,
629                 .num_bru_inputs = 5,
630         },
631 };
632
633 static int vsp1_probe(struct platform_device *pdev)
634 {
635         struct vsp1_device *vsp1;
636         struct resource *irq;
637         struct resource *io;
638         unsigned int i;
639         u32 version;
640         int ret;
641
642         vsp1 = devm_kzalloc(&pdev->dev, sizeof(*vsp1), GFP_KERNEL);
643         if (vsp1 == NULL)
644                 return -ENOMEM;
645
646         vsp1->dev = &pdev->dev;
647         mutex_init(&vsp1->lock);
648         INIT_LIST_HEAD(&vsp1->entities);
649         INIT_LIST_HEAD(&vsp1->videos);
650
651         /* I/O, IRQ and clock resources */
652         io = platform_get_resource(pdev, IORESOURCE_MEM, 0);
653         vsp1->mmio = devm_ioremap_resource(&pdev->dev, io);
654         if (IS_ERR(vsp1->mmio))
655                 return PTR_ERR(vsp1->mmio);
656
657         vsp1->clock = devm_clk_get(&pdev->dev, NULL);
658         if (IS_ERR(vsp1->clock)) {
659                 dev_err(&pdev->dev, "failed to get clock\n");
660                 return PTR_ERR(vsp1->clock);
661         }
662
663         irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
664         if (!irq) {
665                 dev_err(&pdev->dev, "missing IRQ\n");
666                 return -EINVAL;
667         }
668
669         ret = devm_request_irq(&pdev->dev, irq->start, vsp1_irq_handler,
670                               IRQF_SHARED, dev_name(&pdev->dev), vsp1);
671         if (ret < 0) {
672                 dev_err(&pdev->dev, "failed to request IRQ\n");
673                 return ret;
674         }
675
676         /* Configure device parameters based on the version register. */
677         ret = clk_prepare_enable(vsp1->clock);
678         if (ret < 0)
679                 return ret;
680
681         version = vsp1_read(vsp1, VI6_IP_VERSION);
682         clk_disable_unprepare(vsp1->clock);
683
684         for (i = 0; i < ARRAY_SIZE(vsp1_device_infos); ++i) {
685                 if ((version & VI6_IP_VERSION_MODEL_MASK) ==
686                     vsp1_device_infos[i].version) {
687                         vsp1->info = &vsp1_device_infos[i];
688                         break;
689                 }
690         }
691
692         if (!vsp1->info) {
693                 dev_err(&pdev->dev, "unsupported IP version 0x%08x\n", version);
694                 return -ENXIO;
695         }
696
697         dev_dbg(&pdev->dev, "IP version 0x%08x\n", version);
698
699         /* Instanciate entities */
700         ret = vsp1_create_entities(vsp1);
701         if (ret < 0) {
702                 dev_err(&pdev->dev, "failed to create entities\n");
703                 return ret;
704         }
705
706         platform_set_drvdata(pdev, vsp1);
707
708         return 0;
709 }
710
711 static int vsp1_remove(struct platform_device *pdev)
712 {
713         struct vsp1_device *vsp1 = platform_get_drvdata(pdev);
714
715         vsp1_destroy_entities(vsp1);
716
717         return 0;
718 }
719
720 static const struct of_device_id vsp1_of_match[] = {
721         { .compatible = "renesas,vsp1" },
722         { .compatible = "renesas,vsp2" },
723         { },
724 };
725
726 static struct platform_driver vsp1_platform_driver = {
727         .probe          = vsp1_probe,
728         .remove         = vsp1_remove,
729         .driver         = {
730                 .name   = "vsp1",
731                 .pm     = &vsp1_pm_ops,
732                 .of_match_table = vsp1_of_match,
733         },
734 };
735
736 module_platform_driver(vsp1_platform_driver);
737
738 MODULE_ALIAS("vsp1");
739 MODULE_AUTHOR("Laurent Pinchart <laurent.pinchart@ideasonboard.com>");
740 MODULE_DESCRIPTION("Renesas VSP1 Driver");
741 MODULE_LICENSE("GPL");