blob: 6d684ef81dfd74d6277bffcafb8e8a5c6495826d [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
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
42#define VCAP_STRIDE_ALIGN 0x10
43#define VCAP_STRIDE_CALC(x) (((x / VCAP_STRIDE_ALIGN) + \
44 (!(!(x % VCAP_STRIDE_ALIGN)))) * \
45 VCAP_STRIDE_ALIGN)
46
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 Hampson9c4f8a22012-09-12 10:25:50 -0400112 bool top_field;
113
Terence Hampsona1e8af42012-09-18 16:41:57 -0400114 struct timeval vc_ts;
115 uint32_t last_ts;
116
Terence Hampsona6914ca2012-04-09 14:06:50 -0400117 /* Buffers inside vc */
Terence Hampson2cba63f2012-08-21 10:54:38 -0400118 struct vcap_buffer *buf[6];
Terence Hampsona6914ca2012-04-09 14:06:50 -0400119};
120
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400121struct nr_buffer {
Terence Hampsona2cba0d2012-08-08 11:39:53 -0400122 struct ion_handle *nr_handle;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400123 unsigned long paddr;
124 enum nr_buf_pos nr_pos;
125};
126
127struct vp_action {
128 struct list_head in_active;
129 struct list_head out_active;
130
131 /* Buffer index */
132 enum vp_state vp_state;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400133
134 /* Buffers inside vc */
135 struct vcap_buffer *bufTm1;
136 struct vcap_buffer *bufT0;
137 struct vcap_buffer *bufT1;
138 struct vcap_buffer *bufT2;
139 struct vcap_buffer *bufNRT2;
140
141 struct vcap_buffer *bufOut;
142
Terence Hampsona2cba0d2012-08-08 11:39:53 -0400143 struct ion_handle *motionHandle;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400144 void *bufMotion;
145 struct nr_buffer bufNR;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400146};
147
148struct vp_work_t {
149 struct work_struct work;
150 struct vcap_client_data *cd;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400151};
152
Terence Hampsonc4aa4c02012-08-31 04:49:21 -0400153struct vcap_debugfs_params {
154 atomic_t vc_drop_count;
155 uint32_t vc_timestamp;
156 uint32_t vp_timestamp;
157 uint32_t vp_ewma;/* Exponential moving average */
158 uint32_t clk_rate;
159 uint32_t bw_request;
160 uint32_t reg_addr;
161};
162
Terence Hampsona6914ca2012-04-09 14:06:50 -0400163struct vcap_dev {
164 struct v4l2_device v4l2_dev;
165
166 struct video_device *vfd;
167 struct ion_client *ion_client;
168
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400169 struct resource *vcirq;
170 struct resource *vpirq;
Terence Hampsona6914ca2012-04-09 14:06:50 -0400171
172 struct resource *vcapmem;
173 struct resource *vcapio;
174 void __iomem *vcapbase;
175
176 struct vcap_platform_data *vcap_pdata;
177
178 struct regulator *fs_vcap;
179 struct clk *vcap_clk;
180 struct clk *vcap_p_clk;
181 struct clk *vcap_npl_clk;
Terence Hampson779dc762012-06-07 15:59:27 -0400182 struct device *ddev;
Terence Hampsona6914ca2012-04-09 14:06:50 -0400183 /*struct platform_device *pdev;*/
184
185 uint32_t bus_client_handle;
186
Terence Hampson8d1c3272012-07-27 16:36:31 -0400187 int domain_num;
188 struct device *vc_iommu_ctx;
189 struct device *vp_iommu_ctx;
190 struct iommu_domain *iommu_vcap_domain;
191
Terence Hampsona6914ca2012-04-09 14:06:50 -0400192 struct vcap_client_data *vc_client;
193 struct vcap_client_data *vp_client;
194
195 atomic_t vc_enabled;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400196 atomic_t vp_enabled;
197
Terence Hampson54d3a6d2012-07-10 14:05:35 -0400198 struct mutex dev_mutex;
Terence Hampson779dc762012-06-07 15:59:27 -0400199 atomic_t open_clients;
200 bool vc_resource;
201 bool vp_resource;
Terence Hampson54d3a6d2012-07-10 14:05:35 -0400202 bool vp_dummy_event;
203 bool vp_dummy_complete;
Terence Hampsonb128b982012-08-16 14:41:19 -0400204 bool vp_shutdown;
Terence Hampson54d3a6d2012-07-10 14:05:35 -0400205 wait_queue_head_t vp_dummy_waitq;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400206
Terence Hampson2cba63f2012-08-21 10:54:38 -0400207 uint8_t vc_tot_buf;
208
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400209 struct workqueue_struct *vcap_wq;
210 struct vp_work_t vp_work;
211 struct vp_work_t vc_to_vp_work;
212 struct vp_work_t vp_to_vc_work;
Terence Hampson616762d2012-08-16 17:47:44 -0400213
214 struct nr_param nr_param;
215 bool nr_update;
Terence Hampsonc4aa4c02012-08-31 04:49:21 -0400216 struct vcap_debugfs_params dbg_p;
Terence Hampsona6914ca2012-04-09 14:06:50 -0400217};
218
219struct vp_format_data {
220 unsigned int width, height;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400221 unsigned int pixfmt;
Terence Hampsona6914ca2012-04-09 14:06:50 -0400222};
223
224struct vcap_buffer {
225 /* common v4l buffer stuff -- must be first */
226 struct vb2_buffer vb;
227 struct list_head list;
228 unsigned long paddr;
229 struct ion_handle *ion_handle;
230};
231
232struct vcap_client_data {
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400233 bool set_cap, set_decode, set_vp_o;
Terence Hampsona6914ca2012-04-09 14:06:50 -0400234 struct vcap_dev *dev;
235
236 struct vb2_queue vc_vidq;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400237 struct vb2_queue vp_in_vidq;
238 struct vb2_queue vp_out_vidq;
239
240 enum vcap_op_mode op_mode;
Terence Hampsona6914ca2012-04-09 14:06:50 -0400241
242 struct v4l2_format_vc_ext vc_format;
243
244 enum v4l2_buf_type vp_buf_type_field;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400245 struct vp_format_data vp_in_fmt;
246 struct vp_format_data vp_out_fmt;
Terence Hampsona6914ca2012-04-09 14:06:50 -0400247
Terence Hampson2cba63f2012-08-21 10:54:38 -0400248 struct vc_action vc_action;
249 struct vp_action vp_action;
Terence Hampsona6914ca2012-04-09 14:06:50 -0400250 struct workqueue_struct *vcap_work_q;
251 struct ion_handle *vc_ion_handle;
252
253 uint32_t hold_vc;
254 uint32_t hold_vp;
255
256 spinlock_t cap_slock;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400257 bool streaming;
Terence Hampson98d11802012-06-06 18:18:43 -0400258
259 struct v4l2_fh vfh;
Terence Hampsona6914ca2012-04-09 14:06:50 -0400260};
261
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400262struct vcap_hacked_vals {
263 uint32_t value;
264 uint32_t offset;
265};
266
267extern struct vcap_hacked_vals hacked_buf[];
268
Terence Hampsona6914ca2012-04-09 14:06:50 -0400269#endif
Terence Hampsona6c96482012-07-06 17:53:09 -0400270int vcvp_qbuf(struct vb2_queue *q, struct v4l2_buffer *b);
271int vcvp_dqbuf(struct vb2_queue *q, struct v4l2_buffer *b);
Terence Hampsona6914ca2012-04-09 14:06:50 -0400272#endif