blob: 0011ee6696d5745486ebbc4f6411b3b97ed17941 [file] [log] [blame]
Duy Truong790f06d2013-02-13 16:38:12 -08001/* Copyright (c) 2012, The Linux Foundation. All rights reserved.
Terence Hampsona6914ca2012-04-09 14:06:50 -04002 *
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
17#ifdef __KERNEL__
18#include <linux/types.h>
19#include <linux/videodev2.h>
20#include <linux/platform_device.h>
21#include <linux/workqueue.h>
22#include <media/videobuf2-vmalloc.h>
23#include <media/v4l2-device.h>
24#include <media/v4l2-ioctl.h>
25#include <media/v4l2-ctrls.h>
26#include <media/v4l2-fh.h>
27#include <media/v4l2-common.h>
28#include <media/vcap_fmt.h>
29#include <mach/board.h>
Terence Hampsona2cba0d2012-08-08 11:39:53 -040030#include <mach/iommu_domains.h>
Terence Hampsona6914ca2012-04-09 14:06:50 -040031
Terence Hampson98d11802012-06-06 18:18:43 -040032#define to_client_data(val) container_of(val, struct vcap_client_data, vfh)
33
Terence Hampsonaeb793e2012-05-11 11:41:16 -040034#define writel_iowmb(val, addr) \
35 do { \
36 __iowmb(); \
37 writel_relaxed(val, addr); \
38 } while (0)
39
Terence Hampsona1e8af42012-09-18 16:41:57 -040040#define VCAP_USEC (1000000)
Terence Hampson9d6f89c2012-10-03 16:24:04 -040041
Terence Hampsondf1d4de2012-11-05 17:06:02 -050042#define VCAP_STRIDE_ALIGN_16 0x10
43#define VCAP_STRIDE_ALIGN_32 0x20
44#define VCAP_STRIDE_CALC(x, align) (((x / align) + \
45 (!(!(x % align)))) * align)
Terence Hampson9d6f89c2012-10-03 16:24:04 -040046
Terence Hampsonb128b982012-08-16 14:41:19 -040047#define VCAP_BASE (dev->vcapbase)
48#define VCAP_OFFSET(off) (VCAP_BASE + off)
49
Terence Hampsonc4aa4c02012-08-31 04:49:21 -040050struct reg_range {
51 u32 min_val;
52 u32 max_val;
53};
54
55#define VCAP_REG_RANGE_1_MIN 0x0
56#define VCAP_REG_RANGE_1_MAX 0x48
57#define VCAP_REG_RANGE_2_MIN 0x100
58#define VCAP_REG_RANGE_2_MAX 0x104
59#define VCAP_REG_RANGE_3_MIN 0x400
60#define VCAP_REG_RANGE_3_MAX 0x7F0
61#define VCAP_REG_RANGE_4_MIN 0x800
62#define VCAP_REG_RANGE_4_MAX 0x8A0
63#define VCAP_REG_RANGE_5_MIN 0xC00
64#define VCAP_REG_RANGE_5_MAX 0xDF0
65
Terence Hampsonb128b982012-08-16 14:41:19 -040066#define VCAP_SW_RESET_REQ (VCAP_BASE + 0x024)
67#define VCAP_SW_RESET_STATUS (VCAP_BASE + 0x028)
68
Terence Hampson2cba63f2012-08-21 10:54:38 -040069#define VCAP_VP_MIN_BUF 4
70#define VCAP_VC_MAX_BUF 6
71#define VCAP_VC_MIN_BUF 2
Terence Hampsona6914ca2012-04-09 14:06:50 -040072struct vcap_client_data;
73
Terence Hampsonaeb793e2012-05-11 11:41:16 -040074enum vp_state {
75 VP_UNKNOWN = 0,
76 VP_FRAME1,
77 VP_FRAME2,
78 VP_FRAME3,
79 VP_NORMAL,
80};
81
82enum nr_buf_pos {
83 BUF_NOT_IN_USE = 0,
84 NRT2_BUF,
85 T1_BUF,
86 T0_BUF,
87 TM1_BUF,
88};
89
Terence Hampsona6914ca2012-04-09 14:06:50 -040090struct vcap_buf_info {
91 unsigned long vaddr;
92 unsigned long size;
93};
94
Terence Hampsonaeb793e2012-05-11 11:41:16 -040095enum vcap_op_mode {
96 UNKNOWN_VCAP_OP = 0,
97 VC_VCAP_OP,
98 VP_VCAP_OP,
99 VC_AND_VP_VCAP_OP,
100};
101
Terence Hampson2cba63f2012-08-21 10:54:38 -0400102struct vc_action {
Terence Hampsona6914ca2012-04-09 14:06:50 -0400103 struct list_head active;
104
105 /* thread for generating video stream*/
Terence Hampsona6914ca2012-04-09 14:06:50 -0400106 wait_queue_head_t wq;
107
108 /* Buffer index */
Terence Hampson2cba63f2012-08-21 10:54:38 -0400109 uint8_t tot_buf;
110 uint8_t buf_num;
Terence Hampsona6914ca2012-04-09 14:06:50 -0400111
Terence Hampsonaa64d3a2012-10-29 13:05:37 -0400112 bool field1;
Terence Hampsonf0ab1ee2012-10-22 12:43:36 -0400113 bool field_dropped;
Terence Hampson9c4f8a22012-09-12 10:25:50 -0400114
Terence Hampsona1e8af42012-09-18 16:41:57 -0400115 struct timeval vc_ts;
116 uint32_t last_ts;
117
Terence Hampsona6914ca2012-04-09 14:06:50 -0400118 /* Buffers inside vc */
Terence Hampson2cba63f2012-08-21 10:54:38 -0400119 struct vcap_buffer *buf[6];
Terence Hampsona6914ca2012-04-09 14:06:50 -0400120};
121
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400122struct nr_buffer {
Terence Hampsona2cba0d2012-08-08 11:39:53 -0400123 struct ion_handle *nr_handle;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400124 unsigned long paddr;
125 enum nr_buf_pos nr_pos;
126};
127
128struct vp_action {
129 struct list_head in_active;
130 struct list_head out_active;
131
132 /* Buffer index */
133 enum vp_state vp_state;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400134
135 /* Buffers inside vc */
136 struct vcap_buffer *bufTm1;
137 struct vcap_buffer *bufT0;
138 struct vcap_buffer *bufT1;
139 struct vcap_buffer *bufT2;
140 struct vcap_buffer *bufNRT2;
141
142 struct vcap_buffer *bufOut;
143
Terence Hampsona2cba0d2012-08-08 11:39:53 -0400144 struct ion_handle *motionHandle;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400145 void *bufMotion;
146 struct nr_buffer bufNR;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400147};
148
149struct vp_work_t {
150 struct work_struct work;
151 struct vcap_client_data *cd;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400152};
153
Terence Hampsonc4aa4c02012-08-31 04:49:21 -0400154struct vcap_debugfs_params {
155 atomic_t vc_drop_count;
156 uint32_t vc_timestamp;
157 uint32_t vp_timestamp;
158 uint32_t vp_ewma;/* Exponential moving average */
159 uint32_t clk_rate;
160 uint32_t bw_request;
161 uint32_t reg_addr;
162};
163
Terence Hampsona6914ca2012-04-09 14:06:50 -0400164struct vcap_dev {
165 struct v4l2_device v4l2_dev;
166
167 struct video_device *vfd;
168 struct ion_client *ion_client;
169
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400170 struct resource *vcirq;
171 struct resource *vpirq;
Terence Hampsona6914ca2012-04-09 14:06:50 -0400172
173 struct resource *vcapmem;
174 struct resource *vcapio;
175 void __iomem *vcapbase;
176
177 struct vcap_platform_data *vcap_pdata;
178
179 struct regulator *fs_vcap;
180 struct clk *vcap_clk;
181 struct clk *vcap_p_clk;
182 struct clk *vcap_npl_clk;
Terence Hampson779dc762012-06-07 15:59:27 -0400183 struct device *ddev;
Terence Hampsona6914ca2012-04-09 14:06:50 -0400184 /*struct platform_device *pdev;*/
185
186 uint32_t bus_client_handle;
187
Terence Hampson8d1c3272012-07-27 16:36:31 -0400188 int domain_num;
189 struct device *vc_iommu_ctx;
190 struct device *vp_iommu_ctx;
191 struct iommu_domain *iommu_vcap_domain;
192
Terence Hampsona6914ca2012-04-09 14:06:50 -0400193 struct vcap_client_data *vc_client;
194 struct vcap_client_data *vp_client;
195
196 atomic_t vc_enabled;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400197 atomic_t vp_enabled;
198
Terence Hampson54d3a6d2012-07-10 14:05:35 -0400199 struct mutex dev_mutex;
Terence Hampson779dc762012-06-07 15:59:27 -0400200 atomic_t open_clients;
201 bool vc_resource;
202 bool vp_resource;
Terence Hampson54d3a6d2012-07-10 14:05:35 -0400203 bool vp_dummy_event;
204 bool vp_dummy_complete;
Terence Hampsonb128b982012-08-16 14:41:19 -0400205 bool vp_shutdown;
Terence Hampson54d3a6d2012-07-10 14:05:35 -0400206 wait_queue_head_t vp_dummy_waitq;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400207
Terence Hampson2cba63f2012-08-21 10:54:38 -0400208 uint8_t vc_tot_buf;
209
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400210 struct workqueue_struct *vcap_wq;
211 struct vp_work_t vp_work;
212 struct vp_work_t vc_to_vp_work;
213 struct vp_work_t vp_to_vc_work;
Terence Hampson616762d2012-08-16 17:47:44 -0400214
215 struct nr_param nr_param;
216 bool nr_update;
Terence Hampsonc4aa4c02012-08-31 04:49:21 -0400217 struct vcap_debugfs_params dbg_p;
Terence Hampsona6914ca2012-04-09 14:06:50 -0400218};
219
220struct vp_format_data {
221 unsigned int width, height;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400222 unsigned int pixfmt;
Terence Hampsona6914ca2012-04-09 14:06:50 -0400223};
224
225struct vcap_buffer {
226 /* common v4l buffer stuff -- must be first */
227 struct vb2_buffer vb;
228 struct list_head list;
229 unsigned long paddr;
230 struct ion_handle *ion_handle;
231};
232
233struct vcap_client_data {
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400234 bool set_cap, set_decode, set_vp_o;
Terence Hampsona6914ca2012-04-09 14:06:50 -0400235 struct vcap_dev *dev;
236
237 struct vb2_queue vc_vidq;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400238 struct vb2_queue vp_in_vidq;
239 struct vb2_queue vp_out_vidq;
240
241 enum vcap_op_mode op_mode;
Terence Hampsona6914ca2012-04-09 14:06:50 -0400242
243 struct v4l2_format_vc_ext vc_format;
Terence Hampsondf1d4de2012-11-05 17:06:02 -0500244 enum vcap_stride stride;
Terence Hampsona6914ca2012-04-09 14:06:50 -0400245
246 enum v4l2_buf_type vp_buf_type_field;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400247 struct vp_format_data vp_in_fmt;
248 struct vp_format_data vp_out_fmt;
Terence Hampsona6914ca2012-04-09 14:06:50 -0400249
Terence Hampson2cba63f2012-08-21 10:54:38 -0400250 struct vc_action vc_action;
251 struct vp_action vp_action;
Terence Hampsona6914ca2012-04-09 14:06:50 -0400252 struct workqueue_struct *vcap_work_q;
253 struct ion_handle *vc_ion_handle;
254
255 uint32_t hold_vc;
256 uint32_t hold_vp;
257
Terence Hampsonb0c58b12012-10-30 17:56:36 -0400258 /* Mutex ensures only one thread is dq buffer or turning streamoff */
259 struct mutex mutex;
Terence Hampsona6914ca2012-04-09 14:06:50 -0400260 spinlock_t cap_slock;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400261 bool streaming;
Terence Hampson98d11802012-06-06 18:18:43 -0400262
263 struct v4l2_fh vfh;
Terence Hampsona6914ca2012-04-09 14:06:50 -0400264};
265
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400266struct vcap_hacked_vals {
267 uint32_t value;
268 uint32_t offset;
269};
270
271extern struct vcap_hacked_vals hacked_buf[];
272
Terence Hampsona6914ca2012-04-09 14:06:50 -0400273#endif
Terence Hampsona6c96482012-07-06 17:53:09 -0400274int vcvp_qbuf(struct vb2_queue *q, struct v4l2_buffer *b);
275int vcvp_dqbuf(struct vb2_queue *q, struct v4l2_buffer *b);
Terence Hampsona6914ca2012-04-09 14:06:50 -0400276#endif