2 * Copyright 2008-2010 Freescale Semiconductor, Inc. All Rights Reserved.
4 * Freescale VIU video driver
6 * Authors: Hongjun Chen <hong-jun.chen@freescale.com>
7 * Porting to 2.6.35 by DENX Software Engineering,
8 * Anatolij Gustschin <agust@denx.de>
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the
12 * Free Software Foundation; either version 2 of the License, or (at your
13 * option) any later version.
17 #include <linux/module.h>
18 #include <linux/clk.h>
19 #include <linux/kernel.h>
20 #include <linux/i2c.h>
21 #include <linux/init.h>
22 #include <linux/interrupt.h>
24 #include <linux/of_platform.h>
25 #include <linux/version.h>
26 #include <media/v4l2-common.h>
27 #include <media/v4l2-device.h>
28 #include <media/v4l2-ioctl.h>
29 #include <media/videobuf-dma-contig.h>
31 #define DRV_NAME "fsl_viu"
32 #define VIU_MAJOR_VERSION 0
33 #define VIU_MINOR_VERSION 5
35 #define VIU_VERSION KERNEL_VERSION(VIU_MAJOR_VERSION, \
39 #define BUFFER_TIMEOUT msecs_to_jiffies(500) /* 0.5 seconds */
41 #define VIU_VID_MEM_LIMIT 4 /* Video memory limit, in Mb */
43 /* I2C address of video decoder chip is 0x4A */
44 #define VIU_VIDEO_DECODER_ADDR 0x25
46 /* supported controls */
47 static struct v4l2_queryctrl viu_qctrl
[] = {
49 .id
= V4L2_CID_BRIGHTNESS
,
50 .type
= V4L2_CTRL_TYPE_INTEGER
,
58 .id
= V4L2_CID_CONTRAST
,
59 .type
= V4L2_CTRL_TYPE_INTEGER
,
64 .default_value
= 0x10,
67 .id
= V4L2_CID_SATURATION
,
68 .type
= V4L2_CTRL_TYPE_INTEGER
,
77 .type
= V4L2_CTRL_TYPE_INTEGER
,
87 static int qctl_regs
[ARRAY_SIZE(viu_qctrl
)];
89 static int info_level
;
91 #define dprintk(level, fmt, arg...) \
93 if (level <= info_level) \
94 printk(KERN_DEBUG "viu: " fmt , ## arg); \
102 u32 fourcc
; /* v4l2 format id */
107 static struct viu_fmt formats
[] = {
109 .name
= "RGB-16 (5/B-6/G-5/R)",
110 .fourcc
= V4L2_PIX_FMT_RGB565
,
111 .pixelformat
= V4L2_PIX_FMT_RGB565
,
114 .name
= "RGB-32 (A-R-G-B)",
115 .fourcc
= V4L2_PIX_FMT_RGB32
,
116 .pixelformat
= V4L2_PIX_FMT_RGB32
,
124 /* buffer for one video frame */
126 /* common v4l buffer stuff -- must be first */
127 struct videobuf_buffer vb
;
131 struct viu_dmaqueue
{
133 struct list_head active
;
134 struct list_head queued
;
135 struct timer_list timeout
;
158 } __attribute__ ((packed
));
161 struct v4l2_device v4l2_dev
;
167 /* various device info */
168 struct video_device
*vdev
;
169 struct viu_dmaqueue vidq
;
170 enum v4l2_field capfield
;
175 /* Hardware register area */
178 /* Interrupt vector */
180 struct viu_status irqs
;
183 struct v4l2_framebuffer ovbuf
;
184 struct viu_fmt
*ovfmt
;
185 unsigned int ovenable
;
186 enum v4l2_field ovfield
;
189 struct v4l2_rect crop_current
;
195 struct v4l2_subdev
*decoder
;
202 struct videobuf_queue vb_vidq
;
203 spinlock_t vbq_lock
; /* spinlock for the videobuf queue */
206 struct v4l2_window win
;
207 struct v4l2_clip clips
[1];
211 int width
, height
, sizeimage
;
212 enum v4l2_buf_type type
;
215 static struct viu_reg reg_val
;
218 * Macro definitions of VIU registers
221 /* STATUS_CONFIG register */
225 ERR_MASK
= 0x0f << 4, /* Error code mask */
226 ERR_NO
= 0x00, /* No error */
227 ERR_DMA_V
= 0x01 << 4, /* DMA in vertical active */
228 ERR_DMA_VB
= 0x02 << 4, /* DMA in vertical blanking */
229 ERR_LINE_TOO_LONG
= 0x04 << 4, /* Line too long */
230 ERR_TOO_MANG_LINES
= 0x05 << 4, /* Too many lines in field */
231 ERR_LINE_TOO_SHORT
= 0x06 << 4, /* Line too short */
232 ERR_NOT_ENOUGH_LINE
= 0x07 << 4, /* Not enough lines in field */
233 ERR_FIFO_OVERFLOW
= 0x08 << 4, /* FIFO overflow */
234 ERR_FIFO_UNDERFLOW
= 0x09 << 4, /* FIFO underflow */
235 ERR_1bit_ECC
= 0x0a << 4, /* One bit ECC error */
236 ERR_MORE_ECC
= 0x0b << 4, /* Two/more bits ECC error */
238 INT_FIELD_EN
= 0x01 << 8, /* Enable field interrupt */
239 INT_VSYNC_EN
= 0x01 << 9, /* Enable vsync interrupt */
240 INT_HSYNC_EN
= 0x01 << 10, /* Enable hsync interrupt */
241 INT_VSTART_EN
= 0x01 << 11, /* Enable vstart interrupt */
242 INT_DMA_END_EN
= 0x01 << 12, /* Enable DMA end interrupt */
243 INT_ERROR_EN
= 0x01 << 13, /* Enable error interrupt */
244 INT_ECC_EN
= 0x01 << 14, /* Enable ECC interrupt */
246 INT_FIELD_STATUS
= 0x01 << 16, /* field interrupt status */
247 INT_VSYNC_STATUS
= 0x01 << 17, /* vsync interrupt status */
248 INT_HSYNC_STATUS
= 0x01 << 18, /* hsync interrupt status */
249 INT_VSTART_STATUS
= 0x01 << 19, /* vstart interrupt status */
250 INT_DMA_END_STATUS
= 0x01 << 20, /* DMA end interrupt status */
251 INT_ERROR_STATUS
= 0x01 << 21, /* error interrupt status */
253 DMA_ACT
= 0x01 << 27, /* Enable DMA transfer */
254 FIELD_NO
= 0x01 << 28, /* Field number */
255 DITHER_ON
= 0x01 << 29, /* Dithering is on */
256 ROUND_ON
= 0x01 << 30, /* Round is on */
257 MODE_32BIT
= 0x01 << 31, /* Data in RGBa888,
262 #define norm_maxw() 720
263 #define norm_maxh() 576
265 #define INT_ALL_STATUS (INT_FIELD_STATUS | INT_VSYNC_STATUS | \
266 INT_HSYNC_STATUS | INT_VSTART_STATUS | \
267 INT_DMA_END_STATUS | INT_ERROR_STATUS)
269 #define NUM_FORMATS ARRAY_SIZE(formats)
271 static irqreturn_t
viu_intr(int irq
, void *dev_id
);
273 struct viu_fmt
*format_by_fourcc(int fourcc
)
277 for (i
= 0; i
< NUM_FORMATS
; i
++) {
278 if (formats
[i
].pixelformat
== fourcc
)
282 dprintk(0, "unknown pixelformat:'%4.4s'\n", (char *)&fourcc
);
286 void viu_start_dma(struct viu_dev
*dev
)
288 struct viu_reg
*vr
= dev
->vr
;
292 /* Enable DMA operation */
293 out_be32(&vr
->status_cfg
, SOFT_RST
);
294 out_be32(&vr
->status_cfg
, INT_FIELD_EN
);
297 void viu_stop_dma(struct viu_dev
*dev
)
299 struct viu_reg
*vr
= dev
->vr
;
303 out_be32(&vr
->status_cfg
, 0);
305 /* Clear pending interrupts */
306 status_cfg
= in_be32(&vr
->status_cfg
);
307 if (status_cfg
& 0x3f0000)
308 out_be32(&vr
->status_cfg
, status_cfg
& 0x3f0000);
310 if (status_cfg
& DMA_ACT
) {
312 status_cfg
= in_be32(&vr
->status_cfg
);
313 if (status_cfg
& INT_DMA_END_STATUS
)
318 /* timed out, issue soft reset */
319 out_be32(&vr
->status_cfg
, SOFT_RST
);
320 out_be32(&vr
->status_cfg
, 0);
322 /* clear DMA_END and other pending irqs */
323 out_be32(&vr
->status_cfg
, status_cfg
& 0x3f0000);
330 static int restart_video_queue(struct viu_dmaqueue
*vidq
)
332 struct viu_buf
*buf
, *prev
;
334 dprintk(1, "%s vidq=0x%08lx\n", __func__
, (unsigned long)vidq
);
335 if (!list_empty(&vidq
->active
)) {
336 buf
= list_entry(vidq
->active
.next
, struct viu_buf
, vb
.queue
);
337 dprintk(2, "restart_queue [%p/%d]: restart dma\n",
340 viu_stop_dma(vidq
->dev
);
342 /* cancel all outstanding capture requests */
343 list_for_each_entry_safe(buf
, prev
, &vidq
->active
, vb
.queue
) {
344 list_del(&buf
->vb
.queue
);
345 buf
->vb
.state
= VIDEOBUF_ERROR
;
346 wake_up(&buf
->vb
.done
);
348 mod_timer(&vidq
->timeout
, jiffies
+BUFFER_TIMEOUT
);
354 if (list_empty(&vidq
->queued
))
356 buf
= list_entry(vidq
->queued
.next
, struct viu_buf
, vb
.queue
);
358 list_del(&buf
->vb
.queue
);
359 list_add_tail(&buf
->vb
.queue
, &vidq
->active
);
361 dprintk(1, "Restarting video dma\n");
362 viu_stop_dma(vidq
->dev
);
363 viu_start_dma(vidq
->dev
);
365 buf
->vb
.state
= VIDEOBUF_ACTIVE
;
366 mod_timer(&vidq
->timeout
, jiffies
+BUFFER_TIMEOUT
);
367 dprintk(2, "[%p/%d] restart_queue - first active\n",
370 } else if (prev
->vb
.width
== buf
->vb
.width
&&
371 prev
->vb
.height
== buf
->vb
.height
&&
372 prev
->fmt
== buf
->fmt
) {
373 list_del(&buf
->vb
.queue
);
374 list_add_tail(&buf
->vb
.queue
, &vidq
->active
);
375 buf
->vb
.state
= VIDEOBUF_ACTIVE
;
376 dprintk(2, "[%p/%d] restart_queue - move to active\n",
385 static void viu_vid_timeout(unsigned long data
)
387 struct viu_dev
*dev
= (struct viu_dev
*)data
;
389 struct viu_dmaqueue
*vidq
= &dev
->vidq
;
391 while (!list_empty(&vidq
->active
)) {
392 buf
= list_entry(vidq
->active
.next
, struct viu_buf
, vb
.queue
);
393 list_del(&buf
->vb
.queue
);
394 buf
->vb
.state
= VIDEOBUF_ERROR
;
395 wake_up(&buf
->vb
.done
);
396 dprintk(1, "viu/0: [%p/%d] timeout\n", buf
, buf
->vb
.i
);
399 restart_video_queue(vidq
);
403 * Videobuf operations
405 static int buffer_setup(struct videobuf_queue
*vq
, unsigned int *count
,
408 struct viu_fh
*fh
= vq
->priv_data
;
410 *size
= fh
->width
* fh
->height
* fh
->fmt
->depth
>> 3;
414 while (*size
* *count
> VIU_VID_MEM_LIMIT
* 1024 * 1024)
417 dprintk(1, "%s, count=%d, size=%d\n", __func__
, *count
, *size
);
421 static void free_buffer(struct videobuf_queue
*vq
, struct viu_buf
*buf
)
423 struct videobuf_buffer
*vb
= &buf
->vb
;
426 BUG_ON(in_interrupt());
428 videobuf_waiton(&buf
->vb
, 0, 0);
430 if (vq
->int_ops
&& vq
->int_ops
->vaddr
)
431 vaddr
= vq
->int_ops
->vaddr(vb
);
434 videobuf_dma_contig_free(vq
, &buf
->vb
);
436 buf
->vb
.state
= VIDEOBUF_NEEDS_INIT
;
439 inline int buffer_activate(struct viu_dev
*dev
, struct viu_buf
*buf
)
441 struct viu_reg
*vr
= dev
->vr
;
444 /* setup the DMA base address */
445 reg_val
.field_base_addr
= videobuf_to_dma_contig(&buf
->vb
);
447 dprintk(1, "buffer_activate [%p/%d]: dma addr 0x%lx\n",
448 buf
, buf
->vb
.i
, (unsigned long)reg_val
.field_base_addr
);
450 /* interlace is on by default, set horizontal DMA increment */
451 reg_val
.status_cfg
= 0;
452 bpp
= buf
->fmt
->depth
>> 3;
455 reg_val
.status_cfg
&= ~MODE_32BIT
;
456 reg_val
.dma_inc
= buf
->vb
.width
* 2;
459 reg_val
.status_cfg
|= MODE_32BIT
;
460 reg_val
.dma_inc
= buf
->vb
.width
* 4;
463 dprintk(0, "doesn't support color depth(%d)\n",
468 /* setup picture_count register */
469 reg_val
.picture_count
= (buf
->vb
.height
/ 2) << 16 |
472 reg_val
.status_cfg
|= DMA_ACT
| INT_DMA_END_EN
| INT_FIELD_EN
;
474 buf
->vb
.state
= VIDEOBUF_ACTIVE
;
475 dev
->capfield
= buf
->vb
.field
;
477 /* reset dma increment if needed */
478 if (!V4L2_FIELD_HAS_BOTH(buf
->vb
.field
))
481 out_be32(&vr
->dma_inc
, reg_val
.dma_inc
);
482 out_be32(&vr
->picture_count
, reg_val
.picture_count
);
483 out_be32(&vr
->field_base_addr
, reg_val
.field_base_addr
);
484 mod_timer(&dev
->vidq
.timeout
, jiffies
+ BUFFER_TIMEOUT
);
488 static int buffer_prepare(struct videobuf_queue
*vq
,
489 struct videobuf_buffer
*vb
,
490 enum v4l2_field field
)
492 struct viu_fh
*fh
= vq
->priv_data
;
493 struct viu_buf
*buf
= container_of(vb
, struct viu_buf
, vb
);
496 BUG_ON(fh
->fmt
== NULL
);
498 if (fh
->width
< 48 || fh
->width
> norm_maxw() ||
499 fh
->height
< 32 || fh
->height
> norm_maxh())
501 buf
->vb
.size
= (fh
->width
* fh
->height
* fh
->fmt
->depth
) >> 3;
502 if (buf
->vb
.baddr
!= 0 && buf
->vb
.bsize
< buf
->vb
.size
)
505 if (buf
->fmt
!= fh
->fmt
||
506 buf
->vb
.width
!= fh
->width
||
507 buf
->vb
.height
!= fh
->height
||
508 buf
->vb
.field
!= field
) {
510 buf
->vb
.width
= fh
->width
;
511 buf
->vb
.height
= fh
->height
;
512 buf
->vb
.field
= field
;
515 if (buf
->vb
.state
== VIDEOBUF_NEEDS_INIT
) {
516 rc
= videobuf_iolock(vq
, &buf
->vb
, NULL
);
520 buf
->vb
.width
= fh
->width
;
521 buf
->vb
.height
= fh
->height
;
522 buf
->vb
.field
= field
;
526 buf
->vb
.state
= VIDEOBUF_PREPARED
;
530 free_buffer(vq
, buf
);
534 static void buffer_queue(struct videobuf_queue
*vq
, struct videobuf_buffer
*vb
)
536 struct viu_buf
*buf
= container_of(vb
, struct viu_buf
, vb
);
537 struct viu_fh
*fh
= vq
->priv_data
;
538 struct viu_dev
*dev
= fh
->dev
;
539 struct viu_dmaqueue
*vidq
= &dev
->vidq
;
540 struct viu_buf
*prev
;
542 if (!list_empty(&vidq
->queued
)) {
543 dprintk(1, "adding vb queue=0x%08lx\n",
544 (unsigned long)&buf
->vb
.queue
);
545 dprintk(1, "vidq pointer 0x%p, queued 0x%p\n",
546 vidq
, &vidq
->queued
);
547 dprintk(1, "dev %p, queued: self %p, next %p, head %p\n",
548 dev
, &vidq
->queued
, vidq
->queued
.next
,
550 list_add_tail(&buf
->vb
.queue
, &vidq
->queued
);
551 buf
->vb
.state
= VIDEOBUF_QUEUED
;
552 dprintk(2, "[%p/%d] buffer_queue - append to queued\n",
554 } else if (list_empty(&vidq
->active
)) {
555 dprintk(1, "adding vb active=0x%08lx\n",
556 (unsigned long)&buf
->vb
.queue
);
557 list_add_tail(&buf
->vb
.queue
, &vidq
->active
);
558 buf
->vb
.state
= VIDEOBUF_ACTIVE
;
559 mod_timer(&vidq
->timeout
, jiffies
+BUFFER_TIMEOUT
);
560 dprintk(2, "[%p/%d] buffer_queue - first active\n",
563 buffer_activate(dev
, buf
);
565 dprintk(1, "adding vb queue2=0x%08lx\n",
566 (unsigned long)&buf
->vb
.queue
);
567 prev
= list_entry(vidq
->active
.prev
, struct viu_buf
, vb
.queue
);
568 if (prev
->vb
.width
== buf
->vb
.width
&&
569 prev
->vb
.height
== buf
->vb
.height
&&
570 prev
->fmt
== buf
->fmt
) {
571 list_add_tail(&buf
->vb
.queue
, &vidq
->active
);
572 buf
->vb
.state
= VIDEOBUF_ACTIVE
;
573 dprintk(2, "[%p/%d] buffer_queue - append to active\n",
576 list_add_tail(&buf
->vb
.queue
, &vidq
->queued
);
577 buf
->vb
.state
= VIDEOBUF_QUEUED
;
578 dprintk(2, "[%p/%d] buffer_queue - first queued\n",
584 static void buffer_release(struct videobuf_queue
*vq
,
585 struct videobuf_buffer
*vb
)
587 struct viu_buf
*buf
= container_of(vb
, struct viu_buf
, vb
);
588 struct viu_fh
*fh
= vq
->priv_data
;
589 struct viu_dev
*dev
= (struct viu_dev
*)fh
->dev
;
592 free_buffer(vq
, buf
);
595 static struct videobuf_queue_ops viu_video_qops
= {
596 .buf_setup
= buffer_setup
,
597 .buf_prepare
= buffer_prepare
,
598 .buf_queue
= buffer_queue
,
599 .buf_release
= buffer_release
,
603 * IOCTL vidioc handling
605 static int vidioc_querycap(struct file
*file
, void *priv
,
606 struct v4l2_capability
*cap
)
608 strcpy(cap
->driver
, "viu");
609 strcpy(cap
->card
, "viu");
610 cap
->version
= VIU_VERSION
;
611 cap
->capabilities
= V4L2_CAP_VIDEO_CAPTURE
|
613 V4L2_CAP_VIDEO_OVERLAY
|
618 static int vidioc_enum_fmt(struct file
*file
, void *priv
,
619 struct v4l2_fmtdesc
*f
)
621 int index
= f
->index
;
623 if (f
->index
> NUM_FORMATS
)
626 strlcpy(f
->description
, formats
[index
].name
, sizeof(f
->description
));
627 f
->pixelformat
= formats
[index
].fourcc
;
631 static int vidioc_g_fmt_cap(struct file
*file
, void *priv
,
632 struct v4l2_format
*f
)
634 struct viu_fh
*fh
= priv
;
636 f
->fmt
.pix
.width
= fh
->width
;
637 f
->fmt
.pix
.height
= fh
->height
;
638 f
->fmt
.pix
.field
= fh
->vb_vidq
.field
;
639 f
->fmt
.pix
.pixelformat
= fh
->fmt
->pixelformat
;
640 f
->fmt
.pix
.bytesperline
=
641 (f
->fmt
.pix
.width
* fh
->fmt
->depth
) >> 3;
642 f
->fmt
.pix
.sizeimage
= fh
->sizeimage
;
646 static int vidioc_try_fmt_cap(struct file
*file
, void *priv
,
647 struct v4l2_format
*f
)
650 enum v4l2_field field
;
651 unsigned int maxw
, maxh
;
653 fmt
= format_by_fourcc(f
->fmt
.pix
.pixelformat
);
655 dprintk(1, "Fourcc format (0x%08x) invalid.",
656 f
->fmt
.pix
.pixelformat
);
660 field
= f
->fmt
.pix
.field
;
662 if (field
== V4L2_FIELD_ANY
) {
663 field
= V4L2_FIELD_INTERLACED
;
664 } else if (field
!= V4L2_FIELD_INTERLACED
) {
665 dprintk(1, "Field type invalid.\n");
672 f
->fmt
.pix
.field
= field
;
673 if (f
->fmt
.pix
.height
< 32)
674 f
->fmt
.pix
.height
= 32;
675 if (f
->fmt
.pix
.height
> maxh
)
676 f
->fmt
.pix
.height
= maxh
;
677 if (f
->fmt
.pix
.width
< 48)
678 f
->fmt
.pix
.width
= 48;
679 if (f
->fmt
.pix
.width
> maxw
)
680 f
->fmt
.pix
.width
= maxw
;
681 f
->fmt
.pix
.width
&= ~0x03;
682 f
->fmt
.pix
.bytesperline
=
683 (f
->fmt
.pix
.width
* fmt
->depth
) >> 3;
688 static int vidioc_s_fmt_cap(struct file
*file
, void *priv
,
689 struct v4l2_format
*f
)
691 struct viu_fh
*fh
= priv
;
694 ret
= vidioc_try_fmt_cap(file
, fh
, f
);
698 fh
->fmt
= format_by_fourcc(f
->fmt
.pix
.pixelformat
);
699 fh
->width
= f
->fmt
.pix
.width
;
700 fh
->height
= f
->fmt
.pix
.height
;
701 fh
->sizeimage
= f
->fmt
.pix
.sizeimage
;
702 fh
->vb_vidq
.field
= f
->fmt
.pix
.field
;
704 dprintk(1, "set to pixelformat '%4.6s'\n", (char *)&fh
->fmt
->name
);
708 static int vidioc_g_fmt_overlay(struct file
*file
, void *priv
,
709 struct v4l2_format
*f
)
711 struct viu_fh
*fh
= priv
;
713 f
->fmt
.win
= fh
->win
;
717 static int verify_preview(struct viu_dev
*dev
, struct v4l2_window
*win
)
719 enum v4l2_field field
;
722 if (dev
->ovbuf
.base
== NULL
)
724 if (dev
->ovfmt
== NULL
)
726 if (win
->w
.width
< 48 || win
->w
.height
< 32)
730 maxw
= dev
->crop_current
.width
;
731 maxh
= dev
->crop_current
.height
;
733 if (field
== V4L2_FIELD_ANY
) {
734 field
= (win
->w
.height
> maxh
/2)
735 ? V4L2_FIELD_INTERLACED
740 case V4L2_FIELD_BOTTOM
:
743 case V4L2_FIELD_INTERLACED
:
750 if (win
->w
.width
> maxw
)
752 if (win
->w
.height
> maxh
)
753 win
->w
.height
= maxh
;
757 inline void viu_activate_overlay(struct viu_reg
*viu_reg
)
759 struct viu_reg
*vr
= viu_reg
;
761 out_be32(&vr
->field_base_addr
, reg_val
.field_base_addr
);
762 out_be32(&vr
->dma_inc
, reg_val
.dma_inc
);
763 out_be32(&vr
->picture_count
, reg_val
.picture_count
);
766 static int viu_start_preview(struct viu_dev
*dev
, struct viu_fh
*fh
)
770 dprintk(1, "%s %dx%d %s\n", __func__
,
771 fh
->win
.w
.width
, fh
->win
.w
.height
, dev
->ovfmt
->name
);
773 reg_val
.status_cfg
= 0;
776 reg_val
.picture_count
= (fh
->win
.w
.height
/ 2) << 16 |
779 /* setup color depth and dma increment */
780 bpp
= dev
->ovfmt
->depth
/ 8;
783 reg_val
.status_cfg
&= ~MODE_32BIT
;
784 reg_val
.dma_inc
= fh
->win
.w
.width
* 2;
787 reg_val
.status_cfg
|= MODE_32BIT
;
788 reg_val
.dma_inc
= fh
->win
.w
.width
* 4;
791 dprintk(0, "device doesn't support color depth(%d)\n",
796 dev
->ovfield
= fh
->win
.field
;
797 if (!V4L2_FIELD_HAS_BOTH(dev
->ovfield
))
800 reg_val
.status_cfg
|= DMA_ACT
| INT_DMA_END_EN
| INT_FIELD_EN
;
802 /* setup the base address of the overlay buffer */
803 reg_val
.field_base_addr
= (u32
)dev
->ovbuf
.base
;
806 viu_activate_overlay(dev
->vr
);
813 static int vidioc_s_fmt_overlay(struct file
*file
, void *priv
,
814 struct v4l2_format
*f
)
816 struct viu_fh
*fh
= priv
;
817 struct viu_dev
*dev
= (struct viu_dev
*)fh
->dev
;
821 err
= verify_preview(dev
, &f
->fmt
.win
);
825 mutex_lock(&dev
->lock
);
826 fh
->win
= f
->fmt
.win
;
828 spin_lock_irqsave(&dev
->slock
, flags
);
829 viu_start_preview(dev
, fh
);
830 spin_unlock_irqrestore(&dev
->slock
, flags
);
831 mutex_unlock(&dev
->lock
);
835 static int vidioc_try_fmt_overlay(struct file
*file
, void *priv
,
836 struct v4l2_format
*f
)
841 int vidioc_g_fbuf(struct file
*file
, void *priv
, struct v4l2_framebuffer
*arg
)
843 struct viu_fh
*fh
= priv
;
844 struct viu_dev
*dev
= fh
->dev
;
845 struct v4l2_framebuffer
*fb
= arg
;
848 fb
->capability
= V4L2_FBUF_CAP_LIST_CLIPPING
;
852 int vidioc_s_fbuf(struct file
*file
, void *priv
, struct v4l2_framebuffer
*arg
)
854 struct viu_fh
*fh
= priv
;
855 struct viu_dev
*dev
= fh
->dev
;
856 struct v4l2_framebuffer
*fb
= arg
;
859 if (!capable(CAP_SYS_ADMIN
) && !capable(CAP_SYS_RAWIO
))
863 fmt
= format_by_fourcc(fb
->fmt
.pixelformat
);
870 if (dev
->ovbuf
.fmt
.bytesperline
== 0) {
871 dev
->ovbuf
.fmt
.bytesperline
=
872 dev
->ovbuf
.fmt
.width
* fmt
->depth
/ 8;
877 static int vidioc_reqbufs(struct file
*file
, void *priv
,
878 struct v4l2_requestbuffers
*p
)
880 struct viu_fh
*fh
= priv
;
882 return videobuf_reqbufs(&fh
->vb_vidq
, p
);
885 static int vidioc_querybuf(struct file
*file
, void *priv
,
886 struct v4l2_buffer
*p
)
888 struct viu_fh
*fh
= priv
;
890 return videobuf_querybuf(&fh
->vb_vidq
, p
);
893 static int vidioc_qbuf(struct file
*file
, void *priv
, struct v4l2_buffer
*p
)
895 struct viu_fh
*fh
= priv
;
897 return videobuf_qbuf(&fh
->vb_vidq
, p
);
900 static int vidioc_dqbuf(struct file
*file
, void *priv
, struct v4l2_buffer
*p
)
902 struct viu_fh
*fh
= priv
;
904 return videobuf_dqbuf(&fh
->vb_vidq
, p
,
905 file
->f_flags
& O_NONBLOCK
);
908 static int vidioc_streamon(struct file
*file
, void *priv
, enum v4l2_buf_type i
)
910 struct viu_fh
*fh
= priv
;
912 if (fh
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
)
917 return videobuf_streamon(&fh
->vb_vidq
);
920 static int vidioc_streamoff(struct file
*file
, void *priv
, enum v4l2_buf_type i
)
922 struct viu_fh
*fh
= priv
;
924 if (fh
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
)
929 return videobuf_streamoff(&fh
->vb_vidq
);
932 #define decoder_call(viu, o, f, args...) \
933 v4l2_subdev_call(viu->decoder, o, f, ##args)
935 static int vidioc_s_std(struct file
*file
, void *priv
, v4l2_std_id
*id
)
937 struct viu_fh
*fh
= priv
;
939 decoder_call(fh
->dev
, core
, s_std
, *id
);
943 /* only one input in this driver */
944 static int vidioc_enum_input(struct file
*file
, void *priv
,
945 struct v4l2_input
*inp
)
947 struct viu_fh
*fh
= priv
;
952 inp
->type
= V4L2_INPUT_TYPE_CAMERA
;
953 inp
->std
= fh
->dev
->vdev
->tvnorms
;
954 strcpy(inp
->name
, "Camera");
958 static int vidioc_g_input(struct file
*file
, void *priv
, unsigned int *i
)
964 static int vidioc_s_input(struct file
*file
, void *priv
, unsigned int i
)
966 struct viu_fh
*fh
= priv
;
971 decoder_call(fh
->dev
, video
, s_routing
, i
, 0, 0);
976 static int vidioc_queryctrl(struct file
*file
, void *priv
,
977 struct v4l2_queryctrl
*qc
)
981 for (i
= 0; i
< ARRAY_SIZE(viu_qctrl
); i
++) {
982 if (qc
->id
&& qc
->id
== viu_qctrl
[i
].id
) {
983 memcpy(qc
, &(viu_qctrl
[i
]), sizeof(*qc
));
990 static int vidioc_g_ctrl(struct file
*file
, void *priv
,
991 struct v4l2_control
*ctrl
)
995 for (i
= 0; i
< ARRAY_SIZE(viu_qctrl
); i
++) {
996 if (ctrl
->id
== viu_qctrl
[i
].id
) {
997 ctrl
->value
= qctl_regs
[i
];
1003 static int vidioc_s_ctrl(struct file
*file
, void *priv
,
1004 struct v4l2_control
*ctrl
)
1008 for (i
= 0; i
< ARRAY_SIZE(viu_qctrl
); i
++) {
1009 if (ctrl
->id
== viu_qctrl
[i
].id
) {
1010 if (ctrl
->value
< viu_qctrl
[i
].minimum
1011 || ctrl
->value
> viu_qctrl
[i
].maximum
)
1013 qctl_regs
[i
] = ctrl
->value
;
1020 inline void viu_activate_next_buf(struct viu_dev
*dev
,
1021 struct viu_dmaqueue
*viuq
)
1023 struct viu_dmaqueue
*vidq
= viuq
;
1024 struct viu_buf
*buf
;
1026 /* launch another DMA operation for an active/queued buffer */
1027 if (!list_empty(&vidq
->active
)) {
1028 buf
= list_entry(vidq
->active
.next
, struct viu_buf
,
1030 dprintk(1, "start another queued buffer: 0x%p\n", buf
);
1031 buffer_activate(dev
, buf
);
1032 } else if (!list_empty(&vidq
->queued
)) {
1033 buf
= list_entry(vidq
->queued
.next
, struct viu_buf
,
1035 list_del(&buf
->vb
.queue
);
1037 dprintk(1, "start another queued buffer: 0x%p\n", buf
);
1038 list_add_tail(&buf
->vb
.queue
, &vidq
->active
);
1039 buf
->vb
.state
= VIDEOBUF_ACTIVE
;
1040 buffer_activate(dev
, buf
);
1044 inline void viu_default_settings(struct viu_reg
*viu_reg
)
1046 struct viu_reg
*vr
= viu_reg
;
1048 out_be32(&vr
->luminance
, 0x9512A254);
1049 out_be32(&vr
->chroma_r
, 0x03310000);
1050 out_be32(&vr
->chroma_g
, 0x06600F38);
1051 out_be32(&vr
->chroma_b
, 0x00000409);
1052 out_be32(&vr
->alpha
, 0x000000ff);
1053 out_be32(&vr
->req_alarm
, 0x00000090);
1054 dprintk(1, "status reg: 0x%08x, field base: 0x%08x\n",
1055 in_be32(&vr
->status_cfg
), in_be32(&vr
->field_base_addr
));
1058 static void viu_overlay_intr(struct viu_dev
*dev
, u32 status
)
1060 struct viu_reg
*vr
= dev
->vr
;
1062 if (status
& INT_DMA_END_STATUS
)
1065 if (status
& INT_FIELD_STATUS
) {
1066 if (dev
->dma_done
) {
1067 u32 addr
= reg_val
.field_base_addr
;
1070 if (status
& FIELD_NO
)
1071 addr
+= reg_val
.dma_inc
;
1073 out_be32(&vr
->field_base_addr
, addr
);
1074 out_be32(&vr
->dma_inc
, reg_val
.dma_inc
);
1075 out_be32(&vr
->status_cfg
,
1076 (status
& 0xffc0ffff) |
1077 (status
& INT_ALL_STATUS
) |
1078 reg_val
.status_cfg
);
1079 } else if (status
& INT_VSYNC_STATUS
) {
1080 out_be32(&vr
->status_cfg
,
1081 (status
& 0xffc0ffff) |
1082 (status
& INT_ALL_STATUS
) |
1083 reg_val
.status_cfg
);
1088 static void viu_capture_intr(struct viu_dev
*dev
, u32 status
)
1090 struct viu_dmaqueue
*vidq
= &dev
->vidq
;
1091 struct viu_reg
*vr
= dev
->vr
;
1092 struct viu_buf
*buf
;
1097 field_num
= status
& FIELD_NO
;
1098 need_two
= V4L2_FIELD_HAS_BOTH(dev
->capfield
);
1100 if (status
& INT_DMA_END_STATUS
) {
1102 if (((field_num
== 0) && (dev
->field
== 0)) ||
1103 (field_num
&& (dev
->field
== 1)))
1107 if (status
& INT_FIELD_STATUS
) {
1108 dprintk(1, "irq: field %d, done %d\n",
1109 !!field_num
, dma_done
);
1110 if (unlikely(dev
->first
)) {
1111 if (field_num
== 0) {
1113 dprintk(1, "activate first buf\n");
1114 viu_activate_next_buf(dev
, vidq
);
1116 dprintk(1, "wait field 0\n");
1120 /* setup buffer address for next dma operation */
1121 if (!list_empty(&vidq
->active
)) {
1122 u32 addr
= reg_val
.field_base_addr
;
1124 if (field_num
&& need_two
) {
1125 addr
+= reg_val
.dma_inc
;
1126 dprintk(1, "field 1, 0x%lx, dev field %d\n",
1127 (unsigned long)addr
, dev
->field
);
1129 out_be32(&vr
->field_base_addr
, addr
);
1130 out_be32(&vr
->dma_inc
, reg_val
.dma_inc
);
1131 out_be32(&vr
->status_cfg
,
1132 (status
& 0xffc0ffff) |
1133 (status
& INT_ALL_STATUS
) |
1134 reg_val
.status_cfg
);
1139 if (dma_done
&& field_num
&& (dev
->field
== 2)) {
1141 buf
= list_entry(vidq
->active
.next
,
1142 struct viu_buf
, vb
.queue
);
1143 dprintk(1, "viu/0: [%p/%d] 0x%lx/0x%lx: dma complete\n",
1145 (unsigned long)videobuf_to_dma_contig(&buf
->vb
),
1146 (unsigned long)in_be32(&vr
->field_base_addr
));
1148 if (waitqueue_active(&buf
->vb
.done
)) {
1149 list_del(&buf
->vb
.queue
);
1150 do_gettimeofday(&buf
->vb
.ts
);
1151 buf
->vb
.state
= VIDEOBUF_DONE
;
1152 buf
->vb
.field_count
++;
1153 wake_up(&buf
->vb
.done
);
1155 /* activate next dma buffer */
1156 viu_activate_next_buf(dev
, vidq
);
1160 static irqreturn_t
viu_intr(int irq
, void *dev_id
)
1162 struct viu_dev
*dev
= (struct viu_dev
*)dev_id
;
1163 struct viu_reg
*vr
= dev
->vr
;
1167 status
= in_be32(&vr
->status_cfg
);
1169 if (status
& INT_ERROR_STATUS
) {
1170 dev
->irqs
.error_irq
++;
1171 error
= status
& ERR_MASK
;
1173 dprintk(1, "Err: error(%d), times:%d!\n",
1174 error
>> 4, dev
->irqs
.error_irq
);
1175 /* Clear interrupt error bit and error flags */
1176 out_be32(&vr
->status_cfg
,
1177 (status
& 0xffc0ffff) | INT_ERROR_STATUS
);
1180 if (status
& INT_DMA_END_STATUS
) {
1181 dev
->irqs
.dma_end_irq
++;
1183 dprintk(2, "VIU DMA end interrupt times: %d\n",
1184 dev
->irqs
.dma_end_irq
);
1187 if (status
& INT_HSYNC_STATUS
)
1188 dev
->irqs
.hsync_irq
++;
1190 if (status
& INT_FIELD_STATUS
) {
1191 dev
->irqs
.field_irq
++;
1192 dprintk(2, "VIU field interrupt times: %d\n",
1193 dev
->irqs
.field_irq
);
1196 if (status
& INT_VSTART_STATUS
)
1197 dev
->irqs
.vstart_irq
++;
1199 if (status
& INT_VSYNC_STATUS
) {
1200 dev
->irqs
.vsync_irq
++;
1201 dprintk(2, "VIU vsync interrupt times: %d\n",
1202 dev
->irqs
.vsync_irq
);
1205 /* clear all pending irqs */
1206 status
= in_be32(&vr
->status_cfg
);
1207 out_be32(&vr
->status_cfg
,
1208 (status
& 0xffc0ffff) | (status
& INT_ALL_STATUS
));
1210 if (dev
->ovenable
) {
1211 viu_overlay_intr(dev
, status
);
1216 viu_capture_intr(dev
, status
);
1221 * File operations for the device
1223 static int viu_open(struct file
*file
)
1225 struct video_device
*vdev
= video_devdata(file
);
1226 struct viu_dev
*dev
= video_get_drvdata(vdev
);
1229 int minor
= vdev
->minor
;
1233 dprintk(1, "viu: open (minor=%d)\n", minor
);
1236 if (dev
->users
> 1) {
1243 dprintk(1, "open minor=%d type=%s users=%d\n", minor
,
1244 v4l2_type_names
[V4L2_BUF_TYPE_VIDEO_CAPTURE
], dev
->users
);
1246 /* allocate and initialize per filehandle data */
1247 fh
= kzalloc(sizeof(*fh
), GFP_KERNEL
);
1253 file
->private_data
= fh
;
1256 fh
->type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
1257 fh
->fmt
= format_by_fourcc(V4L2_PIX_FMT_RGB32
);
1258 fh
->width
= norm_maxw();
1259 fh
->height
= norm_maxh();
1260 dev
->crop_current
.width
= fh
->width
;
1261 dev
->crop_current
.height
= fh
->height
;
1263 /* Put all controls at a sane state */
1264 for (i
= 0; i
< ARRAY_SIZE(viu_qctrl
); i
++)
1265 qctl_regs
[i
] = viu_qctrl
[i
].default_value
;
1267 dprintk(1, "Open: fh=0x%08lx, dev=0x%08lx, dev->vidq=0x%08lx\n",
1268 (unsigned long)fh
, (unsigned long)dev
,
1269 (unsigned long)&dev
->vidq
);
1270 dprintk(1, "Open: list_empty queued=%d\n",
1271 list_empty(&dev
->vidq
.queued
));
1272 dprintk(1, "Open: list_empty active=%d\n",
1273 list_empty(&dev
->vidq
.active
));
1275 viu_default_settings(vr
);
1277 status_cfg
= in_be32(&vr
->status_cfg
);
1278 out_be32(&vr
->status_cfg
,
1279 status_cfg
& ~(INT_VSYNC_EN
| INT_HSYNC_EN
|
1280 INT_FIELD_EN
| INT_VSTART_EN
|
1281 INT_DMA_END_EN
| INT_ERROR_EN
| INT_ECC_EN
));
1283 status_cfg
= in_be32(&vr
->status_cfg
);
1284 out_be32(&vr
->status_cfg
, status_cfg
| INT_ALL_STATUS
);
1286 spin_lock_init(&fh
->vbq_lock
);
1287 videobuf_queue_dma_contig_init(&fh
->vb_vidq
, &viu_video_qops
,
1288 dev
->dev
, &fh
->vbq_lock
,
1289 fh
->type
, V4L2_FIELD_INTERLACED
,
1290 sizeof(struct viu_buf
), fh
);
1294 static ssize_t
viu_read(struct file
*file
, char __user
*data
, size_t count
,
1297 struct viu_fh
*fh
= file
->private_data
;
1298 struct viu_dev
*dev
= fh
->dev
;
1301 dprintk(2, "%s\n", __func__
);
1305 if (fh
->type
== V4L2_BUF_TYPE_VIDEO_CAPTURE
) {
1307 ret
= videobuf_read_stream(&fh
->vb_vidq
, data
, count
,
1308 ppos
, 0, file
->f_flags
& O_NONBLOCK
);
1314 static unsigned int viu_poll(struct file
*file
, struct poll_table_struct
*wait
)
1316 struct viu_fh
*fh
= file
->private_data
;
1317 struct videobuf_queue
*q
= &fh
->vb_vidq
;
1319 if (V4L2_BUF_TYPE_VIDEO_CAPTURE
!= fh
->type
)
1322 return videobuf_poll_stream(file
, q
, wait
);
1325 static int viu_release(struct file
*file
)
1327 struct viu_fh
*fh
= file
->private_data
;
1328 struct viu_dev
*dev
= fh
->dev
;
1329 int minor
= video_devdata(file
)->minor
;
1332 videobuf_stop(&fh
->vb_vidq
);
1337 dprintk(1, "close (minor=%d, users=%d)\n",
1342 void viu_reset(struct viu_reg
*reg
)
1344 out_be32(®
->status_cfg
, 0);
1345 out_be32(®
->luminance
, 0x9512a254);
1346 out_be32(®
->chroma_r
, 0x03310000);
1347 out_be32(®
->chroma_g
, 0x06600f38);
1348 out_be32(®
->chroma_b
, 0x00000409);
1349 out_be32(®
->field_base_addr
, 0);
1350 out_be32(®
->dma_inc
, 0);
1351 out_be32(®
->picture_count
, 0x01e002d0);
1352 out_be32(®
->req_alarm
, 0x00000090);
1353 out_be32(®
->alpha
, 0x000000ff);
1356 static int viu_mmap(struct file
*file
, struct vm_area_struct
*vma
)
1358 struct viu_fh
*fh
= file
->private_data
;
1361 dprintk(1, "mmap called, vma=0x%08lx\n", (unsigned long)vma
);
1363 ret
= videobuf_mmap_mapper(&fh
->vb_vidq
, vma
);
1365 dprintk(1, "vma start=0x%08lx, size=%ld, ret=%d\n",
1366 (unsigned long)vma
->vm_start
,
1367 (unsigned long)vma
->vm_end
-(unsigned long)vma
->vm_start
,
1373 static struct v4l2_file_operations viu_fops
= {
1374 .owner
= THIS_MODULE
,
1376 .release
= viu_release
,
1379 .ioctl
= video_ioctl2
, /* V4L2 ioctl handler */
1383 static const struct v4l2_ioctl_ops viu_ioctl_ops
= {
1384 .vidioc_querycap
= vidioc_querycap
,
1385 .vidioc_enum_fmt_vid_cap
= vidioc_enum_fmt
,
1386 .vidioc_g_fmt_vid_cap
= vidioc_g_fmt_cap
,
1387 .vidioc_try_fmt_vid_cap
= vidioc_try_fmt_cap
,
1388 .vidioc_s_fmt_vid_cap
= vidioc_s_fmt_cap
,
1389 .vidioc_enum_fmt_vid_overlay
= vidioc_enum_fmt
,
1390 .vidioc_g_fmt_vid_overlay
= vidioc_g_fmt_overlay
,
1391 .vidioc_try_fmt_vid_overlay
= vidioc_try_fmt_overlay
,
1392 .vidioc_s_fmt_vid_overlay
= vidioc_s_fmt_overlay
,
1393 .vidioc_g_fbuf
= vidioc_g_fbuf
,
1394 .vidioc_s_fbuf
= vidioc_s_fbuf
,
1395 .vidioc_reqbufs
= vidioc_reqbufs
,
1396 .vidioc_querybuf
= vidioc_querybuf
,
1397 .vidioc_qbuf
= vidioc_qbuf
,
1398 .vidioc_dqbuf
= vidioc_dqbuf
,
1399 .vidioc_s_std
= vidioc_s_std
,
1400 .vidioc_enum_input
= vidioc_enum_input
,
1401 .vidioc_g_input
= vidioc_g_input
,
1402 .vidioc_s_input
= vidioc_s_input
,
1403 .vidioc_queryctrl
= vidioc_queryctrl
,
1404 .vidioc_g_ctrl
= vidioc_g_ctrl
,
1405 .vidioc_s_ctrl
= vidioc_s_ctrl
,
1406 .vidioc_streamon
= vidioc_streamon
,
1407 .vidioc_streamoff
= vidioc_streamoff
,
1410 static struct video_device viu_template
= {
1414 .ioctl_ops
= &viu_ioctl_ops
,
1415 .release
= video_device_release
,
1417 .tvnorms
= V4L2_STD_NTSC_M
| V4L2_STD_PAL
,
1418 .current_norm
= V4L2_STD_NTSC_M
,
1421 static int __devinit
viu_of_probe(struct platform_device
*op
,
1422 const struct of_device_id
*match
)
1424 struct viu_dev
*viu_dev
;
1425 struct video_device
*vdev
;
1427 struct viu_reg __iomem
*viu_regs
;
1428 struct i2c_adapter
*ad
;
1431 ret
= of_address_to_resource(op
->dev
.of_node
, 0, &r
);
1433 dev_err(&op
->dev
, "Can't parse device node resource\n");
1437 viu_irq
= irq_of_parse_and_map(op
->dev
.of_node
, 0);
1438 if (viu_irq
== NO_IRQ
) {
1439 dev_err(&op
->dev
, "Error while mapping the irq\n");
1443 /* request mem region */
1444 if (!devm_request_mem_region(&op
->dev
, r
.start
,
1445 sizeof(struct viu_reg
), DRV_NAME
)) {
1446 dev_err(&op
->dev
, "Error while requesting mem region\n");
1451 /* remap registers */
1452 viu_regs
= devm_ioremap(&op
->dev
, r
.start
, sizeof(struct viu_reg
));
1454 dev_err(&op
->dev
, "Can't map register set\n");
1459 /* Prepare our private structure */
1460 viu_dev
= devm_kzalloc(&op
->dev
, sizeof(struct viu_dev
), GFP_ATOMIC
);
1462 dev_err(&op
->dev
, "Can't allocate private structure\n");
1467 viu_dev
->vr
= viu_regs
;
1468 viu_dev
->irq
= viu_irq
;
1469 viu_dev
->dev
= &op
->dev
;
1471 /* init video dma queues */
1472 INIT_LIST_HEAD(&viu_dev
->vidq
.active
);
1473 INIT_LIST_HEAD(&viu_dev
->vidq
.queued
);
1475 /* initialize locks */
1476 mutex_init(&viu_dev
->lock
);
1478 snprintf(viu_dev
->v4l2_dev
.name
,
1479 sizeof(viu_dev
->v4l2_dev
.name
), "%s", "VIU");
1480 ret
= v4l2_device_register(viu_dev
->dev
, &viu_dev
->v4l2_dev
);
1482 dev_err(&op
->dev
, "v4l2_device_register() failed: %d\n", ret
);
1486 ad
= i2c_get_adapter(0);
1487 viu_dev
->decoder
= v4l2_i2c_new_subdev(&viu_dev
->v4l2_dev
, ad
,
1488 "saa7115", "saa7113", VIU_VIDEO_DECODER_ADDR
, NULL
);
1490 viu_dev
->vidq
.timeout
.function
= viu_vid_timeout
;
1491 viu_dev
->vidq
.timeout
.data
= (unsigned long)viu_dev
;
1492 init_timer(&viu_dev
->vidq
.timeout
);
1495 /* Allocate memory for video device */
1496 vdev
= video_device_alloc();
1502 memcpy(vdev
, &viu_template
, sizeof(viu_template
));
1504 vdev
->v4l2_dev
= &viu_dev
->v4l2_dev
;
1506 viu_dev
->vdev
= vdev
;
1508 video_set_drvdata(viu_dev
->vdev
, viu_dev
);
1510 ret
= video_register_device(viu_dev
->vdev
, VFL_TYPE_GRABBER
, -1);
1512 video_device_release(viu_dev
->vdev
);
1516 /* enable VIU clock */
1517 viu_dev
->clk
= clk_get(&op
->dev
, "viu_clk");
1518 if (IS_ERR(viu_dev
->clk
)) {
1519 dev_err(&op
->dev
, "failed to find the clock module!\n");
1523 clk_enable(viu_dev
->clk
);
1526 /* reset VIU module */
1527 viu_reset(viu_dev
->vr
);
1529 /* install interrupt handler */
1530 if (request_irq(viu_dev
->irq
, viu_intr
, 0, "viu", (void *)viu_dev
)) {
1531 dev_err(&op
->dev
, "Request VIU IRQ failed.\n");
1536 dev_info(&op
->dev
, "Freescale VIU Video Capture Board\n");
1540 clk_disable(viu_dev
->clk
);
1541 clk_put(viu_dev
->clk
);
1543 video_unregister_device(viu_dev
->vdev
);
1545 i2c_put_adapter(ad
);
1546 v4l2_device_unregister(&viu_dev
->v4l2_dev
);
1548 irq_dispose_mapping(viu_irq
);
1552 static int __devexit
viu_of_remove(struct platform_device
*op
)
1554 struct v4l2_device
*v4l2_dev
= dev_get_drvdata(&op
->dev
);
1555 struct viu_dev
*dev
= container_of(v4l2_dev
, struct viu_dev
, v4l2_dev
);
1556 struct v4l2_subdev
*sdev
= list_entry(v4l2_dev
->subdevs
.next
,
1557 struct v4l2_subdev
, list
);
1558 struct i2c_client
*client
= v4l2_get_subdevdata(sdev
);
1560 free_irq(dev
->irq
, (void *)dev
);
1561 irq_dispose_mapping(dev
->irq
);
1563 clk_disable(dev
->clk
);
1566 video_unregister_device(dev
->vdev
);
1567 i2c_put_adapter(client
->adapter
);
1568 v4l2_device_unregister(&dev
->v4l2_dev
);
1573 static int viu_suspend(struct platform_device
*op
, pm_message_t state
)
1575 struct v4l2_device
*v4l2_dev
= dev_get_drvdata(&op
->dev
);
1576 struct viu_dev
*dev
= container_of(v4l2_dev
, struct viu_dev
, v4l2_dev
);
1578 clk_disable(dev
->clk
);
1582 static int viu_resume(struct platform_device
*op
)
1584 struct v4l2_device
*v4l2_dev
= dev_get_drvdata(&op
->dev
);
1585 struct viu_dev
*dev
= container_of(v4l2_dev
, struct viu_dev
, v4l2_dev
);
1587 clk_enable(dev
->clk
);
1593 * Initialization and module stuff
1595 static struct of_device_id mpc512x_viu_of_match
[] = {
1597 .compatible
= "fsl,mpc5121-viu",
1601 MODULE_DEVICE_TABLE(of
, mpc512x_viu_of_match
);
1603 static struct of_platform_driver viu_of_platform_driver
= {
1604 .probe
= viu_of_probe
,
1605 .remove
= __devexit_p(viu_of_remove
),
1607 .suspend
= viu_suspend
,
1608 .resume
= viu_resume
,
1612 .owner
= THIS_MODULE
,
1613 .of_match_table
= mpc512x_viu_of_match
,
1617 static int __init
viu_init(void)
1619 return of_register_platform_driver(&viu_of_platform_driver
);
1622 static void __exit
viu_exit(void)
1624 of_unregister_platform_driver(&viu_of_platform_driver
);
1627 module_init(viu_init
);
1628 module_exit(viu_exit
);
1630 MODULE_DESCRIPTION("Freescale Video-In(VIU)");
1631 MODULE_AUTHOR("Hongjun Chen");
1632 MODULE_LICENSE("GPL");