blob: 4209d8615f722e331acbfefbbdd4dde8a9d6ab09 [file] [log] [blame]
Laurent Pinchart26e0ca22013-06-04 11:22:30 -03001/*
2 * vsp1_drv.c -- R-Car VSP1 Driver
3 *
Sei Fumizono139c9282015-03-15 11:33:07 -03004 * Copyright (C) 2013-2015 Renesas Electronics Corporation
Laurent Pinchart26e0ca22013-06-04 11:22:30 -03005 *
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>
Laurent Pinchart0b82fb92014-04-08 13:40:13 -030019#include <linux/of.h>
Laurent Pinchart26e0ca22013-06-04 11:22:30 -030020#include <linux/platform_device.h>
21#include <linux/videodev2.h>
22
23#include "vsp1.h"
Laurent Pinchart629bb6d2013-07-10 18:03:46 -030024#include "vsp1_bru.h"
Laurent Pinchart5cdf5742013-07-10 17:30:14 -030025#include "vsp1_hsit.h"
Laurent Pinchart26e0ca22013-06-04 11:22:30 -030026#include "vsp1_lif.h"
Laurent Pinchart989af882013-07-10 12:03:30 -030027#include "vsp1_lut.h"
Laurent Pinchart26e0ca22013-06-04 11:22:30 -030028#include "vsp1_rwpf.h"
Laurent Pincharta626e642013-07-10 12:03:30 -030029#include "vsp1_sru.h"
Laurent Pinchart26e0ca22013-06-04 11:22:30 -030030#include "vsp1_uds.h"
31
32/* -----------------------------------------------------------------------------
33 * Interrupt Handling
34 */
35
36static irqreturn_t vsp1_irq_handler(int irq, void *data)
37{
38 u32 mask = VI6_WFP_IRQ_STA_DFE | VI6_WFP_IRQ_STA_FRE;
39 struct vsp1_device *vsp1 = data;
40 irqreturn_t ret = IRQ_NONE;
41 unsigned int i;
42
Laurent Pinchart32d17592014-04-09 08:13:18 -030043 for (i = 0; i < vsp1->pdata.wpf_count; ++i) {
Laurent Pinchart26e0ca22013-06-04 11:22:30 -030044 struct vsp1_rwpf *wpf = vsp1->wpf[i];
45 struct vsp1_pipeline *pipe;
46 u32 status;
47
48 if (wpf == NULL)
49 continue;
50
51 pipe = to_vsp1_pipeline(&wpf->entity.subdev.entity);
52 status = vsp1_read(vsp1, VI6_WPF_IRQ_STA(i));
53 vsp1_write(vsp1, VI6_WPF_IRQ_STA(i), ~status & mask);
54
55 if (status & VI6_WFP_IRQ_STA_FRE) {
56 vsp1_pipeline_frame_end(pipe);
57 ret = IRQ_HANDLED;
58 }
59 }
60
61 return ret;
62}
63
64/* -----------------------------------------------------------------------------
65 * Entities
66 */
67
68/*
69 * vsp1_create_links - Create links from all sources to the given sink
70 *
71 * This function creates media links from all valid sources to the given sink
72 * pad. Links that would be invalid according to the VSP1 hardware capabilities
73 * are skipped. Those include all links
74 *
75 * - from a UDS to a UDS (UDS entities can't be chained)
76 * - from an entity to itself (no loops are allowed)
77 */
78static int vsp1_create_links(struct vsp1_device *vsp1, struct vsp1_entity *sink)
79{
80 struct media_entity *entity = &sink->subdev.entity;
81 struct vsp1_entity *source;
82 unsigned int pad;
83 int ret;
84
85 list_for_each_entry(source, &vsp1->entities, list_dev) {
86 u32 flags;
87
88 if (source->type == sink->type)
89 continue;
90
91 if (source->type == VSP1_ENTITY_LIF ||
92 source->type == VSP1_ENTITY_WPF)
93 continue;
94
95 flags = source->type == VSP1_ENTITY_RPF &&
96 sink->type == VSP1_ENTITY_WPF &&
97 source->index == sink->index
98 ? MEDIA_LNK_FL_ENABLED : 0;
99
100 for (pad = 0; pad < entity->num_pads; ++pad) {
101 if (!(entity->pads[pad].flags & MEDIA_PAD_FL_SINK))
102 continue;
103
Mauro Carvalho Chehab8df00a12015-08-07 08:14:38 -0300104 ret = media_create_pad_link(&source->subdev.entity,
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300105 source->source_pad,
106 entity, pad, flags);
107 if (ret < 0)
108 return ret;
Katsuya Matsubaradb32eb62013-07-26 06:32:11 -0300109
110 if (flags & MEDIA_LNK_FL_ENABLED)
111 source->sink = entity;
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300112 }
113 }
114
115 return 0;
116}
117
118static void vsp1_destroy_entities(struct vsp1_device *vsp1)
119{
120 struct vsp1_entity *entity;
121 struct vsp1_entity *next;
122
123 list_for_each_entry_safe(entity, next, &vsp1->entities, list_dev) {
124 list_del(&entity->list_dev);
125 vsp1_entity_destroy(entity);
126 }
127
128 v4l2_device_unregister(&vsp1->v4l2_dev);
129 media_device_unregister(&vsp1->media_dev);
130}
131
132static int vsp1_create_entities(struct vsp1_device *vsp1)
133{
134 struct media_device *mdev = &vsp1->media_dev;
135 struct v4l2_device *vdev = &vsp1->v4l2_dev;
136 struct vsp1_entity *entity;
137 unsigned int i;
138 int ret;
139
140 mdev->dev = vsp1->dev;
141 strlcpy(mdev->model, "VSP1", sizeof(mdev->model));
Laurent Pinchart10d79b92013-08-22 14:11:47 -0300142 snprintf(mdev->bus_info, sizeof(mdev->bus_info), "platform:%s",
143 dev_name(mdev->dev));
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300144 ret = media_device_register(mdev);
145 if (ret < 0) {
146 dev_err(vsp1->dev, "media device registration failed (%d)\n",
147 ret);
148 return ret;
149 }
150
151 vdev->mdev = mdev;
152 ret = v4l2_device_register(vsp1->dev, vdev);
153 if (ret < 0) {
154 dev_err(vsp1->dev, "V4L2 device registration failed (%d)\n",
155 ret);
156 goto done;
157 }
158
159 /* Instantiate all the entities. */
Laurent Pinchart629bb6d2013-07-10 18:03:46 -0300160 vsp1->bru = vsp1_bru_create(vsp1);
161 if (IS_ERR(vsp1->bru)) {
162 ret = PTR_ERR(vsp1->bru);
163 goto done;
164 }
165
166 list_add_tail(&vsp1->bru->entity.list_dev, &vsp1->entities);
167
Laurent Pinchart5cdf5742013-07-10 17:30:14 -0300168 vsp1->hsi = vsp1_hsit_create(vsp1, true);
169 if (IS_ERR(vsp1->hsi)) {
170 ret = PTR_ERR(vsp1->hsi);
171 goto done;
172 }
173
174 list_add_tail(&vsp1->hsi->entity.list_dev, &vsp1->entities);
175
176 vsp1->hst = vsp1_hsit_create(vsp1, false);
177 if (IS_ERR(vsp1->hst)) {
178 ret = PTR_ERR(vsp1->hst);
179 goto done;
180 }
181
182 list_add_tail(&vsp1->hst->entity.list_dev, &vsp1->entities);
183
Laurent Pinchart32d17592014-04-09 08:13:18 -0300184 if (vsp1->pdata.features & VSP1_HAS_LIF) {
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300185 vsp1->lif = vsp1_lif_create(vsp1);
186 if (IS_ERR(vsp1->lif)) {
187 ret = PTR_ERR(vsp1->lif);
188 goto done;
189 }
190
191 list_add_tail(&vsp1->lif->entity.list_dev, &vsp1->entities);
192 }
193
Laurent Pinchart32d17592014-04-09 08:13:18 -0300194 if (vsp1->pdata.features & VSP1_HAS_LUT) {
Laurent Pinchart989af882013-07-10 12:03:30 -0300195 vsp1->lut = vsp1_lut_create(vsp1);
196 if (IS_ERR(vsp1->lut)) {
197 ret = PTR_ERR(vsp1->lut);
198 goto done;
199 }
200
201 list_add_tail(&vsp1->lut->entity.list_dev, &vsp1->entities);
202 }
203
Laurent Pinchart32d17592014-04-09 08:13:18 -0300204 for (i = 0; i < vsp1->pdata.rpf_count; ++i) {
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300205 struct vsp1_rwpf *rpf;
206
207 rpf = vsp1_rpf_create(vsp1, i);
208 if (IS_ERR(rpf)) {
209 ret = PTR_ERR(rpf);
210 goto done;
211 }
212
213 vsp1->rpf[i] = rpf;
214 list_add_tail(&rpf->entity.list_dev, &vsp1->entities);
215 }
216
Laurent Pinchart32d17592014-04-09 08:13:18 -0300217 if (vsp1->pdata.features & VSP1_HAS_SRU) {
Laurent Pincharta626e642013-07-10 12:03:30 -0300218 vsp1->sru = vsp1_sru_create(vsp1);
219 if (IS_ERR(vsp1->sru)) {
220 ret = PTR_ERR(vsp1->sru);
221 goto done;
222 }
223
224 list_add_tail(&vsp1->sru->entity.list_dev, &vsp1->entities);
225 }
226
Laurent Pinchart32d17592014-04-09 08:13:18 -0300227 for (i = 0; i < vsp1->pdata.uds_count; ++i) {
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300228 struct vsp1_uds *uds;
229
230 uds = vsp1_uds_create(vsp1, i);
231 if (IS_ERR(uds)) {
232 ret = PTR_ERR(uds);
233 goto done;
234 }
235
236 vsp1->uds[i] = uds;
237 list_add_tail(&uds->entity.list_dev, &vsp1->entities);
238 }
239
Laurent Pinchart32d17592014-04-09 08:13:18 -0300240 for (i = 0; i < vsp1->pdata.wpf_count; ++i) {
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300241 struct vsp1_rwpf *wpf;
242
243 wpf = vsp1_wpf_create(vsp1, i);
244 if (IS_ERR(wpf)) {
245 ret = PTR_ERR(wpf);
246 goto done;
247 }
248
249 vsp1->wpf[i] = wpf;
250 list_add_tail(&wpf->entity.list_dev, &vsp1->entities);
251 }
252
Javier Martinez Canillas7213fe72015-09-03 11:20:34 -0300253 /* Register all subdevs. */
254 list_for_each_entry(entity, &vsp1->entities, list_dev) {
255 ret = v4l2_device_register_subdev(&vsp1->v4l2_dev,
256 &entity->subdev);
257 if (ret < 0)
258 goto done;
259 }
260
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300261 /* Create links. */
262 list_for_each_entry(entity, &vsp1->entities, list_dev) {
Javier Martinez Canillasc7621b32015-09-03 12:19:25 -0300263 if (entity->type == VSP1_ENTITY_LIF) {
Javier Martinez Canillasd8a2cf42015-12-11 15:16:32 -0200264 ret = vsp1_wpf_create_links(vsp1, entity);
Javier Martinez Canillasc7621b32015-09-03 12:19:25 -0300265 if (ret < 0)
266 goto done;
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300267 continue;
Javier Martinez Canillasc7621b32015-09-03 12:19:25 -0300268 }
269
270 if (entity->type == VSP1_ENTITY_RPF) {
Javier Martinez Canillasd8a2cf42015-12-11 15:16:32 -0200271 ret = vsp1_rpf_create_links(vsp1, entity);
Javier Martinez Canillasc7621b32015-09-03 12:19:25 -0300272 if (ret < 0)
273 goto done;
274 continue;
275 }
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300276
277 ret = vsp1_create_links(vsp1, entity);
278 if (ret < 0)
279 goto done;
280 }
281
Laurent Pinchart32d17592014-04-09 08:13:18 -0300282 if (vsp1->pdata.features & VSP1_HAS_LIF) {
Mauro Carvalho Chehab8df00a12015-08-07 08:14:38 -0300283 ret = media_create_pad_link(
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300284 &vsp1->wpf[0]->entity.subdev.entity, RWPF_PAD_SOURCE,
285 &vsp1->lif->entity.subdev.entity, LIF_PAD_SINK, 0);
286 if (ret < 0)
287 return ret;
288 }
289
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300290 ret = v4l2_device_register_subdev_nodes(&vsp1->v4l2_dev);
291
292done:
293 if (ret < 0)
294 vsp1_destroy_entities(vsp1);
295
296 return ret;
297}
298
299static int vsp1_device_init(struct vsp1_device *vsp1)
300{
301 unsigned int i;
302 u32 status;
303
304 /* Reset any channel that might be running. */
305 status = vsp1_read(vsp1, VI6_STATUS);
306
Laurent Pinchart32d17592014-04-09 08:13:18 -0300307 for (i = 0; i < vsp1->pdata.wpf_count; ++i) {
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300308 unsigned int timeout;
309
310 if (!(status & VI6_STATUS_SYS_ACT(i)))
311 continue;
312
313 vsp1_write(vsp1, VI6_SRESET, VI6_SRESET_SRTS(i));
314 for (timeout = 10; timeout > 0; --timeout) {
315 status = vsp1_read(vsp1, VI6_STATUS);
316 if (!(status & VI6_STATUS_SYS_ACT(i)))
317 break;
318
319 usleep_range(1000, 2000);
320 }
321
322 if (!timeout) {
323 dev_err(vsp1->dev, "failed to reset wpf.%u\n", i);
324 return -ETIMEDOUT;
325 }
326 }
327
328 vsp1_write(vsp1, VI6_CLK_DCSWT, (8 << VI6_CLK_DCSWT_CSTPW_SHIFT) |
329 (8 << VI6_CLK_DCSWT_CSTRW_SHIFT));
330
Laurent Pinchart32d17592014-04-09 08:13:18 -0300331 for (i = 0; i < vsp1->pdata.rpf_count; ++i)
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300332 vsp1_write(vsp1, VI6_DPR_RPF_ROUTE(i), VI6_DPR_NODE_UNUSED);
333
Laurent Pinchart32d17592014-04-09 08:13:18 -0300334 for (i = 0; i < vsp1->pdata.uds_count; ++i)
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300335 vsp1_write(vsp1, VI6_DPR_UDS_ROUTE(i), VI6_DPR_NODE_UNUSED);
336
337 vsp1_write(vsp1, VI6_DPR_SRU_ROUTE, VI6_DPR_NODE_UNUSED);
338 vsp1_write(vsp1, VI6_DPR_LUT_ROUTE, VI6_DPR_NODE_UNUSED);
339 vsp1_write(vsp1, VI6_DPR_CLU_ROUTE, VI6_DPR_NODE_UNUSED);
340 vsp1_write(vsp1, VI6_DPR_HST_ROUTE, VI6_DPR_NODE_UNUSED);
341 vsp1_write(vsp1, VI6_DPR_HSI_ROUTE, VI6_DPR_NODE_UNUSED);
342 vsp1_write(vsp1, VI6_DPR_BRU_ROUTE, VI6_DPR_NODE_UNUSED);
343
344 vsp1_write(vsp1, VI6_DPR_HGO_SMPPT, (7 << VI6_DPR_SMPPT_TGW_SHIFT) |
345 (VI6_DPR_NODE_UNUSED << VI6_DPR_SMPPT_PT_SHIFT));
346 vsp1_write(vsp1, VI6_DPR_HGT_SMPPT, (7 << VI6_DPR_SMPPT_TGW_SHIFT) |
347 (VI6_DPR_NODE_UNUSED << VI6_DPR_SMPPT_PT_SHIFT));
348
349 return 0;
350}
351
352/*
353 * vsp1_device_get - Acquire the VSP1 device
354 *
355 * Increment the VSP1 reference count and initialize the device if the first
356 * reference is taken.
357 *
Laurent Pinchart4c16d6a2014-05-31 08:50:32 -0300358 * Return 0 on success or a negative error code otherwise.
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300359 */
Laurent Pinchart4c16d6a2014-05-31 08:50:32 -0300360int vsp1_device_get(struct vsp1_device *vsp1)
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300361{
Laurent Pinchart4c16d6a2014-05-31 08:50:32 -0300362 int ret = 0;
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300363
364 mutex_lock(&vsp1->lock);
365 if (vsp1->ref_count > 0)
366 goto done;
367
Laurent Pinchart4fc78782014-04-02 11:21:56 -0300368 ret = clk_prepare_enable(vsp1->clock);
Laurent Pinchart4c16d6a2014-05-31 08:50:32 -0300369 if (ret < 0)
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300370 goto done;
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300371
372 ret = vsp1_device_init(vsp1);
373 if (ret < 0) {
Laurent Pinchart4fc78782014-04-02 11:21:56 -0300374 clk_disable_unprepare(vsp1->clock);
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300375 goto done;
376 }
377
378done:
Laurent Pinchart4c16d6a2014-05-31 08:50:32 -0300379 if (!ret)
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300380 vsp1->ref_count++;
381
382 mutex_unlock(&vsp1->lock);
Laurent Pinchart4c16d6a2014-05-31 08:50:32 -0300383 return ret;
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300384}
385
386/*
387 * vsp1_device_put - Release the VSP1 device
388 *
389 * Decrement the VSP1 reference count and cleanup the device if the last
390 * reference is released.
391 */
392void vsp1_device_put(struct vsp1_device *vsp1)
393{
394 mutex_lock(&vsp1->lock);
395
396 if (--vsp1->ref_count == 0)
Laurent Pinchart4fc78782014-04-02 11:21:56 -0300397 clk_disable_unprepare(vsp1->clock);
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300398
399 mutex_unlock(&vsp1->lock);
400}
401
402/* -----------------------------------------------------------------------------
403 * Power Management
404 */
405
406#ifdef CONFIG_PM_SLEEP
407static int vsp1_pm_suspend(struct device *dev)
408{
409 struct vsp1_device *vsp1 = dev_get_drvdata(dev);
410
411 WARN_ON(mutex_is_locked(&vsp1->lock));
412
413 if (vsp1->ref_count == 0)
414 return 0;
415
Sei Fumizono139c9282015-03-15 11:33:07 -0300416 vsp1_pipelines_suspend(vsp1);
417
Laurent Pinchart4fc78782014-04-02 11:21:56 -0300418 clk_disable_unprepare(vsp1->clock);
Sei Fumizono139c9282015-03-15 11:33:07 -0300419
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300420 return 0;
421}
422
423static int vsp1_pm_resume(struct device *dev)
424{
425 struct vsp1_device *vsp1 = dev_get_drvdata(dev);
426
427 WARN_ON(mutex_is_locked(&vsp1->lock));
428
Sei Fumizono139c9282015-03-15 11:33:07 -0300429 if (vsp1->ref_count == 0)
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300430 return 0;
431
Sei Fumizono139c9282015-03-15 11:33:07 -0300432 clk_prepare_enable(vsp1->clock);
433
434 vsp1_pipelines_resume(vsp1);
435
436 return 0;
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300437}
438#endif
439
440static const struct dev_pm_ops vsp1_pm_ops = {
441 SET_SYSTEM_SLEEP_PM_OPS(vsp1_pm_suspend, vsp1_pm_resume)
442};
443
444/* -----------------------------------------------------------------------------
445 * Platform Driver
446 */
447
Laurent Pinchart32d17592014-04-09 08:13:18 -0300448static int vsp1_parse_dt(struct vsp1_device *vsp1)
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300449{
Laurent Pinchart32d17592014-04-09 08:13:18 -0300450 struct device_node *np = vsp1->dev->of_node;
451 struct vsp1_platform_data *pdata = &vsp1->pdata;
Laurent Pinchart0b82fb92014-04-08 13:40:13 -0300452
453 if (of_property_read_bool(np, "renesas,has-lif"))
454 pdata->features |= VSP1_HAS_LIF;
455 if (of_property_read_bool(np, "renesas,has-lut"))
456 pdata->features |= VSP1_HAS_LUT;
457 if (of_property_read_bool(np, "renesas,has-sru"))
458 pdata->features |= VSP1_HAS_SRU;
459
460 of_property_read_u32(np, "renesas,#rpf", &pdata->rpf_count);
461 of_property_read_u32(np, "renesas,#uds", &pdata->uds_count);
462 of_property_read_u32(np, "renesas,#wpf", &pdata->wpf_count);
463
Laurent Pinchart32d17592014-04-09 08:13:18 -0300464 if (pdata->rpf_count <= 0 || pdata->rpf_count > VSP1_MAX_RPF) {
465 dev_err(vsp1->dev, "invalid number of RPF (%u)\n",
466 pdata->rpf_count);
467 return -EINVAL;
468 }
469
470 if (pdata->uds_count <= 0 || pdata->uds_count > VSP1_MAX_UDS) {
471 dev_err(vsp1->dev, "invalid number of UDS (%u)\n",
472 pdata->uds_count);
473 return -EINVAL;
474 }
475
476 if (pdata->wpf_count <= 0 || pdata->wpf_count > VSP1_MAX_WPF) {
477 dev_err(vsp1->dev, "invalid number of WPF (%u)\n",
478 pdata->wpf_count);
479 return -EINVAL;
480 }
481
482 return 0;
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300483}
484
485static int vsp1_probe(struct platform_device *pdev)
486{
487 struct vsp1_device *vsp1;
488 struct resource *irq;
489 struct resource *io;
490 int ret;
491
492 vsp1 = devm_kzalloc(&pdev->dev, sizeof(*vsp1), GFP_KERNEL);
493 if (vsp1 == NULL)
494 return -ENOMEM;
495
496 vsp1->dev = &pdev->dev;
497 mutex_init(&vsp1->lock);
498 INIT_LIST_HEAD(&vsp1->entities);
499
Laurent Pinchart32d17592014-04-09 08:13:18 -0300500 ret = vsp1_parse_dt(vsp1);
Laurent Pinchart0b82fb92014-04-08 13:40:13 -0300501 if (ret < 0)
502 return ret;
503
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300504 /* I/O, IRQ and clock resources */
505 io = platform_get_resource(pdev, IORESOURCE_MEM, 0);
506 vsp1->mmio = devm_ioremap_resource(&pdev->dev, io);
Mauro Carvalho Chehabcbec6d32013-08-24 08:47:51 -0300507 if (IS_ERR(vsp1->mmio))
508 return PTR_ERR(vsp1->mmio);
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300509
510 vsp1->clock = devm_clk_get(&pdev->dev, NULL);
511 if (IS_ERR(vsp1->clock)) {
512 dev_err(&pdev->dev, "failed to get clock\n");
513 return PTR_ERR(vsp1->clock);
514 }
515
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300516 irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
517 if (!irq) {
518 dev_err(&pdev->dev, "missing IRQ\n");
519 return -EINVAL;
520 }
521
522 ret = devm_request_irq(&pdev->dev, irq->start, vsp1_irq_handler,
523 IRQF_SHARED, dev_name(&pdev->dev), vsp1);
524 if (ret < 0) {
525 dev_err(&pdev->dev, "failed to request IRQ\n");
526 return ret;
527 }
528
529 /* Instanciate entities */
530 ret = vsp1_create_entities(vsp1);
531 if (ret < 0) {
532 dev_err(&pdev->dev, "failed to create entities\n");
533 return ret;
534 }
535
536 platform_set_drvdata(pdev, vsp1);
537
538 return 0;
539}
540
541static int vsp1_remove(struct platform_device *pdev)
542{
543 struct vsp1_device *vsp1 = platform_get_drvdata(pdev);
544
545 vsp1_destroy_entities(vsp1);
546
547 return 0;
548}
549
Laurent Pinchart0b82fb92014-04-08 13:40:13 -0300550static const struct of_device_id vsp1_of_match[] = {
551 { .compatible = "renesas,vsp1" },
552 { },
553};
554
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300555static struct platform_driver vsp1_platform_driver = {
556 .probe = vsp1_probe,
557 .remove = vsp1_remove,
558 .driver = {
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300559 .name = "vsp1",
560 .pm = &vsp1_pm_ops,
Laurent Pinchart0b82fb92014-04-08 13:40:13 -0300561 .of_match_table = vsp1_of_match,
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300562 },
563};
564
565module_platform_driver(vsp1_platform_driver);
566
567MODULE_ALIAS("vsp1");
568MODULE_AUTHOR("Laurent Pinchart <laurent.pinchart@ideasonboard.com>");
569MODULE_DESCRIPTION("Renesas VSP1 Driver");
570MODULE_LICENSE("GPL");