2 * SoC-camera host driver for Renesas R-Car VIN unit
4 * Copyright (C) 2011-2013 Renesas Solutions Corp.
5 * Copyright (C) 2013 Cogent Embedded, Inc., <source@cogentembedded.com>
7 * Based on V4L2 Driver for SuperH Mobile CEU interface "sh_mobile_ceu_camera.c"
9 * Copyright (C) 2008 Magnus Damm
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the
13 * Free Software Foundation; either version 2 of the License, or (at your
14 * option) any later version.
17 #include <linux/delay.h>
18 #include <linux/interrupt.h>
20 #include <linux/kernel.h>
21 #include <linux/module.h>
23 #include <linux/of_device.h>
24 #include <linux/platform_data/camera-rcar.h>
25 #include <linux/platform_device.h>
26 #include <linux/pm_runtime.h>
27 #include <linux/slab.h>
28 #include <linux/videodev2.h>
30 #include <media/soc_camera.h>
31 #include <media/soc_mediabus.h>
32 #include <media/v4l2-common.h>
33 #include <media/v4l2-dev.h>
34 #include <media/v4l2-device.h>
35 #include <media/v4l2-mediabus.h>
36 #include <media/v4l2-of.h>
37 #include <media/v4l2-subdev.h>
38 #include <media/videobuf2-dma-contig.h>
40 #include "soc_scale_crop.h"
42 #define DRV_NAME "rcar_vin"
44 /* Register offsets for R-Car VIN */
45 #define VNMC_REG 0x00 /* Video n Main Control Register */
46 #define VNMS_REG 0x04 /* Video n Module Status Register */
47 #define VNFC_REG 0x08 /* Video n Frame Capture Register */
48 #define VNSLPRC_REG 0x0C /* Video n Start Line Pre-Clip Register */
49 #define VNELPRC_REG 0x10 /* Video n End Line Pre-Clip Register */
50 #define VNSPPRC_REG 0x14 /* Video n Start Pixel Pre-Clip Register */
51 #define VNEPPRC_REG 0x18 /* Video n End Pixel Pre-Clip Register */
52 #define VNSLPOC_REG 0x1C /* Video n Start Line Post-Clip Register */
53 #define VNELPOC_REG 0x20 /* Video n End Line Post-Clip Register */
54 #define VNSPPOC_REG 0x24 /* Video n Start Pixel Post-Clip Register */
55 #define VNEPPOC_REG 0x28 /* Video n End Pixel Post-Clip Register */
56 #define VNIS_REG 0x2C /* Video n Image Stride Register */
57 #define VNMB_REG(m) (0x30 + ((m) << 2)) /* Video n Memory Base m Register */
58 #define VNIE_REG 0x40 /* Video n Interrupt Enable Register */
59 #define VNINTS_REG 0x44 /* Video n Interrupt Status Register */
60 #define VNSI_REG 0x48 /* Video n Scanline Interrupt Register */
61 #define VNMTC_REG 0x4C /* Video n Memory Transfer Control Register */
62 #define VNYS_REG 0x50 /* Video n Y Scale Register */
63 #define VNXS_REG 0x54 /* Video n X Scale Register */
64 #define VNDMR_REG 0x58 /* Video n Data Mode Register */
65 #define VNDMR2_REG 0x5C /* Video n Data Mode Register 2 */
66 #define VNUVAOF_REG 0x60 /* Video n UV Address Offset Register */
68 /* Register bit fields for R-Car VIN */
69 /* Video n Main Control Register bits */
70 #define VNMC_FOC (1 << 21)
71 #define VNMC_YCAL (1 << 19)
72 #define VNMC_INF_YUV8_BT656 (0 << 16)
73 #define VNMC_INF_YUV8_BT601 (1 << 16)
74 #define VNMC_INF_YUV10_BT656 (2 << 16)
75 #define VNMC_INF_YUV10_BT601 (3 << 16)
76 #define VNMC_INF_YUV16 (5 << 16)
77 #define VNMC_VUP (1 << 10)
78 #define VNMC_IM_ODD (0 << 3)
79 #define VNMC_IM_ODD_EVEN (1 << 3)
80 #define VNMC_IM_EVEN (2 << 3)
81 #define VNMC_IM_FULL (3 << 3)
82 #define VNMC_BPS (1 << 1)
83 #define VNMC_ME (1 << 0)
85 /* Video n Module Status Register bits */
86 #define VNMS_FBS_MASK (3 << 3)
87 #define VNMS_FBS_SHIFT 3
88 #define VNMS_AV (1 << 1)
89 #define VNMS_CA (1 << 0)
91 /* Video n Frame Capture Register bits */
92 #define VNFC_C_FRAME (1 << 1)
93 #define VNFC_S_FRAME (1 << 0)
95 /* Video n Interrupt Enable Register bits */
96 #define VNIE_FIE (1 << 4)
97 #define VNIE_EFE (1 << 1)
99 /* Video n Data Mode Register bits */
100 #define VNDMR_EXRGB (1 << 8)
101 #define VNDMR_BPSM (1 << 4)
102 #define VNDMR_DTMD_YCSEP (1 << 1)
103 #define VNDMR_DTMD_ARGB1555 (1 << 0)
105 /* Video n Data Mode Register 2 bits */
106 #define VNDMR2_VPS (1 << 30)
107 #define VNDMR2_HPS (1 << 29)
108 #define VNDMR2_FTEV (1 << 17)
110 #define VIN_MAX_WIDTH 2048
111 #define VIN_MAX_HEIGHT 2048
120 enum rcar_vin_state {
126 struct rcar_vin_priv {
130 /* State of the VIN module in capturing mode */
131 enum rcar_vin_state state;
132 struct soc_camera_host ici;
133 struct list_head capture;
134 #define MAX_BUFFER_NUM 3
135 struct vb2_buffer *queue_buf[MAX_BUFFER_NUM];
136 struct vb2_alloc_ctx *alloc_ctx;
137 enum v4l2_field field;
138 unsigned int pdata_flags;
139 unsigned int vb_count;
140 unsigned int nr_hw_slots;
141 bool request_to_stop;
142 struct completion capture_stop;
146 #define is_continuous_transfer(priv) (priv->vb_count > MAX_BUFFER_NUM)
148 struct rcar_vin_buffer {
149 struct vb2_buffer vb;
150 struct list_head list;
153 #define to_buf_list(vb2_buffer) (&container_of(vb2_buffer, \
154 struct rcar_vin_buffer, \
157 struct rcar_vin_cam {
158 /* VIN offsets within the camera output, before the VIN scaler */
159 unsigned int vin_left;
160 unsigned int vin_top;
161 /* Client output, as seen by the VIN */
165 * User window from S_CROP / G_CROP, produced by client cropping and
166 * scaling, VIN scaling and VIN cropping, mapped back onto the client
169 struct v4l2_rect subrect;
170 /* Camera cropping rectangle */
171 struct v4l2_rect rect;
172 const struct soc_mbus_pixelfmt *extra_fmt;
176 * .queue_setup() is called to check whether the driver can accept the requested
177 * number of buffers and to fill in plane sizes for the current frame format if
180 static int rcar_vin_videobuf_setup(struct vb2_queue *vq,
181 const struct v4l2_format *fmt,
183 unsigned int *num_planes,
184 unsigned int sizes[], void *alloc_ctxs[])
186 struct soc_camera_device *icd = soc_camera_from_vb2q(vq);
187 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
188 struct rcar_vin_priv *priv = ici->priv;
191 const struct soc_camera_format_xlate *xlate;
192 unsigned int bytes_per_line;
195 xlate = soc_camera_xlate_by_fourcc(icd,
196 fmt->fmt.pix.pixelformat);
199 ret = soc_mbus_bytes_per_line(fmt->fmt.pix.width,
204 bytes_per_line = max_t(u32, fmt->fmt.pix.bytesperline, ret);
206 ret = soc_mbus_image_size(xlate->host_fmt, bytes_per_line,
207 fmt->fmt.pix.height);
211 sizes[0] = max_t(u32, fmt->fmt.pix.sizeimage, ret);
213 /* Called from VIDIOC_REQBUFS or in compatibility mode */
214 sizes[0] = icd->sizeimage;
217 alloc_ctxs[0] = priv->alloc_ctx;
219 if (!vq->num_buffers)
224 priv->vb_count = *count;
228 /* Number of hardware slots */
229 if (is_continuous_transfer(priv))
230 priv->nr_hw_slots = MAX_BUFFER_NUM;
232 priv->nr_hw_slots = 1;
234 dev_dbg(icd->parent, "count=%d, size=%u\n", *count, sizes[0]);
239 static int rcar_vin_setup(struct rcar_vin_priv *priv)
241 struct soc_camera_device *icd = priv->ici.icd;
242 struct rcar_vin_cam *cam = icd->host_priv;
243 u32 vnmc, dmr, interrupts;
244 bool progressive = false, output_is_yuv = false;
246 switch (priv->field) {
250 case V4L2_FIELD_BOTTOM:
253 case V4L2_FIELD_INTERLACED:
254 case V4L2_FIELD_INTERLACED_TB:
257 case V4L2_FIELD_INTERLACED_BT:
258 vnmc = VNMC_IM_FULL | VNMC_FOC;
260 case V4L2_FIELD_NONE:
261 if (is_continuous_transfer(priv)) {
262 vnmc = VNMC_IM_ODD_EVEN;
273 /* input interface */
274 switch (icd->current_fmt->code) {
275 case V4L2_MBUS_FMT_YUYV8_1X16:
276 /* BT.601/BT.1358 16bit YCbCr422 */
277 vnmc |= VNMC_INF_YUV16;
279 case V4L2_MBUS_FMT_YUYV8_2X8:
280 /* BT.656 8bit YCbCr422 or BT.601 8bit YCbCr422 */
281 vnmc |= priv->pdata_flags & RCAR_VIN_BT656 ?
282 VNMC_INF_YUV8_BT656 : VNMC_INF_YUV8_BT601;
284 case V4L2_MBUS_FMT_YUYV10_2X10:
285 /* BT.656 10bit YCbCr422 or BT.601 10bit YCbCr422 */
286 vnmc |= priv->pdata_flags & RCAR_VIN_BT656 ?
287 VNMC_INF_YUV10_BT656 : VNMC_INF_YUV10_BT601;
294 switch (icd->current_fmt->host_fmt->fourcc) {
295 case V4L2_PIX_FMT_NV16:
296 iowrite32(ALIGN(cam->width * cam->height, 0x80),
297 priv->base + VNUVAOF_REG);
298 dmr = VNDMR_DTMD_YCSEP;
299 output_is_yuv = true;
301 case V4L2_PIX_FMT_YUYV:
303 output_is_yuv = true;
305 case V4L2_PIX_FMT_UYVY:
307 output_is_yuv = true;
309 case V4L2_PIX_FMT_RGB555X:
310 dmr = VNDMR_DTMD_ARGB1555;
312 case V4L2_PIX_FMT_RGB565:
315 case V4L2_PIX_FMT_RGB32:
316 if (priv->chip == RCAR_GEN2 || priv->chip == RCAR_H1 ||
317 priv->chip == RCAR_E1) {
322 dev_warn(icd->parent, "Invalid fourcc format (0x%x)\n",
323 icd->current_fmt->host_fmt->fourcc);
327 /* Always update on field change */
330 /* If input and output use the same colorspace, use bypass mode */
334 /* progressive or interlaced mode */
335 interrupts = progressive ? VNIE_FIE | VNIE_EFE : VNIE_EFE;
338 iowrite32(interrupts, priv->base + VNINTS_REG);
339 /* enable interrupts */
340 iowrite32(interrupts, priv->base + VNIE_REG);
341 /* start capturing */
342 iowrite32(dmr, priv->base + VNDMR_REG);
343 iowrite32(vnmc | VNMC_ME, priv->base + VNMC_REG);
348 static void rcar_vin_capture(struct rcar_vin_priv *priv)
350 if (is_continuous_transfer(priv))
351 /* Continuous Frame Capture Mode */
352 iowrite32(VNFC_C_FRAME, priv->base + VNFC_REG);
354 /* Single Frame Capture Mode */
355 iowrite32(VNFC_S_FRAME, priv->base + VNFC_REG);
358 static void rcar_vin_request_capture_stop(struct rcar_vin_priv *priv)
360 priv->state = STOPPING;
362 /* set continuous & single transfer off */
363 iowrite32(0, priv->base + VNFC_REG);
364 /* disable capture (release DMA buffer), reset */
365 iowrite32(ioread32(priv->base + VNMC_REG) & ~VNMC_ME,
366 priv->base + VNMC_REG);
368 /* update the status if stopped already */
369 if (!(ioread32(priv->base + VNMS_REG) & VNMS_CA))
370 priv->state = STOPPED;
373 static int rcar_vin_get_free_hw_slot(struct rcar_vin_priv *priv)
377 for (slot = 0; slot < priv->nr_hw_slots; slot++)
378 if (priv->queue_buf[slot] == NULL)
384 static int rcar_vin_hw_ready(struct rcar_vin_priv *priv)
386 /* Ensure all HW slots are filled */
387 return rcar_vin_get_free_hw_slot(priv) < 0 ? 1 : 0;
390 /* Moves a buffer from the queue to the HW slots */
391 static int rcar_vin_fill_hw_slot(struct rcar_vin_priv *priv)
393 struct vb2_buffer *vb;
394 dma_addr_t phys_addr_top;
397 if (list_empty(&priv->capture))
400 /* Find a free HW slot */
401 slot = rcar_vin_get_free_hw_slot(priv);
405 vb = &list_entry(priv->capture.next, struct rcar_vin_buffer, list)->vb;
406 list_del_init(to_buf_list(vb));
407 priv->queue_buf[slot] = vb;
408 phys_addr_top = vb2_dma_contig_plane_dma_addr(vb, 0);
409 iowrite32(phys_addr_top, priv->base + VNMB_REG(slot));
414 static void rcar_vin_videobuf_queue(struct vb2_buffer *vb)
416 struct soc_camera_device *icd = soc_camera_from_vb2q(vb->vb2_queue);
417 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
418 struct rcar_vin_priv *priv = ici->priv;
421 size = icd->sizeimage;
423 if (vb2_plane_size(vb, 0) < size) {
424 dev_err(icd->parent, "Buffer #%d too small (%lu < %lu)\n",
425 vb->v4l2_buf.index, vb2_plane_size(vb, 0), size);
429 vb2_set_plane_payload(vb, 0, size);
431 dev_dbg(icd->parent, "%s (vb=0x%p) 0x%p %lu\n", __func__,
432 vb, vb2_plane_vaddr(vb, 0), vb2_get_plane_payload(vb, 0));
434 spin_lock_irq(&priv->lock);
436 list_add_tail(to_buf_list(vb), &priv->capture);
437 rcar_vin_fill_hw_slot(priv);
439 /* If we weren't running, and have enough buffers, start capturing! */
440 if (priv->state != RUNNING && rcar_vin_hw_ready(priv)) {
441 if (rcar_vin_setup(priv)) {
443 list_del_init(to_buf_list(vb));
444 spin_unlock_irq(&priv->lock);
447 priv->request_to_stop = false;
448 init_completion(&priv->capture_stop);
449 priv->state = RUNNING;
450 rcar_vin_capture(priv);
453 spin_unlock_irq(&priv->lock);
458 vb2_buffer_done(vb, VB2_BUF_STATE_ERROR);
461 static void rcar_vin_videobuf_release(struct vb2_buffer *vb)
463 struct soc_camera_device *icd = soc_camera_from_vb2q(vb->vb2_queue);
464 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
465 struct rcar_vin_priv *priv = ici->priv;
469 spin_lock_irq(&priv->lock);
471 /* Is the buffer in use by the VIN hardware? */
472 for (i = 0; i < MAX_BUFFER_NUM; i++) {
473 if (priv->queue_buf[i] == vb) {
480 while (priv->state != STOPPED) {
482 /* issue stop if running */
483 if (priv->state == RUNNING)
484 rcar_vin_request_capture_stop(priv);
486 /* wait until capturing has been stopped */
487 if (priv->state == STOPPING) {
488 priv->request_to_stop = true;
489 spin_unlock_irq(&priv->lock);
490 wait_for_completion(&priv->capture_stop);
491 spin_lock_irq(&priv->lock);
495 * Capturing has now stopped. The buffer we have been asked
496 * to release could be any of the current buffers in use, so
497 * release all buffers that are in use by HW
499 for (i = 0; i < MAX_BUFFER_NUM; i++) {
500 if (priv->queue_buf[i]) {
501 vb2_buffer_done(priv->queue_buf[i],
502 VB2_BUF_STATE_ERROR);
503 priv->queue_buf[i] = NULL;
507 list_del_init(to_buf_list(vb));
510 spin_unlock_irq(&priv->lock);
513 static int rcar_vin_videobuf_init(struct vb2_buffer *vb)
515 INIT_LIST_HEAD(to_buf_list(vb));
519 static int rcar_vin_stop_streaming(struct vb2_queue *vq)
521 struct soc_camera_device *icd = soc_camera_from_vb2q(vq);
522 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
523 struct rcar_vin_priv *priv = ici->priv;
524 struct list_head *buf_head, *tmp;
526 spin_lock_irq(&priv->lock);
527 list_for_each_safe(buf_head, tmp, &priv->capture)
528 list_del_init(buf_head);
529 spin_unlock_irq(&priv->lock);
534 static struct vb2_ops rcar_vin_vb2_ops = {
535 .queue_setup = rcar_vin_videobuf_setup,
536 .buf_init = rcar_vin_videobuf_init,
537 .buf_cleanup = rcar_vin_videobuf_release,
538 .buf_queue = rcar_vin_videobuf_queue,
539 .stop_streaming = rcar_vin_stop_streaming,
540 .wait_prepare = soc_camera_unlock,
541 .wait_finish = soc_camera_lock,
544 static irqreturn_t rcar_vin_irq(int irq, void *data)
546 struct rcar_vin_priv *priv = data;
548 bool can_run = false, hw_stopped;
550 unsigned int handled = 0;
552 spin_lock(&priv->lock);
554 int_status = ioread32(priv->base + VNINTS_REG);
558 iowrite32(int_status, priv->base + VNINTS_REG);
561 /* nothing to do if capture status is 'STOPPED' */
562 if (priv->state == STOPPED)
565 hw_stopped = !(ioread32(priv->base + VNMS_REG) & VNMS_CA);
567 if (!priv->request_to_stop) {
568 if (is_continuous_transfer(priv))
569 slot = (ioread32(priv->base + VNMS_REG) &
570 VNMS_FBS_MASK) >> VNMS_FBS_SHIFT;
574 priv->queue_buf[slot]->v4l2_buf.field = priv->field;
575 priv->queue_buf[slot]->v4l2_buf.sequence = priv->sequence++;
576 do_gettimeofday(&priv->queue_buf[slot]->v4l2_buf.timestamp);
577 vb2_buffer_done(priv->queue_buf[slot], VB2_BUF_STATE_DONE);
578 priv->queue_buf[slot] = NULL;
580 if (priv->state != STOPPING)
581 can_run = rcar_vin_fill_hw_slot(priv);
583 if (hw_stopped || !can_run) {
584 priv->state = STOPPED;
585 } else if (is_continuous_transfer(priv) &&
586 list_empty(&priv->capture) &&
587 priv->state == RUNNING) {
589 * The continuous capturing requires an explicit stop
590 * operation when there is no buffer to be set into
591 * the VnMBm registers.
593 rcar_vin_request_capture_stop(priv);
595 rcar_vin_capture(priv);
598 } else if (hw_stopped) {
599 priv->state = STOPPED;
600 priv->request_to_stop = false;
601 complete(&priv->capture_stop);
605 spin_unlock(&priv->lock);
607 return IRQ_RETVAL(handled);
610 static int rcar_vin_add_device(struct soc_camera_device *icd)
612 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
613 struct rcar_vin_priv *priv = ici->priv;
616 for (i = 0; i < MAX_BUFFER_NUM; i++)
617 priv->queue_buf[i] = NULL;
619 pm_runtime_get_sync(ici->v4l2_dev.dev);
621 dev_dbg(icd->parent, "R-Car VIN driver attached to camera %d\n",
627 static void rcar_vin_remove_device(struct soc_camera_device *icd)
629 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
630 struct rcar_vin_priv *priv = ici->priv;
631 struct vb2_buffer *vb;
634 /* disable capture, disable interrupts */
635 iowrite32(ioread32(priv->base + VNMC_REG) & ~VNMC_ME,
636 priv->base + VNMC_REG);
637 iowrite32(0, priv->base + VNIE_REG);
639 priv->state = STOPPED;
640 priv->request_to_stop = false;
642 /* make sure active buffer is cancelled */
643 spin_lock_irq(&priv->lock);
644 for (i = 0; i < MAX_BUFFER_NUM; i++) {
645 vb = priv->queue_buf[i];
647 list_del_init(to_buf_list(vb));
648 vb2_buffer_done(vb, VB2_BUF_STATE_ERROR);
651 spin_unlock_irq(&priv->lock);
653 pm_runtime_put(ici->v4l2_dev.dev);
655 dev_dbg(icd->parent, "R-Car VIN driver detached from camera %d\n",
659 /* Called with .host_lock held */
660 static int rcar_vin_clock_start(struct soc_camera_host *ici)
662 /* VIN does not have "mclk" */
666 /* Called with .host_lock held */
667 static void rcar_vin_clock_stop(struct soc_camera_host *ici)
669 /* VIN does not have "mclk" */
672 /* rect is guaranteed to not exceed the scaled camera rectangle */
673 static int rcar_vin_set_rect(struct soc_camera_device *icd)
675 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
676 struct rcar_vin_cam *cam = icd->host_priv;
677 struct rcar_vin_priv *priv = ici->priv;
678 unsigned int left_offset, top_offset;
679 unsigned char dsize = 0;
680 struct v4l2_rect *cam_subrect = &cam->subrect;
682 dev_dbg(icd->parent, "Crop %ux%u@%u:%u\n",
683 icd->user_width, icd->user_height, cam->vin_left, cam->vin_top);
685 left_offset = cam->vin_left;
686 top_offset = cam->vin_top;
688 if (icd->current_fmt->host_fmt->fourcc == V4L2_PIX_FMT_RGB32 &&
689 priv->chip == RCAR_E1)
692 dev_dbg(icd->parent, "Cam %ux%u@%u:%u\n",
693 cam->width, cam->height, cam->vin_left, cam->vin_top);
694 dev_dbg(icd->parent, "Cam subrect %ux%u@%u:%u\n",
695 cam_subrect->width, cam_subrect->height,
696 cam_subrect->left, cam_subrect->top);
698 /* Set Start/End Pixel/Line Pre-Clip */
699 iowrite32(left_offset << dsize, priv->base + VNSPPRC_REG);
700 iowrite32((left_offset + cam->width - 1) << dsize,
701 priv->base + VNEPPRC_REG);
702 switch (priv->field) {
703 case V4L2_FIELD_INTERLACED:
704 case V4L2_FIELD_INTERLACED_TB:
705 case V4L2_FIELD_INTERLACED_BT:
706 iowrite32(top_offset / 2, priv->base + VNSLPRC_REG);
707 iowrite32((top_offset + cam->height) / 2 - 1,
708 priv->base + VNELPRC_REG);
711 iowrite32(top_offset, priv->base + VNSLPRC_REG);
712 iowrite32(top_offset + cam->height - 1,
713 priv->base + VNELPRC_REG);
717 /* Set Start/End Pixel/Line Post-Clip */
718 iowrite32(0, priv->base + VNSPPOC_REG);
719 iowrite32(0, priv->base + VNSLPOC_REG);
720 iowrite32((cam_subrect->width - 1) << dsize, priv->base + VNEPPOC_REG);
721 switch (priv->field) {
722 case V4L2_FIELD_INTERLACED:
723 case V4L2_FIELD_INTERLACED_TB:
724 case V4L2_FIELD_INTERLACED_BT:
725 iowrite32(cam_subrect->height / 2 - 1,
726 priv->base + VNELPOC_REG);
729 iowrite32(cam_subrect->height - 1, priv->base + VNELPOC_REG);
733 iowrite32(ALIGN(cam->width, 0x10), priv->base + VNIS_REG);
738 static void capture_stop_preserve(struct rcar_vin_priv *priv, u32 *vnmc)
740 *vnmc = ioread32(priv->base + VNMC_REG);
742 iowrite32(*vnmc & ~VNMC_ME, priv->base + VNMC_REG);
745 static void capture_restore(struct rcar_vin_priv *priv, u32 vnmc)
747 unsigned long timeout = jiffies + 10 * HZ;
750 * Wait until the end of the current frame. It can take a long time,
751 * but if it has been aborted by a MRST1 reset, it should exit sooner.
753 while ((ioread32(priv->base + VNMS_REG) & VNMS_AV) &&
754 time_before(jiffies, timeout))
757 if (time_after(jiffies, timeout)) {
758 dev_err(priv->ici.v4l2_dev.dev,
759 "Timeout waiting for frame end! Interface problem?\n");
763 iowrite32(vnmc, priv->base + VNMC_REG);
766 #define VIN_MBUS_FLAGS (V4L2_MBUS_MASTER | \
767 V4L2_MBUS_PCLK_SAMPLE_RISING | \
768 V4L2_MBUS_HSYNC_ACTIVE_HIGH | \
769 V4L2_MBUS_HSYNC_ACTIVE_LOW | \
770 V4L2_MBUS_VSYNC_ACTIVE_HIGH | \
771 V4L2_MBUS_VSYNC_ACTIVE_LOW | \
772 V4L2_MBUS_DATA_ACTIVE_HIGH)
774 static int rcar_vin_set_bus_param(struct soc_camera_device *icd)
776 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
777 struct rcar_vin_priv *priv = ici->priv;
778 struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
779 struct v4l2_mbus_config cfg;
780 unsigned long common_flags;
785 capture_stop_preserve(priv, &vnmc);
787 ret = v4l2_subdev_call(sd, video, g_mbus_config, &cfg);
789 common_flags = soc_mbus_config_compatible(&cfg, VIN_MBUS_FLAGS);
791 dev_warn(icd->parent,
792 "MBUS flags incompatible: camera 0x%x, host 0x%x\n",
793 cfg.flags, VIN_MBUS_FLAGS);
796 } else if (ret != -ENOIOCTLCMD) {
799 common_flags = VIN_MBUS_FLAGS;
802 /* Make choises, based on platform preferences */
803 if ((common_flags & V4L2_MBUS_HSYNC_ACTIVE_HIGH) &&
804 (common_flags & V4L2_MBUS_HSYNC_ACTIVE_LOW)) {
805 if (priv->pdata_flags & RCAR_VIN_HSYNC_ACTIVE_LOW)
806 common_flags &= ~V4L2_MBUS_HSYNC_ACTIVE_HIGH;
808 common_flags &= ~V4L2_MBUS_HSYNC_ACTIVE_LOW;
811 if ((common_flags & V4L2_MBUS_VSYNC_ACTIVE_HIGH) &&
812 (common_flags & V4L2_MBUS_VSYNC_ACTIVE_LOW)) {
813 if (priv->pdata_flags & RCAR_VIN_VSYNC_ACTIVE_LOW)
814 common_flags &= ~V4L2_MBUS_VSYNC_ACTIVE_HIGH;
816 common_flags &= ~V4L2_MBUS_VSYNC_ACTIVE_LOW;
819 cfg.flags = common_flags;
820 ret = v4l2_subdev_call(sd, video, s_mbus_config, &cfg);
821 if (ret < 0 && ret != -ENOIOCTLCMD)
824 val = priv->field == V4L2_FIELD_NONE ? VNDMR2_FTEV : 0;
825 if (!(common_flags & V4L2_MBUS_VSYNC_ACTIVE_LOW))
827 if (!(common_flags & V4L2_MBUS_HSYNC_ACTIVE_LOW))
829 iowrite32(val, priv->base + VNDMR2_REG);
831 ret = rcar_vin_set_rect(icd);
835 capture_restore(priv, vnmc);
840 static int rcar_vin_try_bus_param(struct soc_camera_device *icd,
841 unsigned char buswidth)
843 struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
844 struct v4l2_mbus_config cfg;
847 ret = v4l2_subdev_call(sd, video, g_mbus_config, &cfg);
848 if (ret == -ENOIOCTLCMD)
856 /* check is there common mbus flags */
857 ret = soc_mbus_config_compatible(&cfg, VIN_MBUS_FLAGS);
861 dev_warn(icd->parent,
862 "MBUS flags incompatible: camera 0x%x, host 0x%x\n",
863 cfg.flags, VIN_MBUS_FLAGS);
868 static bool rcar_vin_packing_supported(const struct soc_mbus_pixelfmt *fmt)
870 return fmt->packing == SOC_MBUS_PACKING_NONE ||
871 (fmt->bits_per_sample > 8 &&
872 fmt->packing == SOC_MBUS_PACKING_EXTEND16);
875 static const struct soc_mbus_pixelfmt rcar_vin_formats[] = {
877 .fourcc = V4L2_PIX_FMT_NV16,
879 .bits_per_sample = 8,
880 .packing = SOC_MBUS_PACKING_2X8_PADHI,
881 .order = SOC_MBUS_ORDER_LE,
882 .layout = SOC_MBUS_LAYOUT_PLANAR_Y_C,
885 .fourcc = V4L2_PIX_FMT_UYVY,
887 .bits_per_sample = 16,
888 .packing = SOC_MBUS_PACKING_NONE,
889 .order = SOC_MBUS_ORDER_LE,
890 .layout = SOC_MBUS_LAYOUT_PACKED,
893 .fourcc = V4L2_PIX_FMT_RGB565,
895 .bits_per_sample = 16,
896 .packing = SOC_MBUS_PACKING_NONE,
897 .order = SOC_MBUS_ORDER_LE,
898 .layout = SOC_MBUS_LAYOUT_PACKED,
901 .fourcc = V4L2_PIX_FMT_RGB555X,
903 .bits_per_sample = 16,
904 .packing = SOC_MBUS_PACKING_NONE,
905 .order = SOC_MBUS_ORDER_LE,
906 .layout = SOC_MBUS_LAYOUT_PACKED,
909 .fourcc = V4L2_PIX_FMT_RGB32,
911 .bits_per_sample = 32,
912 .packing = SOC_MBUS_PACKING_NONE,
913 .order = SOC_MBUS_ORDER_LE,
914 .layout = SOC_MBUS_LAYOUT_PACKED,
918 static int rcar_vin_get_formats(struct soc_camera_device *icd, unsigned int idx,
919 struct soc_camera_format_xlate *xlate)
921 struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
922 struct device *dev = icd->parent;
925 struct rcar_vin_cam *cam;
926 enum v4l2_mbus_pixelcode code;
927 const struct soc_mbus_pixelfmt *fmt;
929 ret = v4l2_subdev_call(sd, video, enum_mbus_fmt, idx, &code);
933 fmt = soc_mbus_get_fmtdesc(code);
935 dev_warn(dev, "unsupported format code #%u: %d\n", idx, code);
939 ret = rcar_vin_try_bus_param(icd, fmt->bits_per_sample);
943 if (!icd->host_priv) {
944 struct v4l2_mbus_framefmt mf;
945 struct v4l2_rect rect;
946 struct device *dev = icd->parent;
949 ret = v4l2_subdev_call(sd, video, g_mbus_fmt, &mf);
953 /* Cache current client geometry */
954 ret = soc_camera_client_g_rect(sd, &rect);
955 if (ret == -ENOIOCTLCMD) {
956 /* Sensor driver doesn't support cropping */
959 rect.width = mf.width;
960 rect.height = mf.height;
961 } else if (ret < 0) {
966 * If sensor proposes too large format then try smaller ones:
967 * 1280x960, 640x480, 320x240
969 for (shift = 0; shift < 3; shift++) {
970 if (mf.width <= VIN_MAX_WIDTH &&
971 mf.height <= VIN_MAX_HEIGHT)
974 mf.width = 1280 >> shift;
975 mf.height = 960 >> shift;
976 ret = v4l2_device_call_until_err(sd->v4l2_dev,
977 soc_camera_grp_id(icd),
986 "Failed to configure the client below %ux%x\n",
987 mf.width, mf.height);
991 dev_dbg(dev, "camera fmt %ux%u\n", mf.width, mf.height);
993 cam = kzalloc(sizeof(*cam), GFP_KERNEL);
997 * We are called with current camera crop,
998 * initialise subrect with it
1001 cam->subrect = rect;
1002 cam->width = mf.width;
1003 cam->height = mf.height;
1005 icd->host_priv = cam;
1007 cam = icd->host_priv;
1010 /* Beginning of a pass */
1012 cam->extra_fmt = NULL;
1015 case V4L2_MBUS_FMT_YUYV8_1X16:
1016 case V4L2_MBUS_FMT_YUYV8_2X8:
1017 case V4L2_MBUS_FMT_YUYV10_2X10:
1021 /* Add all our formats that can be generated by VIN */
1022 cam->extra_fmt = rcar_vin_formats;
1024 n = ARRAY_SIZE(rcar_vin_formats);
1026 for (k = 0; xlate && k < n; k++, xlate++) {
1027 xlate->host_fmt = &rcar_vin_formats[k];
1029 dev_dbg(dev, "Providing format %s using code %d\n",
1030 rcar_vin_formats[k].name, code);
1034 if (!rcar_vin_packing_supported(fmt))
1037 dev_dbg(dev, "Providing format %s in pass-through mode\n",
1042 /* Generic pass-through */
1045 xlate->host_fmt = fmt;
1053 static void rcar_vin_put_formats(struct soc_camera_device *icd)
1055 kfree(icd->host_priv);
1056 icd->host_priv = NULL;
1059 static int rcar_vin_set_crop(struct soc_camera_device *icd,
1060 const struct v4l2_crop *a)
1062 struct v4l2_crop a_writable = *a;
1063 const struct v4l2_rect *rect = &a_writable.c;
1064 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
1065 struct rcar_vin_priv *priv = ici->priv;
1066 struct v4l2_crop cam_crop;
1067 struct rcar_vin_cam *cam = icd->host_priv;
1068 struct v4l2_rect *cam_rect = &cam_crop.c;
1069 struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
1070 struct device *dev = icd->parent;
1071 struct v4l2_mbus_framefmt mf;
1075 dev_dbg(dev, "S_CROP(%ux%u@%u:%u)\n", rect->width, rect->height,
1076 rect->left, rect->top);
1078 /* During camera cropping its output window can change too, stop VIN */
1079 capture_stop_preserve(priv, &vnmc);
1080 dev_dbg(dev, "VNMC_REG 0x%x\n", vnmc);
1082 /* Apply iterative camera S_CROP for new input window. */
1083 ret = soc_camera_client_s_crop(sd, &a_writable, &cam_crop,
1084 &cam->rect, &cam->subrect);
1088 dev_dbg(dev, "camera cropped to %ux%u@%u:%u\n",
1089 cam_rect->width, cam_rect->height,
1090 cam_rect->left, cam_rect->top);
1092 /* On success cam_crop contains current camera crop */
1094 /* Retrieve camera output window */
1095 ret = v4l2_subdev_call(sd, video, g_mbus_fmt, &mf);
1099 if (mf.width > VIN_MAX_WIDTH || mf.height > VIN_MAX_HEIGHT)
1102 /* Cache camera output window */
1103 cam->width = mf.width;
1104 cam->height = mf.height;
1106 icd->user_width = cam->width;
1107 icd->user_height = cam->height;
1109 cam->vin_left = rect->left & ~1;
1110 cam->vin_top = rect->top & ~1;
1112 /* Use VIN cropping to crop to the new window. */
1113 ret = rcar_vin_set_rect(icd);
1117 cam->subrect = *rect;
1119 dev_dbg(dev, "VIN cropped to %ux%u@%u:%u\n",
1120 icd->user_width, icd->user_height,
1121 cam->vin_left, cam->vin_top);
1123 /* Restore capture */
1124 for (i = 0; i < MAX_BUFFER_NUM; i++) {
1125 if (priv->queue_buf[i] && priv->state == STOPPED) {
1130 capture_restore(priv, vnmc);
1132 /* Even if only camera cropping succeeded */
1136 static int rcar_vin_get_crop(struct soc_camera_device *icd,
1137 struct v4l2_crop *a)
1139 struct rcar_vin_cam *cam = icd->host_priv;
1141 a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1142 a->c = cam->subrect;
1147 /* Similar to set_crop multistage iterative algorithm */
1148 static int rcar_vin_set_fmt(struct soc_camera_device *icd,
1149 struct v4l2_format *f)
1151 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
1152 struct rcar_vin_priv *priv = ici->priv;
1153 struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
1154 struct rcar_vin_cam *cam = icd->host_priv;
1155 struct v4l2_pix_format *pix = &f->fmt.pix;
1156 struct v4l2_mbus_framefmt mf;
1157 struct device *dev = icd->parent;
1158 __u32 pixfmt = pix->pixelformat;
1159 const struct soc_camera_format_xlate *xlate;
1160 unsigned int vin_sub_width = 0, vin_sub_height = 0;
1163 enum v4l2_field field;
1166 dev_dbg(dev, "S_FMT(pix=0x%x, %ux%u)\n",
1167 pixfmt, pix->width, pix->height);
1169 switch (pix->field) {
1171 pix->field = V4L2_FIELD_NONE;
1173 case V4L2_FIELD_NONE:
1174 case V4L2_FIELD_TOP:
1175 case V4L2_FIELD_BOTTOM:
1176 case V4L2_FIELD_INTERLACED_TB:
1177 case V4L2_FIELD_INTERLACED_BT:
1180 case V4L2_FIELD_INTERLACED:
1181 /* Query for standard if not explicitly mentioned _TB/_BT */
1182 ret = v4l2_subdev_call(sd, video, querystd, &std);
1184 std = V4L2_STD_625_50;
1186 field = std & V4L2_STD_625_50 ? V4L2_FIELD_INTERLACED_TB :
1187 V4L2_FIELD_INTERLACED_BT;
1191 xlate = soc_camera_xlate_by_fourcc(icd, pixfmt);
1193 dev_warn(dev, "Format %x not found\n", pixfmt);
1196 /* Calculate client output geometry */
1197 soc_camera_calc_client_output(icd, &cam->rect, &cam->subrect, pix, &mf,
1199 mf.field = pix->field;
1200 mf.colorspace = pix->colorspace;
1201 mf.code = xlate->code;
1204 case V4L2_PIX_FMT_RGB32:
1205 can_scale = priv->chip != RCAR_E1;
1207 case V4L2_PIX_FMT_UYVY:
1208 case V4L2_PIX_FMT_YUYV:
1209 case V4L2_PIX_FMT_RGB565:
1210 case V4L2_PIX_FMT_RGB555X:
1218 dev_dbg(dev, "request camera output %ux%u\n", mf.width, mf.height);
1220 ret = soc_camera_client_scale(icd, &cam->rect, &cam->subrect,
1221 &mf, &vin_sub_width, &vin_sub_height,
1224 /* Done with the camera. Now see if we can improve the result */
1225 dev_dbg(dev, "Camera %d fmt %ux%u, requested %ux%u\n",
1226 ret, mf.width, mf.height, pix->width, pix->height);
1228 if (ret == -ENOIOCTLCMD)
1229 dev_dbg(dev, "Sensor doesn't support scaling\n");
1233 if (mf.code != xlate->code)
1236 /* Prepare VIN crop */
1237 cam->width = mf.width;
1238 cam->height = mf.height;
1240 /* Use VIN scaling to scale to the requested user window. */
1242 /* We cannot scale up */
1243 if (pix->width > vin_sub_width)
1244 vin_sub_width = pix->width;
1246 if (pix->height > vin_sub_height)
1247 vin_sub_height = pix->height;
1249 pix->colorspace = mf.colorspace;
1252 pix->width = vin_sub_width;
1253 pix->height = vin_sub_height;
1257 * We have calculated CFLCR, the actual configuration will be performed
1258 * in rcar_vin_set_bus_param()
1261 dev_dbg(dev, "W: %u : %u, H: %u : %u\n",
1262 vin_sub_width, pix->width, vin_sub_height, pix->height);
1264 icd->current_fmt = xlate;
1266 priv->field = field;
1271 static int rcar_vin_try_fmt(struct soc_camera_device *icd,
1272 struct v4l2_format *f)
1274 const struct soc_camera_format_xlate *xlate;
1275 struct v4l2_pix_format *pix = &f->fmt.pix;
1276 struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
1277 struct v4l2_mbus_framefmt mf;
1278 __u32 pixfmt = pix->pixelformat;
1282 xlate = soc_camera_xlate_by_fourcc(icd, pixfmt);
1284 xlate = icd->current_fmt;
1285 dev_dbg(icd->parent, "Format %x not found, keeping %x\n",
1286 pixfmt, xlate->host_fmt->fourcc);
1287 pixfmt = xlate->host_fmt->fourcc;
1288 pix->pixelformat = pixfmt;
1289 pix->colorspace = icd->colorspace;
1292 /* FIXME: calculate using depth and bus width */
1293 v4l_bound_align_image(&pix->width, 2, VIN_MAX_WIDTH, 1,
1294 &pix->height, 4, VIN_MAX_HEIGHT, 2, 0);
1297 height = pix->height;
1299 /* let soc-camera calculate these values */
1300 pix->bytesperline = 0;
1303 /* limit to sensor capabilities */
1304 mf.width = pix->width;
1305 mf.height = pix->height;
1306 mf.field = pix->field;
1307 mf.code = xlate->code;
1308 mf.colorspace = pix->colorspace;
1310 ret = v4l2_device_call_until_err(sd->v4l2_dev, soc_camera_grp_id(icd),
1311 video, try_mbus_fmt, &mf);
1315 pix->width = mf.width;
1316 pix->height = mf.height;
1317 pix->field = mf.field;
1318 pix->colorspace = mf.colorspace;
1320 if (pixfmt == V4L2_PIX_FMT_NV16) {
1321 /* FIXME: check against rect_max after converting soc-camera */
1322 /* We can scale precisely, need a bigger image from camera */
1323 if (pix->width < width || pix->height < height) {
1325 * We presume, the sensor behaves sanely, i.e. if
1326 * requested a bigger rectangle, it will not return a
1329 mf.width = VIN_MAX_WIDTH;
1330 mf.height = VIN_MAX_HEIGHT;
1331 ret = v4l2_device_call_until_err(sd->v4l2_dev,
1332 soc_camera_grp_id(icd),
1333 video, try_mbus_fmt,
1336 dev_err(icd->parent,
1337 "client try_fmt() = %d\n", ret);
1341 /* We will scale exactly */
1342 if (mf.width > width)
1344 if (mf.height > height)
1345 pix->height = height;
1351 static unsigned int rcar_vin_poll(struct file *file, poll_table *pt)
1353 struct soc_camera_device *icd = file->private_data;
1355 return vb2_poll(&icd->vb2_vidq, file, pt);
1358 static int rcar_vin_querycap(struct soc_camera_host *ici,
1359 struct v4l2_capability *cap)
1361 strlcpy(cap->card, "R_Car_VIN", sizeof(cap->card));
1362 cap->capabilities = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING;
1366 static int rcar_vin_init_videobuf2(struct vb2_queue *vq,
1367 struct soc_camera_device *icd)
1369 vq->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1370 vq->io_modes = VB2_MMAP | VB2_USERPTR;
1372 vq->ops = &rcar_vin_vb2_ops;
1373 vq->mem_ops = &vb2_dma_contig_memops;
1374 vq->buf_struct_size = sizeof(struct rcar_vin_buffer);
1375 vq->timestamp_type = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
1377 return vb2_queue_init(vq);
1380 static struct soc_camera_host_ops rcar_vin_host_ops = {
1381 .owner = THIS_MODULE,
1382 .add = rcar_vin_add_device,
1383 .remove = rcar_vin_remove_device,
1384 .clock_start = rcar_vin_clock_start,
1385 .clock_stop = rcar_vin_clock_stop,
1386 .get_formats = rcar_vin_get_formats,
1387 .put_formats = rcar_vin_put_formats,
1388 .get_crop = rcar_vin_get_crop,
1389 .set_crop = rcar_vin_set_crop,
1390 .try_fmt = rcar_vin_try_fmt,
1391 .set_fmt = rcar_vin_set_fmt,
1392 .poll = rcar_vin_poll,
1393 .querycap = rcar_vin_querycap,
1394 .set_bus_param = rcar_vin_set_bus_param,
1395 .init_videobuf2 = rcar_vin_init_videobuf2,
1399 static struct of_device_id rcar_vin_of_table[] = {
1400 { .compatible = "renesas,vin-r8a7791", .data = (void *)RCAR_GEN2 },
1401 { .compatible = "renesas,vin-r8a7790", .data = (void *)RCAR_GEN2 },
1402 { .compatible = "renesas,vin-r8a7779", .data = (void *)RCAR_H1 },
1403 { .compatible = "renesas,vin-r8a7778", .data = (void *)RCAR_M1 },
1406 MODULE_DEVICE_TABLE(of, rcar_vin_of_table);
1409 static struct platform_device_id rcar_vin_id_table[] = {
1410 { "r8a7791-vin", RCAR_GEN2 },
1411 { "r8a7790-vin", RCAR_GEN2 },
1412 { "r8a7779-vin", RCAR_H1 },
1413 { "r8a7778-vin", RCAR_M1 },
1414 { "uPD35004-vin", RCAR_E1 },
1417 MODULE_DEVICE_TABLE(platform, rcar_vin_id_table);
1419 static int rcar_vin_probe(struct platform_device *pdev)
1421 const struct of_device_id *match = NULL;
1422 struct rcar_vin_priv *priv;
1423 struct resource *mem;
1424 struct rcar_vin_platform_data *pdata;
1425 unsigned int pdata_flags;
1428 if (pdev->dev.of_node) {
1429 struct v4l2_of_endpoint ep;
1430 struct device_node *np;
1432 match = of_match_device(of_match_ptr(rcar_vin_of_table),
1435 np = of_graph_get_next_endpoint(pdev->dev.of_node, NULL);
1437 dev_err(&pdev->dev, "could not find endpoint\n");
1441 ret = v4l2_of_parse_endpoint(np, &ep);
1443 dev_err(&pdev->dev, "could not parse endpoint\n");
1447 if (ep.bus_type == V4L2_MBUS_BT656)
1448 pdata_flags = RCAR_VIN_BT656;
1451 if (ep.bus.parallel.flags & V4L2_MBUS_HSYNC_ACTIVE_LOW)
1452 pdata_flags |= RCAR_VIN_HSYNC_ACTIVE_LOW;
1453 if (ep.bus.parallel.flags & V4L2_MBUS_VSYNC_ACTIVE_LOW)
1454 pdata_flags |= RCAR_VIN_VSYNC_ACTIVE_LOW;
1459 dev_dbg(&pdev->dev, "pdata_flags = %08x\n", pdata_flags);
1461 pdata = pdev->dev.platform_data;
1462 if (!pdata || !pdata->flags) {
1463 dev_err(&pdev->dev, "platform data not set\n");
1466 pdata_flags = pdata->flags;
1469 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1473 irq = platform_get_irq(pdev, 0);
1477 priv = devm_kzalloc(&pdev->dev, sizeof(struct rcar_vin_priv),
1482 priv->base = devm_ioremap_resource(&pdev->dev, mem);
1483 if (IS_ERR(priv->base))
1484 return PTR_ERR(priv->base);
1486 ret = devm_request_irq(&pdev->dev, irq, rcar_vin_irq, IRQF_SHARED,
1487 dev_name(&pdev->dev), priv);
1491 priv->alloc_ctx = vb2_dma_contig_init_ctx(&pdev->dev);
1492 if (IS_ERR(priv->alloc_ctx))
1493 return PTR_ERR(priv->alloc_ctx);
1495 priv->ici.priv = priv;
1496 priv->ici.v4l2_dev.dev = &pdev->dev;
1497 priv->ici.drv_name = dev_name(&pdev->dev);
1498 priv->ici.ops = &rcar_vin_host_ops;
1500 priv->pdata_flags = pdata_flags;
1502 priv->ici.nr = pdev->id;
1503 priv->chip = pdev->id_entry->driver_data;
1505 priv->ici.nr = of_alias_get_id(pdev->dev.of_node, "vin");
1506 priv->chip = (enum chip_id)match->data;
1509 spin_lock_init(&priv->lock);
1510 INIT_LIST_HEAD(&priv->capture);
1512 priv->state = STOPPED;
1514 pm_suspend_ignore_children(&pdev->dev, true);
1515 pm_runtime_enable(&pdev->dev);
1517 ret = soc_camera_host_register(&priv->ici);
1524 pm_runtime_disable(&pdev->dev);
1525 vb2_dma_contig_cleanup_ctx(priv->alloc_ctx);
1530 static int rcar_vin_remove(struct platform_device *pdev)
1532 struct soc_camera_host *soc_host = to_soc_camera_host(&pdev->dev);
1533 struct rcar_vin_priv *priv = container_of(soc_host,
1534 struct rcar_vin_priv, ici);
1536 soc_camera_host_unregister(soc_host);
1537 pm_runtime_disable(&pdev->dev);
1538 vb2_dma_contig_cleanup_ctx(priv->alloc_ctx);
1543 static struct platform_driver rcar_vin_driver = {
1544 .probe = rcar_vin_probe,
1545 .remove = rcar_vin_remove,
1548 .owner = THIS_MODULE,
1549 .of_match_table = of_match_ptr(rcar_vin_of_table),
1551 .id_table = rcar_vin_id_table,
1554 module_platform_driver(rcar_vin_driver);
1556 MODULE_LICENSE("GPL");
1557 MODULE_ALIAS("platform:rcar_vin");
1558 MODULE_DESCRIPTION("Renesas R-Car VIN camera host driver");