blob: 7b6d817725102e7c71b21a6c8e3385533c9443cd [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 Hampsona1e8af42012-09-18 16:41:57 -040041#define VCAP_USEC (1000000)
Terence Hampsonb128b982012-08-16 14:41:19 -040042#define VCAP_BASE (dev->vcapbase)
43#define VCAP_OFFSET(off) (VCAP_BASE + off)
44
45#define VCAP_SW_RESET_REQ (VCAP_BASE + 0x024)
46#define VCAP_SW_RESET_STATUS (VCAP_BASE + 0x028)
47
Terence Hampson2cba63f2012-08-21 10:54:38 -040048#define VCAP_VP_MIN_BUF 4
49#define VCAP_VC_MAX_BUF 6
50#define VCAP_VC_MIN_BUF 2
Terence Hampsona6914ca2012-04-09 14:06:50 -040051struct vcap_client_data;
52
Terence Hampsonaeb793e2012-05-11 11:41:16 -040053enum vp_state {
54 VP_UNKNOWN = 0,
55 VP_FRAME1,
56 VP_FRAME2,
57 VP_FRAME3,
58 VP_NORMAL,
59};
60
61enum nr_buf_pos {
62 BUF_NOT_IN_USE = 0,
63 NRT2_BUF,
64 T1_BUF,
65 T0_BUF,
66 TM1_BUF,
67};
68
Terence Hampsona6914ca2012-04-09 14:06:50 -040069struct vcap_buf_info {
70 unsigned long vaddr;
71 unsigned long size;
72};
73
Terence Hampsonaeb793e2012-05-11 11:41:16 -040074enum vcap_op_mode {
75 UNKNOWN_VCAP_OP = 0,
76 VC_VCAP_OP,
77 VP_VCAP_OP,
78 VC_AND_VP_VCAP_OP,
79};
80
Terence Hampson2cba63f2012-08-21 10:54:38 -040081struct vc_action {
Terence Hampsona6914ca2012-04-09 14:06:50 -040082 struct list_head active;
83
84 /* thread for generating video stream*/
Terence Hampsona6914ca2012-04-09 14:06:50 -040085 wait_queue_head_t wq;
86
87 /* Buffer index */
Terence Hampson2cba63f2012-08-21 10:54:38 -040088 uint8_t tot_buf;
89 uint8_t buf_num;
Terence Hampsona6914ca2012-04-09 14:06:50 -040090
Terence Hampsona1e8af42012-09-18 16:41:57 -040091 struct timeval vc_ts;
92 uint32_t last_ts;
93
Terence Hampsona6914ca2012-04-09 14:06:50 -040094 /* Buffers inside vc */
Terence Hampson2cba63f2012-08-21 10:54:38 -040095 struct vcap_buffer *buf[6];
Terence Hampsona6914ca2012-04-09 14:06:50 -040096};
97
Terence Hampsonaeb793e2012-05-11 11:41:16 -040098struct nr_buffer {
Terence Hampsona2cba0d2012-08-08 11:39:53 -040099 struct ion_handle *nr_handle;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400100 unsigned long paddr;
101 enum nr_buf_pos nr_pos;
102};
103
104struct vp_action {
105 struct list_head in_active;
106 struct list_head out_active;
107
108 /* Buffer index */
109 enum vp_state vp_state;
110#ifdef TOP_FIELD_FIX
111 bool top_field;
112#endif
113
114 /* Buffers inside vc */
115 struct vcap_buffer *bufTm1;
116 struct vcap_buffer *bufT0;
117 struct vcap_buffer *bufT1;
118 struct vcap_buffer *bufT2;
119 struct vcap_buffer *bufNRT2;
120
121 struct vcap_buffer *bufOut;
122
Terence Hampsona2cba0d2012-08-08 11:39:53 -0400123 struct ion_handle *motionHandle;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400124 void *bufMotion;
125 struct nr_buffer bufNR;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400126};
127
128struct vp_work_t {
129 struct work_struct work;
130 struct vcap_client_data *cd;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400131};
132
Terence Hampsona6914ca2012-04-09 14:06:50 -0400133struct vcap_dev {
134 struct v4l2_device v4l2_dev;
135
136 struct video_device *vfd;
137 struct ion_client *ion_client;
138
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400139 struct resource *vcirq;
140 struct resource *vpirq;
Terence Hampsona6914ca2012-04-09 14:06:50 -0400141
142 struct resource *vcapmem;
143 struct resource *vcapio;
144 void __iomem *vcapbase;
145
146 struct vcap_platform_data *vcap_pdata;
147
148 struct regulator *fs_vcap;
149 struct clk *vcap_clk;
150 struct clk *vcap_p_clk;
151 struct clk *vcap_npl_clk;
Terence Hampson779dc762012-06-07 15:59:27 -0400152 struct device *ddev;
Terence Hampsona6914ca2012-04-09 14:06:50 -0400153 /*struct platform_device *pdev;*/
154
155 uint32_t bus_client_handle;
156
157 struct vcap_client_data *vc_client;
158 struct vcap_client_data *vp_client;
159
160 atomic_t vc_enabled;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400161 atomic_t vp_enabled;
162
Terence Hampson54d3a6d2012-07-10 14:05:35 -0400163 struct mutex dev_mutex;
Terence Hampson779dc762012-06-07 15:59:27 -0400164 atomic_t open_clients;
165 bool vc_resource;
166 bool vp_resource;
Terence Hampson54d3a6d2012-07-10 14:05:35 -0400167 bool vp_dummy_event;
168 bool vp_dummy_complete;
Terence Hampsonb128b982012-08-16 14:41:19 -0400169 bool vp_shutdown;
Terence Hampson54d3a6d2012-07-10 14:05:35 -0400170 wait_queue_head_t vp_dummy_waitq;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400171
Terence Hampson2cba63f2012-08-21 10:54:38 -0400172 uint8_t vc_tot_buf;
173
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400174 struct workqueue_struct *vcap_wq;
175 struct vp_work_t vp_work;
176 struct vp_work_t vc_to_vp_work;
177 struct vp_work_t vp_to_vc_work;
Terence Hampson616762d2012-08-16 17:47:44 -0400178
179 struct nr_param nr_param;
180 bool nr_update;
Terence Hampsona6914ca2012-04-09 14:06:50 -0400181};
182
183struct vp_format_data {
184 unsigned int width, height;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400185 unsigned int pixfmt;
Terence Hampsona6914ca2012-04-09 14:06:50 -0400186};
187
188struct vcap_buffer {
189 /* common v4l buffer stuff -- must be first */
190 struct vb2_buffer vb;
191 struct list_head list;
192 unsigned long paddr;
193 struct ion_handle *ion_handle;
194};
195
196struct vcap_client_data {
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400197 bool set_cap, set_decode, set_vp_o;
Terence Hampsona6914ca2012-04-09 14:06:50 -0400198 struct vcap_dev *dev;
199
200 struct vb2_queue vc_vidq;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400201 struct vb2_queue vp_in_vidq;
202 struct vb2_queue vp_out_vidq;
203
204 enum vcap_op_mode op_mode;
Terence Hampsona6914ca2012-04-09 14:06:50 -0400205
206 struct v4l2_format_vc_ext vc_format;
207
208 enum v4l2_buf_type vp_buf_type_field;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400209 struct vp_format_data vp_in_fmt;
210 struct vp_format_data vp_out_fmt;
Terence Hampsona6914ca2012-04-09 14:06:50 -0400211
Terence Hampson2cba63f2012-08-21 10:54:38 -0400212 struct vc_action vc_action;
213 struct vp_action vp_action;
Terence Hampsona6914ca2012-04-09 14:06:50 -0400214 struct workqueue_struct *vcap_work_q;
215 struct ion_handle *vc_ion_handle;
216
217 uint32_t hold_vc;
218 uint32_t hold_vp;
219
220 spinlock_t cap_slock;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400221 bool streaming;
Terence Hampson98d11802012-06-06 18:18:43 -0400222
223 struct v4l2_fh vfh;
Terence Hampsona6914ca2012-04-09 14:06:50 -0400224};
225
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400226struct vcap_hacked_vals {
227 uint32_t value;
228 uint32_t offset;
229};
230
231extern struct vcap_hacked_vals hacked_buf[];
232
Terence Hampsona6914ca2012-04-09 14:06:50 -0400233#endif
Terence Hampsona6c96482012-07-06 17:53:09 -0400234int vcvp_qbuf(struct vb2_queue *q, struct v4l2_buffer *b);
235int vcvp_dqbuf(struct vb2_queue *q, struct v4l2_buffer *b);
Terence Hampsona6914ca2012-04-09 14:06:50 -0400236#endif