blob: 1e18c9ea6f852df831511ccac7ac995c12835de9 [file] [log] [blame]
Terence Hampsona6914ca2012-04-09 14:06:50 -04001/* Copyright (c) 2012, Code Aurora Forum. All rights reserved.
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 */
13
14#ifndef VCAP_V4L2_H
15#define VCAP_V4L2_H
16
Terence Hampsonaeb793e2012-05-11 11:41:16 -040017#define TOP_FIELD_FIX
Terence Hampsona6914ca2012-04-09 14:06:50 -040018#ifdef __KERNEL__
19#include <linux/types.h>
20#include <linux/videodev2.h>
21#include <linux/platform_device.h>
22#include <linux/workqueue.h>
23#include <media/videobuf2-vmalloc.h>
24#include <media/v4l2-device.h>
25#include <media/v4l2-ioctl.h>
26#include <media/v4l2-ctrls.h>
27#include <media/v4l2-fh.h>
28#include <media/v4l2-common.h>
29#include <media/vcap_fmt.h>
30#include <mach/board.h>
Terence Hampsona2cba0d2012-08-08 11:39:53 -040031#include <mach/iommu_domains.h>
Terence Hampsona6914ca2012-04-09 14:06:50 -040032
Terence Hampson98d11802012-06-06 18:18:43 -040033#define to_client_data(val) container_of(val, struct vcap_client_data, vfh)
34
Terence Hampsonaeb793e2012-05-11 11:41:16 -040035#define writel_iowmb(val, addr) \
36 do { \
37 __iowmb(); \
38 writel_relaxed(val, addr); \
39 } while (0)
40
Terence Hampsonb128b982012-08-16 14:41:19 -040041#define VCAP_BASE (dev->vcapbase)
42#define VCAP_OFFSET(off) (VCAP_BASE + off)
43
44#define VCAP_SW_RESET_REQ (VCAP_BASE + 0x024)
45#define VCAP_SW_RESET_STATUS (VCAP_BASE + 0x028)
46
Terence Hampson2cba63f2012-08-21 10:54:38 -040047#define VCAP_VP_MIN_BUF 4
48#define VCAP_VC_MAX_BUF 6
49#define VCAP_VC_MIN_BUF 2
Terence Hampsona6914ca2012-04-09 14:06:50 -040050struct vcap_client_data;
51
Terence Hampsonaeb793e2012-05-11 11:41:16 -040052enum vp_state {
53 VP_UNKNOWN = 0,
54 VP_FRAME1,
55 VP_FRAME2,
56 VP_FRAME3,
57 VP_NORMAL,
58};
59
60enum nr_buf_pos {
61 BUF_NOT_IN_USE = 0,
62 NRT2_BUF,
63 T1_BUF,
64 T0_BUF,
65 TM1_BUF,
66};
67
Terence Hampsona6914ca2012-04-09 14:06:50 -040068struct vcap_buf_info {
69 unsigned long vaddr;
70 unsigned long size;
71};
72
Terence Hampsonaeb793e2012-05-11 11:41:16 -040073enum vcap_op_mode {
74 UNKNOWN_VCAP_OP = 0,
75 VC_VCAP_OP,
76 VP_VCAP_OP,
77 VC_AND_VP_VCAP_OP,
78};
79
Terence Hampson2cba63f2012-08-21 10:54:38 -040080struct vc_action {
Terence Hampsona6914ca2012-04-09 14:06:50 -040081 struct list_head active;
82
83 /* thread for generating video stream*/
Terence Hampsona6914ca2012-04-09 14:06:50 -040084 wait_queue_head_t wq;
85
86 /* Buffer index */
Terence Hampson2cba63f2012-08-21 10:54:38 -040087 uint8_t tot_buf;
88 uint8_t buf_num;
Terence Hampsona6914ca2012-04-09 14:06:50 -040089
90 /* Buffers inside vc */
Terence Hampson2cba63f2012-08-21 10:54:38 -040091 struct vcap_buffer *buf[6];
Terence Hampsona6914ca2012-04-09 14:06:50 -040092};
93
Terence Hampsonaeb793e2012-05-11 11:41:16 -040094struct nr_buffer {
Terence Hampsona2cba0d2012-08-08 11:39:53 -040095 struct ion_handle *nr_handle;
Terence Hampsonaeb793e2012-05-11 11:41:16 -040096 unsigned long paddr;
97 enum nr_buf_pos nr_pos;
98};
99
100struct vp_action {
101 struct list_head in_active;
102 struct list_head out_active;
103
104 /* Buffer index */
105 enum vp_state vp_state;
106#ifdef TOP_FIELD_FIX
107 bool top_field;
108#endif
109
110 /* Buffers inside vc */
111 struct vcap_buffer *bufTm1;
112 struct vcap_buffer *bufT0;
113 struct vcap_buffer *bufT1;
114 struct vcap_buffer *bufT2;
115 struct vcap_buffer *bufNRT2;
116
117 struct vcap_buffer *bufOut;
118
Terence Hampsona2cba0d2012-08-08 11:39:53 -0400119 struct ion_handle *motionHandle;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400120 void *bufMotion;
121 struct nr_buffer bufNR;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400122};
123
124struct vp_work_t {
125 struct work_struct work;
126 struct vcap_client_data *cd;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400127};
128
Terence Hampsona6914ca2012-04-09 14:06:50 -0400129struct vcap_dev {
130 struct v4l2_device v4l2_dev;
131
132 struct video_device *vfd;
133 struct ion_client *ion_client;
134
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400135 struct resource *vcirq;
136 struct resource *vpirq;
Terence Hampsona6914ca2012-04-09 14:06:50 -0400137
138 struct resource *vcapmem;
139 struct resource *vcapio;
140 void __iomem *vcapbase;
141
142 struct vcap_platform_data *vcap_pdata;
143
144 struct regulator *fs_vcap;
145 struct clk *vcap_clk;
146 struct clk *vcap_p_clk;
147 struct clk *vcap_npl_clk;
Terence Hampson779dc762012-06-07 15:59:27 -0400148 struct device *ddev;
Terence Hampsona6914ca2012-04-09 14:06:50 -0400149 /*struct platform_device *pdev;*/
150
151 uint32_t bus_client_handle;
152
153 struct vcap_client_data *vc_client;
154 struct vcap_client_data *vp_client;
155
156 atomic_t vc_enabled;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400157 atomic_t vp_enabled;
158
Terence Hampson54d3a6d2012-07-10 14:05:35 -0400159 struct mutex dev_mutex;
Terence Hampson779dc762012-06-07 15:59:27 -0400160 atomic_t open_clients;
161 bool vc_resource;
162 bool vp_resource;
Terence Hampson54d3a6d2012-07-10 14:05:35 -0400163 bool vp_dummy_event;
164 bool vp_dummy_complete;
Terence Hampsonb128b982012-08-16 14:41:19 -0400165 bool vp_shutdown;
Terence Hampson54d3a6d2012-07-10 14:05:35 -0400166 wait_queue_head_t vp_dummy_waitq;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400167
Terence Hampson2cba63f2012-08-21 10:54:38 -0400168 uint8_t vc_tot_buf;
169
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400170 struct workqueue_struct *vcap_wq;
171 struct vp_work_t vp_work;
172 struct vp_work_t vc_to_vp_work;
173 struct vp_work_t vp_to_vc_work;
Terence Hampson616762d2012-08-16 17:47:44 -0400174
175 struct nr_param nr_param;
176 bool nr_update;
Terence Hampsona6914ca2012-04-09 14:06:50 -0400177};
178
179struct vp_format_data {
180 unsigned int width, height;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400181 unsigned int pixfmt;
Terence Hampsona6914ca2012-04-09 14:06:50 -0400182};
183
184struct vcap_buffer {
185 /* common v4l buffer stuff -- must be first */
186 struct vb2_buffer vb;
187 struct list_head list;
188 unsigned long paddr;
189 struct ion_handle *ion_handle;
190};
191
192struct vcap_client_data {
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400193 bool set_cap, set_decode, set_vp_o;
Terence Hampsona6914ca2012-04-09 14:06:50 -0400194 struct vcap_dev *dev;
195
196 struct vb2_queue vc_vidq;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400197 struct vb2_queue vp_in_vidq;
198 struct vb2_queue vp_out_vidq;
199
200 enum vcap_op_mode op_mode;
Terence Hampsona6914ca2012-04-09 14:06:50 -0400201
202 struct v4l2_format_vc_ext vc_format;
203
204 enum v4l2_buf_type vp_buf_type_field;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400205 struct vp_format_data vp_in_fmt;
206 struct vp_format_data vp_out_fmt;
Terence Hampsona6914ca2012-04-09 14:06:50 -0400207
Terence Hampson2cba63f2012-08-21 10:54:38 -0400208 struct vc_action vc_action;
209 struct vp_action vp_action;
Terence Hampsona6914ca2012-04-09 14:06:50 -0400210 struct workqueue_struct *vcap_work_q;
211 struct ion_handle *vc_ion_handle;
212
213 uint32_t hold_vc;
214 uint32_t hold_vp;
215
216 spinlock_t cap_slock;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400217 bool streaming;
Terence Hampson98d11802012-06-06 18:18:43 -0400218
219 struct v4l2_fh vfh;
Terence Hampsona6914ca2012-04-09 14:06:50 -0400220};
221
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400222struct vcap_hacked_vals {
223 uint32_t value;
224 uint32_t offset;
225};
226
227extern struct vcap_hacked_vals hacked_buf[];
228
Terence Hampsona6914ca2012-04-09 14:06:50 -0400229#endif
Terence Hampsona6c96482012-07-06 17:53:09 -0400230int vcvp_qbuf(struct vb2_queue *q, struct v4l2_buffer *b);
231int vcvp_dqbuf(struct vb2_queue *q, struct v4l2_buffer *b);
Terence Hampsona6914ca2012-04-09 14:06:50 -0400232#endif