Linux 3.14.25
[platform/adaptation/renesas_rcar/renesas_kernel.git] / drivers / media / platform / vsp1 / vsp1_video.h
1 /*
2  * vsp1_video.h  --  R-Car VSP1 Video Node
3  *
4  * Copyright (C) 2013 Renesas Corporation
5  *
6  * Contact: Laurent Pinchart (laurent.pinchart@ideasonboard.com)
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  */
13 #ifndef __VSP1_VIDEO_H__
14 #define __VSP1_VIDEO_H__
15
16 #include <linux/list.h>
17 #include <linux/spinlock.h>
18 #include <linux/wait.h>
19
20 #include <media/media-entity.h>
21 #include <media/videobuf2-core.h>
22
23 struct vsp1_video;
24
25 /*
26  * struct vsp1_format_info - VSP1 video format description
27  * @mbus: media bus format code
28  * @fourcc: V4L2 pixel format FCC identifier
29  * @planes: number of planes
30  * @bpp: bits per pixel
31  * @hwfmt: VSP1 hardware format
32  * @swap_yc: the Y and C components are swapped (Y comes before C)
33  * @swap_uv: the U and V components are swapped (V comes before U)
34  * @hsub: horizontal subsampling factor
35  * @vsub: vertical subsampling factor
36  */
37 struct vsp1_format_info {
38         u32 fourcc;
39         unsigned int mbus;
40         unsigned int hwfmt;
41         unsigned int swap;
42         unsigned int planes;
43         unsigned int bpp[3];
44         bool swap_yc;
45         bool swap_uv;
46         unsigned int hsub;
47         unsigned int vsub;
48 };
49
50 enum vsp1_pipeline_state {
51         VSP1_PIPELINE_STOPPED,
52         VSP1_PIPELINE_RUNNING,
53         VSP1_PIPELINE_STOPPING,
54 };
55
56 /*
57  * struct vsp1_pipeline - A VSP1 hardware pipeline
58  * @media: the media pipeline
59  * @irqlock: protects the pipeline state
60  * @lock: protects the pipeline use count and stream count
61  */
62 struct vsp1_pipeline {
63         struct media_pipeline pipe;
64
65         spinlock_t irqlock;
66         enum vsp1_pipeline_state state;
67         wait_queue_head_t wq;
68
69         struct mutex lock;
70         unsigned int use_count;
71         unsigned int stream_count;
72         unsigned int buffers_ready;
73
74         unsigned int num_video;
75         unsigned int num_inputs;
76         struct vsp1_rwpf *inputs[VPS1_MAX_RPF];
77         struct vsp1_rwpf *output;
78         struct vsp1_entity *lif;
79
80         struct list_head entities;
81 };
82
83 static inline struct vsp1_pipeline *to_vsp1_pipeline(struct media_entity *e)
84 {
85         if (likely(e->pipe))
86                 return container_of(e->pipe, struct vsp1_pipeline, pipe);
87         else
88                 return NULL;
89 }
90
91 struct vsp1_video_buffer {
92         struct vb2_buffer buf;
93         struct list_head queue;
94
95         dma_addr_t addr[3];
96         unsigned int length[3];
97 };
98
99 static inline struct vsp1_video_buffer *
100 to_vsp1_video_buffer(struct vb2_buffer *vb)
101 {
102         return container_of(vb, struct vsp1_video_buffer, buf);
103 }
104
105 struct vsp1_video_operations {
106         void (*queue)(struct vsp1_video *video, struct vsp1_video_buffer *buf);
107 };
108
109 struct vsp1_video {
110         struct vsp1_device *vsp1;
111         struct vsp1_entity *rwpf;
112
113         const struct vsp1_video_operations *ops;
114
115         struct video_device video;
116         enum v4l2_buf_type type;
117         struct media_pad pad;
118
119         struct mutex lock;
120         struct v4l2_pix_format_mplane format;
121         const struct vsp1_format_info *fmtinfo;
122
123         struct vsp1_pipeline pipe;
124         unsigned int pipe_index;
125
126         struct vb2_queue queue;
127         void *alloc_ctx;
128         spinlock_t irqlock;
129         struct list_head irqqueue;
130         unsigned int sequence;
131 };
132
133 static inline struct vsp1_video *to_vsp1_video(struct video_device *vdev)
134 {
135         return container_of(vdev, struct vsp1_video, video);
136 }
137
138 int vsp1_video_init(struct vsp1_video *video, struct vsp1_entity *rwpf);
139 void vsp1_video_cleanup(struct vsp1_video *video);
140
141 void vsp1_pipeline_frame_end(struct vsp1_pipeline *pipe);
142
143 #endif /* __VSP1_VIDEO_H__ */