blob: a017cf26fce7912bab3c3689ba9e800774b22181 [file] [log] [blame]
Terence Hampsonaeb793e2012-05-11 11:41:16 -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#include <linux/kernel.h>
14#include <linux/init.h>
15#include <linux/sched.h>
16#include <linux/kthread.h>
17#include <linux/freezer.h>
18#include <mach/camera.h>
19#include <linux/io.h>
20#include <mach/clk.h>
21#include <linux/clk.h>
22
Terence Hampson98d11802012-06-06 18:18:43 -040023#include <media/v4l2-event.h>
Terence Hampsonaeb793e2012-05-11 11:41:16 -040024#include <media/vcap_v4l2.h>
25#include <media/vcap_fmt.h>
26#include "vcap_vp.h"
27
28static unsigned debug;
29
30#define dprintk(level, fmt, arg...) \
31 do { \
32 if (debug >= level) \
33 printk(KERN_DEBUG "VP: " fmt, ## arg); \
34 } while (0)
35
36void config_nr_buffer(struct vcap_client_data *c_data,
37 struct vcap_buffer *buf)
38{
39 struct vcap_dev *dev = c_data->dev;
40 int size = c_data->vp_in_fmt.height * c_data->vp_in_fmt.width;
41
42 writel_relaxed(buf->paddr, VCAP_VP_NR_T2_Y_BASE_ADDR);
43 writel_relaxed(buf->paddr + size, VCAP_VP_NR_T2_C_BASE_ADDR);
44}
45
46void config_in_buffer(struct vcap_client_data *c_data,
47 struct vcap_buffer *buf)
48{
49 struct vcap_dev *dev = c_data->dev;
50 int size = c_data->vp_in_fmt.height * c_data->vp_in_fmt.width;
51
52 writel_relaxed(buf->paddr, VCAP_VP_T2_Y_BASE_ADDR);
53 writel_relaxed(buf->paddr + size, VCAP_VP_T2_C_BASE_ADDR);
54}
55
56void config_out_buffer(struct vcap_client_data *c_data,
57 struct vcap_buffer *buf)
58{
59 struct vcap_dev *dev = c_data->dev;
60 int size;
61 size = c_data->vp_out_fmt.height * c_data->vp_out_fmt.width;
62 writel_relaxed(buf->paddr, VCAP_VP_OUT_Y_BASE_ADDR);
63 writel_relaxed(buf->paddr + size, VCAP_VP_OUT_C_BASE_ADDR);
64}
65
66int vp_setup_buffers(struct vcap_client_data *c_data)
67{
68 struct vp_action *vp_act;
69 struct vcap_dev *dev;
70 unsigned long flags = 0;
71
72 if (!c_data->streaming)
73 return -ENOEXEC;
74 dev = c_data->dev;
75 dprintk(2, "Start setup buffers\n");
76
Terence Hampsonb128b982012-08-16 14:41:19 -040077 if (dev->vp_shutdown) {
78 dprintk(1, "%s: VP shutting down, no buf setup\n",
79 __func__);
80 return -EPERM;
81 }
82
Terence Hampsonaeb793e2012-05-11 11:41:16 -040083 /* No need to verify vp_client is not NULL caller does so */
Terence Hampson2cba63f2012-08-21 10:54:38 -040084 vp_act = &dev->vp_client->vp_action;
Terence Hampsonaeb793e2012-05-11 11:41:16 -040085
86 spin_lock_irqsave(&dev->vp_client->cap_slock, flags);
87 if (list_empty(&vp_act->in_active)) {
88 spin_unlock_irqrestore(&dev->vp_client->cap_slock, flags);
89 dprintk(1, "%s: VP We have no more input buffers\n",
90 __func__);
91 return -EAGAIN;
92 }
93
94 if (list_empty(&vp_act->out_active)) {
95 spin_unlock_irqrestore(&dev->vp_client->cap_slock,
96 flags);
97 dprintk(1, "%s: VP We have no more output buffers\n",
98 __func__);
99 return -EAGAIN;
100 }
101
102 vp_act->bufT2 = list_entry(vp_act->in_active.next,
103 struct vcap_buffer, list);
104 list_del(&vp_act->bufT2->list);
105
106 vp_act->bufOut = list_entry(vp_act->out_active.next,
107 struct vcap_buffer, list);
108 list_del(&vp_act->bufOut->list);
109 spin_unlock_irqrestore(&dev->vp_client->cap_slock, flags);
110
111 config_in_buffer(c_data, vp_act->bufT2);
112 config_out_buffer(c_data, vp_act->bufOut);
113 return 0;
114}
115
116static void mov_buf_to_vc(struct work_struct *work)
117{
118 struct vp_work_t *vp_work = container_of(work, struct vp_work_t, work);
119 struct v4l2_buffer p;
120 struct vb2_buffer *vb_vc;
121 struct vcap_buffer *buf_vc;
122 struct vb2_buffer *vb_vp;
123 struct vcap_buffer *buf_vp;
124 int rc;
125
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400126 p.memory = V4L2_MEMORY_USERPTR;
127
128 /* This loop exits when there is no more buffers left */
129 while (1) {
Terence Hampsona6c96482012-07-06 17:53:09 -0400130 p.type = V4L2_BUF_TYPE_INTERLACED_IN_DECODER;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400131 if (!vp_work->cd->streaming)
132 return;
Terence Hampsona6c96482012-07-06 17:53:09 -0400133 rc = vcvp_dqbuf(&vp_work->cd->vp_in_vidq, &p);
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400134 if (rc < 0)
135 return;
136
137 vb_vc = vp_work->cd->vc_vidq.bufs[p.index];
138 if (NULL == vb_vc) {
139 dprintk(1, "%s: buffer is NULL\n", __func__);
Terence Hampsona6c96482012-07-06 17:53:09 -0400140 vcvp_qbuf(&vp_work->cd->vp_in_vidq, &p);
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400141 return;
142 }
143 buf_vc = container_of(vb_vc, struct vcap_buffer, vb);
144
145 vb_vp = vp_work->cd->vp_in_vidq.bufs[p.index];
146 if (NULL == vb_vp) {
147 dprintk(1, "%s: buffer is NULL\n", __func__);
Terence Hampsona6c96482012-07-06 17:53:09 -0400148 vcvp_qbuf(&vp_work->cd->vp_in_vidq, &p);
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400149 return;
150 }
151 buf_vp = container_of(vb_vp, struct vcap_buffer, vb);
152 buf_vc->ion_handle = buf_vp->ion_handle;
153 buf_vc->paddr = buf_vp->paddr;
154 buf_vp->ion_handle = NULL;
155 buf_vp->paddr = 0;
156
157 p.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
158 /* This call should not fail */
Terence Hampsona6c96482012-07-06 17:53:09 -0400159 rc = vcvp_qbuf(&vp_work->cd->vc_vidq, &p);
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400160 if (rc < 0) {
161 dprintk(1, "%s: qbuf to vc failed\n", __func__);
162 buf_vp->ion_handle = buf_vc->ion_handle;
163 buf_vp->paddr = buf_vc->paddr;
164 buf_vc->ion_handle = NULL;
165 buf_vc->paddr = 0;
166 p.type = V4L2_BUF_TYPE_INTERLACED_IN_DECODER;
Terence Hampsona6c96482012-07-06 17:53:09 -0400167 vcvp_qbuf(&vp_work->cd->vp_in_vidq, &p);
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400168 }
169 }
170}
171
Terence Hampson616762d2012-08-16 17:47:44 -0400172void update_nr_value(struct vcap_dev *dev)
Terence Hampson3dff4ef2012-06-13 15:20:59 -0400173{
Terence Hampson3dff4ef2012-06-13 15:20:59 -0400174 struct nr_param *par;
Terence Hampson616762d2012-08-16 17:47:44 -0400175 par = &dev->nr_param;
Terence Hampson3dff4ef2012-06-13 15:20:59 -0400176 if (par->mode == NR_MANUAL) {
177 writel_relaxed(par->window << 24 | par->decay_ratio << 20,
178 VCAP_VP_NR_CONFIG);
179 writel_relaxed(par->luma.max_blend_ratio << 24 |
180 par->luma.scale_diff_ratio << 12 |
181 par->luma.diff_limit_ratio << 8 |
182 par->luma.scale_motion_ratio << 4 |
183 par->luma.blend_limit_ratio << 0,
184 VCAP_VP_NR_LUMA_CONFIG);
185 writel_relaxed(par->chroma.max_blend_ratio << 24 |
186 par->chroma.scale_diff_ratio << 12 |
187 par->chroma.diff_limit_ratio << 8 |
188 par->chroma.scale_motion_ratio << 4 |
189 par->chroma.blend_limit_ratio << 0,
190 VCAP_VP_NR_CHROMA_CONFIG);
191 }
Terence Hampson616762d2012-08-16 17:47:44 -0400192 dev->nr_update = false;
Terence Hampson3dff4ef2012-06-13 15:20:59 -0400193}
194
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400195static void vp_wq_fnc(struct work_struct *work)
196{
197 struct vp_work_t *vp_work = container_of(work, struct vp_work_t, work);
198 struct vcap_dev *dev;
199 struct vp_action *vp_act;
Terence Hampson3dff4ef2012-06-13 15:20:59 -0400200 unsigned long flags = 0;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400201 uint32_t irq;
202 int rc;
Terence Hampson9c4f8a22012-09-12 10:25:50 -0400203 bool top_field = 0;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400204
205 if (vp_work && vp_work->cd && vp_work->cd->dev)
206 dev = vp_work->cd->dev;
207 else
208 return;
209
Terence Hampson2cba63f2012-08-21 10:54:38 -0400210 vp_act = &dev->vp_client->vp_action;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400211
212 rc = readl_relaxed(VCAP_OFFSET(0x048));
213 while (!(rc & 0x00000100))
214 rc = readl_relaxed(VCAP_OFFSET(0x048));
215
Terence Hampsonad33c512012-07-16 17:50:00 -0400216 irq = readl_relaxed(VCAP_VP_INT_STATUS);
217
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400218 writel_relaxed(0x00000000, VCAP_VP_BAL_VMOTION_STATE);
219 writel_relaxed(0x40000000, VCAP_VP_REDUCT_AVG_MOTION2);
220
Terence Hampson3dff4ef2012-06-13 15:20:59 -0400221 spin_lock_irqsave(&dev->vp_client->cap_slock, flags);
Terence Hampson616762d2012-08-16 17:47:44 -0400222 if (dev->nr_update == true)
223 update_nr_value(dev);
Terence Hampson3dff4ef2012-06-13 15:20:59 -0400224 spin_unlock_irqrestore(&dev->vp_client->cap_slock, flags);
225
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400226 /* Queue the done buffers */
227 if (vp_act->vp_state == VP_NORMAL &&
228 vp_act->bufNR.nr_pos != TM1_BUF) {
229 vb2_buffer_done(&vp_act->bufTm1->vb, VB2_BUF_STATE_DONE);
230 if (vp_work->cd->op_mode == VC_AND_VP_VCAP_OP)
231 queue_work(dev->vcap_wq, &dev->vp_to_vc_work.work);
232 }
233
Terence Hampson3af95c02012-09-18 16:43:38 -0400234 if (vp_act->bufT0 != NULL && vp_act->vp_state == VP_NORMAL) {
235 vp_act->bufOut->vb.v4l2_buf.timestamp =
236 vp_act->bufT0->vb.v4l2_buf.timestamp;
237 }
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400238 vb2_buffer_done(&vp_act->bufOut->vb, VB2_BUF_STATE_DONE);
239
240 /* Cycle to next state */
241 if (vp_act->vp_state != VP_NORMAL)
242 vp_act->vp_state++;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400243
244 /* Cycle Buffers*/
Terence Hampson616762d2012-08-16 17:47:44 -0400245 if (dev->nr_param.mode) {
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400246 if (vp_act->bufNR.nr_pos == TM1_BUF)
247 vp_act->bufNR.nr_pos = BUF_NOT_IN_USE;
248
249 if (vp_act->bufNR.nr_pos != BUF_NOT_IN_USE)
250 vp_act->bufNR.nr_pos++;
251
252 vp_act->bufTm1 = vp_act->bufT0;
253 vp_act->bufT0 = vp_act->bufT1;
254 vp_act->bufT1 = vp_act->bufNRT2;
255 vp_act->bufNRT2 = vp_act->bufT2;
256 config_nr_buffer(vp_work->cd, vp_act->bufNRT2);
257 } else {
258 vp_act->bufTm1 = vp_act->bufT0;
259 vp_act->bufT0 = vp_act->bufT1;
260 vp_act->bufT1 = vp_act->bufT2;
261 }
262
263 rc = vp_setup_buffers(vp_work->cd);
264 if (rc < 0) {
265 /* setup_buf failed because we are waiting for buffers */
266 writel_relaxed(0x00000000, VCAP_VP_INTERRUPT_ENABLE);
267 writel_iowmb(irq, VCAP_VP_INT_CLEAR);
268 atomic_set(&dev->vp_enabled, 0);
Terence Hampsonb128b982012-08-16 14:41:19 -0400269 if (dev->vp_shutdown)
270 wake_up(&dev->vp_dummy_waitq);
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400271 return;
272 }
273
274 /* Config VP */
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400275 if (vp_act->bufT2->vb.v4l2_buf.field == V4L2_FIELD_TOP)
276 top_field = 1;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400277
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400278 writel_iowmb(0x00000000 | top_field, VCAP_VP_CTRL);
Terence Hampsona2cba0d2012-08-08 11:39:53 -0400279 writel_iowmb(0x00010000 | top_field, VCAP_VP_CTRL);
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400280 enable_irq(dev->vpirq->start);
281 writel_iowmb(irq, VCAP_VP_INT_CLEAR);
282}
283
284irqreturn_t vp_handler(struct vcap_dev *dev)
285{
286 struct vcap_client_data *c_data;
287 struct vp_action *vp_act;
Terence Hampson98d11802012-06-06 18:18:43 -0400288 struct v4l2_event v4l2_evt;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400289 uint32_t irq;
290 int rc;
291
292 irq = readl_relaxed(VCAP_VP_INT_STATUS);
Terence Hampson54d3a6d2012-07-10 14:05:35 -0400293 if (dev->vp_dummy_event == true) {
294 writel_relaxed(irq, VCAP_VP_INT_CLEAR);
295 dev->vp_dummy_complete = true;
296 wake_up(&dev->vp_dummy_waitq);
297 return IRQ_HANDLED;
298 }
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400299
Terence Hampson98d11802012-06-06 18:18:43 -0400300 if (irq & 0x02000000) {
301 v4l2_evt.type = V4L2_EVENT_PRIVATE_START +
302 VCAP_VP_REG_R_ERR_EVENT;
303 v4l2_event_queue(dev->vfd, &v4l2_evt);
304 }
305 if (irq & 0x01000000) {
306 v4l2_evt.type = V4L2_EVENT_PRIVATE_START +
Terence Hampsonf3cd9a12012-09-21 11:18:02 -0400307 VCAP_VP_REG_W_ERR_EVENT;
Terence Hampson98d11802012-06-06 18:18:43 -0400308 v4l2_event_queue(dev->vfd, &v4l2_evt);
309 }
310 if (irq & 0x00020000) {
311 v4l2_evt.type = V4L2_EVENT_PRIVATE_START +
312 VCAP_VP_IN_HEIGHT_ERR_EVENT;
313 v4l2_event_queue(dev->vfd, &v4l2_evt);
314 }
315 if (irq & 0x00010000) {
316 v4l2_evt.type = V4L2_EVENT_PRIVATE_START +
317 VCAP_VP_IN_WIDTH_ERR_EVENT;
318 v4l2_event_queue(dev->vfd, &v4l2_evt);
319 }
320
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400321 dprintk(1, "%s: irq=0x%08x\n", __func__, irq);
Terence Hampson72452632012-08-13 12:32:24 -0400322 if (!(irq & (VP_PIC_DONE | VP_MODE_CHANGE))) {
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400323 writel_relaxed(irq, VCAP_VP_INT_CLEAR);
324 pr_err("VP IRQ shows some error\n");
325 return IRQ_HANDLED;
326 }
327
328 if (dev->vp_client == NULL) {
329 writel_relaxed(irq, VCAP_VP_INT_CLEAR);
330 pr_err("VC: There is no active vp client\n");
331 return IRQ_HANDLED;
332 }
333
Terence Hampson2cba63f2012-08-21 10:54:38 -0400334 vp_act = &dev->vp_client->vp_action;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400335 c_data = dev->vp_client;
336
337 if (vp_act->vp_state == VP_UNKNOWN) {
338 writel_relaxed(irq, VCAP_VP_INT_CLEAR);
339 pr_err("%s: VP is in an unknown state\n",
340 __func__);
341 return -EAGAIN;
342 }
343
344 INIT_WORK(&dev->vp_work.work, vp_wq_fnc);
345 dev->vp_work.cd = c_data;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400346 rc = queue_work(dev->vcap_wq, &dev->vp_work.work);
347
348 disable_irq_nosync(dev->vpirq->start);
349 return IRQ_HANDLED;
350}
351
Terence Hampsonb128b982012-08-16 14:41:19 -0400352int vp_sw_reset(struct vcap_dev *dev)
353{
354 int timeout;
355 writel_iowmb(0x00000010, VCAP_SW_RESET_REQ);
356 timeout = 10000;
357 while (1) {
358 if (!(readl_relaxed(VCAP_SW_RESET_STATUS) & 0x10))
359 break;
360 timeout--;
361 if (timeout == 0) {
362 /* This should not happen */
363 pr_err("VP is not resetting properly\n");
364 writel_iowmb(0x00000000, VCAP_SW_RESET_REQ);
365 return -EINVAL;
366 }
367 }
368 return 0;
369}
370
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400371void vp_stop_capture(struct vcap_client_data *c_data)
372{
373 struct vcap_dev *dev = c_data->dev;
Terence Hampsonb128b982012-08-16 14:41:19 -0400374 int rc;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400375
Terence Hampsonb128b982012-08-16 14:41:19 -0400376 dev->vp_shutdown = true;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400377 flush_workqueue(dev->vcap_wq);
378
Terence Hampsonb128b982012-08-16 14:41:19 -0400379 if (atomic_read(&dev->vp_enabled) == 1) {
380 rc = wait_event_interruptible_timeout(dev->vp_dummy_waitq,
381 !atomic_read(&dev->vp_enabled),
382 msecs_to_jiffies(50));
383 if (rc == 0 && atomic_read(&dev->vp_enabled) == 1) {
384 /* This should not happen, if it does hw is stuck */
385 pr_err("%s: VP Timeout and VP still running\n",
386 __func__);
387 }
388 }
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400389
Terence Hampsonb128b982012-08-16 14:41:19 -0400390 vp_sw_reset(dev);
391 dev->vp_shutdown = false;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400392}
393
394int config_vp_format(struct vcap_client_data *c_data)
395{
396 struct vcap_dev *dev = c_data->dev;
Terence Hampsonb128b982012-08-16 14:41:19 -0400397 int rc;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400398
399 INIT_WORK(&dev->vp_to_vc_work.work, mov_buf_to_vc);
400 dev->vp_to_vc_work.cd = c_data;
401
402 /* SW restart VP */
Terence Hampsonb128b982012-08-16 14:41:19 -0400403 rc = vp_sw_reset(dev);
404 if (rc < 0)
405 return rc;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400406
407 /* Film Mode related settings */
408 writel_iowmb(0x00000000, VCAP_VP_FILM_PROJECTION_T0);
409 writel_relaxed(0x00000000, VCAP_VP_FILM_PROJECTION_T2);
410 writel_relaxed(0x00000000, VCAP_VP_FILM_PAST_MAX_PROJ);
411 writel_relaxed(0x00000000, VCAP_VP_FILM_PAST_MIN_PROJ);
412 writel_relaxed(0x00000000, VCAP_VP_FILM_SEQUENCE_HIST);
413 writel_relaxed(0x00000000, VCAP_VP_FILM_MODE_STATE);
414
415 writel_relaxed(0x00000000, VCAP_VP_BAL_VMOTION_STATE);
416 writel_relaxed(0x00000010, VCAP_VP_REDUCT_AVG_MOTION);
417 writel_relaxed(0x40000000, VCAP_VP_REDUCT_AVG_MOTION2);
418 writel_relaxed(0x40000000, VCAP_VP_NR_AVG_LUMA);
419 writel_relaxed(0x40000000, VCAP_VP_NR_AVG_CHROMA);
420 writel_relaxed(0x40000000, VCAP_VP_NR_CTRL_LUMA);
421 writel_relaxed(0x40000000, VCAP_VP_NR_CTRL_CHROMA);
422 writel_relaxed(0x00000000, VCAP_VP_BAL_AVG_BLEND);
423 writel_relaxed(0x00000000, VCAP_VP_VMOTION_HIST);
424 writel_relaxed(0x05047D19, VCAP_VP_FILM_ANALYSIS_CONFIG);
425 writel_relaxed(0x20260200, VCAP_VP_FILM_STATE_CONFIG);
426 writel_relaxed(0x23A60114, VCAP_VP_FVM_CONFIG);
427 writel_relaxed(0x03043210, VCAP_VP_FILM_ANALYSIS_CONFIG2);
428 writel_relaxed(0x04DB7A51, VCAP_VP_MIXED_ANALYSIS_CONFIG);
429 writel_relaxed(0x14224916, VCAP_VP_SPATIAL_CONFIG);
430 writel_relaxed(0x83270400, VCAP_VP_SPATIAL_CONFIG2);
431 writel_relaxed(0x0F000F92, VCAP_VP_SPATIAL_CONFIG3);
432 writel_relaxed(0x00000000, VCAP_VP_TEMPORAL_CONFIG);
433 writel_relaxed(0x00000000, VCAP_VP_PIXEL_DIFF_CONFIG);
434 writel_relaxed(0x0C090511, VCAP_VP_H_FREQ_CONFIG);
435 writel_relaxed(0x0A000000, VCAP_VP_NR_CONFIG);
436 writel_relaxed(0x008F4149, VCAP_VP_NR_LUMA_CONFIG);
437 writel_relaxed(0x008F4149, VCAP_VP_NR_CHROMA_CONFIG);
438 writel_relaxed(0x43C0FD0C, VCAP_VP_BAL_CONFIG);
439 writel_relaxed(0x00000255, VCAP_VP_BAL_MOTION_CONFIG);
440 writel_relaxed(0x24154252, VCAP_VP_BAL_LIGHT_COMB);
441 writel_relaxed(0x10024414, VCAP_VP_BAL_VMOTION_CONFIG);
442 writel_relaxed(0x00000002, VCAP_VP_NR_CONFIG2);
443 writel_relaxed((c_data->vp_out_fmt.height-1)<<16 |
444 (c_data->vp_out_fmt.width - 1), VCAP_VP_FRAME_SIZE);
445 writel_relaxed(0x00000000, VCAP_VP_SPLIT_SCRN_CTRL);
446
447 return 0;
448}
449
450int init_motion_buf(struct vcap_client_data *c_data)
451{
Terence Hampsona2cba0d2012-08-08 11:39:53 -0400452 int rc;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400453 struct vcap_dev *dev = c_data->dev;
Terence Hampsona2cba0d2012-08-08 11:39:53 -0400454 struct ion_handle *handle = NULL;
455 unsigned long paddr, ionflag = 0;
456 void *vaddr;
457 size_t len;
458 size_t size = ((c_data->vp_out_fmt.width + 63) >> 6) *
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400459 ((c_data->vp_out_fmt.height + 7) >> 3) * 16;
460
Terence Hampson2cba63f2012-08-21 10:54:38 -0400461 if (c_data->vp_action.motionHandle) {
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400462 pr_err("Motion buffer has already been created");
463 return -ENOEXEC;
464 }
465
Terence Hampsona2cba0d2012-08-08 11:39:53 -0400466 handle = ion_alloc(dev->ion_client, size, SZ_4K,
Hanumant Singh7d72bad2012-08-29 18:39:44 -0700467 ION_HEAP(ION_CP_MM_HEAP_ID), 0);
Terence Hampsona2cba0d2012-08-08 11:39:53 -0400468 if (IS_ERR_OR_NULL(handle)) {
469 pr_err("%s: ion_alloc failed\n", __func__);
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400470 return -ENOMEM;
Terence Hampsona2cba0d2012-08-08 11:39:53 -0400471 }
472 rc = ion_phys(dev->ion_client, handle, &paddr, &len);
473 if (rc < 0) {
474 pr_err("%s: ion_phys failed\n", __func__);
475 ion_free(dev->ion_client, handle);
476 return rc;
477 }
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400478
Terence Hampsona2cba0d2012-08-08 11:39:53 -0400479 rc = ion_handle_get_flags(dev->ion_client, handle, &ionflag);
480 if (rc) {
481 pr_err("%s: get flags ion handle failed\n", __func__);
482 ion_free(dev->ion_client, handle);
483 return rc;
484 }
485
Mitchel Humpherys911b4b72012-09-12 14:42:50 -0700486 vaddr = ion_map_kernel(dev->ion_client, handle);
Terence Hampsona2cba0d2012-08-08 11:39:53 -0400487 if (IS_ERR(vaddr)) {
488 pr_err("%s: Map motion buffer failed\n", __func__);
489 ion_free(dev->ion_client, handle);
490 rc = -ENOMEM;
491 return rc;
492 }
493
494 memset(vaddr, 0, size);
Terence Hampson2cba63f2012-08-21 10:54:38 -0400495 c_data->vp_action.motionHandle = handle;
Terence Hampsona2cba0d2012-08-08 11:39:53 -0400496
497 vaddr = NULL;
498 ion_unmap_kernel(dev->ion_client, handle);
499
500 writel_iowmb(paddr, VCAP_VP_MOTION_EST_ADDR);
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400501 return 0;
502}
503
504void deinit_motion_buf(struct vcap_client_data *c_data)
505{
506 struct vcap_dev *dev = c_data->dev;
Terence Hampson2cba63f2012-08-21 10:54:38 -0400507 if (!c_data->vp_action.motionHandle) {
Terence Hampsonad33c512012-07-16 17:50:00 -0400508 pr_err("Motion buffer has not been created");
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400509 return;
510 }
511
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400512 writel_iowmb(0x00000000, VCAP_VP_MOTION_EST_ADDR);
Terence Hampson2cba63f2012-08-21 10:54:38 -0400513 ion_free(dev->ion_client, c_data->vp_action.motionHandle);
514 c_data->vp_action.motionHandle = NULL;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400515 return;
516}
517
518int init_nr_buf(struct vcap_client_data *c_data)
519{
520 struct vcap_dev *dev = c_data->dev;
Terence Hampsona2cba0d2012-08-08 11:39:53 -0400521 struct ion_handle *handle = NULL;
522 size_t frame_size, tot_size, len;
523 unsigned long paddr;
524 int rc;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400525
Terence Hampson2cba63f2012-08-21 10:54:38 -0400526 if (c_data->vp_action.bufNR.nr_handle) {
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400527 pr_err("NR buffer has already been created");
528 return -ENOEXEC;
529 }
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400530
531 frame_size = c_data->vp_in_fmt.width * c_data->vp_in_fmt.height;
532 if (c_data->vp_in_fmt.pixfmt == V4L2_PIX_FMT_NV16)
533 tot_size = frame_size * 2;
534 else
535 tot_size = frame_size / 2 * 3;
536
Terence Hampsona2cba0d2012-08-08 11:39:53 -0400537 handle = ion_alloc(dev->ion_client, tot_size, SZ_4K,
Hanumant Singh7d72bad2012-08-29 18:39:44 -0700538 ION_HEAP(ION_CP_MM_HEAP_ID), 0);
Terence Hampsona2cba0d2012-08-08 11:39:53 -0400539 if (IS_ERR_OR_NULL(handle)) {
540 pr_err("%s: ion_alloc failed\n", __func__);
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400541 return -ENOMEM;
Terence Hampsona2cba0d2012-08-08 11:39:53 -0400542 }
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400543
Terence Hampsona2cba0d2012-08-08 11:39:53 -0400544 rc = ion_phys(dev->ion_client, handle, &paddr, &len);
545 if (rc < 0) {
546 pr_err("%s: ion_phys failed\n", __func__);
547 ion_free(dev->ion_client, handle);
548 return rc;
549 }
550
Terence Hampson2cba63f2012-08-21 10:54:38 -0400551 c_data->vp_action.bufNR.nr_handle = handle;
Terence Hampson616762d2012-08-16 17:47:44 -0400552 update_nr_value(dev);
Terence Hampson3dff4ef2012-06-13 15:20:59 -0400553
Terence Hampson2cba63f2012-08-21 10:54:38 -0400554 c_data->vp_action.bufNR.paddr = paddr;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400555 rc = readl_relaxed(VCAP_VP_NR_CONFIG2);
Terence Hampsona2cba0d2012-08-08 11:39:53 -0400556 rc |= (((c_data->vp_out_fmt.width / 16) << 20) | 0x1);
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400557 writel_relaxed(rc, VCAP_VP_NR_CONFIG2);
Terence Hampsona2cba0d2012-08-08 11:39:53 -0400558 writel_relaxed(paddr, VCAP_VP_NR_T2_Y_BASE_ADDR);
559 writel_relaxed(paddr + frame_size, VCAP_VP_NR_T2_C_BASE_ADDR);
Terence Hampson2cba63f2012-08-21 10:54:38 -0400560 c_data->vp_action.bufNR.nr_pos = NRT2_BUF;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400561 return 0;
562}
563
564void deinit_nr_buf(struct vcap_client_data *c_data)
565{
566 struct vcap_dev *dev = c_data->dev;
567 struct nr_buffer *buf;
568 uint32_t rc;
569
Terence Hampson2cba63f2012-08-21 10:54:38 -0400570 if (!c_data->vp_action.bufNR.nr_handle) {
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400571 pr_err("NR buffer has not been created");
572 return;
573 }
Terence Hampson2cba63f2012-08-21 10:54:38 -0400574 buf = &c_data->vp_action.bufNR;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400575
576 rc = readl_relaxed(VCAP_VP_NR_CONFIG2);
Terence Hampsona2cba0d2012-08-08 11:39:53 -0400577 rc &= !(0x0FF00001);
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400578 writel_relaxed(rc, VCAP_VP_NR_CONFIG2);
579
Terence Hampsona2cba0d2012-08-08 11:39:53 -0400580 ion_free(dev->ion_client, buf->nr_handle);
581 buf->nr_handle = NULL;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400582 buf->paddr = 0;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400583 return;
584}
585
Terence Hampson3dff4ef2012-06-13 15:20:59 -0400586int nr_s_param(struct vcap_client_data *c_data, struct nr_param *param)
587{
588 if (param->mode != NR_MANUAL)
589 return 0;
590
591 /* Verify values in range */
Terence Hampson616762d2012-08-16 17:47:44 -0400592 if (param->window > VP_NR_MAX_WINDOW)
Terence Hampson3dff4ef2012-06-13 15:20:59 -0400593 return -EINVAL;
Terence Hampson616762d2012-08-16 17:47:44 -0400594 if (param->luma.max_blend_ratio > VP_NR_MAX_RATIO)
Terence Hampson3dff4ef2012-06-13 15:20:59 -0400595 return -EINVAL;
Terence Hampson616762d2012-08-16 17:47:44 -0400596 if (param->luma.scale_diff_ratio > VP_NR_MAX_RATIO)
Terence Hampson3dff4ef2012-06-13 15:20:59 -0400597 return -EINVAL;
Terence Hampson616762d2012-08-16 17:47:44 -0400598 if (param->luma.diff_limit_ratio > VP_NR_MAX_RATIO)
Terence Hampson3dff4ef2012-06-13 15:20:59 -0400599 return -EINVAL;
Terence Hampson616762d2012-08-16 17:47:44 -0400600 if (param->luma.scale_motion_ratio > VP_NR_MAX_RATIO)
Terence Hampson3dff4ef2012-06-13 15:20:59 -0400601 return -EINVAL;
Terence Hampson616762d2012-08-16 17:47:44 -0400602 if (param->luma.blend_limit_ratio > VP_NR_MAX_RATIO)
Terence Hampson3dff4ef2012-06-13 15:20:59 -0400603 return -EINVAL;
Terence Hampson616762d2012-08-16 17:47:44 -0400604 if (param->chroma.max_blend_ratio > VP_NR_MAX_RATIO)
Terence Hampson3dff4ef2012-06-13 15:20:59 -0400605 return -EINVAL;
Terence Hampson616762d2012-08-16 17:47:44 -0400606 if (param->chroma.scale_diff_ratio > VP_NR_MAX_RATIO)
Terence Hampson3dff4ef2012-06-13 15:20:59 -0400607 return -EINVAL;
Terence Hampson616762d2012-08-16 17:47:44 -0400608 if (param->chroma.diff_limit_ratio > VP_NR_MAX_RATIO)
Terence Hampson3dff4ef2012-06-13 15:20:59 -0400609 return -EINVAL;
Terence Hampson616762d2012-08-16 17:47:44 -0400610 if (param->chroma.scale_motion_ratio > VP_NR_MAX_RATIO)
Terence Hampson3dff4ef2012-06-13 15:20:59 -0400611 return -EINVAL;
Terence Hampson616762d2012-08-16 17:47:44 -0400612 if (param->chroma.blend_limit_ratio > VP_NR_MAX_RATIO)
Terence Hampson3dff4ef2012-06-13 15:20:59 -0400613 return -EINVAL;
614 return 0;
615}
616
617void nr_g_param(struct vcap_client_data *c_data, struct nr_param *param)
618{
619 struct vcap_dev *dev = c_data->dev;
620 uint32_t rc;
621 rc = readl_relaxed(VCAP_VP_NR_CONFIG);
622 param->window = BITS_VALUE(rc, 24, 4);
623 param->decay_ratio = BITS_VALUE(rc, 20, 3);
624
625 rc = readl_relaxed(VCAP_VP_NR_LUMA_CONFIG);
626 param->luma.max_blend_ratio = BITS_VALUE(rc, 24, 4);
627 param->luma.scale_diff_ratio = BITS_VALUE(rc, 12, 4);
628 param->luma.diff_limit_ratio = BITS_VALUE(rc, 8, 4);
629 param->luma.scale_motion_ratio = BITS_VALUE(rc, 4, 4);
630 param->luma.blend_limit_ratio = BITS_VALUE(rc, 0, 4);
631
632 rc = readl_relaxed(VCAP_VP_NR_CHROMA_CONFIG);
633 param->chroma.max_blend_ratio = BITS_VALUE(rc, 24, 4);
634 param->chroma.scale_diff_ratio = BITS_VALUE(rc, 12, 4);
635 param->chroma.diff_limit_ratio = BITS_VALUE(rc, 8, 4);
636 param->chroma.scale_motion_ratio = BITS_VALUE(rc, 4, 4);
637 param->chroma.blend_limit_ratio = BITS_VALUE(rc, 0, 4);
638}
639
640void s_default_nr_val(struct nr_param *param)
641{
642 param->window = 10;
643 param->decay_ratio = 0;
644 param->luma.max_blend_ratio = 0;
645 param->luma.scale_diff_ratio = 4;
646 param->luma.diff_limit_ratio = 1;
647 param->luma.scale_motion_ratio = 4;
648 param->luma.blend_limit_ratio = 9;
649 param->chroma.max_blend_ratio = 0;
650 param->chroma.scale_diff_ratio = 4;
651 param->chroma.diff_limit_ratio = 1;
652 param->chroma.scale_motion_ratio = 4;
653 param->chroma.blend_limit_ratio = 9;
654}
655
Terence Hampson54d3a6d2012-07-10 14:05:35 -0400656int vp_dummy_event(struct vcap_client_data *c_data)
657{
658 struct vcap_dev *dev = c_data->dev;
659 unsigned int width, height;
Terence Hampsona2cba0d2012-08-08 11:39:53 -0400660 struct ion_handle *handle = NULL;
Terence Hampson54d3a6d2012-07-10 14:05:35 -0400661 unsigned long paddr;
Terence Hampsona2cba0d2012-08-08 11:39:53 -0400662 size_t len;
Terence Hampson54d3a6d2012-07-10 14:05:35 -0400663 uint32_t reg;
664 int rc = 0;
665
666 dprintk(2, "%s: Start VP dummy event\n", __func__);
Terence Hampsona2cba0d2012-08-08 11:39:53 -0400667 handle = ion_alloc(dev->ion_client, 0x1200, SZ_4K,
Hanumant Singh7d72bad2012-08-29 18:39:44 -0700668 ION_HEAP(ION_CP_MM_HEAP_ID), 0);
Terence Hampsona2cba0d2012-08-08 11:39:53 -0400669 if (IS_ERR_OR_NULL(handle)) {
670 pr_err("%s: ion_alloc failed\n", __func__);
Terence Hampson54d3a6d2012-07-10 14:05:35 -0400671 return -ENOMEM;
672 }
Terence Hampsona2cba0d2012-08-08 11:39:53 -0400673
674 rc = ion_phys(dev->ion_client, handle, &paddr, &len);
675 if (rc < 0) {
676 pr_err("%s: ion_phys failed\n", __func__);
677 ion_free(dev->ion_client, handle);
678 return rc;
679 }
Terence Hampson54d3a6d2012-07-10 14:05:35 -0400680
681 width = c_data->vp_out_fmt.width;
682 height = c_data->vp_out_fmt.height;
683
684 c_data->vp_out_fmt.width = 0x3F;
685 c_data->vp_out_fmt.height = 0x16;
686
687 config_vp_format(c_data);
688 writel_relaxed(paddr, VCAP_VP_T1_Y_BASE_ADDR);
689 writel_relaxed(paddr + 0x2C0, VCAP_VP_T1_C_BASE_ADDR);
690 writel_relaxed(paddr + 0x440, VCAP_VP_T2_Y_BASE_ADDR);
691 writel_relaxed(paddr + 0x700, VCAP_VP_T2_C_BASE_ADDR);
692 writel_relaxed(paddr + 0x880, VCAP_VP_OUT_Y_BASE_ADDR);
693 writel_relaxed(paddr + 0xB40, VCAP_VP_OUT_C_BASE_ADDR);
694 writel_iowmb(paddr + 0x1100, VCAP_VP_MOTION_EST_ADDR);
695 writel_relaxed(4 << 20 | 0x2 << 4, VCAP_VP_IN_CONFIG);
696 writel_relaxed(4 << 20 | 0x1 << 4, VCAP_VP_OUT_CONFIG);
697
698 dev->vp_dummy_event = true;
699
Terence Hampsonb128b982012-08-16 14:41:19 -0400700 enable_irq(dev->vpirq->start);
Terence Hampson54d3a6d2012-07-10 14:05:35 -0400701 writel_relaxed(0x01100101, VCAP_VP_INTERRUPT_ENABLE);
702 writel_iowmb(0x00000000, VCAP_VP_CTRL);
Terence Hampsona2cba0d2012-08-08 11:39:53 -0400703 writel_iowmb(0x00010000, VCAP_VP_CTRL);
Terence Hampson54d3a6d2012-07-10 14:05:35 -0400704
Terence Hampson54d3a6d2012-07-10 14:05:35 -0400705 rc = wait_event_interruptible_timeout(dev->vp_dummy_waitq,
706 dev->vp_dummy_complete, msecs_to_jiffies(50));
707 if (!rc && !dev->vp_dummy_complete) {
708 pr_err("%s: VP dummy event timeout", __func__);
709 rc = -ETIME;
Terence Hampson54d3a6d2012-07-10 14:05:35 -0400710
Terence Hampsonb128b982012-08-16 14:41:19 -0400711 vp_sw_reset(dev);
Terence Hampson54d3a6d2012-07-10 14:05:35 -0400712 dev->vp_dummy_complete = false;
713 }
714
715 writel_relaxed(0x00000000, VCAP_VP_INTERRUPT_ENABLE);
716 disable_irq(dev->vpirq->start);
717 dev->vp_dummy_event = false;
718
719 reg = readl_relaxed(VCAP_OFFSET(0x0D94));
720 writel_relaxed(reg, VCAP_OFFSET(0x0D9C));
721
722 c_data->vp_out_fmt.width = width;
723 c_data->vp_out_fmt.height = height;
Terence Hampsona2cba0d2012-08-08 11:39:53 -0400724 ion_free(dev->ion_client, handle);
Terence Hampson54d3a6d2012-07-10 14:05:35 -0400725
726 dprintk(2, "%s: Exit VP dummy event\n", __func__);
727 return rc;
728}
729
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400730int kickoff_vp(struct vcap_client_data *c_data)
731{
732 struct vcap_dev *dev;
733 struct vp_action *vp_act;
734 unsigned long flags = 0;
735 unsigned int chroma_fmt = 0;
736 int size;
Terence Hampson9c4f8a22012-09-12 10:25:50 -0400737 bool top_field = 0;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400738
739 if (!c_data->streaming)
740 return -ENOEXEC;
741
742 dev = c_data->dev;
743 dprintk(2, "Start Kickoff\n");
744
745 if (dev->vp_client == NULL) {
746 pr_err("No active vp client\n");
747 return -ENODEV;
748 }
Terence Hampson2cba63f2012-08-21 10:54:38 -0400749 vp_act = &dev->vp_client->vp_action;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400750
751 spin_lock_irqsave(&dev->vp_client->cap_slock, flags);
752 if (list_empty(&vp_act->in_active)) {
753 spin_unlock_irqrestore(&dev->vp_client->cap_slock, flags);
754 pr_err("%s: VP We have no more input buffers\n",
755 __func__);
756 return -EAGAIN;
757 }
758
759 vp_act->bufT1 = list_entry(vp_act->in_active.next,
760 struct vcap_buffer, list);
761 list_del(&vp_act->bufT1->list);
762
763 if (list_empty(&vp_act->in_active)) {
764 spin_unlock_irqrestore(&dev->vp_client->cap_slock, flags);
765 list_add(&vp_act->bufT1->list, &vp_act->in_active);
766 pr_err("%s: VP We have no more input buffers\n",
767 __func__);
768 return -EAGAIN;
769 }
770
771 vp_act->bufT2 = list_entry(vp_act->in_active.next,
772 struct vcap_buffer, list);
773 list_del(&vp_act->bufT2->list);
774
775 if (list_empty(&vp_act->out_active)) {
776 spin_unlock_irqrestore(&dev->vp_client->cap_slock, flags);
777 list_add(&vp_act->bufT2->list, &vp_act->in_active);
778 list_add(&vp_act->bufT1->list, &vp_act->in_active);
779 pr_err("%s: VP We have no more output buffers\n",
780 __func__);
781 return -EAGAIN;
782 }
783
784 vp_act->bufOut = list_entry(vp_act->out_active.next,
785 struct vcap_buffer, list);
786 list_del(&vp_act->bufOut->list);
787 spin_unlock_irqrestore(&dev->vp_client->cap_slock, flags);
788
789 size = c_data->vp_in_fmt.height * c_data->vp_in_fmt.width;
790 writel_relaxed(vp_act->bufT1->paddr, VCAP_VP_T1_Y_BASE_ADDR);
791 writel_relaxed(vp_act->bufT1->paddr + size, VCAP_VP_T1_C_BASE_ADDR);
792
793 config_in_buffer(c_data, vp_act->bufT2);
794 config_out_buffer(c_data, vp_act->bufOut);
795
796 /* Config VP */
797 if (c_data->vp_in_fmt.pixfmt == V4L2_PIX_FMT_NV16)
798 chroma_fmt = 1;
799 writel_relaxed((c_data->vp_in_fmt.width / 16) << 20 |
800 chroma_fmt << 11 | 0x2 << 4, VCAP_VP_IN_CONFIG);
801
802 chroma_fmt = 0;
Terence Hampson779dc762012-06-07 15:59:27 -0400803 if (c_data->vp_out_fmt.pixfmt == V4L2_PIX_FMT_NV16)
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400804 chroma_fmt = 1;
805
Terence Hampsonad33c512012-07-16 17:50:00 -0400806 writel_relaxed((c_data->vp_out_fmt.width / 16) << 20 |
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400807 chroma_fmt << 11 | 0x1 << 4, VCAP_VP_OUT_CONFIG);
808
809 /* Enable Interrupt */
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400810 if (vp_act->bufT2->vb.v4l2_buf.field == V4L2_FIELD_TOP)
811 top_field = 1;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400812 vp_act->vp_state = VP_FRAME2;
Terence Hampson72452632012-08-13 12:32:24 -0400813 writel_relaxed(0x01100001, VCAP_VP_INTERRUPT_ENABLE);
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400814 writel_iowmb(0x00000000 | top_field, VCAP_VP_CTRL);
Terence Hampsona2cba0d2012-08-08 11:39:53 -0400815 writel_iowmb(0x00010000 | top_field, VCAP_VP_CTRL);
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400816 atomic_set(&c_data->dev->vp_enabled, 1);
817 enable_irq(dev->vpirq->start);
818 return 0;
819}
820
821int continue_vp(struct vcap_client_data *c_data)
822{
823 struct vcap_dev *dev;
824 struct vp_action *vp_act;
825 int rc;
Terence Hampson9c4f8a22012-09-12 10:25:50 -0400826 bool top_field = 0;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400827
828 dprintk(2, "Start Continue\n");
829 dev = c_data->dev;
830
831 if (dev->vp_client == NULL) {
832 pr_err("No active vp client\n");
833 return -ENODEV;
834 }
Terence Hampson2cba63f2012-08-21 10:54:38 -0400835 vp_act = &dev->vp_client->vp_action;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400836
837 if (vp_act->vp_state == VP_UNKNOWN) {
838 pr_err("%s: VP is in an unknown state\n",
839 __func__);
840 return -EAGAIN;
841 }
842
843 rc = vp_setup_buffers(c_data);
844 if (rc < 0)
845 return rc;
846
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400847 if (vp_act->bufT2->vb.v4l2_buf.field == V4L2_FIELD_TOP)
848 top_field = 1;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400849
850 /* Config VP & Enable Interrupt */
Terence Hampson72452632012-08-13 12:32:24 -0400851 writel_relaxed(0x01100001, VCAP_VP_INTERRUPT_ENABLE);
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400852 writel_iowmb(0x00000000 | top_field, VCAP_VP_CTRL);
Terence Hampsona2cba0d2012-08-08 11:39:53 -0400853 writel_iowmb(0x00010000 | top_field, VCAP_VP_CTRL);
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400854
855 atomic_set(&c_data->dev->vp_enabled, 1);
856 enable_irq(dev->vpirq->start);
857 return 0;
858}