blob: 533bc796391ed3053a5f21c92e94eba92cdc46a4 [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);
Javier Martinez Canillas9832e152015-12-11 20:57:08 -0200130 media_device_cleanup(&vsp1->media_dev);
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300131}
132
133static int vsp1_create_entities(struct vsp1_device *vsp1)
134{
135 struct media_device *mdev = &vsp1->media_dev;
136 struct v4l2_device *vdev = &vsp1->v4l2_dev;
137 struct vsp1_entity *entity;
138 unsigned int i;
139 int ret;
140
141 mdev->dev = vsp1->dev;
142 strlcpy(mdev->model, "VSP1", sizeof(mdev->model));
Laurent Pinchart10d79b92013-08-22 14:11:47 -0300143 snprintf(mdev->bus_info, sizeof(mdev->bus_info), "platform:%s",
144 dev_name(mdev->dev));
Javier Martinez Canillas9832e152015-12-11 20:57:08 -0200145 media_device_init(mdev);
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300146
147 vdev->mdev = mdev;
148 ret = v4l2_device_register(vsp1->dev, vdev);
149 if (ret < 0) {
150 dev_err(vsp1->dev, "V4L2 device registration failed (%d)\n",
151 ret);
152 goto done;
153 }
154
155 /* Instantiate all the entities. */
Laurent Pinchart629bb6d2013-07-10 18:03:46 -0300156 vsp1->bru = vsp1_bru_create(vsp1);
157 if (IS_ERR(vsp1->bru)) {
158 ret = PTR_ERR(vsp1->bru);
159 goto done;
160 }
161
162 list_add_tail(&vsp1->bru->entity.list_dev, &vsp1->entities);
163
Laurent Pinchart5cdf5742013-07-10 17:30:14 -0300164 vsp1->hsi = vsp1_hsit_create(vsp1, true);
165 if (IS_ERR(vsp1->hsi)) {
166 ret = PTR_ERR(vsp1->hsi);
167 goto done;
168 }
169
170 list_add_tail(&vsp1->hsi->entity.list_dev, &vsp1->entities);
171
172 vsp1->hst = vsp1_hsit_create(vsp1, false);
173 if (IS_ERR(vsp1->hst)) {
174 ret = PTR_ERR(vsp1->hst);
175 goto done;
176 }
177
178 list_add_tail(&vsp1->hst->entity.list_dev, &vsp1->entities);
179
Laurent Pinchart32d17592014-04-09 08:13:18 -0300180 if (vsp1->pdata.features & VSP1_HAS_LIF) {
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300181 vsp1->lif = vsp1_lif_create(vsp1);
182 if (IS_ERR(vsp1->lif)) {
183 ret = PTR_ERR(vsp1->lif);
184 goto done;
185 }
186
187 list_add_tail(&vsp1->lif->entity.list_dev, &vsp1->entities);
188 }
189
Laurent Pinchart32d17592014-04-09 08:13:18 -0300190 if (vsp1->pdata.features & VSP1_HAS_LUT) {
Laurent Pinchart989af882013-07-10 12:03:30 -0300191 vsp1->lut = vsp1_lut_create(vsp1);
192 if (IS_ERR(vsp1->lut)) {
193 ret = PTR_ERR(vsp1->lut);
194 goto done;
195 }
196
197 list_add_tail(&vsp1->lut->entity.list_dev, &vsp1->entities);
198 }
199
Laurent Pinchart32d17592014-04-09 08:13:18 -0300200 for (i = 0; i < vsp1->pdata.rpf_count; ++i) {
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300201 struct vsp1_rwpf *rpf;
202
203 rpf = vsp1_rpf_create(vsp1, i);
204 if (IS_ERR(rpf)) {
205 ret = PTR_ERR(rpf);
206 goto done;
207 }
208
209 vsp1->rpf[i] = rpf;
210 list_add_tail(&rpf->entity.list_dev, &vsp1->entities);
211 }
212
Laurent Pinchart32d17592014-04-09 08:13:18 -0300213 if (vsp1->pdata.features & VSP1_HAS_SRU) {
Laurent Pincharta626e642013-07-10 12:03:30 -0300214 vsp1->sru = vsp1_sru_create(vsp1);
215 if (IS_ERR(vsp1->sru)) {
216 ret = PTR_ERR(vsp1->sru);
217 goto done;
218 }
219
220 list_add_tail(&vsp1->sru->entity.list_dev, &vsp1->entities);
221 }
222
Laurent Pinchart32d17592014-04-09 08:13:18 -0300223 for (i = 0; i < vsp1->pdata.uds_count; ++i) {
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300224 struct vsp1_uds *uds;
225
226 uds = vsp1_uds_create(vsp1, i);
227 if (IS_ERR(uds)) {
228 ret = PTR_ERR(uds);
229 goto done;
230 }
231
232 vsp1->uds[i] = uds;
233 list_add_tail(&uds->entity.list_dev, &vsp1->entities);
234 }
235
Laurent Pinchart32d17592014-04-09 08:13:18 -0300236 for (i = 0; i < vsp1->pdata.wpf_count; ++i) {
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300237 struct vsp1_rwpf *wpf;
238
239 wpf = vsp1_wpf_create(vsp1, i);
240 if (IS_ERR(wpf)) {
241 ret = PTR_ERR(wpf);
242 goto done;
243 }
244
245 vsp1->wpf[i] = wpf;
246 list_add_tail(&wpf->entity.list_dev, &vsp1->entities);
247 }
248
Javier Martinez Canillas7213fe72015-09-03 11:20:34 -0300249 /* Register all subdevs. */
250 list_for_each_entry(entity, &vsp1->entities, list_dev) {
251 ret = v4l2_device_register_subdev(&vsp1->v4l2_dev,
252 &entity->subdev);
253 if (ret < 0)
254 goto done;
255 }
256
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300257 /* Create links. */
258 list_for_each_entry(entity, &vsp1->entities, list_dev) {
Javier Martinez Canillas5017e1b2016-01-19 11:45:12 -0200259 if (entity->type == VSP1_ENTITY_WPF) {
Javier Martinez Canillasd8a2cf42015-12-11 15:16:32 -0200260 ret = vsp1_wpf_create_links(vsp1, entity);
Javier Martinez Canillasc7621b32015-09-03 12:19:25 -0300261 if (ret < 0)
262 goto done;
Javier Martinez Canillas1488eee2015-12-11 15:16:33 -0200263 } else if (entity->type == VSP1_ENTITY_RPF) {
Javier Martinez Canillasd8a2cf42015-12-11 15:16:32 -0200264 ret = vsp1_rpf_create_links(vsp1, entity);
Javier Martinez Canillasc7621b32015-09-03 12:19:25 -0300265 if (ret < 0)
266 goto done;
Javier Martinez Canillas5017e1b2016-01-19 11:45:12 -0200267 }
268
269 if (entity->type != VSP1_ENTITY_LIF &&
270 entity->type != VSP1_ENTITY_RPF) {
Javier Martinez Canillas1488eee2015-12-11 15:16:33 -0200271 ret = vsp1_create_links(vsp1, entity);
272 if (ret < 0)
273 goto done;
Javier Martinez Canillasc7621b32015-09-03 12:19:25 -0300274 }
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300275 }
276
Laurent Pinchart32d17592014-04-09 08:13:18 -0300277 if (vsp1->pdata.features & VSP1_HAS_LIF) {
Mauro Carvalho Chehab8df00a12015-08-07 08:14:38 -0300278 ret = media_create_pad_link(
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300279 &vsp1->wpf[0]->entity.subdev.entity, RWPF_PAD_SOURCE,
280 &vsp1->lif->entity.subdev.entity, LIF_PAD_SINK, 0);
281 if (ret < 0)
282 return ret;
283 }
284
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300285 ret = v4l2_device_register_subdev_nodes(&vsp1->v4l2_dev);
Javier Martinez Canillas9832e152015-12-11 20:57:08 -0200286 if (ret < 0)
287 goto done;
288
289 ret = media_device_register(mdev);
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300290
291done:
292 if (ret < 0)
293 vsp1_destroy_entities(vsp1);
294
295 return ret;
296}
297
298static int vsp1_device_init(struct vsp1_device *vsp1)
299{
300 unsigned int i;
301 u32 status;
302
303 /* Reset any channel that might be running. */
304 status = vsp1_read(vsp1, VI6_STATUS);
305
Laurent Pinchart32d17592014-04-09 08:13:18 -0300306 for (i = 0; i < vsp1->pdata.wpf_count; ++i) {
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300307 unsigned int timeout;
308
309 if (!(status & VI6_STATUS_SYS_ACT(i)))
310 continue;
311
312 vsp1_write(vsp1, VI6_SRESET, VI6_SRESET_SRTS(i));
313 for (timeout = 10; timeout > 0; --timeout) {
314 status = vsp1_read(vsp1, VI6_STATUS);
315 if (!(status & VI6_STATUS_SYS_ACT(i)))
316 break;
317
318 usleep_range(1000, 2000);
319 }
320
321 if (!timeout) {
322 dev_err(vsp1->dev, "failed to reset wpf.%u\n", i);
323 return -ETIMEDOUT;
324 }
325 }
326
327 vsp1_write(vsp1, VI6_CLK_DCSWT, (8 << VI6_CLK_DCSWT_CSTPW_SHIFT) |
328 (8 << VI6_CLK_DCSWT_CSTRW_SHIFT));
329
Laurent Pinchart32d17592014-04-09 08:13:18 -0300330 for (i = 0; i < vsp1->pdata.rpf_count; ++i)
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300331 vsp1_write(vsp1, VI6_DPR_RPF_ROUTE(i), VI6_DPR_NODE_UNUSED);
332
Laurent Pinchart32d17592014-04-09 08:13:18 -0300333 for (i = 0; i < vsp1->pdata.uds_count; ++i)
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300334 vsp1_write(vsp1, VI6_DPR_UDS_ROUTE(i), VI6_DPR_NODE_UNUSED);
335
336 vsp1_write(vsp1, VI6_DPR_SRU_ROUTE, VI6_DPR_NODE_UNUSED);
337 vsp1_write(vsp1, VI6_DPR_LUT_ROUTE, VI6_DPR_NODE_UNUSED);
338 vsp1_write(vsp1, VI6_DPR_CLU_ROUTE, VI6_DPR_NODE_UNUSED);
339 vsp1_write(vsp1, VI6_DPR_HST_ROUTE, VI6_DPR_NODE_UNUSED);
340 vsp1_write(vsp1, VI6_DPR_HSI_ROUTE, VI6_DPR_NODE_UNUSED);
341 vsp1_write(vsp1, VI6_DPR_BRU_ROUTE, VI6_DPR_NODE_UNUSED);
342
343 vsp1_write(vsp1, VI6_DPR_HGO_SMPPT, (7 << VI6_DPR_SMPPT_TGW_SHIFT) |
344 (VI6_DPR_NODE_UNUSED << VI6_DPR_SMPPT_PT_SHIFT));
345 vsp1_write(vsp1, VI6_DPR_HGT_SMPPT, (7 << VI6_DPR_SMPPT_TGW_SHIFT) |
346 (VI6_DPR_NODE_UNUSED << VI6_DPR_SMPPT_PT_SHIFT));
347
348 return 0;
349}
350
351/*
352 * vsp1_device_get - Acquire the VSP1 device
353 *
354 * Increment the VSP1 reference count and initialize the device if the first
355 * reference is taken.
356 *
Laurent Pinchart4c16d6a2014-05-31 08:50:32 -0300357 * Return 0 on success or a negative error code otherwise.
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300358 */
Laurent Pinchart4c16d6a2014-05-31 08:50:32 -0300359int vsp1_device_get(struct vsp1_device *vsp1)
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300360{
Laurent Pinchart4c16d6a2014-05-31 08:50:32 -0300361 int ret = 0;
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300362
363 mutex_lock(&vsp1->lock);
364 if (vsp1->ref_count > 0)
365 goto done;
366
Laurent Pinchart4fc78782014-04-02 11:21:56 -0300367 ret = clk_prepare_enable(vsp1->clock);
Laurent Pinchart4c16d6a2014-05-31 08:50:32 -0300368 if (ret < 0)
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300369 goto done;
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300370
371 ret = vsp1_device_init(vsp1);
372 if (ret < 0) {
Laurent Pinchart4fc78782014-04-02 11:21:56 -0300373 clk_disable_unprepare(vsp1->clock);
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300374 goto done;
375 }
376
377done:
Laurent Pinchart4c16d6a2014-05-31 08:50:32 -0300378 if (!ret)
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300379 vsp1->ref_count++;
380
381 mutex_unlock(&vsp1->lock);
Laurent Pinchart4c16d6a2014-05-31 08:50:32 -0300382 return ret;
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300383}
384
385/*
386 * vsp1_device_put - Release the VSP1 device
387 *
388 * Decrement the VSP1 reference count and cleanup the device if the last
389 * reference is released.
390 */
391void vsp1_device_put(struct vsp1_device *vsp1)
392{
393 mutex_lock(&vsp1->lock);
394
395 if (--vsp1->ref_count == 0)
Laurent Pinchart4fc78782014-04-02 11:21:56 -0300396 clk_disable_unprepare(vsp1->clock);
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300397
398 mutex_unlock(&vsp1->lock);
399}
400
401/* -----------------------------------------------------------------------------
402 * Power Management
403 */
404
405#ifdef CONFIG_PM_SLEEP
406static int vsp1_pm_suspend(struct device *dev)
407{
408 struct vsp1_device *vsp1 = dev_get_drvdata(dev);
409
410 WARN_ON(mutex_is_locked(&vsp1->lock));
411
412 if (vsp1->ref_count == 0)
413 return 0;
414
Sei Fumizono139c9282015-03-15 11:33:07 -0300415 vsp1_pipelines_suspend(vsp1);
416
Laurent Pinchart4fc78782014-04-02 11:21:56 -0300417 clk_disable_unprepare(vsp1->clock);
Sei Fumizono139c9282015-03-15 11:33:07 -0300418
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300419 return 0;
420}
421
422static int vsp1_pm_resume(struct device *dev)
423{
424 struct vsp1_device *vsp1 = dev_get_drvdata(dev);
425
426 WARN_ON(mutex_is_locked(&vsp1->lock));
427
Sei Fumizono139c9282015-03-15 11:33:07 -0300428 if (vsp1->ref_count == 0)
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300429 return 0;
430
Sei Fumizono139c9282015-03-15 11:33:07 -0300431 clk_prepare_enable(vsp1->clock);
432
433 vsp1_pipelines_resume(vsp1);
434
435 return 0;
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300436}
437#endif
438
439static const struct dev_pm_ops vsp1_pm_ops = {
440 SET_SYSTEM_SLEEP_PM_OPS(vsp1_pm_suspend, vsp1_pm_resume)
441};
442
443/* -----------------------------------------------------------------------------
444 * Platform Driver
445 */
446
Laurent Pinchart32d17592014-04-09 08:13:18 -0300447static int vsp1_parse_dt(struct vsp1_device *vsp1)
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300448{
Laurent Pinchart32d17592014-04-09 08:13:18 -0300449 struct device_node *np = vsp1->dev->of_node;
450 struct vsp1_platform_data *pdata = &vsp1->pdata;
Laurent Pinchart0b82fb92014-04-08 13:40:13 -0300451
452 if (of_property_read_bool(np, "renesas,has-lif"))
453 pdata->features |= VSP1_HAS_LIF;
454 if (of_property_read_bool(np, "renesas,has-lut"))
455 pdata->features |= VSP1_HAS_LUT;
456 if (of_property_read_bool(np, "renesas,has-sru"))
457 pdata->features |= VSP1_HAS_SRU;
458
459 of_property_read_u32(np, "renesas,#rpf", &pdata->rpf_count);
460 of_property_read_u32(np, "renesas,#uds", &pdata->uds_count);
461 of_property_read_u32(np, "renesas,#wpf", &pdata->wpf_count);
462
Laurent Pinchart32d17592014-04-09 08:13:18 -0300463 if (pdata->rpf_count <= 0 || pdata->rpf_count > VSP1_MAX_RPF) {
464 dev_err(vsp1->dev, "invalid number of RPF (%u)\n",
465 pdata->rpf_count);
466 return -EINVAL;
467 }
468
469 if (pdata->uds_count <= 0 || pdata->uds_count > VSP1_MAX_UDS) {
470 dev_err(vsp1->dev, "invalid number of UDS (%u)\n",
471 pdata->uds_count);
472 return -EINVAL;
473 }
474
475 if (pdata->wpf_count <= 0 || pdata->wpf_count > VSP1_MAX_WPF) {
476 dev_err(vsp1->dev, "invalid number of WPF (%u)\n",
477 pdata->wpf_count);
478 return -EINVAL;
479 }
480
481 return 0;
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300482}
483
484static int vsp1_probe(struct platform_device *pdev)
485{
486 struct vsp1_device *vsp1;
487 struct resource *irq;
488 struct resource *io;
489 int ret;
490
491 vsp1 = devm_kzalloc(&pdev->dev, sizeof(*vsp1), GFP_KERNEL);
492 if (vsp1 == NULL)
493 return -ENOMEM;
494
495 vsp1->dev = &pdev->dev;
496 mutex_init(&vsp1->lock);
497 INIT_LIST_HEAD(&vsp1->entities);
498
Laurent Pinchart32d17592014-04-09 08:13:18 -0300499 ret = vsp1_parse_dt(vsp1);
Laurent Pinchart0b82fb92014-04-08 13:40:13 -0300500 if (ret < 0)
501 return ret;
502
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300503 /* I/O, IRQ and clock resources */
504 io = platform_get_resource(pdev, IORESOURCE_MEM, 0);
505 vsp1->mmio = devm_ioremap_resource(&pdev->dev, io);
Mauro Carvalho Chehabcbec6d32013-08-24 08:47:51 -0300506 if (IS_ERR(vsp1->mmio))
507 return PTR_ERR(vsp1->mmio);
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300508
509 vsp1->clock = devm_clk_get(&pdev->dev, NULL);
510 if (IS_ERR(vsp1->clock)) {
511 dev_err(&pdev->dev, "failed to get clock\n");
512 return PTR_ERR(vsp1->clock);
513 }
514
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300515 irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
516 if (!irq) {
517 dev_err(&pdev->dev, "missing IRQ\n");
518 return -EINVAL;
519 }
520
521 ret = devm_request_irq(&pdev->dev, irq->start, vsp1_irq_handler,
522 IRQF_SHARED, dev_name(&pdev->dev), vsp1);
523 if (ret < 0) {
524 dev_err(&pdev->dev, "failed to request IRQ\n");
525 return ret;
526 }
527
528 /* Instanciate entities */
529 ret = vsp1_create_entities(vsp1);
530 if (ret < 0) {
531 dev_err(&pdev->dev, "failed to create entities\n");
532 return ret;
533 }
534
535 platform_set_drvdata(pdev, vsp1);
536
537 return 0;
538}
539
540static int vsp1_remove(struct platform_device *pdev)
541{
542 struct vsp1_device *vsp1 = platform_get_drvdata(pdev);
543
544 vsp1_destroy_entities(vsp1);
545
546 return 0;
547}
548
Laurent Pinchart0b82fb92014-04-08 13:40:13 -0300549static const struct of_device_id vsp1_of_match[] = {
550 { .compatible = "renesas,vsp1" },
551 { },
552};
553
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300554static struct platform_driver vsp1_platform_driver = {
555 .probe = vsp1_probe,
556 .remove = vsp1_remove,
557 .driver = {
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300558 .name = "vsp1",
559 .pm = &vsp1_pm_ops,
Laurent Pinchart0b82fb92014-04-08 13:40:13 -0300560 .of_match_table = vsp1_of_match,
Laurent Pinchart26e0ca22013-06-04 11:22:30 -0300561 },
562};
563
564module_platform_driver(vsp1_platform_driver);
565
566MODULE_ALIAS("vsp1");
567MODULE_AUTHOR("Laurent Pinchart <laurent.pinchart@ideasonboard.com>");
568MODULE_DESCRIPTION("Renesas VSP1 Driver");
569MODULE_LICENSE("GPL");