• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * vsp1_video.h  --  R-Car VSP1 Video Node
3  *
4  * Copyright (C) 2013-2014 Renesas Electronics 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  * @alpha: has an alpha channel
37  */
38 struct vsp1_format_info {
39 	u32 fourcc;
40 	unsigned int mbus;
41 	unsigned int hwfmt;
42 	unsigned int swap;
43 	unsigned int planes;
44 	unsigned int bpp[3];
45 	bool swap_yc;
46 	bool swap_uv;
47 	unsigned int hsub;
48 	unsigned int vsub;
49 	bool alpha;
50 };
51 
52 enum vsp1_pipeline_state {
53 	VSP1_PIPELINE_STOPPED,
54 	VSP1_PIPELINE_RUNNING,
55 	VSP1_PIPELINE_STOPPING,
56 };
57 
58 /*
59  * struct vsp1_pipeline - A VSP1 hardware pipeline
60  * @media: the media pipeline
61  * @irqlock: protects the pipeline state
62  * @lock: protects the pipeline use count and stream count
63  */
64 struct vsp1_pipeline {
65 	struct media_pipeline pipe;
66 
67 	spinlock_t irqlock;
68 	enum vsp1_pipeline_state state;
69 	wait_queue_head_t wq;
70 
71 	struct mutex lock;
72 	unsigned int use_count;
73 	unsigned int stream_count;
74 	unsigned int buffers_ready;
75 
76 	unsigned int num_video;
77 	unsigned int num_inputs;
78 	struct vsp1_rwpf *inputs[VSP1_MAX_RPF];
79 	struct vsp1_rwpf *output;
80 	struct vsp1_entity *bru;
81 	struct vsp1_entity *lif;
82 	struct vsp1_entity *uds;
83 	struct vsp1_entity *uds_input;
84 
85 	struct list_head entities;
86 };
87 
to_vsp1_pipeline(struct media_entity * e)88 static inline struct vsp1_pipeline *to_vsp1_pipeline(struct media_entity *e)
89 {
90 	if (likely(e->pipe))
91 		return container_of(e->pipe, struct vsp1_pipeline, pipe);
92 	else
93 		return NULL;
94 }
95 
96 struct vsp1_video_buffer {
97 	struct vb2_buffer buf;
98 	struct list_head queue;
99 
100 	dma_addr_t addr[3];
101 	unsigned int length[3];
102 };
103 
104 static inline struct vsp1_video_buffer *
to_vsp1_video_buffer(struct vb2_buffer * vb)105 to_vsp1_video_buffer(struct vb2_buffer *vb)
106 {
107 	return container_of(vb, struct vsp1_video_buffer, buf);
108 }
109 
110 struct vsp1_video_operations {
111 	void (*queue)(struct vsp1_video *video, struct vsp1_video_buffer *buf);
112 };
113 
114 struct vsp1_video {
115 	struct vsp1_device *vsp1;
116 	struct vsp1_entity *rwpf;
117 
118 	const struct vsp1_video_operations *ops;
119 
120 	struct video_device video;
121 	enum v4l2_buf_type type;
122 	struct media_pad pad;
123 
124 	struct mutex lock;
125 	struct v4l2_pix_format_mplane format;
126 	const struct vsp1_format_info *fmtinfo;
127 
128 	struct vsp1_pipeline pipe;
129 	unsigned int pipe_index;
130 
131 	struct vb2_queue queue;
132 	void *alloc_ctx;
133 	spinlock_t irqlock;
134 	struct list_head irqqueue;
135 	unsigned int sequence;
136 };
137 
to_vsp1_video(struct video_device * vdev)138 static inline struct vsp1_video *to_vsp1_video(struct video_device *vdev)
139 {
140 	return container_of(vdev, struct vsp1_video, video);
141 }
142 
143 int vsp1_video_init(struct vsp1_video *video, struct vsp1_entity *rwpf);
144 void vsp1_video_cleanup(struct vsp1_video *video);
145 
146 void vsp1_pipeline_frame_end(struct vsp1_pipeline *pipe);
147 
148 void vsp1_pipeline_propagate_alpha(struct vsp1_pipeline *pipe,
149 				   struct vsp1_entity *input,
150 				   unsigned int alpha);
151 
152 #endif /* __VSP1_VIDEO_H__ */
153