Merge tag 'iio-for-3.17a' of git://git.kernel.org/pub/scm/linux/kernel/git/jic23...
[sfrench/cifs-2.6.git] / drivers / staging / media / davinci_vpfe / vpfe_video.h
1 /*
2  * Copyright (C) 2012 Texas Instruments Inc
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation version 2.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16  *
17  * Contributors:
18  *      Manjunath Hadli <manjunath.hadli@ti.com>
19  *      Prabhakar Lad <prabhakar.lad@ti.com>
20  */
21
22 #ifndef _DAVINCI_VPFE_VIDEO_H
23 #define _DAVINCI_VPFE_VIDEO_H
24
25 #include <media/videobuf2-dma-contig.h>
26
27 struct vpfe_device;
28
29 /*
30  * struct vpfe_video_operations - VPFE video operations
31  * @queue:      Resume streaming when a buffer is queued. Called on VIDIOC_QBUF
32  *              if there was no buffer previously queued.
33  */
34 struct vpfe_video_operations {
35         int (*queue)(struct vpfe_device *vpfe_dev, unsigned long addr);
36 };
37
38 enum vpfe_pipeline_stream_state {
39         VPFE_PIPELINE_STREAM_STOPPED = 0,
40         VPFE_PIPELINE_STREAM_CONTINUOUS = 1,
41         VPFE_PIPELINE_STREAM_SINGLESHOT = 2,
42 };
43
44 enum vpfe_video_state {
45         /* indicates that buffer is not queued */
46         VPFE_VIDEO_BUFFER_NOT_QUEUED = 0,
47         /* indicates that buffer is queued */
48         VPFE_VIDEO_BUFFER_QUEUED = 1,
49 };
50
51 struct vpfe_pipeline {
52         /* media pipeline */
53         struct media_pipeline           *pipe;
54         /* state of the pipeline, continuous,
55          * single-shot or stopped
56          */
57         enum vpfe_pipeline_stream_state state;
58         /* number of active input video entities */
59         unsigned int                    input_num;
60         /* number of active output video entities */
61         unsigned int                    output_num;
62         /* input video nodes in case of single-shot mode */
63         struct vpfe_video_device        *inputs[10];
64         /* capturing video nodes */
65         struct vpfe_video_device        *outputs[10];
66 };
67
68 #define to_vpfe_pipeline(__e) \
69         container_of((__e)->pipe, struct vpfe_pipeline, pipe)
70
71 #define to_vpfe_video(vdev) \
72         container_of(vdev, struct vpfe_video_device, video_dev)
73
74 struct vpfe_cap_buffer {
75         struct vb2_buffer vb;
76         struct list_head list;
77 };
78
79 struct vpfe_video_device {
80         /* vpfe device */
81         struct vpfe_device                      *vpfe_dev;
82         /* video dev */
83         struct video_device                     video_dev;
84         /* media pad of video entity */
85         struct media_pad                        pad;
86         /* video operations supported by video device */
87         const struct vpfe_video_operations      *ops;
88         /* type of the video buffers used by user */
89         enum v4l2_buf_type                      type;
90         /* Indicates id of the field which is being captured */
91         u32                                     field_id;
92         /* pipeline for which video device is part of */
93         struct vpfe_pipeline                    pipe;
94         /* Indicates whether streaming started */
95         u8                                      started;
96         /* Indicates state of the stream */
97         unsigned int                            state;
98         /* current input at the sub device */
99         int                                     current_input;
100         /*
101          * This field keeps track of type of buffer exchange mechanism
102          * user has selected
103          */
104         enum v4l2_memory                        memory;
105         /* number of open instances of the channel */
106         u32                                     usrs;
107         /* flag to indicate whether decoder is initialized */
108         u8                                      initialized;
109         /* skip frame count */
110         u8                                      skip_frame_count;
111         /* skip frame count init value */
112         u8                                      skip_frame_count_init;
113         /* time per frame for skipping */
114         struct v4l2_fract                       timeperframe;
115         /* ptr to currently selected sub device */
116         struct vpfe_ext_subdev_info             *current_ext_subdev;
117         /* Pointer pointing to current vpfe_cap_buffer */
118         struct vpfe_cap_buffer                  *cur_frm;
119         /* Pointer pointing to next vpfe_cap_buffer */
120         struct vpfe_cap_buffer                  *next_frm;
121         /* Used to store pixel format */
122         struct v4l2_format                      fmt;
123         struct vb2_queue                        buffer_queue;
124         /* allocator-specific contexts for each plane */
125         struct vb2_alloc_ctx *alloc_ctx;
126         /* Queue of filled frames */
127         struct list_head                        dma_queue;
128         spinlock_t                              irqlock;
129         /* IRQ lock for DMA queue */
130         spinlock_t                              dma_queue_lock;
131         /* lock used to access this structure */
132         struct mutex                            lock;
133         /* number of users performing IO */
134         u32                                     io_usrs;
135         /* Currently selected or default standard */
136         v4l2_std_id                             stdid;
137         /*
138          * offset where second field starts from the starting of the
139          * buffer for field separated YCbCr formats
140          */
141         u32                                     field_off;
142 };
143
144 int vpfe_video_is_pipe_ready(struct vpfe_pipeline *pipe);
145 void vpfe_video_unregister(struct vpfe_video_device *video);
146 int vpfe_video_register(struct vpfe_video_device *video,
147                         struct v4l2_device *vdev);
148 int vpfe_video_init(struct vpfe_video_device *video, const char *name);
149 void vpfe_video_process_buffer_complete(struct vpfe_video_device *video);
150 void vpfe_video_schedule_bottom_field(struct vpfe_video_device *video);
151 void vpfe_video_schedule_next_buffer(struct vpfe_video_device *video);
152
153 #endif          /* _DAVINCI_VPFE_VIDEO_H */