blob: 374e681318fa6af8cd7f0119577cbc7a49eb4181 [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>
31
Terence Hampsonaeb793e2012-05-11 11:41:16 -040032#define writel_iowmb(val, addr) \
33 do { \
34 __iowmb(); \
35 writel_relaxed(val, addr); \
36 } while (0)
37
Terence Hampsona6914ca2012-04-09 14:06:50 -040038struct vcap_client_data;
39
40enum rdy_buf {
41 VC_NO_BUF = 0,
42 VC_BUF1 = 1 << 1,
43 VC_BUF2 = 1 << 2,
44 VC_BUF1N2 = 0x11 << 1,
45};
46
Terence Hampsonaeb793e2012-05-11 11:41:16 -040047enum vp_state {
48 VP_UNKNOWN = 0,
49 VP_FRAME1,
50 VP_FRAME2,
51 VP_FRAME3,
52 VP_NORMAL,
53};
54
55enum nr_buf_pos {
56 BUF_NOT_IN_USE = 0,
57 NRT2_BUF,
58 T1_BUF,
59 T0_BUF,
60 TM1_BUF,
61};
62
Terence Hampsona6914ca2012-04-09 14:06:50 -040063struct vcap_buf_info {
64 unsigned long vaddr;
65 unsigned long size;
66};
67
Terence Hampsonaeb793e2012-05-11 11:41:16 -040068enum vcap_op_mode {
69 UNKNOWN_VCAP_OP = 0,
70 VC_VCAP_OP,
71 VP_VCAP_OP,
72 VC_AND_VP_VCAP_OP,
73};
74
Terence Hampsona6914ca2012-04-09 14:06:50 -040075struct vcap_action {
76 struct list_head active;
77
78 /* thread for generating video stream*/
79 struct task_struct *kthread;
80 wait_queue_head_t wq;
81
82 /* Buffer index */
83 enum rdy_buf buf_ind;
84
85 /* Buffers inside vc */
86 struct vcap_buffer *buf1;
87 struct vcap_buffer *buf2;
88
89 /* Counters to control fps rate */
90 int frame;
91 int ini_jiffies;
92};
93
Terence Hampsonaeb793e2012-05-11 11:41:16 -040094struct nr_buffer {
95 void *vaddr;
96 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
119 void *bufMotion;
120 struct nr_buffer bufNR;
121 bool nr_enabled;
122};
123
124struct vp_work_t {
125 struct work_struct work;
126 struct vcap_client_data *cd;
127 uint32_t irq;
128};
129
Terence Hampsona6914ca2012-04-09 14:06:50 -0400130struct vcap_dev {
131 struct v4l2_device v4l2_dev;
132
133 struct video_device *vfd;
134 struct ion_client *ion_client;
135
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400136 struct resource *vcirq;
137 struct resource *vpirq;
Terence Hampsona6914ca2012-04-09 14:06:50 -0400138
139 struct resource *vcapmem;
140 struct resource *vcapio;
141 void __iomem *vcapbase;
142
143 struct vcap_platform_data *vcap_pdata;
144
145 struct regulator *fs_vcap;
146 struct clk *vcap_clk;
147 struct clk *vcap_p_clk;
148 struct clk *vcap_npl_clk;
149 /*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 Hampsona6914ca2012-04-09 14:06:50 -0400159 atomic_t vc_resource;
160 atomic_t vp_resource;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400161
162 struct workqueue_struct *vcap_wq;
163 struct vp_work_t vp_work;
164 struct vp_work_t vc_to_vp_work;
165 struct vp_work_t vp_to_vc_work;
Terence Hampsona6914ca2012-04-09 14:06:50 -0400166};
167
168struct vp_format_data {
169 unsigned int width, height;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400170 unsigned int pixfmt;
Terence Hampsona6914ca2012-04-09 14:06:50 -0400171};
172
173struct vcap_buffer {
174 /* common v4l buffer stuff -- must be first */
175 struct vb2_buffer vb;
176 struct list_head list;
177 unsigned long paddr;
178 struct ion_handle *ion_handle;
179};
180
181struct vcap_client_data {
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400182 bool set_cap, set_decode, set_vp_o;
Terence Hampsona6914ca2012-04-09 14:06:50 -0400183 struct vcap_dev *dev;
184
185 struct vb2_queue vc_vidq;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400186 struct vb2_queue vp_in_vidq;
187 struct vb2_queue vp_out_vidq;
188
189 enum vcap_op_mode op_mode;
Terence Hampsona6914ca2012-04-09 14:06:50 -0400190
191 struct v4l2_format_vc_ext vc_format;
192
193 enum v4l2_buf_type vp_buf_type_field;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400194 struct vp_format_data vp_in_fmt;
195 struct vp_format_data vp_out_fmt;
Terence Hampsona6914ca2012-04-09 14:06:50 -0400196
197 struct vcap_action vid_vc_action;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400198 struct vp_action vid_vp_action;
Terence Hampsona6914ca2012-04-09 14:06:50 -0400199 struct workqueue_struct *vcap_work_q;
200 struct ion_handle *vc_ion_handle;
201
202 uint32_t hold_vc;
203 uint32_t hold_vp;
204
205 spinlock_t cap_slock;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400206 bool streaming;
Terence Hampsona6914ca2012-04-09 14:06:50 -0400207};
208
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400209struct vcap_hacked_vals {
210 uint32_t value;
211 uint32_t offset;
212};
213
214extern struct vcap_hacked_vals hacked_buf[];
215
Terence Hampsona6914ca2012-04-09 14:06:50 -0400216#endif
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400217int free_ion_handle(struct vcap_dev *dev, struct vb2_queue *q,
218 struct v4l2_buffer *b);
219
220int get_phys_addr(struct vcap_dev *dev, struct vb2_queue *q,
221 struct v4l2_buffer *b);
Terence Hampsona6914ca2012-04-09 14:06:50 -0400222#endif