blob: e1d69d544a99d7cd3463e225b9d3c960ba381a1b [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 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 Hampsona6914ca2012-04-09 14:06:50 -040040struct vcap_client_data;
41
42enum rdy_buf {
43 VC_NO_BUF = 0,
44 VC_BUF1 = 1 << 1,
45 VC_BUF2 = 1 << 2,
46 VC_BUF1N2 = 0x11 << 1,
47};
48
Terence Hampsonaeb793e2012-05-11 11:41:16 -040049enum vp_state {
50 VP_UNKNOWN = 0,
51 VP_FRAME1,
52 VP_FRAME2,
53 VP_FRAME3,
54 VP_NORMAL,
55};
56
57enum nr_buf_pos {
58 BUF_NOT_IN_USE = 0,
59 NRT2_BUF,
60 T1_BUF,
61 T0_BUF,
62 TM1_BUF,
63};
64
Terence Hampsona6914ca2012-04-09 14:06:50 -040065struct vcap_buf_info {
66 unsigned long vaddr;
67 unsigned long size;
68};
69
Terence Hampsonaeb793e2012-05-11 11:41:16 -040070enum vcap_op_mode {
71 UNKNOWN_VCAP_OP = 0,
72 VC_VCAP_OP,
73 VP_VCAP_OP,
74 VC_AND_VP_VCAP_OP,
75};
76
Terence Hampsona6914ca2012-04-09 14:06:50 -040077struct vcap_action {
78 struct list_head active;
79
80 /* thread for generating video stream*/
81 struct task_struct *kthread;
82 wait_queue_head_t wq;
83
84 /* Buffer index */
85 enum rdy_buf buf_ind;
86
87 /* Buffers inside vc */
88 struct vcap_buffer *buf1;
89 struct vcap_buffer *buf2;
90
91 /* Counters to control fps rate */
92 int frame;
93 int ini_jiffies;
94};
95
Terence Hampsonaeb793e2012-05-11 11:41:16 -040096struct nr_buffer {
97 void *vaddr;
98 unsigned long paddr;
99 enum nr_buf_pos nr_pos;
100};
101
102struct vp_action {
103 struct list_head in_active;
104 struct list_head out_active;
105
106 /* Buffer index */
107 enum vp_state vp_state;
108#ifdef TOP_FIELD_FIX
109 bool top_field;
110#endif
111
112 /* Buffers inside vc */
113 struct vcap_buffer *bufTm1;
114 struct vcap_buffer *bufT0;
115 struct vcap_buffer *bufT1;
116 struct vcap_buffer *bufT2;
117 struct vcap_buffer *bufNRT2;
118
119 struct vcap_buffer *bufOut;
120
121 void *bufMotion;
122 struct nr_buffer bufNR;
123 bool nr_enabled;
124};
125
126struct vp_work_t {
127 struct work_struct work;
128 struct vcap_client_data *cd;
129 uint32_t irq;
130};
131
Terence Hampsona6914ca2012-04-09 14:06:50 -0400132struct vcap_dev {
133 struct v4l2_device v4l2_dev;
134
135 struct video_device *vfd;
136 struct ion_client *ion_client;
137
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400138 struct resource *vcirq;
139 struct resource *vpirq;
Terence Hampsona6914ca2012-04-09 14:06:50 -0400140
141 struct resource *vcapmem;
142 struct resource *vcapio;
143 void __iomem *vcapbase;
144
145 struct vcap_platform_data *vcap_pdata;
146
147 struct regulator *fs_vcap;
148 struct clk *vcap_clk;
149 struct clk *vcap_p_clk;
150 struct clk *vcap_npl_clk;
Terence Hampson779dc762012-06-07 15:59:27 -0400151 struct device *ddev;
Terence Hampsona6914ca2012-04-09 14:06:50 -0400152 /*struct platform_device *pdev;*/
153
154 uint32_t bus_client_handle;
155
156 struct vcap_client_data *vc_client;
157 struct vcap_client_data *vp_client;
158
159 atomic_t vc_enabled;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400160 atomic_t vp_enabled;
161
Terence Hampson779dc762012-06-07 15:59:27 -0400162 spinlock_t dev_slock;
163 atomic_t open_clients;
164 bool vc_resource;
165 bool vp_resource;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400166
167 struct workqueue_struct *vcap_wq;
168 struct vp_work_t vp_work;
169 struct vp_work_t vc_to_vp_work;
170 struct vp_work_t vp_to_vc_work;
Terence Hampsona6914ca2012-04-09 14:06:50 -0400171};
172
173struct vp_format_data {
174 unsigned int width, height;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400175 unsigned int pixfmt;
Terence Hampsona6914ca2012-04-09 14:06:50 -0400176};
177
178struct vcap_buffer {
179 /* common v4l buffer stuff -- must be first */
180 struct vb2_buffer vb;
181 struct list_head list;
182 unsigned long paddr;
183 struct ion_handle *ion_handle;
184};
185
186struct vcap_client_data {
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400187 bool set_cap, set_decode, set_vp_o;
Terence Hampsona6914ca2012-04-09 14:06:50 -0400188 struct vcap_dev *dev;
189
190 struct vb2_queue vc_vidq;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400191 struct vb2_queue vp_in_vidq;
192 struct vb2_queue vp_out_vidq;
193
194 enum vcap_op_mode op_mode;
Terence Hampsona6914ca2012-04-09 14:06:50 -0400195
196 struct v4l2_format_vc_ext vc_format;
197
198 enum v4l2_buf_type vp_buf_type_field;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400199 struct vp_format_data vp_in_fmt;
200 struct vp_format_data vp_out_fmt;
Terence Hampsona6914ca2012-04-09 14:06:50 -0400201
202 struct vcap_action vid_vc_action;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400203 struct vp_action vid_vp_action;
Terence Hampsona6914ca2012-04-09 14:06:50 -0400204 struct workqueue_struct *vcap_work_q;
205 struct ion_handle *vc_ion_handle;
206
207 uint32_t hold_vc;
208 uint32_t hold_vp;
209
210 spinlock_t cap_slock;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400211 bool streaming;
Terence Hampson98d11802012-06-06 18:18:43 -0400212
213 struct v4l2_fh vfh;
Terence Hampsona6914ca2012-04-09 14:06:50 -0400214};
215
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400216struct vcap_hacked_vals {
217 uint32_t value;
218 uint32_t offset;
219};
220
221extern struct vcap_hacked_vals hacked_buf[];
222
Terence Hampsona6914ca2012-04-09 14:06:50 -0400223#endif
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400224int free_ion_handle(struct vcap_dev *dev, struct vb2_queue *q,
225 struct v4l2_buffer *b);
226
227int get_phys_addr(struct vcap_dev *dev, struct vb2_queue *q,
228 struct v4l2_buffer *b);
Terence Hampsona6c96482012-07-06 17:53:09 -0400229
230int vcvp_qbuf(struct vb2_queue *q, struct v4l2_buffer *b);
231int vcvp_dqbuf(struct vb2_queue *q, struct v4l2_buffer *b);
232
Terence Hampsona6914ca2012-04-09 14:06:50 -0400233#endif