2 * SuperH Video Output Unit (VOU) driver
4 * Copyright (C) 2010, Guennadi Liakhovetski <g.liakhovetski@gmx.de>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
11 #include <linux/dma-mapping.h>
12 #include <linux/delay.h>
13 #include <linux/errno.h>
15 #include <linux/i2c.h>
16 #include <linux/init.h>
17 #include <linux/interrupt.h>
18 #include <linux/kernel.h>
19 #include <linux/platform_device.h>
20 #include <linux/pm_runtime.h>
21 #include <linux/slab.h>
22 #include <linux/videodev2.h>
23 #include <linux/module.h>
25 #include <media/sh_vou.h>
26 #include <media/v4l2-common.h>
27 #include <media/v4l2-device.h>
28 #include <media/v4l2-ioctl.h>
29 #include <media/v4l2-mediabus.h>
30 #include <media/videobuf-dma-contig.h>
32 /* Mirror addresses are not available for all registers */
60 #define VOU_MAX_IMAGE_WIDTH 720
61 #define VOU_MAX_IMAGE_HEIGHT 576
63 struct sh_vou_device
{
64 struct v4l2_device v4l2_dev
;
65 struct video_device vdev
;
66 struct sh_vou_pdata
*pdata
;
69 /* State information */
70 struct v4l2_pix_format pix
;
71 struct v4l2_rect rect
;
72 struct list_head queue
;
75 struct videobuf_buffer
*active
;
76 enum sh_vou_status status
;
77 struct mutex fop_lock
;
82 struct videobuf_queue vbq
;
85 /* Register access routines for sides A, B and mirror addresses */
86 static void sh_vou_reg_a_write(struct sh_vou_device
*vou_dev
, unsigned int reg
,
89 __raw_writel(value
, vou_dev
->base
+ reg
);
92 static void sh_vou_reg_ab_write(struct sh_vou_device
*vou_dev
, unsigned int reg
,
95 __raw_writel(value
, vou_dev
->base
+ reg
);
96 __raw_writel(value
, vou_dev
->base
+ reg
+ 0x1000);
99 static void sh_vou_reg_m_write(struct sh_vou_device
*vou_dev
, unsigned int reg
,
102 __raw_writel(value
, vou_dev
->base
+ reg
+ 0x2000);
105 static u32
sh_vou_reg_a_read(struct sh_vou_device
*vou_dev
, unsigned int reg
)
107 return __raw_readl(vou_dev
->base
+ reg
);
110 static void sh_vou_reg_a_set(struct sh_vou_device
*vou_dev
, unsigned int reg
,
113 u32 old
= __raw_readl(vou_dev
->base
+ reg
);
115 value
= (value
& mask
) | (old
& ~mask
);
116 __raw_writel(value
, vou_dev
->base
+ reg
);
119 static void sh_vou_reg_b_set(struct sh_vou_device
*vou_dev
, unsigned int reg
,
122 sh_vou_reg_a_set(vou_dev
, reg
+ 0x1000, value
, mask
);
125 static void sh_vou_reg_ab_set(struct sh_vou_device
*vou_dev
, unsigned int reg
,
128 sh_vou_reg_a_set(vou_dev
, reg
, value
, mask
);
129 sh_vou_reg_b_set(vou_dev
, reg
, value
, mask
);
142 /* Further pixel formats can be added */
143 static struct sh_vou_fmt vou_fmt
[] = {
145 .pfmt
= V4L2_PIX_FMT_NV12
,
148 .desc
= "YVU420 planar",
153 .pfmt
= V4L2_PIX_FMT_NV16
,
156 .desc
= "YVYU planar",
161 .pfmt
= V4L2_PIX_FMT_RGB24
,
169 .pfmt
= V4L2_PIX_FMT_RGB565
,
177 .pfmt
= V4L2_PIX_FMT_RGB565X
,
180 .desc
= "RGB565 byteswapped",
186 static void sh_vou_schedule_next(struct sh_vou_device
*vou_dev
,
187 struct videobuf_buffer
*vb
)
189 dma_addr_t addr1
, addr2
;
191 addr1
= videobuf_to_dma_contig(vb
);
192 switch (vou_dev
->pix
.pixelformat
) {
193 case V4L2_PIX_FMT_NV12
:
194 case V4L2_PIX_FMT_NV16
:
195 addr2
= addr1
+ vou_dev
->pix
.width
* vou_dev
->pix
.height
;
201 sh_vou_reg_m_write(vou_dev
, VOUAD1R
, addr1
);
202 sh_vou_reg_m_write(vou_dev
, VOUAD2R
, addr2
);
205 static void sh_vou_stream_start(struct sh_vou_device
*vou_dev
,
206 struct videobuf_buffer
*vb
)
208 unsigned int row_coeff
;
209 #ifdef __LITTLE_ENDIAN
215 switch (vou_dev
->pix
.pixelformat
) {
217 case V4L2_PIX_FMT_NV12
:
218 case V4L2_PIX_FMT_NV16
:
221 case V4L2_PIX_FMT_RGB565
:
223 case V4L2_PIX_FMT_RGB565X
:
226 case V4L2_PIX_FMT_RGB24
:
231 sh_vou_reg_a_write(vou_dev
, VOUSWR
, dataswap
);
232 sh_vou_reg_ab_write(vou_dev
, VOUAIR
, vou_dev
->pix
.width
* row_coeff
);
233 sh_vou_schedule_next(vou_dev
, vb
);
236 static void free_buffer(struct videobuf_queue
*vq
, struct videobuf_buffer
*vb
)
238 BUG_ON(in_interrupt());
240 /* Wait until this buffer is no longer in STATE_QUEUED or STATE_ACTIVE */
241 videobuf_waiton(vq
, vb
, 0, 0);
242 videobuf_dma_contig_free(vq
, vb
);
243 vb
->state
= VIDEOBUF_NEEDS_INIT
;
246 /* Locking: caller holds fop_lock mutex */
247 static int sh_vou_buf_setup(struct videobuf_queue
*vq
, unsigned int *count
,
250 struct video_device
*vdev
= vq
->priv_data
;
251 struct sh_vou_device
*vou_dev
= video_get_drvdata(vdev
);
253 *size
= vou_fmt
[vou_dev
->pix_idx
].bpp
* vou_dev
->pix
.width
*
254 vou_dev
->pix
.height
/ 8;
259 /* Taking into account maximum frame size, *count will stay >= 2 */
260 if (PAGE_ALIGN(*size
) * *count
> 4 * 1024 * 1024)
261 *count
= 4 * 1024 * 1024 / PAGE_ALIGN(*size
);
263 dev_dbg(vou_dev
->v4l2_dev
.dev
, "%s(): count=%d, size=%d\n", __func__
,
269 /* Locking: caller holds fop_lock mutex */
270 static int sh_vou_buf_prepare(struct videobuf_queue
*vq
,
271 struct videobuf_buffer
*vb
,
272 enum v4l2_field field
)
274 struct video_device
*vdev
= vq
->priv_data
;
275 struct sh_vou_device
*vou_dev
= video_get_drvdata(vdev
);
276 struct v4l2_pix_format
*pix
= &vou_dev
->pix
;
277 int bytes_per_line
= vou_fmt
[vou_dev
->pix_idx
].bpp
* pix
->width
/ 8;
280 dev_dbg(vou_dev
->v4l2_dev
.dev
, "%s()\n", __func__
);
282 if (vb
->width
!= pix
->width
||
283 vb
->height
!= pix
->height
||
284 vb
->field
!= pix
->field
) {
285 vb
->width
= pix
->width
;
286 vb
->height
= pix
->height
;
288 if (vb
->state
!= VIDEOBUF_NEEDS_INIT
)
292 vb
->size
= vb
->height
* bytes_per_line
;
293 if (vb
->baddr
&& vb
->bsize
< vb
->size
) {
294 /* User buffer too small */
295 dev_warn(vq
->dev
, "User buffer too small: [%zu] @ %lx\n",
296 vb
->bsize
, vb
->baddr
);
300 if (vb
->state
== VIDEOBUF_NEEDS_INIT
) {
301 ret
= videobuf_iolock(vq
, vb
, NULL
);
303 dev_warn(vq
->dev
, "IOLOCK buf-type %d: %d\n",
307 vb
->state
= VIDEOBUF_PREPARED
;
310 dev_dbg(vou_dev
->v4l2_dev
.dev
,
311 "%s(): fmt #%d, %u bytes per line, phys %pad, type %d, state %d\n",
312 __func__
, vou_dev
->pix_idx
, bytes_per_line
,
313 ({ dma_addr_t addr
= videobuf_to_dma_contig(vb
); &addr
; }),
314 vb
->memory
, vb
->state
);
319 /* Locking: caller holds fop_lock mutex and vq->irqlock spinlock */
320 static void sh_vou_buf_queue(struct videobuf_queue
*vq
,
321 struct videobuf_buffer
*vb
)
323 struct video_device
*vdev
= vq
->priv_data
;
324 struct sh_vou_device
*vou_dev
= video_get_drvdata(vdev
);
326 dev_dbg(vou_dev
->v4l2_dev
.dev
, "%s()\n", __func__
);
328 vb
->state
= VIDEOBUF_QUEUED
;
329 list_add_tail(&vb
->queue
, &vou_dev
->queue
);
331 if (vou_dev
->status
== SH_VOU_RUNNING
) {
333 } else if (!vou_dev
->active
) {
334 vou_dev
->active
= vb
;
335 /* Start from side A: we use mirror addresses, so, set B */
336 sh_vou_reg_a_write(vou_dev
, VOURPR
, 1);
337 dev_dbg(vou_dev
->v4l2_dev
.dev
, "%s: first buffer status 0x%x\n",
338 __func__
, sh_vou_reg_a_read(vou_dev
, VOUSTR
));
339 sh_vou_schedule_next(vou_dev
, vb
);
340 /* Only activate VOU after the second buffer */
341 } else if (vou_dev
->active
->queue
.next
== &vb
->queue
) {
342 /* Second buffer - initialise register side B */
343 sh_vou_reg_a_write(vou_dev
, VOURPR
, 0);
344 sh_vou_stream_start(vou_dev
, vb
);
346 /* Register side switching with frame VSYNC */
347 sh_vou_reg_a_write(vou_dev
, VOURCR
, 5);
348 dev_dbg(vou_dev
->v4l2_dev
.dev
, "%s: second buffer status 0x%x\n",
349 __func__
, sh_vou_reg_a_read(vou_dev
, VOUSTR
));
351 /* Enable End-of-Frame (VSYNC) interrupts */
352 sh_vou_reg_a_write(vou_dev
, VOUIR
, 0x10004);
353 /* Two buffers on the queue - activate the hardware */
355 vou_dev
->status
= SH_VOU_RUNNING
;
356 sh_vou_reg_a_write(vou_dev
, VOUER
, 0x107);
360 static void sh_vou_buf_release(struct videobuf_queue
*vq
,
361 struct videobuf_buffer
*vb
)
363 struct video_device
*vdev
= vq
->priv_data
;
364 struct sh_vou_device
*vou_dev
= video_get_drvdata(vdev
);
367 dev_dbg(vou_dev
->v4l2_dev
.dev
, "%s()\n", __func__
);
369 spin_lock_irqsave(&vou_dev
->lock
, flags
);
371 if (vou_dev
->active
== vb
) {
373 sh_vou_reg_a_set(vou_dev
, VOUER
, 0, 1);
374 /* ...but the current frame will complete */
375 sh_vou_reg_a_set(vou_dev
, VOUIR
, 0, 0x30000);
376 vou_dev
->active
= NULL
;
379 if ((vb
->state
== VIDEOBUF_ACTIVE
|| vb
->state
== VIDEOBUF_QUEUED
)) {
380 vb
->state
= VIDEOBUF_ERROR
;
381 list_del(&vb
->queue
);
384 spin_unlock_irqrestore(&vou_dev
->lock
, flags
);
389 static struct videobuf_queue_ops sh_vou_video_qops
= {
390 .buf_setup
= sh_vou_buf_setup
,
391 .buf_prepare
= sh_vou_buf_prepare
,
392 .buf_queue
= sh_vou_buf_queue
,
393 .buf_release
= sh_vou_buf_release
,
397 static int sh_vou_querycap(struct file
*file
, void *priv
,
398 struct v4l2_capability
*cap
)
400 struct sh_vou_device
*vou_dev
= video_drvdata(file
);
402 dev_dbg(vou_dev
->v4l2_dev
.dev
, "%s()\n", __func__
);
404 strlcpy(cap
->card
, "SuperH VOU", sizeof(cap
->card
));
405 strlcpy(cap
->driver
, "sh-vou", sizeof(cap
->driver
));
406 strlcpy(cap
->bus_info
, "platform:sh-vou", sizeof(cap
->bus_info
));
407 cap
->device_caps
= V4L2_CAP_VIDEO_OUTPUT
| V4L2_CAP_STREAMING
;
408 cap
->capabilities
= cap
->device_caps
| V4L2_CAP_DEVICE_CAPS
;
412 /* Enumerate formats, that the device can accept from the user */
413 static int sh_vou_enum_fmt_vid_out(struct file
*file
, void *priv
,
414 struct v4l2_fmtdesc
*fmt
)
416 struct sh_vou_device
*vou_dev
= video_drvdata(file
);
418 if (fmt
->index
>= ARRAY_SIZE(vou_fmt
))
421 dev_dbg(vou_dev
->v4l2_dev
.dev
, "%s()\n", __func__
);
423 fmt
->type
= V4L2_BUF_TYPE_VIDEO_OUTPUT
;
424 strlcpy(fmt
->description
, vou_fmt
[fmt
->index
].desc
,
425 sizeof(fmt
->description
));
426 fmt
->pixelformat
= vou_fmt
[fmt
->index
].pfmt
;
431 static int sh_vou_g_fmt_vid_out(struct file
*file
, void *priv
,
432 struct v4l2_format
*fmt
)
434 struct sh_vou_device
*vou_dev
= video_drvdata(file
);
436 dev_dbg(vou_dev
->v4l2_dev
.dev
, "%s()\n", __func__
);
438 fmt
->type
= V4L2_BUF_TYPE_VIDEO_OUTPUT
;
439 fmt
->fmt
.pix
= vou_dev
->pix
;
444 static const unsigned char vou_scale_h_num
[] = {1, 9, 2, 9, 4};
445 static const unsigned char vou_scale_h_den
[] = {1, 8, 1, 4, 1};
446 static const unsigned char vou_scale_h_fld
[] = {0, 2, 1, 3};
447 static const unsigned char vou_scale_v_num
[] = {1, 2, 4};
448 static const unsigned char vou_scale_v_den
[] = {1, 1, 1};
449 static const unsigned char vou_scale_v_fld
[] = {0, 1};
451 static void sh_vou_configure_geometry(struct sh_vou_device
*vou_dev
,
452 int pix_idx
, int w_idx
, int h_idx
)
454 struct sh_vou_fmt
*fmt
= vou_fmt
+ pix_idx
;
455 unsigned int black_left
, black_top
, width_max
,
456 frame_in_height
, frame_out_height
, frame_out_top
;
457 struct v4l2_rect
*rect
= &vou_dev
->rect
;
458 struct v4l2_pix_format
*pix
= &vou_dev
->pix
;
459 u32 vouvcr
= 0, dsr_h
, dsr_v
;
461 if (vou_dev
->std
& V4L2_STD_525_60
) {
463 /* height_max = 262; */
466 /* height_max = 312; */
469 frame_in_height
= pix
->height
/ 2;
470 frame_out_height
= rect
->height
/ 2;
471 frame_out_top
= rect
->top
/ 2;
474 * Cropping scheme: max useful image is 720x480, and the total video
475 * area is 858x525 (NTSC) or 864x625 (PAL). AK8813 / 8814 starts
476 * sampling data beginning with fixed 276th (NTSC) / 288th (PAL) clock,
477 * of which the first 33 / 25 clocks HSYNC must be held active. This
478 * has to be configured in CR[HW]. 1 pixel equals 2 clock periods.
479 * This gives CR[HW] = 16 / 12, VPR[HVP] = 138 / 144, which gives
480 * exactly 858 - 138 = 864 - 144 = 720! We call the out-of-display area,
481 * beyond DSR, specified on the left and top by the VPR register "black
482 * pixels" and out-of-image area (DPR) "background pixels." We fix VPR
483 * at 138 / 144 : 20, because that's the HSYNC timing, that our first
484 * client requires, and that's exactly what leaves us 720 pixels for the
485 * image; we leave VPR[VVP] at default 20 for now, because the client
486 * doesn't seem to have any special requirements for it. Otherwise we
487 * could also set it to max - 240 = 22 / 72. Thus VPR depends only on
488 * the selected standard, and DPR and DSR are selected according to
489 * cropping. Q: how does the client detect the first valid line? Does
490 * HSYNC stay inactive during invalid (black) lines?
492 black_left
= width_max
- VOU_MAX_IMAGE_WIDTH
;
495 dsr_h
= rect
->width
+ rect
->left
;
496 dsr_v
= frame_out_height
+ frame_out_top
;
498 dev_dbg(vou_dev
->v4l2_dev
.dev
,
499 "image %ux%u, black %u:%u, offset %u:%u, display %ux%u\n",
500 pix
->width
, frame_in_height
, black_left
, black_top
,
501 rect
->left
, frame_out_top
, dsr_h
, dsr_v
);
503 /* VOUISR height - half of a frame height in frame mode */
504 sh_vou_reg_ab_write(vou_dev
, VOUISR
, (pix
->width
<< 16) | frame_in_height
);
505 sh_vou_reg_ab_write(vou_dev
, VOUVPR
, (black_left
<< 16) | black_top
);
506 sh_vou_reg_ab_write(vou_dev
, VOUDPR
, (rect
->left
<< 16) | frame_out_top
);
507 sh_vou_reg_ab_write(vou_dev
, VOUDSR
, (dsr_h
<< 16) | dsr_v
);
510 * if necessary, we could set VOUHIR to
511 * max(black_left + dsr_h, width_max) here
515 vouvcr
|= (1 << 15) | (vou_scale_h_fld
[w_idx
- 1] << 4);
517 vouvcr
|= (1 << 14) | vou_scale_v_fld
[h_idx
- 1];
519 dev_dbg(vou_dev
->v4l2_dev
.dev
, "%s: scaling 0x%x\n", fmt
->desc
, vouvcr
);
521 /* To produce a colour bar for testing set bit 23 of VOUVCR */
522 sh_vou_reg_ab_write(vou_dev
, VOUVCR
, vouvcr
);
523 sh_vou_reg_ab_write(vou_dev
, VOUDFR
,
524 fmt
->pkf
| (fmt
->yf
<< 8) | (fmt
->rgb
<< 16));
527 struct sh_vou_geometry
{
528 struct v4l2_rect output
;
529 unsigned int in_width
;
530 unsigned int in_height
;
536 * Find input geometry, that we can use to produce output, closest to the
537 * requested rectangle, using VOU scaling
539 static void vou_adjust_input(struct sh_vou_geometry
*geo
, v4l2_std_id std
)
541 /* The compiler cannot know, that best and idx will indeed be set */
542 unsigned int best_err
= UINT_MAX
, best
= 0, img_height_max
;
545 if (std
& V4L2_STD_525_60
)
546 img_height_max
= 480;
548 img_height_max
= 576;
550 /* Image width must be a multiple of 4 */
551 v4l_bound_align_image(&geo
->in_width
, 0, VOU_MAX_IMAGE_WIDTH
, 2,
552 &geo
->in_height
, 0, img_height_max
, 1, 0);
554 /* Select scales to come as close as possible to the output image */
555 for (i
= ARRAY_SIZE(vou_scale_h_num
) - 1; i
>= 0; i
--) {
557 unsigned int found
= geo
->output
.width
* vou_scale_h_den
[i
] /
560 if (found
> VOU_MAX_IMAGE_WIDTH
)
561 /* scales increase */
564 err
= abs(found
- geo
->in_width
);
565 if (err
< best_err
) {
574 geo
->in_width
= best
;
575 geo
->scale_idx_h
= idx
;
579 /* This loop can be replaced with one division */
580 for (i
= ARRAY_SIZE(vou_scale_v_num
) - 1; i
>= 0; i
--) {
582 unsigned int found
= geo
->output
.height
* vou_scale_v_den
[i
] /
585 if (found
> img_height_max
)
586 /* scales increase */
589 err
= abs(found
- geo
->in_height
);
590 if (err
< best_err
) {
599 geo
->in_height
= best
;
600 geo
->scale_idx_v
= idx
;
604 * Find output geometry, that we can produce, using VOU scaling, closest to
605 * the requested rectangle
607 static void vou_adjust_output(struct sh_vou_geometry
*geo
, v4l2_std_id std
)
609 unsigned int best_err
= UINT_MAX
, best
= geo
->in_width
,
610 width_max
, height_max
, img_height_max
;
611 int i
, idx_h
= 0, idx_v
= 0;
613 if (std
& V4L2_STD_525_60
) {
615 height_max
= 262 * 2;
616 img_height_max
= 480;
619 height_max
= 312 * 2;
620 img_height_max
= 576;
623 /* Select scales to come as close as possible to the output image */
624 for (i
= 0; i
< ARRAY_SIZE(vou_scale_h_num
); i
++) {
626 unsigned int found
= geo
->in_width
* vou_scale_h_num
[i
] /
629 if (found
> VOU_MAX_IMAGE_WIDTH
)
630 /* scales increase */
633 err
= abs(found
- geo
->output
.width
);
634 if (err
< best_err
) {
643 geo
->output
.width
= best
;
644 geo
->scale_idx_h
= idx_h
;
645 if (geo
->output
.left
+ best
> width_max
)
646 geo
->output
.left
= width_max
- best
;
648 pr_debug("%s(): W %u * %u/%u = %u\n", __func__
, geo
->in_width
,
649 vou_scale_h_num
[idx_h
], vou_scale_h_den
[idx_h
], best
);
653 /* This loop can be replaced with one division */
654 for (i
= 0; i
< ARRAY_SIZE(vou_scale_v_num
); i
++) {
656 unsigned int found
= geo
->in_height
* vou_scale_v_num
[i
] /
659 if (found
> img_height_max
)
660 /* scales increase */
663 err
= abs(found
- geo
->output
.height
);
664 if (err
< best_err
) {
673 geo
->output
.height
= best
;
674 geo
->scale_idx_v
= idx_v
;
675 if (geo
->output
.top
+ best
> height_max
)
676 geo
->output
.top
= height_max
- best
;
678 pr_debug("%s(): H %u * %u/%u = %u\n", __func__
, geo
->in_height
,
679 vou_scale_v_num
[idx_v
], vou_scale_v_den
[idx_v
], best
);
682 static int sh_vou_try_fmt_vid_out(struct file
*file
, void *priv
,
683 struct v4l2_format
*fmt
)
685 struct sh_vou_device
*vou_dev
= video_drvdata(file
);
686 struct v4l2_pix_format
*pix
= &fmt
->fmt
.pix
;
687 unsigned int img_height_max
;
690 dev_dbg(vou_dev
->v4l2_dev
.dev
, "%s()\n", __func__
);
692 pix
->field
= V4L2_FIELD_INTERLACED
;
693 pix
->colorspace
= V4L2_COLORSPACE_SMPTE170M
;
694 pix
->ycbcr_enc
= pix
->quantization
= 0;
696 for (pix_idx
= 0; pix_idx
< ARRAY_SIZE(vou_fmt
); pix_idx
++)
697 if (vou_fmt
[pix_idx
].pfmt
== pix
->pixelformat
)
700 if (pix_idx
== ARRAY_SIZE(vou_fmt
))
703 if (vou_dev
->std
& V4L2_STD_525_60
)
704 img_height_max
= 480;
706 img_height_max
= 576;
708 v4l_bound_align_image(&pix
->width
, 0, VOU_MAX_IMAGE_WIDTH
, 2,
709 &pix
->height
, 0, img_height_max
, 1, 0);
710 pix
->bytesperline
= pix
->width
* vou_fmt
[pix_idx
].bpl
;
711 pix
->sizeimage
= pix
->height
* ((pix
->width
* vou_fmt
[pix_idx
].bpp
) >> 3);
716 static int sh_vou_s_fmt_vid_out(struct file
*file
, void *priv
,
717 struct v4l2_format
*fmt
)
719 struct sh_vou_device
*vou_dev
= video_drvdata(file
);
720 struct v4l2_pix_format
*pix
= &fmt
->fmt
.pix
;
721 unsigned int img_height_max
;
722 struct sh_vou_geometry geo
;
723 struct v4l2_subdev_format format
= {
724 .which
= V4L2_SUBDEV_FORMAT_ACTIVE
,
725 /* Revisit: is this the correct code? */
726 .format
.code
= MEDIA_BUS_FMT_YUYV8_2X8
,
727 .format
.field
= V4L2_FIELD_INTERLACED
,
728 .format
.colorspace
= V4L2_COLORSPACE_SMPTE170M
,
730 struct v4l2_mbus_framefmt
*mbfmt
= &format
.format
;
731 int ret
= sh_vou_try_fmt_vid_out(file
, priv
, fmt
);
737 for (pix_idx
= 0; pix_idx
< ARRAY_SIZE(vou_fmt
); pix_idx
++)
738 if (vou_fmt
[pix_idx
].pfmt
== pix
->pixelformat
)
741 geo
.in_width
= pix
->width
;
742 geo
.in_height
= pix
->height
;
743 geo
.output
= vou_dev
->rect
;
745 vou_adjust_output(&geo
, vou_dev
->std
);
747 mbfmt
->width
= geo
.output
.width
;
748 mbfmt
->height
= geo
.output
.height
;
749 ret
= v4l2_device_call_until_err(&vou_dev
->v4l2_dev
, 0, pad
,
750 set_fmt
, NULL
, &format
);
751 /* Must be implemented, so, don't check for -ENOIOCTLCMD */
755 dev_dbg(vou_dev
->v4l2_dev
.dev
, "%s(): %ux%u -> %ux%u\n", __func__
,
756 geo
.output
.width
, geo
.output
.height
, mbfmt
->width
, mbfmt
->height
);
758 if (vou_dev
->std
& V4L2_STD_525_60
)
759 img_height_max
= 480;
761 img_height_max
= 576;
764 if ((unsigned)mbfmt
->width
> VOU_MAX_IMAGE_WIDTH
||
765 (unsigned)mbfmt
->height
> img_height_max
||
766 mbfmt
->code
!= MEDIA_BUS_FMT_YUYV8_2X8
)
769 if (mbfmt
->width
!= geo
.output
.width
||
770 mbfmt
->height
!= geo
.output
.height
) {
771 geo
.output
.width
= mbfmt
->width
;
772 geo
.output
.height
= mbfmt
->height
;
774 vou_adjust_input(&geo
, vou_dev
->std
);
777 /* We tried to preserve output rectangle, but it could have changed */
778 vou_dev
->rect
= geo
.output
;
779 pix
->width
= geo
.in_width
;
780 pix
->height
= geo
.in_height
;
782 dev_dbg(vou_dev
->v4l2_dev
.dev
, "%s(): %ux%u\n", __func__
,
783 pix
->width
, pix
->height
);
785 vou_dev
->pix_idx
= pix_idx
;
789 sh_vou_configure_geometry(vou_dev
, pix_idx
,
790 geo
.scale_idx_h
, geo
.scale_idx_v
);
795 static int sh_vou_reqbufs(struct file
*file
, void *priv
,
796 struct v4l2_requestbuffers
*req
)
798 struct sh_vou_device
*vou_dev
= video_drvdata(file
);
799 struct sh_vou_file
*vou_file
= priv
;
801 dev_dbg(vou_dev
->v4l2_dev
.dev
, "%s()\n", __func__
);
803 if (req
->type
!= V4L2_BUF_TYPE_VIDEO_OUTPUT
)
806 return videobuf_reqbufs(&vou_file
->vbq
, req
);
809 static int sh_vou_querybuf(struct file
*file
, void *priv
,
810 struct v4l2_buffer
*b
)
812 struct sh_vou_device
*vou_dev
= video_drvdata(file
);
813 struct sh_vou_file
*vou_file
= priv
;
815 dev_dbg(vou_dev
->v4l2_dev
.dev
, "%s()\n", __func__
);
817 return videobuf_querybuf(&vou_file
->vbq
, b
);
820 static int sh_vou_qbuf(struct file
*file
, void *priv
, struct v4l2_buffer
*b
)
822 struct sh_vou_device
*vou_dev
= video_drvdata(file
);
823 struct sh_vou_file
*vou_file
= priv
;
825 dev_dbg(vou_dev
->v4l2_dev
.dev
, "%s()\n", __func__
);
827 return videobuf_qbuf(&vou_file
->vbq
, b
);
830 static int sh_vou_dqbuf(struct file
*file
, void *priv
, struct v4l2_buffer
*b
)
832 struct sh_vou_device
*vou_dev
= video_drvdata(file
);
833 struct sh_vou_file
*vou_file
= priv
;
835 dev_dbg(vou_dev
->v4l2_dev
.dev
, "%s()\n", __func__
);
837 return videobuf_dqbuf(&vou_file
->vbq
, b
, file
->f_flags
& O_NONBLOCK
);
840 static int sh_vou_streamon(struct file
*file
, void *priv
,
841 enum v4l2_buf_type buftype
)
843 struct sh_vou_device
*vou_dev
= video_drvdata(file
);
844 struct sh_vou_file
*vou_file
= priv
;
847 dev_dbg(vou_dev
->v4l2_dev
.dev
, "%s()\n", __func__
);
849 ret
= v4l2_device_call_until_err(&vou_dev
->v4l2_dev
, 0,
851 if (ret
< 0 && ret
!= -ENOIOCTLCMD
)
854 /* This calls our .buf_queue() (== sh_vou_buf_queue) */
855 return videobuf_streamon(&vou_file
->vbq
);
858 static int sh_vou_streamoff(struct file
*file
, void *priv
,
859 enum v4l2_buf_type buftype
)
861 struct sh_vou_device
*vou_dev
= video_drvdata(file
);
862 struct sh_vou_file
*vou_file
= priv
;
864 dev_dbg(vou_dev
->v4l2_dev
.dev
, "%s()\n", __func__
);
867 * This calls buf_release from host driver's videobuf_queue_ops for all
868 * remaining buffers. When the last buffer is freed, stop streaming
870 videobuf_streamoff(&vou_file
->vbq
);
871 v4l2_device_call_until_err(&vou_dev
->v4l2_dev
, 0, video
, s_stream
, 0);
876 static int sh_vou_enum_output(struct file
*file
, void *fh
,
877 struct v4l2_output
*a
)
879 struct sh_vou_device
*vou_dev
= video_drvdata(file
);
883 strlcpy(a
->name
, "Video Out", sizeof(a
->name
));
884 a
->type
= V4L2_OUTPUT_TYPE_ANALOG
;
885 a
->std
= vou_dev
->vdev
.tvnorms
;
889 int sh_vou_g_output(struct file
*file
, void *fh
, unsigned int *i
)
895 int sh_vou_s_output(struct file
*file
, void *fh
, unsigned int i
)
897 return i
? -EINVAL
: 0;
900 static u32
sh_vou_ntsc_mode(enum sh_vou_bus_fmt bus_fmt
)
904 pr_warning("%s(): Invalid bus-format code %d, using default 8-bit\n",
906 case SH_VOU_BUS_8BIT
:
908 case SH_VOU_BUS_16BIT
:
910 case SH_VOU_BUS_BT656
:
915 static int sh_vou_s_std(struct file
*file
, void *priv
, v4l2_std_id std_id
)
917 struct sh_vou_device
*vou_dev
= video_drvdata(file
);
920 dev_dbg(vou_dev
->v4l2_dev
.dev
, "%s(): 0x%llx\n", __func__
, std_id
);
922 if (std_id
& ~vou_dev
->vdev
.tvnorms
)
925 ret
= v4l2_device_call_until_err(&vou_dev
->v4l2_dev
, 0, video
,
926 s_std_output
, std_id
);
927 /* Shall we continue, if the subdev doesn't support .s_std_output()? */
928 if (ret
< 0 && ret
!= -ENOIOCTLCMD
)
931 if (std_id
& V4L2_STD_525_60
)
932 sh_vou_reg_ab_set(vou_dev
, VOUCR
,
933 sh_vou_ntsc_mode(vou_dev
->pdata
->bus_fmt
) << 29, 7 << 29);
935 sh_vou_reg_ab_set(vou_dev
, VOUCR
, 5 << 29, 7 << 29);
937 vou_dev
->std
= std_id
;
942 static int sh_vou_g_std(struct file
*file
, void *priv
, v4l2_std_id
*std
)
944 struct sh_vou_device
*vou_dev
= video_drvdata(file
);
946 dev_dbg(vou_dev
->v4l2_dev
.dev
, "%s()\n", __func__
);
953 static int sh_vou_g_selection(struct file
*file
, void *fh
,
954 struct v4l2_selection
*sel
)
956 struct sh_vou_device
*vou_dev
= video_drvdata(file
);
958 if (sel
->type
!= V4L2_BUF_TYPE_VIDEO_OUTPUT
)
960 switch (sel
->target
) {
961 case V4L2_SEL_TGT_COMPOSE
:
962 sel
->r
= vou_dev
->rect
;
964 case V4L2_SEL_TGT_COMPOSE_DEFAULT
:
965 case V4L2_SEL_TGT_COMPOSE_BOUNDS
:
968 sel
->r
.width
= VOU_MAX_IMAGE_WIDTH
;
969 sel
->r
.height
= VOU_MAX_IMAGE_HEIGHT
;
977 /* Assume a dull encoder, do all the work ourselves. */
978 static int sh_vou_s_selection(struct file
*file
, void *fh
,
979 struct v4l2_selection
*sel
)
981 struct v4l2_rect
*rect
= &sel
->r
;
982 struct sh_vou_device
*vou_dev
= video_drvdata(file
);
983 struct v4l2_crop sd_crop
= {.type
= V4L2_BUF_TYPE_VIDEO_OUTPUT
};
984 struct v4l2_pix_format
*pix
= &vou_dev
->pix
;
985 struct sh_vou_geometry geo
;
986 struct v4l2_subdev_format format
= {
987 .which
= V4L2_SUBDEV_FORMAT_ACTIVE
,
988 /* Revisit: is this the correct code? */
989 .format
.code
= MEDIA_BUS_FMT_YUYV8_2X8
,
990 .format
.field
= V4L2_FIELD_INTERLACED
,
991 .format
.colorspace
= V4L2_COLORSPACE_SMPTE170M
,
993 unsigned int img_height_max
;
996 if (sel
->type
!= V4L2_BUF_TYPE_VIDEO_OUTPUT
||
997 sel
->target
!= V4L2_SEL_TGT_COMPOSE
)
1000 if (vou_dev
->std
& V4L2_STD_525_60
)
1001 img_height_max
= 480;
1003 img_height_max
= 576;
1005 v4l_bound_align_image(&rect
->width
, 0, VOU_MAX_IMAGE_WIDTH
, 1,
1006 &rect
->height
, 0, img_height_max
, 1, 0);
1008 if (rect
->width
+ rect
->left
> VOU_MAX_IMAGE_WIDTH
)
1009 rect
->left
= VOU_MAX_IMAGE_WIDTH
- rect
->width
;
1011 if (rect
->height
+ rect
->top
> img_height_max
)
1012 rect
->top
= img_height_max
- rect
->height
;
1015 geo
.in_width
= pix
->width
;
1016 geo
.in_height
= pix
->height
;
1018 /* Configure the encoder one-to-one, position at 0, ignore errors */
1019 sd_crop
.c
.width
= geo
.output
.width
;
1020 sd_crop
.c
.height
= geo
.output
.height
;
1022 * We first issue a S_CROP, so that the subsequent S_FMT delivers the
1023 * final encoder configuration.
1025 v4l2_device_call_until_err(&vou_dev
->v4l2_dev
, 0, video
,
1027 format
.format
.width
= geo
.output
.width
;
1028 format
.format
.height
= geo
.output
.height
;
1029 ret
= v4l2_device_call_until_err(&vou_dev
->v4l2_dev
, 0, pad
,
1030 set_fmt
, NULL
, &format
);
1031 /* Must be implemented, so, don't check for -ENOIOCTLCMD */
1036 if ((unsigned)format
.format
.width
> VOU_MAX_IMAGE_WIDTH
||
1037 (unsigned)format
.format
.height
> img_height_max
||
1038 format
.format
.code
!= MEDIA_BUS_FMT_YUYV8_2X8
)
1041 geo
.output
.width
= format
.format
.width
;
1042 geo
.output
.height
= format
.format
.height
;
1045 * No down-scaling. According to the API, current call has precedence:
1046 * http://v4l2spec.bytesex.org/spec/x1904.htm#AEN1954 paragraph two.
1048 vou_adjust_input(&geo
, vou_dev
->std
);
1050 /* We tried to preserve output rectangle, but it could have changed */
1051 vou_dev
->rect
= geo
.output
;
1052 pix
->width
= geo
.in_width
;
1053 pix
->height
= geo
.in_height
;
1055 sh_vou_configure_geometry(vou_dev
, vou_dev
->pix_idx
,
1056 geo
.scale_idx_h
, geo
.scale_idx_v
);
1061 static irqreturn_t
sh_vou_isr(int irq
, void *dev_id
)
1063 struct sh_vou_device
*vou_dev
= dev_id
;
1064 static unsigned long j
;
1065 struct videobuf_buffer
*vb
;
1067 u32 irq_status
= sh_vou_reg_a_read(vou_dev
, VOUIR
), masked
;
1068 u32 vou_status
= sh_vou_reg_a_read(vou_dev
, VOUSTR
);
1070 if (!(irq_status
& 0x300)) {
1071 if (printk_timed_ratelimit(&j
, 500))
1072 dev_warn(vou_dev
->v4l2_dev
.dev
, "IRQ status 0x%x!\n",
1077 spin_lock(&vou_dev
->lock
);
1078 if (!vou_dev
->active
|| list_empty(&vou_dev
->queue
)) {
1079 if (printk_timed_ratelimit(&j
, 500))
1080 dev_warn(vou_dev
->v4l2_dev
.dev
,
1081 "IRQ without active buffer: %x!\n", irq_status
);
1082 /* Just ack: buf_release will disable further interrupts */
1083 sh_vou_reg_a_set(vou_dev
, VOUIR
, 0, 0x300);
1084 spin_unlock(&vou_dev
->lock
);
1088 masked
= ~(0x300 & irq_status
) & irq_status
& 0x30304;
1089 dev_dbg(vou_dev
->v4l2_dev
.dev
,
1090 "IRQ status 0x%x -> 0x%x, VOU status 0x%x, cnt %d\n",
1091 irq_status
, masked
, vou_status
, cnt
);
1094 /* side = vou_status & 0x10000; */
1096 /* Clear only set interrupts */
1097 sh_vou_reg_a_write(vou_dev
, VOUIR
, masked
);
1099 vb
= vou_dev
->active
;
1100 list_del(&vb
->queue
);
1102 vb
->state
= VIDEOBUF_DONE
;
1103 v4l2_get_timestamp(&vb
->ts
);
1107 if (list_empty(&vou_dev
->queue
)) {
1109 dev_dbg(vou_dev
->v4l2_dev
.dev
, "%s: queue empty after %d\n",
1111 sh_vou_reg_a_set(vou_dev
, VOUER
, 0, 1);
1112 vou_dev
->active
= NULL
;
1113 vou_dev
->status
= SH_VOU_INITIALISING
;
1114 /* Disable End-of-Frame (VSYNC) interrupts */
1115 sh_vou_reg_a_set(vou_dev
, VOUIR
, 0, 0x30000);
1116 spin_unlock(&vou_dev
->lock
);
1120 vou_dev
->active
= list_entry(vou_dev
->queue
.next
,
1121 struct videobuf_buffer
, queue
);
1123 if (vou_dev
->active
->queue
.next
!= &vou_dev
->queue
) {
1124 struct videobuf_buffer
*new = list_entry(vou_dev
->active
->queue
.next
,
1125 struct videobuf_buffer
, queue
);
1126 sh_vou_schedule_next(vou_dev
, new);
1129 spin_unlock(&vou_dev
->lock
);
1134 static int sh_vou_hw_init(struct sh_vou_device
*vou_dev
)
1136 struct sh_vou_pdata
*pdata
= vou_dev
->pdata
;
1137 u32 voucr
= sh_vou_ntsc_mode(pdata
->bus_fmt
) << 29;
1140 /* Disable all IRQs */
1141 sh_vou_reg_a_write(vou_dev
, VOUIR
, 0);
1143 /* Reset VOU interfaces - registers unaffected */
1144 sh_vou_reg_a_write(vou_dev
, VOUSRR
, 0x101);
1145 while (--i
&& (sh_vou_reg_a_read(vou_dev
, VOUSRR
) & 0x101))
1151 dev_dbg(vou_dev
->v4l2_dev
.dev
, "Reset took %dus\n", 100 - i
);
1153 if (pdata
->flags
& SH_VOU_PCLK_FALLING
)
1155 if (pdata
->flags
& SH_VOU_HSYNC_LOW
)
1157 if (pdata
->flags
& SH_VOU_VSYNC_LOW
)
1159 sh_vou_reg_ab_set(vou_dev
, VOUCR
, voucr
, 0xfc000000);
1161 /* Manual register side switching at first */
1162 sh_vou_reg_a_write(vou_dev
, VOURCR
, 4);
1163 /* Default - fixed HSYNC length, can be made configurable is required */
1164 sh_vou_reg_ab_write(vou_dev
, VOUMSR
, 0x800000);
1169 /* File operations */
1170 static int sh_vou_open(struct file
*file
)
1172 struct sh_vou_device
*vou_dev
= video_drvdata(file
);
1173 struct sh_vou_file
*vou_file
= kzalloc(sizeof(struct sh_vou_file
),
1179 dev_dbg(vou_dev
->v4l2_dev
.dev
, "%s()\n", __func__
);
1181 v4l2_fh_init(&vou_file
->fh
, &vou_dev
->vdev
);
1182 if (mutex_lock_interruptible(&vou_dev
->fop_lock
)) {
1184 return -ERESTARTSYS
;
1186 v4l2_fh_add(&vou_file
->fh
);
1187 if (v4l2_fh_is_singular(&vou_file
->fh
)) {
1191 vou_dev
->status
= SH_VOU_INITIALISING
;
1192 pm_runtime_get_sync(vou_dev
->v4l2_dev
.dev
);
1193 ret
= sh_vou_hw_init(vou_dev
);
1195 pm_runtime_put(vou_dev
->v4l2_dev
.dev
);
1196 vou_dev
->status
= SH_VOU_IDLE
;
1197 v4l2_fh_del(&vou_file
->fh
);
1198 v4l2_fh_exit(&vou_file
->fh
);
1199 mutex_unlock(&vou_dev
->fop_lock
);
1205 videobuf_queue_dma_contig_init(&vou_file
->vbq
, &sh_vou_video_qops
,
1206 vou_dev
->v4l2_dev
.dev
, &vou_dev
->lock
,
1207 V4L2_BUF_TYPE_VIDEO_OUTPUT
,
1209 sizeof(struct videobuf_buffer
),
1210 &vou_dev
->vdev
, &vou_dev
->fop_lock
);
1211 mutex_unlock(&vou_dev
->fop_lock
);
1213 file
->private_data
= vou_file
;
1218 static int sh_vou_release(struct file
*file
)
1220 struct sh_vou_device
*vou_dev
= video_drvdata(file
);
1221 struct sh_vou_file
*vou_file
= file
->private_data
;
1223 dev_dbg(vou_dev
->v4l2_dev
.dev
, "%s()\n", __func__
);
1225 mutex_lock(&vou_dev
->fop_lock
);
1226 if (v4l2_fh_is_singular(&vou_file
->fh
)) {
1228 vou_dev
->status
= SH_VOU_IDLE
;
1229 sh_vou_reg_a_set(vou_dev
, VOUER
, 0, 0x101);
1230 pm_runtime_put(vou_dev
->v4l2_dev
.dev
);
1232 v4l2_fh_del(&vou_file
->fh
);
1233 v4l2_fh_exit(&vou_file
->fh
);
1234 mutex_unlock(&vou_dev
->fop_lock
);
1236 file
->private_data
= NULL
;
1242 static int sh_vou_mmap(struct file
*file
, struct vm_area_struct
*vma
)
1244 struct sh_vou_device
*vou_dev
= video_drvdata(file
);
1245 struct sh_vou_file
*vou_file
= file
->private_data
;
1248 dev_dbg(vou_dev
->v4l2_dev
.dev
, "%s()\n", __func__
);
1250 if (mutex_lock_interruptible(&vou_dev
->fop_lock
))
1251 return -ERESTARTSYS
;
1252 ret
= videobuf_mmap_mapper(&vou_file
->vbq
, vma
);
1253 mutex_unlock(&vou_dev
->fop_lock
);
1257 static unsigned int sh_vou_poll(struct file
*file
, poll_table
*wait
)
1259 struct sh_vou_device
*vou_dev
= video_drvdata(file
);
1260 struct sh_vou_file
*vou_file
= file
->private_data
;
1263 dev_dbg(vou_dev
->v4l2_dev
.dev
, "%s()\n", __func__
);
1265 mutex_lock(&vou_dev
->fop_lock
);
1266 res
= videobuf_poll_stream(file
, &vou_file
->vbq
, wait
);
1267 mutex_unlock(&vou_dev
->fop_lock
);
1271 /* sh_vou display ioctl operations */
1272 static const struct v4l2_ioctl_ops sh_vou_ioctl_ops
= {
1273 .vidioc_querycap
= sh_vou_querycap
,
1274 .vidioc_enum_fmt_vid_out
= sh_vou_enum_fmt_vid_out
,
1275 .vidioc_g_fmt_vid_out
= sh_vou_g_fmt_vid_out
,
1276 .vidioc_s_fmt_vid_out
= sh_vou_s_fmt_vid_out
,
1277 .vidioc_try_fmt_vid_out
= sh_vou_try_fmt_vid_out
,
1278 .vidioc_reqbufs
= sh_vou_reqbufs
,
1279 .vidioc_querybuf
= sh_vou_querybuf
,
1280 .vidioc_qbuf
= sh_vou_qbuf
,
1281 .vidioc_dqbuf
= sh_vou_dqbuf
,
1282 .vidioc_streamon
= sh_vou_streamon
,
1283 .vidioc_streamoff
= sh_vou_streamoff
,
1284 .vidioc_g_output
= sh_vou_g_output
,
1285 .vidioc_s_output
= sh_vou_s_output
,
1286 .vidioc_enum_output
= sh_vou_enum_output
,
1287 .vidioc_s_std
= sh_vou_s_std
,
1288 .vidioc_g_std
= sh_vou_g_std
,
1289 .vidioc_g_selection
= sh_vou_g_selection
,
1290 .vidioc_s_selection
= sh_vou_s_selection
,
1293 static const struct v4l2_file_operations sh_vou_fops
= {
1294 .owner
= THIS_MODULE
,
1295 .open
= sh_vou_open
,
1296 .release
= sh_vou_release
,
1297 .unlocked_ioctl
= video_ioctl2
,
1298 .mmap
= sh_vou_mmap
,
1299 .poll
= sh_vou_poll
,
1302 static const struct video_device sh_vou_video_template
= {
1304 .fops
= &sh_vou_fops
,
1305 .ioctl_ops
= &sh_vou_ioctl_ops
,
1306 .tvnorms
= V4L2_STD_525_60
, /* PAL only supported in 8-bit non-bt656 mode */
1307 .vfl_dir
= VFL_DIR_TX
,
1310 static int sh_vou_probe(struct platform_device
*pdev
)
1312 struct sh_vou_pdata
*vou_pdata
= pdev
->dev
.platform_data
;
1313 struct v4l2_rect
*rect
;
1314 struct v4l2_pix_format
*pix
;
1315 struct i2c_adapter
*i2c_adap
;
1316 struct video_device
*vdev
;
1317 struct sh_vou_device
*vou_dev
;
1318 struct resource
*reg_res
;
1319 struct v4l2_subdev
*subdev
;
1322 reg_res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
1323 irq
= platform_get_irq(pdev
, 0);
1325 if (!vou_pdata
|| !reg_res
|| irq
<= 0) {
1326 dev_err(&pdev
->dev
, "Insufficient VOU platform information.\n");
1330 vou_dev
= devm_kzalloc(&pdev
->dev
, sizeof(*vou_dev
), GFP_KERNEL
);
1334 INIT_LIST_HEAD(&vou_dev
->queue
);
1335 spin_lock_init(&vou_dev
->lock
);
1336 mutex_init(&vou_dev
->fop_lock
);
1337 vou_dev
->pdata
= vou_pdata
;
1338 vou_dev
->status
= SH_VOU_IDLE
;
1340 rect
= &vou_dev
->rect
;
1341 pix
= &vou_dev
->pix
;
1343 /* Fill in defaults */
1344 vou_dev
->std
= V4L2_STD_NTSC_M
;
1347 rect
->width
= VOU_MAX_IMAGE_WIDTH
;
1349 pix
->width
= VOU_MAX_IMAGE_WIDTH
;
1351 pix
->pixelformat
= V4L2_PIX_FMT_NV16
;
1352 pix
->field
= V4L2_FIELD_NONE
;
1353 pix
->bytesperline
= VOU_MAX_IMAGE_WIDTH
;
1354 pix
->sizeimage
= VOU_MAX_IMAGE_WIDTH
* 2 * 480;
1355 pix
->colorspace
= V4L2_COLORSPACE_SMPTE170M
;
1357 vou_dev
->base
= devm_ioremap_resource(&pdev
->dev
, reg_res
);
1358 if (IS_ERR(vou_dev
->base
))
1359 return PTR_ERR(vou_dev
->base
);
1361 ret
= devm_request_irq(&pdev
->dev
, irq
, sh_vou_isr
, 0, "vou", vou_dev
);
1365 ret
= v4l2_device_register(&pdev
->dev
, &vou_dev
->v4l2_dev
);
1367 dev_err(&pdev
->dev
, "Error registering v4l2 device\n");
1371 vdev
= &vou_dev
->vdev
;
1372 *vdev
= sh_vou_video_template
;
1373 if (vou_pdata
->bus_fmt
== SH_VOU_BUS_8BIT
)
1374 vdev
->tvnorms
|= V4L2_STD_PAL
;
1375 vdev
->v4l2_dev
= &vou_dev
->v4l2_dev
;
1376 vdev
->release
= video_device_release_empty
;
1377 vdev
->lock
= &vou_dev
->fop_lock
;
1379 video_set_drvdata(vdev
, vou_dev
);
1381 pm_runtime_enable(&pdev
->dev
);
1382 pm_runtime_resume(&pdev
->dev
);
1384 i2c_adap
= i2c_get_adapter(vou_pdata
->i2c_adap
);
1390 ret
= sh_vou_hw_init(vou_dev
);
1394 subdev
= v4l2_i2c_new_subdev_board(&vou_dev
->v4l2_dev
, i2c_adap
,
1395 vou_pdata
->board_info
, NULL
);
1401 ret
= video_register_device(vdev
, VFL_TYPE_GRABBER
, -1);
1410 i2c_put_adapter(i2c_adap
);
1412 pm_runtime_disable(&pdev
->dev
);
1413 v4l2_device_unregister(&vou_dev
->v4l2_dev
);
1417 static int sh_vou_remove(struct platform_device
*pdev
)
1419 struct v4l2_device
*v4l2_dev
= platform_get_drvdata(pdev
);
1420 struct sh_vou_device
*vou_dev
= container_of(v4l2_dev
,
1421 struct sh_vou_device
, v4l2_dev
);
1422 struct v4l2_subdev
*sd
= list_entry(v4l2_dev
->subdevs
.next
,
1423 struct v4l2_subdev
, list
);
1424 struct i2c_client
*client
= v4l2_get_subdevdata(sd
);
1426 pm_runtime_disable(&pdev
->dev
);
1427 video_unregister_device(&vou_dev
->vdev
);
1428 i2c_put_adapter(client
->adapter
);
1429 v4l2_device_unregister(&vou_dev
->v4l2_dev
);
1433 static struct platform_driver __refdata sh_vou
= {
1434 .remove
= sh_vou_remove
,
1440 module_platform_driver_probe(sh_vou
, sh_vou_probe
);
1442 MODULE_DESCRIPTION("SuperH VOU driver");
1443 MODULE_AUTHOR("Guennadi Liakhovetski <g.liakhovetski@gmx.de>");
1444 MODULE_LICENSE("GPL v2");
1445 MODULE_VERSION("0.1.0");
1446 MODULE_ALIAS("platform:sh-vou");