]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/media/platform/vsp1/vsp1_drv.c
[media] v4l: vsp1: Use pipeline display list to decide how to write to modules
[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                 ret = v4l2_device_register_subdev_nodes(&vsp1->v4l2_dev);
392         else
393                 ret = vsp1_drm_init(vsp1);
394         if (ret < 0)
395                 goto done;
396
397         ret = media_device_register(mdev);
398
399 done:
400         if (ret < 0)
401                 vsp1_destroy_entities(vsp1);
402
403         return ret;
404 }
405
406 int vsp1_reset_wpf(struct vsp1_device *vsp1, unsigned int index)
407 {
408         unsigned int timeout;
409         u32 status;
410
411         status = vsp1_read(vsp1, VI6_STATUS);
412         if (!(status & VI6_STATUS_SYS_ACT(index)))
413                 return 0;
414
415         vsp1_write(vsp1, VI6_SRESET, VI6_SRESET_SRTS(index));
416         for (timeout = 10; timeout > 0; --timeout) {
417                 status = vsp1_read(vsp1, VI6_STATUS);
418                 if (!(status & VI6_STATUS_SYS_ACT(index)))
419                         break;
420
421                 usleep_range(1000, 2000);
422         }
423
424         if (!timeout) {
425                 dev_err(vsp1->dev, "failed to reset wpf.%u\n", index);
426                 return -ETIMEDOUT;
427         }
428
429         return 0;
430 }
431
432 static int vsp1_device_init(struct vsp1_device *vsp1)
433 {
434         unsigned int i;
435         int ret;
436
437         /* Reset any channel that might be running. */
438         for (i = 0; i < vsp1->info->wpf_count; ++i) {
439                 ret = vsp1_reset_wpf(vsp1, i);
440                 if (ret < 0)
441                         return ret;
442         }
443
444         vsp1_write(vsp1, VI6_CLK_DCSWT, (8 << VI6_CLK_DCSWT_CSTPW_SHIFT) |
445                    (8 << VI6_CLK_DCSWT_CSTRW_SHIFT));
446
447         for (i = 0; i < vsp1->info->rpf_count; ++i)
448                 vsp1_write(vsp1, VI6_DPR_RPF_ROUTE(i), VI6_DPR_NODE_UNUSED);
449
450         for (i = 0; i < vsp1->info->uds_count; ++i)
451                 vsp1_write(vsp1, VI6_DPR_UDS_ROUTE(i), VI6_DPR_NODE_UNUSED);
452
453         vsp1_write(vsp1, VI6_DPR_SRU_ROUTE, VI6_DPR_NODE_UNUSED);
454         vsp1_write(vsp1, VI6_DPR_LUT_ROUTE, VI6_DPR_NODE_UNUSED);
455         vsp1_write(vsp1, VI6_DPR_CLU_ROUTE, VI6_DPR_NODE_UNUSED);
456         vsp1_write(vsp1, VI6_DPR_HST_ROUTE, VI6_DPR_NODE_UNUSED);
457         vsp1_write(vsp1, VI6_DPR_HSI_ROUTE, VI6_DPR_NODE_UNUSED);
458         vsp1_write(vsp1, VI6_DPR_BRU_ROUTE, VI6_DPR_NODE_UNUSED);
459
460         vsp1_write(vsp1, VI6_DPR_HGO_SMPPT, (7 << VI6_DPR_SMPPT_TGW_SHIFT) |
461                    (VI6_DPR_NODE_UNUSED << VI6_DPR_SMPPT_PT_SHIFT));
462         vsp1_write(vsp1, VI6_DPR_HGT_SMPPT, (7 << VI6_DPR_SMPPT_TGW_SHIFT) |
463                    (VI6_DPR_NODE_UNUSED << VI6_DPR_SMPPT_PT_SHIFT));
464
465         if (!vsp1->info->uapi)
466                 vsp1_dl_setup(vsp1);
467
468         return 0;
469 }
470
471 /*
472  * vsp1_device_get - Acquire the VSP1 device
473  *
474  * Increment the VSP1 reference count and initialize the device if the first
475  * reference is taken.
476  *
477  * Return 0 on success or a negative error code otherwise.
478  */
479 int vsp1_device_get(struct vsp1_device *vsp1)
480 {
481         int ret = 0;
482
483         mutex_lock(&vsp1->lock);
484         if (vsp1->ref_count > 0)
485                 goto done;
486
487         ret = clk_prepare_enable(vsp1->clock);
488         if (ret < 0)
489                 goto done;
490
491         ret = vsp1_device_init(vsp1);
492         if (ret < 0) {
493                 clk_disable_unprepare(vsp1->clock);
494                 goto done;
495         }
496
497 done:
498         if (!ret)
499                 vsp1->ref_count++;
500
501         mutex_unlock(&vsp1->lock);
502         return ret;
503 }
504
505 /*
506  * vsp1_device_put - Release the VSP1 device
507  *
508  * Decrement the VSP1 reference count and cleanup the device if the last
509  * reference is released.
510  */
511 void vsp1_device_put(struct vsp1_device *vsp1)
512 {
513         mutex_lock(&vsp1->lock);
514
515         if (--vsp1->ref_count == 0)
516                 clk_disable_unprepare(vsp1->clock);
517
518         mutex_unlock(&vsp1->lock);
519 }
520
521 /* -----------------------------------------------------------------------------
522  * Power Management
523  */
524
525 #ifdef CONFIG_PM_SLEEP
526 static int vsp1_pm_suspend(struct device *dev)
527 {
528         struct vsp1_device *vsp1 = dev_get_drvdata(dev);
529
530         WARN_ON(mutex_is_locked(&vsp1->lock));
531
532         if (vsp1->ref_count == 0)
533                 return 0;
534
535         vsp1_pipelines_suspend(vsp1);
536
537         clk_disable_unprepare(vsp1->clock);
538
539         return 0;
540 }
541
542 static int vsp1_pm_resume(struct device *dev)
543 {
544         struct vsp1_device *vsp1 = dev_get_drvdata(dev);
545
546         WARN_ON(mutex_is_locked(&vsp1->lock));
547
548         if (vsp1->ref_count == 0)
549                 return 0;
550
551         clk_prepare_enable(vsp1->clock);
552
553         vsp1_pipelines_resume(vsp1);
554
555         return 0;
556 }
557 #endif
558
559 static const struct dev_pm_ops vsp1_pm_ops = {
560         SET_SYSTEM_SLEEP_PM_OPS(vsp1_pm_suspend, vsp1_pm_resume)
561 };
562
563 /* -----------------------------------------------------------------------------
564  * Platform Driver
565  */
566
567 static const struct vsp1_device_info vsp1_device_infos[] = {
568         {
569                 .version = VI6_IP_VERSION_MODEL_VSPS_H2,
570                 .features = VSP1_HAS_BRU | VSP1_HAS_LUT | VSP1_HAS_SRU,
571                 .rpf_count = 5,
572                 .uds_count = 3,
573                 .wpf_count = 4,
574                 .num_bru_inputs = 4,
575                 .uapi = true,
576         }, {
577                 .version = VI6_IP_VERSION_MODEL_VSPR_H2,
578                 .features = VSP1_HAS_BRU | VSP1_HAS_SRU,
579                 .rpf_count = 5,
580                 .uds_count = 1,
581                 .wpf_count = 4,
582                 .num_bru_inputs = 4,
583                 .uapi = true,
584         }, {
585                 .version = VI6_IP_VERSION_MODEL_VSPD_GEN2,
586                 .features = VSP1_HAS_BRU | VSP1_HAS_LIF | VSP1_HAS_LUT,
587                 .rpf_count = 4,
588                 .uds_count = 1,
589                 .wpf_count = 4,
590                 .num_bru_inputs = 4,
591                 .uapi = true,
592         }, {
593                 .version = VI6_IP_VERSION_MODEL_VSPS_M2,
594                 .features = VSP1_HAS_BRU | VSP1_HAS_LUT | VSP1_HAS_SRU,
595                 .rpf_count = 5,
596                 .uds_count = 3,
597                 .wpf_count = 4,
598                 .num_bru_inputs = 4,
599                 .uapi = true,
600         }, {
601                 .version = VI6_IP_VERSION_MODEL_VSPI_GEN3,
602                 .features = VSP1_HAS_LUT | VSP1_HAS_SRU,
603                 .rpf_count = 1,
604                 .uds_count = 1,
605                 .wpf_count = 1,
606                 .uapi = true,
607         }, {
608                 .version = VI6_IP_VERSION_MODEL_VSPBD_GEN3,
609                 .features = VSP1_HAS_BRU,
610                 .rpf_count = 5,
611                 .wpf_count = 1,
612                 .num_bru_inputs = 5,
613                 .uapi = true,
614         }, {
615                 .version = VI6_IP_VERSION_MODEL_VSPBC_GEN3,
616                 .features = VSP1_HAS_BRU | VSP1_HAS_LUT,
617                 .rpf_count = 5,
618                 .wpf_count = 1,
619                 .num_bru_inputs = 5,
620                 .uapi = true,
621         }, {
622                 .version = VI6_IP_VERSION_MODEL_VSPD_GEN3,
623                 .features = VSP1_HAS_BRU | VSP1_HAS_LIF,
624                 .rpf_count = 5,
625                 .wpf_count = 2,
626                 .num_bru_inputs = 5,
627         },
628 };
629
630 static int vsp1_probe(struct platform_device *pdev)
631 {
632         struct vsp1_device *vsp1;
633         struct resource *irq;
634         struct resource *io;
635         unsigned int i;
636         u32 version;
637         int ret;
638
639         vsp1 = devm_kzalloc(&pdev->dev, sizeof(*vsp1), GFP_KERNEL);
640         if (vsp1 == NULL)
641                 return -ENOMEM;
642
643         vsp1->dev = &pdev->dev;
644         mutex_init(&vsp1->lock);
645         INIT_LIST_HEAD(&vsp1->entities);
646         INIT_LIST_HEAD(&vsp1->videos);
647
648         /* I/O, IRQ and clock resources */
649         io = platform_get_resource(pdev, IORESOURCE_MEM, 0);
650         vsp1->mmio = devm_ioremap_resource(&pdev->dev, io);
651         if (IS_ERR(vsp1->mmio))
652                 return PTR_ERR(vsp1->mmio);
653
654         vsp1->clock = devm_clk_get(&pdev->dev, NULL);
655         if (IS_ERR(vsp1->clock)) {
656                 dev_err(&pdev->dev, "failed to get clock\n");
657                 return PTR_ERR(vsp1->clock);
658         }
659
660         irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
661         if (!irq) {
662                 dev_err(&pdev->dev, "missing IRQ\n");
663                 return -EINVAL;
664         }
665
666         ret = devm_request_irq(&pdev->dev, irq->start, vsp1_irq_handler,
667                               IRQF_SHARED, dev_name(&pdev->dev), vsp1);
668         if (ret < 0) {
669                 dev_err(&pdev->dev, "failed to request IRQ\n");
670                 return ret;
671         }
672
673         /* Configure device parameters based on the version register. */
674         ret = clk_prepare_enable(vsp1->clock);
675         if (ret < 0)
676                 return ret;
677
678         version = vsp1_read(vsp1, VI6_IP_VERSION);
679         clk_disable_unprepare(vsp1->clock);
680
681         for (i = 0; i < ARRAY_SIZE(vsp1_device_infos); ++i) {
682                 if ((version & VI6_IP_VERSION_MODEL_MASK) ==
683                     vsp1_device_infos[i].version) {
684                         vsp1->info = &vsp1_device_infos[i];
685                         break;
686                 }
687         }
688
689         if (!vsp1->info) {
690                 dev_err(&pdev->dev, "unsupported IP version 0x%08x\n", version);
691                 return -ENXIO;
692         }
693
694         dev_dbg(&pdev->dev, "IP version 0x%08x\n", version);
695
696         /* Instanciate entities */
697         ret = vsp1_create_entities(vsp1);
698         if (ret < 0) {
699                 dev_err(&pdev->dev, "failed to create entities\n");
700                 return ret;
701         }
702
703         platform_set_drvdata(pdev, vsp1);
704
705         return 0;
706 }
707
708 static int vsp1_remove(struct platform_device *pdev)
709 {
710         struct vsp1_device *vsp1 = platform_get_drvdata(pdev);
711
712         vsp1_destroy_entities(vsp1);
713
714         return 0;
715 }
716
717 static const struct of_device_id vsp1_of_match[] = {
718         { .compatible = "renesas,vsp1" },
719         { .compatible = "renesas,vsp2" },
720         { },
721 };
722
723 static struct platform_driver vsp1_platform_driver = {
724         .probe          = vsp1_probe,
725         .remove         = vsp1_remove,
726         .driver         = {
727                 .name   = "vsp1",
728                 .pm     = &vsp1_pm_ops,
729                 .of_match_table = vsp1_of_match,
730         },
731 };
732
733 module_platform_driver(vsp1_platform_driver);
734
735 MODULE_ALIAS("vsp1");
736 MODULE_AUTHOR("Laurent Pinchart <laurent.pinchart@ideasonboard.com>");
737 MODULE_DESCRIPTION("Renesas VSP1 Driver");
738 MODULE_LICENSE("GPL");