blob: c81206fc6401f7fd90ebf44685411a3cf6344b31 [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;
203#ifndef TOP_FIELD_FIX
204 bool top_field;
205#endif
206
207 if (vp_work && vp_work->cd && vp_work->cd->dev)
208 dev = vp_work->cd->dev;
209 else
210 return;
211
Terence Hampson2cba63f2012-08-21 10:54:38 -0400212 vp_act = &dev->vp_client->vp_action;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400213
214 rc = readl_relaxed(VCAP_OFFSET(0x048));
215 while (!(rc & 0x00000100))
216 rc = readl_relaxed(VCAP_OFFSET(0x048));
217
Terence Hampsonad33c512012-07-16 17:50:00 -0400218 irq = readl_relaxed(VCAP_VP_INT_STATUS);
219
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400220 writel_relaxed(0x00000000, VCAP_VP_BAL_VMOTION_STATE);
221 writel_relaxed(0x40000000, VCAP_VP_REDUCT_AVG_MOTION2);
222
Terence Hampson3dff4ef2012-06-13 15:20:59 -0400223 spin_lock_irqsave(&dev->vp_client->cap_slock, flags);
Terence Hampson616762d2012-08-16 17:47:44 -0400224 if (dev->nr_update == true)
225 update_nr_value(dev);
Terence Hampson3dff4ef2012-06-13 15:20:59 -0400226 spin_unlock_irqrestore(&dev->vp_client->cap_slock, flags);
227
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400228 /* Queue the done buffers */
229 if (vp_act->vp_state == VP_NORMAL &&
230 vp_act->bufNR.nr_pos != TM1_BUF) {
231 vb2_buffer_done(&vp_act->bufTm1->vb, VB2_BUF_STATE_DONE);
232 if (vp_work->cd->op_mode == VC_AND_VP_VCAP_OP)
233 queue_work(dev->vcap_wq, &dev->vp_to_vc_work.work);
234 }
235
Terence Hampson3af95c02012-09-18 16:43:38 -0400236 if (vp_act->bufT0 != NULL && vp_act->vp_state == VP_NORMAL) {
237 vp_act->bufOut->vb.v4l2_buf.timestamp =
238 vp_act->bufT0->vb.v4l2_buf.timestamp;
239 }
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400240 vb2_buffer_done(&vp_act->bufOut->vb, VB2_BUF_STATE_DONE);
241
242 /* Cycle to next state */
243 if (vp_act->vp_state != VP_NORMAL)
244 vp_act->vp_state++;
245#ifdef TOP_FIELD_FIX
246 vp_act->top_field = !vp_act->top_field;
247#endif
248
249 /* Cycle Buffers*/
Terence Hampson616762d2012-08-16 17:47:44 -0400250 if (dev->nr_param.mode) {
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400251 if (vp_act->bufNR.nr_pos == TM1_BUF)
252 vp_act->bufNR.nr_pos = BUF_NOT_IN_USE;
253
254 if (vp_act->bufNR.nr_pos != BUF_NOT_IN_USE)
255 vp_act->bufNR.nr_pos++;
256
257 vp_act->bufTm1 = vp_act->bufT0;
258 vp_act->bufT0 = vp_act->bufT1;
259 vp_act->bufT1 = vp_act->bufNRT2;
260 vp_act->bufNRT2 = vp_act->bufT2;
261 config_nr_buffer(vp_work->cd, vp_act->bufNRT2);
262 } else {
263 vp_act->bufTm1 = vp_act->bufT0;
264 vp_act->bufT0 = vp_act->bufT1;
265 vp_act->bufT1 = vp_act->bufT2;
266 }
267
268 rc = vp_setup_buffers(vp_work->cd);
269 if (rc < 0) {
270 /* setup_buf failed because we are waiting for buffers */
271 writel_relaxed(0x00000000, VCAP_VP_INTERRUPT_ENABLE);
272 writel_iowmb(irq, VCAP_VP_INT_CLEAR);
273 atomic_set(&dev->vp_enabled, 0);
Terence Hampsonb128b982012-08-16 14:41:19 -0400274 if (dev->vp_shutdown)
275 wake_up(&dev->vp_dummy_waitq);
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400276 return;
277 }
278
279 /* Config VP */
280#ifndef TOP_FIELD_FIX
281 if (vp_act->bufT2->vb.v4l2_buf.field == V4L2_FIELD_TOP)
282 top_field = 1;
283#endif
284
285#ifdef TOP_FIELD_FIX
286 writel_iowmb(0x00000000 | vp_act->top_field << 0, VCAP_VP_CTRL);
Terence Hampsona2cba0d2012-08-08 11:39:53 -0400287 writel_iowmb(0x00010000 | vp_act->top_field << 0, VCAP_VP_CTRL);
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400288#else
289 writel_iowmb(0x00000000 | top_field, VCAP_VP_CTRL);
Terence Hampsona2cba0d2012-08-08 11:39:53 -0400290 writel_iowmb(0x00010000 | top_field, VCAP_VP_CTRL);
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400291#endif
292 enable_irq(dev->vpirq->start);
293 writel_iowmb(irq, VCAP_VP_INT_CLEAR);
294}
295
296irqreturn_t vp_handler(struct vcap_dev *dev)
297{
298 struct vcap_client_data *c_data;
299 struct vp_action *vp_act;
Terence Hampson98d11802012-06-06 18:18:43 -0400300 struct v4l2_event v4l2_evt;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400301 uint32_t irq;
302 int rc;
303
304 irq = readl_relaxed(VCAP_VP_INT_STATUS);
Terence Hampson54d3a6d2012-07-10 14:05:35 -0400305 if (dev->vp_dummy_event == true) {
306 writel_relaxed(irq, VCAP_VP_INT_CLEAR);
307 dev->vp_dummy_complete = true;
308 wake_up(&dev->vp_dummy_waitq);
309 return IRQ_HANDLED;
310 }
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400311
Terence Hampson98d11802012-06-06 18:18:43 -0400312 if (irq & 0x02000000) {
313 v4l2_evt.type = V4L2_EVENT_PRIVATE_START +
314 VCAP_VP_REG_R_ERR_EVENT;
315 v4l2_event_queue(dev->vfd, &v4l2_evt);
316 }
317 if (irq & 0x01000000) {
318 v4l2_evt.type = V4L2_EVENT_PRIVATE_START +
319 VCAP_VC_LINE_ERR_EVENT;
320 v4l2_event_queue(dev->vfd, &v4l2_evt);
321 }
322 if (irq & 0x00020000) {
323 v4l2_evt.type = V4L2_EVENT_PRIVATE_START +
324 VCAP_VP_IN_HEIGHT_ERR_EVENT;
325 v4l2_event_queue(dev->vfd, &v4l2_evt);
326 }
327 if (irq & 0x00010000) {
328 v4l2_evt.type = V4L2_EVENT_PRIVATE_START +
329 VCAP_VP_IN_WIDTH_ERR_EVENT;
330 v4l2_event_queue(dev->vfd, &v4l2_evt);
331 }
332
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400333 dprintk(1, "%s: irq=0x%08x\n", __func__, irq);
Terence Hampson72452632012-08-13 12:32:24 -0400334 if (!(irq & (VP_PIC_DONE | VP_MODE_CHANGE))) {
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400335 writel_relaxed(irq, VCAP_VP_INT_CLEAR);
336 pr_err("VP IRQ shows some error\n");
337 return IRQ_HANDLED;
338 }
339
340 if (dev->vp_client == NULL) {
341 writel_relaxed(irq, VCAP_VP_INT_CLEAR);
342 pr_err("VC: There is no active vp client\n");
343 return IRQ_HANDLED;
344 }
345
Terence Hampson2cba63f2012-08-21 10:54:38 -0400346 vp_act = &dev->vp_client->vp_action;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400347 c_data = dev->vp_client;
348
349 if (vp_act->vp_state == VP_UNKNOWN) {
350 writel_relaxed(irq, VCAP_VP_INT_CLEAR);
351 pr_err("%s: VP is in an unknown state\n",
352 __func__);
353 return -EAGAIN;
354 }
355
356 INIT_WORK(&dev->vp_work.work, vp_wq_fnc);
357 dev->vp_work.cd = c_data;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400358 rc = queue_work(dev->vcap_wq, &dev->vp_work.work);
359
360 disable_irq_nosync(dev->vpirq->start);
361 return IRQ_HANDLED;
362}
363
Terence Hampsonb128b982012-08-16 14:41:19 -0400364int vp_sw_reset(struct vcap_dev *dev)
365{
366 int timeout;
367 writel_iowmb(0x00000010, VCAP_SW_RESET_REQ);
368 timeout = 10000;
369 while (1) {
370 if (!(readl_relaxed(VCAP_SW_RESET_STATUS) & 0x10))
371 break;
372 timeout--;
373 if (timeout == 0) {
374 /* This should not happen */
375 pr_err("VP is not resetting properly\n");
376 writel_iowmb(0x00000000, VCAP_SW_RESET_REQ);
377 return -EINVAL;
378 }
379 }
380 return 0;
381}
382
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400383void vp_stop_capture(struct vcap_client_data *c_data)
384{
385 struct vcap_dev *dev = c_data->dev;
Terence Hampsonb128b982012-08-16 14:41:19 -0400386 int rc;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400387
Terence Hampsonb128b982012-08-16 14:41:19 -0400388 dev->vp_shutdown = true;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400389 flush_workqueue(dev->vcap_wq);
390
Terence Hampsonb128b982012-08-16 14:41:19 -0400391 if (atomic_read(&dev->vp_enabled) == 1) {
392 rc = wait_event_interruptible_timeout(dev->vp_dummy_waitq,
393 !atomic_read(&dev->vp_enabled),
394 msecs_to_jiffies(50));
395 if (rc == 0 && atomic_read(&dev->vp_enabled) == 1) {
396 /* This should not happen, if it does hw is stuck */
397 pr_err("%s: VP Timeout and VP still running\n",
398 __func__);
399 }
400 }
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400401
Terence Hampsonb128b982012-08-16 14:41:19 -0400402 vp_sw_reset(dev);
403 dev->vp_shutdown = false;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400404}
405
406int config_vp_format(struct vcap_client_data *c_data)
407{
408 struct vcap_dev *dev = c_data->dev;
Terence Hampsonb128b982012-08-16 14:41:19 -0400409 int rc;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400410
411 INIT_WORK(&dev->vp_to_vc_work.work, mov_buf_to_vc);
412 dev->vp_to_vc_work.cd = c_data;
413
414 /* SW restart VP */
Terence Hampsonb128b982012-08-16 14:41:19 -0400415 rc = vp_sw_reset(dev);
416 if (rc < 0)
417 return rc;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400418
419 /* Film Mode related settings */
420 writel_iowmb(0x00000000, VCAP_VP_FILM_PROJECTION_T0);
421 writel_relaxed(0x00000000, VCAP_VP_FILM_PROJECTION_T2);
422 writel_relaxed(0x00000000, VCAP_VP_FILM_PAST_MAX_PROJ);
423 writel_relaxed(0x00000000, VCAP_VP_FILM_PAST_MIN_PROJ);
424 writel_relaxed(0x00000000, VCAP_VP_FILM_SEQUENCE_HIST);
425 writel_relaxed(0x00000000, VCAP_VP_FILM_MODE_STATE);
426
427 writel_relaxed(0x00000000, VCAP_VP_BAL_VMOTION_STATE);
428 writel_relaxed(0x00000010, VCAP_VP_REDUCT_AVG_MOTION);
429 writel_relaxed(0x40000000, VCAP_VP_REDUCT_AVG_MOTION2);
430 writel_relaxed(0x40000000, VCAP_VP_NR_AVG_LUMA);
431 writel_relaxed(0x40000000, VCAP_VP_NR_AVG_CHROMA);
432 writel_relaxed(0x40000000, VCAP_VP_NR_CTRL_LUMA);
433 writel_relaxed(0x40000000, VCAP_VP_NR_CTRL_CHROMA);
434 writel_relaxed(0x00000000, VCAP_VP_BAL_AVG_BLEND);
435 writel_relaxed(0x00000000, VCAP_VP_VMOTION_HIST);
436 writel_relaxed(0x05047D19, VCAP_VP_FILM_ANALYSIS_CONFIG);
437 writel_relaxed(0x20260200, VCAP_VP_FILM_STATE_CONFIG);
438 writel_relaxed(0x23A60114, VCAP_VP_FVM_CONFIG);
439 writel_relaxed(0x03043210, VCAP_VP_FILM_ANALYSIS_CONFIG2);
440 writel_relaxed(0x04DB7A51, VCAP_VP_MIXED_ANALYSIS_CONFIG);
441 writel_relaxed(0x14224916, VCAP_VP_SPATIAL_CONFIG);
442 writel_relaxed(0x83270400, VCAP_VP_SPATIAL_CONFIG2);
443 writel_relaxed(0x0F000F92, VCAP_VP_SPATIAL_CONFIG3);
444 writel_relaxed(0x00000000, VCAP_VP_TEMPORAL_CONFIG);
445 writel_relaxed(0x00000000, VCAP_VP_PIXEL_DIFF_CONFIG);
446 writel_relaxed(0x0C090511, VCAP_VP_H_FREQ_CONFIG);
447 writel_relaxed(0x0A000000, VCAP_VP_NR_CONFIG);
448 writel_relaxed(0x008F4149, VCAP_VP_NR_LUMA_CONFIG);
449 writel_relaxed(0x008F4149, VCAP_VP_NR_CHROMA_CONFIG);
450 writel_relaxed(0x43C0FD0C, VCAP_VP_BAL_CONFIG);
451 writel_relaxed(0x00000255, VCAP_VP_BAL_MOTION_CONFIG);
452 writel_relaxed(0x24154252, VCAP_VP_BAL_LIGHT_COMB);
453 writel_relaxed(0x10024414, VCAP_VP_BAL_VMOTION_CONFIG);
454 writel_relaxed(0x00000002, VCAP_VP_NR_CONFIG2);
455 writel_relaxed((c_data->vp_out_fmt.height-1)<<16 |
456 (c_data->vp_out_fmt.width - 1), VCAP_VP_FRAME_SIZE);
457 writel_relaxed(0x00000000, VCAP_VP_SPLIT_SCRN_CTRL);
458
459 return 0;
460}
461
462int init_motion_buf(struct vcap_client_data *c_data)
463{
Terence Hampsona2cba0d2012-08-08 11:39:53 -0400464 int rc;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400465 struct vcap_dev *dev = c_data->dev;
Terence Hampsona2cba0d2012-08-08 11:39:53 -0400466 struct ion_handle *handle = NULL;
467 unsigned long paddr, ionflag = 0;
468 void *vaddr;
469 size_t len;
470 size_t size = ((c_data->vp_out_fmt.width + 63) >> 6) *
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400471 ((c_data->vp_out_fmt.height + 7) >> 3) * 16;
472
Terence Hampson2cba63f2012-08-21 10:54:38 -0400473 if (c_data->vp_action.motionHandle) {
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400474 pr_err("Motion buffer has already been created");
475 return -ENOEXEC;
476 }
477
Terence Hampsona2cba0d2012-08-08 11:39:53 -0400478 handle = ion_alloc(dev->ion_client, size, SZ_4K,
479 ION_HEAP(ION_CP_MM_HEAP_ID));
480 if (IS_ERR_OR_NULL(handle)) {
481 pr_err("%s: ion_alloc failed\n", __func__);
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400482 return -ENOMEM;
Terence Hampsona2cba0d2012-08-08 11:39:53 -0400483 }
484 rc = ion_phys(dev->ion_client, handle, &paddr, &len);
485 if (rc < 0) {
486 pr_err("%s: ion_phys failed\n", __func__);
487 ion_free(dev->ion_client, handle);
488 return rc;
489 }
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400490
Terence Hampsona2cba0d2012-08-08 11:39:53 -0400491 rc = ion_handle_get_flags(dev->ion_client, handle, &ionflag);
492 if (rc) {
493 pr_err("%s: get flags ion handle failed\n", __func__);
494 ion_free(dev->ion_client, handle);
495 return rc;
496 }
497
498 vaddr = ion_map_kernel(dev->ion_client, handle, ionflag);
499 if (IS_ERR(vaddr)) {
500 pr_err("%s: Map motion buffer failed\n", __func__);
501 ion_free(dev->ion_client, handle);
502 rc = -ENOMEM;
503 return rc;
504 }
505
506 memset(vaddr, 0, size);
Terence Hampson2cba63f2012-08-21 10:54:38 -0400507 c_data->vp_action.motionHandle = handle;
Terence Hampsona2cba0d2012-08-08 11:39:53 -0400508
509 vaddr = NULL;
510 ion_unmap_kernel(dev->ion_client, handle);
511
512 writel_iowmb(paddr, VCAP_VP_MOTION_EST_ADDR);
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400513 return 0;
514}
515
516void deinit_motion_buf(struct vcap_client_data *c_data)
517{
518 struct vcap_dev *dev = c_data->dev;
Terence Hampson2cba63f2012-08-21 10:54:38 -0400519 if (!c_data->vp_action.motionHandle) {
Terence Hampsonad33c512012-07-16 17:50:00 -0400520 pr_err("Motion buffer has not been created");
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400521 return;
522 }
523
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400524 writel_iowmb(0x00000000, VCAP_VP_MOTION_EST_ADDR);
Terence Hampson2cba63f2012-08-21 10:54:38 -0400525 ion_free(dev->ion_client, c_data->vp_action.motionHandle);
526 c_data->vp_action.motionHandle = NULL;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400527 return;
528}
529
530int init_nr_buf(struct vcap_client_data *c_data)
531{
532 struct vcap_dev *dev = c_data->dev;
Terence Hampsona2cba0d2012-08-08 11:39:53 -0400533 struct ion_handle *handle = NULL;
534 size_t frame_size, tot_size, len;
535 unsigned long paddr;
536 int rc;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400537
Terence Hampson2cba63f2012-08-21 10:54:38 -0400538 if (c_data->vp_action.bufNR.nr_handle) {
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400539 pr_err("NR buffer has already been created");
540 return -ENOEXEC;
541 }
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400542
543 frame_size = c_data->vp_in_fmt.width * c_data->vp_in_fmt.height;
544 if (c_data->vp_in_fmt.pixfmt == V4L2_PIX_FMT_NV16)
545 tot_size = frame_size * 2;
546 else
547 tot_size = frame_size / 2 * 3;
548
Terence Hampsona2cba0d2012-08-08 11:39:53 -0400549 handle = ion_alloc(dev->ion_client, tot_size, SZ_4K,
550 ION_HEAP(ION_CP_MM_HEAP_ID));
551 if (IS_ERR_OR_NULL(handle)) {
552 pr_err("%s: ion_alloc failed\n", __func__);
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400553 return -ENOMEM;
Terence Hampsona2cba0d2012-08-08 11:39:53 -0400554 }
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400555
Terence Hampsona2cba0d2012-08-08 11:39:53 -0400556 rc = ion_phys(dev->ion_client, handle, &paddr, &len);
557 if (rc < 0) {
558 pr_err("%s: ion_phys failed\n", __func__);
559 ion_free(dev->ion_client, handle);
560 return rc;
561 }
562
Terence Hampson2cba63f2012-08-21 10:54:38 -0400563 c_data->vp_action.bufNR.nr_handle = handle;
Terence Hampson616762d2012-08-16 17:47:44 -0400564 update_nr_value(dev);
Terence Hampson3dff4ef2012-06-13 15:20:59 -0400565
Terence Hampson2cba63f2012-08-21 10:54:38 -0400566 c_data->vp_action.bufNR.paddr = paddr;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400567 rc = readl_relaxed(VCAP_VP_NR_CONFIG2);
Terence Hampsona2cba0d2012-08-08 11:39:53 -0400568 rc |= (((c_data->vp_out_fmt.width / 16) << 20) | 0x1);
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400569 writel_relaxed(rc, VCAP_VP_NR_CONFIG2);
Terence Hampsona2cba0d2012-08-08 11:39:53 -0400570 writel_relaxed(paddr, VCAP_VP_NR_T2_Y_BASE_ADDR);
571 writel_relaxed(paddr + frame_size, VCAP_VP_NR_T2_C_BASE_ADDR);
Terence Hampson2cba63f2012-08-21 10:54:38 -0400572 c_data->vp_action.bufNR.nr_pos = NRT2_BUF;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400573 return 0;
574}
575
576void deinit_nr_buf(struct vcap_client_data *c_data)
577{
578 struct vcap_dev *dev = c_data->dev;
579 struct nr_buffer *buf;
580 uint32_t rc;
581
Terence Hampson2cba63f2012-08-21 10:54:38 -0400582 if (!c_data->vp_action.bufNR.nr_handle) {
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400583 pr_err("NR buffer has not been created");
584 return;
585 }
Terence Hampson2cba63f2012-08-21 10:54:38 -0400586 buf = &c_data->vp_action.bufNR;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400587
588 rc = readl_relaxed(VCAP_VP_NR_CONFIG2);
Terence Hampsona2cba0d2012-08-08 11:39:53 -0400589 rc &= !(0x0FF00001);
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400590 writel_relaxed(rc, VCAP_VP_NR_CONFIG2);
591
Terence Hampsona2cba0d2012-08-08 11:39:53 -0400592 ion_free(dev->ion_client, buf->nr_handle);
593 buf->nr_handle = NULL;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400594 buf->paddr = 0;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400595 return;
596}
597
Terence Hampson3dff4ef2012-06-13 15:20:59 -0400598int nr_s_param(struct vcap_client_data *c_data, struct nr_param *param)
599{
600 if (param->mode != NR_MANUAL)
601 return 0;
602
603 /* Verify values in range */
Terence Hampson616762d2012-08-16 17:47:44 -0400604 if (param->window > VP_NR_MAX_WINDOW)
Terence Hampson3dff4ef2012-06-13 15:20:59 -0400605 return -EINVAL;
Terence Hampson616762d2012-08-16 17:47:44 -0400606 if (param->luma.max_blend_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->luma.scale_diff_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->luma.diff_limit_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->luma.scale_motion_ratio > VP_NR_MAX_RATIO)
Terence Hampson3dff4ef2012-06-13 15:20:59 -0400613 return -EINVAL;
Terence Hampson616762d2012-08-16 17:47:44 -0400614 if (param->luma.blend_limit_ratio > VP_NR_MAX_RATIO)
Terence Hampson3dff4ef2012-06-13 15:20:59 -0400615 return -EINVAL;
Terence Hampson616762d2012-08-16 17:47:44 -0400616 if (param->chroma.max_blend_ratio > VP_NR_MAX_RATIO)
Terence Hampson3dff4ef2012-06-13 15:20:59 -0400617 return -EINVAL;
Terence Hampson616762d2012-08-16 17:47:44 -0400618 if (param->chroma.scale_diff_ratio > VP_NR_MAX_RATIO)
Terence Hampson3dff4ef2012-06-13 15:20:59 -0400619 return -EINVAL;
Terence Hampson616762d2012-08-16 17:47:44 -0400620 if (param->chroma.diff_limit_ratio > VP_NR_MAX_RATIO)
Terence Hampson3dff4ef2012-06-13 15:20:59 -0400621 return -EINVAL;
Terence Hampson616762d2012-08-16 17:47:44 -0400622 if (param->chroma.scale_motion_ratio > VP_NR_MAX_RATIO)
Terence Hampson3dff4ef2012-06-13 15:20:59 -0400623 return -EINVAL;
Terence Hampson616762d2012-08-16 17:47:44 -0400624 if (param->chroma.blend_limit_ratio > VP_NR_MAX_RATIO)
Terence Hampson3dff4ef2012-06-13 15:20:59 -0400625 return -EINVAL;
626 return 0;
627}
628
629void nr_g_param(struct vcap_client_data *c_data, struct nr_param *param)
630{
631 struct vcap_dev *dev = c_data->dev;
632 uint32_t rc;
633 rc = readl_relaxed(VCAP_VP_NR_CONFIG);
634 param->window = BITS_VALUE(rc, 24, 4);
635 param->decay_ratio = BITS_VALUE(rc, 20, 3);
636
637 rc = readl_relaxed(VCAP_VP_NR_LUMA_CONFIG);
638 param->luma.max_blend_ratio = BITS_VALUE(rc, 24, 4);
639 param->luma.scale_diff_ratio = BITS_VALUE(rc, 12, 4);
640 param->luma.diff_limit_ratio = BITS_VALUE(rc, 8, 4);
641 param->luma.scale_motion_ratio = BITS_VALUE(rc, 4, 4);
642 param->luma.blend_limit_ratio = BITS_VALUE(rc, 0, 4);
643
644 rc = readl_relaxed(VCAP_VP_NR_CHROMA_CONFIG);
645 param->chroma.max_blend_ratio = BITS_VALUE(rc, 24, 4);
646 param->chroma.scale_diff_ratio = BITS_VALUE(rc, 12, 4);
647 param->chroma.diff_limit_ratio = BITS_VALUE(rc, 8, 4);
648 param->chroma.scale_motion_ratio = BITS_VALUE(rc, 4, 4);
649 param->chroma.blend_limit_ratio = BITS_VALUE(rc, 0, 4);
650}
651
652void s_default_nr_val(struct nr_param *param)
653{
654 param->window = 10;
655 param->decay_ratio = 0;
656 param->luma.max_blend_ratio = 0;
657 param->luma.scale_diff_ratio = 4;
658 param->luma.diff_limit_ratio = 1;
659 param->luma.scale_motion_ratio = 4;
660 param->luma.blend_limit_ratio = 9;
661 param->chroma.max_blend_ratio = 0;
662 param->chroma.scale_diff_ratio = 4;
663 param->chroma.diff_limit_ratio = 1;
664 param->chroma.scale_motion_ratio = 4;
665 param->chroma.blend_limit_ratio = 9;
666}
667
Terence Hampson54d3a6d2012-07-10 14:05:35 -0400668int vp_dummy_event(struct vcap_client_data *c_data)
669{
670 struct vcap_dev *dev = c_data->dev;
671 unsigned int width, height;
Terence Hampsona2cba0d2012-08-08 11:39:53 -0400672 struct ion_handle *handle = NULL;
Terence Hampson54d3a6d2012-07-10 14:05:35 -0400673 unsigned long paddr;
Terence Hampsona2cba0d2012-08-08 11:39:53 -0400674 size_t len;
Terence Hampson54d3a6d2012-07-10 14:05:35 -0400675 uint32_t reg;
676 int rc = 0;
677
678 dprintk(2, "%s: Start VP dummy event\n", __func__);
Terence Hampsona2cba0d2012-08-08 11:39:53 -0400679 handle = ion_alloc(dev->ion_client, 0x1200, SZ_4K,
680 ION_HEAP(ION_CP_MM_HEAP_ID));
681 if (IS_ERR_OR_NULL(handle)) {
682 pr_err("%s: ion_alloc failed\n", __func__);
Terence Hampson54d3a6d2012-07-10 14:05:35 -0400683 return -ENOMEM;
684 }
Terence Hampsona2cba0d2012-08-08 11:39:53 -0400685
686 rc = ion_phys(dev->ion_client, handle, &paddr, &len);
687 if (rc < 0) {
688 pr_err("%s: ion_phys failed\n", __func__);
689 ion_free(dev->ion_client, handle);
690 return rc;
691 }
Terence Hampson54d3a6d2012-07-10 14:05:35 -0400692
693 width = c_data->vp_out_fmt.width;
694 height = c_data->vp_out_fmt.height;
695
696 c_data->vp_out_fmt.width = 0x3F;
697 c_data->vp_out_fmt.height = 0x16;
698
699 config_vp_format(c_data);
700 writel_relaxed(paddr, VCAP_VP_T1_Y_BASE_ADDR);
701 writel_relaxed(paddr + 0x2C0, VCAP_VP_T1_C_BASE_ADDR);
702 writel_relaxed(paddr + 0x440, VCAP_VP_T2_Y_BASE_ADDR);
703 writel_relaxed(paddr + 0x700, VCAP_VP_T2_C_BASE_ADDR);
704 writel_relaxed(paddr + 0x880, VCAP_VP_OUT_Y_BASE_ADDR);
705 writel_relaxed(paddr + 0xB40, VCAP_VP_OUT_C_BASE_ADDR);
706 writel_iowmb(paddr + 0x1100, VCAP_VP_MOTION_EST_ADDR);
707 writel_relaxed(4 << 20 | 0x2 << 4, VCAP_VP_IN_CONFIG);
708 writel_relaxed(4 << 20 | 0x1 << 4, VCAP_VP_OUT_CONFIG);
709
710 dev->vp_dummy_event = true;
711
Terence Hampsonb128b982012-08-16 14:41:19 -0400712 enable_irq(dev->vpirq->start);
Terence Hampson54d3a6d2012-07-10 14:05:35 -0400713 writel_relaxed(0x01100101, VCAP_VP_INTERRUPT_ENABLE);
714 writel_iowmb(0x00000000, VCAP_VP_CTRL);
Terence Hampsona2cba0d2012-08-08 11:39:53 -0400715 writel_iowmb(0x00010000, VCAP_VP_CTRL);
Terence Hampson54d3a6d2012-07-10 14:05:35 -0400716
Terence Hampson54d3a6d2012-07-10 14:05:35 -0400717 rc = wait_event_interruptible_timeout(dev->vp_dummy_waitq,
718 dev->vp_dummy_complete, msecs_to_jiffies(50));
719 if (!rc && !dev->vp_dummy_complete) {
720 pr_err("%s: VP dummy event timeout", __func__);
721 rc = -ETIME;
Terence Hampson54d3a6d2012-07-10 14:05:35 -0400722
Terence Hampsonb128b982012-08-16 14:41:19 -0400723 vp_sw_reset(dev);
Terence Hampson54d3a6d2012-07-10 14:05:35 -0400724 dev->vp_dummy_complete = false;
725 }
726
727 writel_relaxed(0x00000000, VCAP_VP_INTERRUPT_ENABLE);
728 disable_irq(dev->vpirq->start);
729 dev->vp_dummy_event = false;
730
731 reg = readl_relaxed(VCAP_OFFSET(0x0D94));
732 writel_relaxed(reg, VCAP_OFFSET(0x0D9C));
733
734 c_data->vp_out_fmt.width = width;
735 c_data->vp_out_fmt.height = height;
Terence Hampsona2cba0d2012-08-08 11:39:53 -0400736 ion_free(dev->ion_client, handle);
Terence Hampson54d3a6d2012-07-10 14:05:35 -0400737
738 dprintk(2, "%s: Exit VP dummy event\n", __func__);
739 return rc;
740}
741
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400742int kickoff_vp(struct vcap_client_data *c_data)
743{
744 struct vcap_dev *dev;
745 struct vp_action *vp_act;
746 unsigned long flags = 0;
747 unsigned int chroma_fmt = 0;
748 int size;
749#ifndef TOP_FIELD_FIX
750 bool top_field;
751#endif
752
753 if (!c_data->streaming)
754 return -ENOEXEC;
755
756 dev = c_data->dev;
757 dprintk(2, "Start Kickoff\n");
758
759 if (dev->vp_client == NULL) {
760 pr_err("No active vp client\n");
761 return -ENODEV;
762 }
Terence Hampson2cba63f2012-08-21 10:54:38 -0400763 vp_act = &dev->vp_client->vp_action;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400764
765 spin_lock_irqsave(&dev->vp_client->cap_slock, flags);
766 if (list_empty(&vp_act->in_active)) {
767 spin_unlock_irqrestore(&dev->vp_client->cap_slock, flags);
768 pr_err("%s: VP We have no more input buffers\n",
769 __func__);
770 return -EAGAIN;
771 }
772
773 vp_act->bufT1 = list_entry(vp_act->in_active.next,
774 struct vcap_buffer, list);
775 list_del(&vp_act->bufT1->list);
776
777 if (list_empty(&vp_act->in_active)) {
778 spin_unlock_irqrestore(&dev->vp_client->cap_slock, flags);
779 list_add(&vp_act->bufT1->list, &vp_act->in_active);
780 pr_err("%s: VP We have no more input buffers\n",
781 __func__);
782 return -EAGAIN;
783 }
784
785 vp_act->bufT2 = list_entry(vp_act->in_active.next,
786 struct vcap_buffer, list);
787 list_del(&vp_act->bufT2->list);
788
789 if (list_empty(&vp_act->out_active)) {
790 spin_unlock_irqrestore(&dev->vp_client->cap_slock, flags);
791 list_add(&vp_act->bufT2->list, &vp_act->in_active);
792 list_add(&vp_act->bufT1->list, &vp_act->in_active);
793 pr_err("%s: VP We have no more output buffers\n",
794 __func__);
795 return -EAGAIN;
796 }
797
798 vp_act->bufOut = list_entry(vp_act->out_active.next,
799 struct vcap_buffer, list);
800 list_del(&vp_act->bufOut->list);
801 spin_unlock_irqrestore(&dev->vp_client->cap_slock, flags);
802
803 size = c_data->vp_in_fmt.height * c_data->vp_in_fmt.width;
804 writel_relaxed(vp_act->bufT1->paddr, VCAP_VP_T1_Y_BASE_ADDR);
805 writel_relaxed(vp_act->bufT1->paddr + size, VCAP_VP_T1_C_BASE_ADDR);
806
807 config_in_buffer(c_data, vp_act->bufT2);
808 config_out_buffer(c_data, vp_act->bufOut);
809
810 /* Config VP */
811 if (c_data->vp_in_fmt.pixfmt == V4L2_PIX_FMT_NV16)
812 chroma_fmt = 1;
813 writel_relaxed((c_data->vp_in_fmt.width / 16) << 20 |
814 chroma_fmt << 11 | 0x2 << 4, VCAP_VP_IN_CONFIG);
815
816 chroma_fmt = 0;
Terence Hampson779dc762012-06-07 15:59:27 -0400817 if (c_data->vp_out_fmt.pixfmt == V4L2_PIX_FMT_NV16)
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400818 chroma_fmt = 1;
819
Terence Hampsonad33c512012-07-16 17:50:00 -0400820 writel_relaxed((c_data->vp_out_fmt.width / 16) << 20 |
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400821 chroma_fmt << 11 | 0x1 << 4, VCAP_VP_OUT_CONFIG);
822
823 /* Enable Interrupt */
824#ifdef TOP_FIELD_FIX
825 vp_act->top_field = 1;
826#else
827 if (vp_act->bufT2->vb.v4l2_buf.field == V4L2_FIELD_TOP)
828 top_field = 1;
829#endif
830 vp_act->vp_state = VP_FRAME2;
Terence Hampson72452632012-08-13 12:32:24 -0400831 writel_relaxed(0x01100001, VCAP_VP_INTERRUPT_ENABLE);
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400832#ifdef TOP_FIELD_FIX
833 writel_iowmb(0x00000000 | vp_act->top_field << 0, VCAP_VP_CTRL);
Terence Hampsona2cba0d2012-08-08 11:39:53 -0400834 writel_iowmb(0x00010000 | vp_act->top_field << 0, VCAP_VP_CTRL);
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400835#else
836 writel_iowmb(0x00000000 | top_field, VCAP_VP_CTRL);
Terence Hampsona2cba0d2012-08-08 11:39:53 -0400837 writel_iowmb(0x00010000 | top_field, VCAP_VP_CTRL);
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400838#endif
839 atomic_set(&c_data->dev->vp_enabled, 1);
840 enable_irq(dev->vpirq->start);
841 return 0;
842}
843
844int continue_vp(struct vcap_client_data *c_data)
845{
846 struct vcap_dev *dev;
847 struct vp_action *vp_act;
848 int rc;
849#ifndef TOP_FIELD_FIX
850 bool top_field;
851#endif
852
853 dprintk(2, "Start Continue\n");
854 dev = c_data->dev;
855
856 if (dev->vp_client == NULL) {
857 pr_err("No active vp client\n");
858 return -ENODEV;
859 }
Terence Hampson2cba63f2012-08-21 10:54:38 -0400860 vp_act = &dev->vp_client->vp_action;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400861
862 if (vp_act->vp_state == VP_UNKNOWN) {
863 pr_err("%s: VP is in an unknown state\n",
864 __func__);
865 return -EAGAIN;
866 }
867
868 rc = vp_setup_buffers(c_data);
869 if (rc < 0)
870 return rc;
871
872#ifndef TOP_FIELD_FIX
873 if (vp_act->bufT2->vb.v4l2_buf.field == V4L2_FIELD_TOP)
874 top_field = 1;
875#endif
876
877 /* Config VP & Enable Interrupt */
Terence Hampson72452632012-08-13 12:32:24 -0400878 writel_relaxed(0x01100001, VCAP_VP_INTERRUPT_ENABLE);
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400879#ifdef TOP_FIELD_FIX
880 writel_iowmb(0x00000000 | vp_act->top_field << 0, VCAP_VP_CTRL);
Terence Hampsona2cba0d2012-08-08 11:39:53 -0400881 writel_iowmb(0x00010000 | vp_act->top_field << 0, VCAP_VP_CTRL);
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400882#else
883 writel_iowmb(0x00000000 | top_field, VCAP_VP_CTRL);
Terence Hampsona2cba0d2012-08-08 11:39:53 -0400884 writel_iowmb(0x00010000 | top_field, VCAP_VP_CTRL);
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400885#endif
886
887 atomic_set(&c_data->dev->vp_enabled, 1);
888 enable_irq(dev->vpirq->start);
889 return 0;
890}