blob: 139de285ae0ee238ef48a85d4351b5a2e731db82 [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
236 vb2_buffer_done(&vp_act->bufOut->vb, VB2_BUF_STATE_DONE);
237
238 /* Cycle to next state */
239 if (vp_act->vp_state != VP_NORMAL)
240 vp_act->vp_state++;
241#ifdef TOP_FIELD_FIX
242 vp_act->top_field = !vp_act->top_field;
243#endif
244
245 /* Cycle Buffers*/
Terence Hampson616762d2012-08-16 17:47:44 -0400246 if (dev->nr_param.mode) {
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400247 if (vp_act->bufNR.nr_pos == TM1_BUF)
248 vp_act->bufNR.nr_pos = BUF_NOT_IN_USE;
249
250 if (vp_act->bufNR.nr_pos != BUF_NOT_IN_USE)
251 vp_act->bufNR.nr_pos++;
252
253 vp_act->bufTm1 = vp_act->bufT0;
254 vp_act->bufT0 = vp_act->bufT1;
255 vp_act->bufT1 = vp_act->bufNRT2;
256 vp_act->bufNRT2 = vp_act->bufT2;
257 config_nr_buffer(vp_work->cd, vp_act->bufNRT2);
258 } else {
259 vp_act->bufTm1 = vp_act->bufT0;
260 vp_act->bufT0 = vp_act->bufT1;
261 vp_act->bufT1 = vp_act->bufT2;
262 }
263
264 rc = vp_setup_buffers(vp_work->cd);
265 if (rc < 0) {
266 /* setup_buf failed because we are waiting for buffers */
267 writel_relaxed(0x00000000, VCAP_VP_INTERRUPT_ENABLE);
268 writel_iowmb(irq, VCAP_VP_INT_CLEAR);
269 atomic_set(&dev->vp_enabled, 0);
Terence Hampsonb128b982012-08-16 14:41:19 -0400270 if (dev->vp_shutdown)
271 wake_up(&dev->vp_dummy_waitq);
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400272 return;
273 }
274
275 /* Config VP */
276#ifndef TOP_FIELD_FIX
277 if (vp_act->bufT2->vb.v4l2_buf.field == V4L2_FIELD_TOP)
278 top_field = 1;
279#endif
280
281#ifdef TOP_FIELD_FIX
282 writel_iowmb(0x00000000 | vp_act->top_field << 0, VCAP_VP_CTRL);
Terence Hampsona2cba0d2012-08-08 11:39:53 -0400283 writel_iowmb(0x00010000 | vp_act->top_field << 0, VCAP_VP_CTRL);
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400284#else
285 writel_iowmb(0x00000000 | top_field, VCAP_VP_CTRL);
Terence Hampsona2cba0d2012-08-08 11:39:53 -0400286 writel_iowmb(0x00010000 | top_field, VCAP_VP_CTRL);
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400287#endif
288 enable_irq(dev->vpirq->start);
289 writel_iowmb(irq, VCAP_VP_INT_CLEAR);
290}
291
292irqreturn_t vp_handler(struct vcap_dev *dev)
293{
294 struct vcap_client_data *c_data;
295 struct vp_action *vp_act;
Terence Hampson98d11802012-06-06 18:18:43 -0400296 struct v4l2_event v4l2_evt;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400297 uint32_t irq;
298 int rc;
299
300 irq = readl_relaxed(VCAP_VP_INT_STATUS);
Terence Hampson54d3a6d2012-07-10 14:05:35 -0400301 if (dev->vp_dummy_event == true) {
302 writel_relaxed(irq, VCAP_VP_INT_CLEAR);
303 dev->vp_dummy_complete = true;
304 wake_up(&dev->vp_dummy_waitq);
305 return IRQ_HANDLED;
306 }
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400307
Terence Hampson98d11802012-06-06 18:18:43 -0400308 if (irq & 0x02000000) {
309 v4l2_evt.type = V4L2_EVENT_PRIVATE_START +
310 VCAP_VP_REG_R_ERR_EVENT;
311 v4l2_event_queue(dev->vfd, &v4l2_evt);
312 }
313 if (irq & 0x01000000) {
314 v4l2_evt.type = V4L2_EVENT_PRIVATE_START +
315 VCAP_VC_LINE_ERR_EVENT;
316 v4l2_event_queue(dev->vfd, &v4l2_evt);
317 }
318 if (irq & 0x00020000) {
319 v4l2_evt.type = V4L2_EVENT_PRIVATE_START +
320 VCAP_VP_IN_HEIGHT_ERR_EVENT;
321 v4l2_event_queue(dev->vfd, &v4l2_evt);
322 }
323 if (irq & 0x00010000) {
324 v4l2_evt.type = V4L2_EVENT_PRIVATE_START +
325 VCAP_VP_IN_WIDTH_ERR_EVENT;
326 v4l2_event_queue(dev->vfd, &v4l2_evt);
327 }
328
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400329 dprintk(1, "%s: irq=0x%08x\n", __func__, irq);
Terence Hampson72452632012-08-13 12:32:24 -0400330 if (!(irq & (VP_PIC_DONE | VP_MODE_CHANGE))) {
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400331 writel_relaxed(irq, VCAP_VP_INT_CLEAR);
332 pr_err("VP IRQ shows some error\n");
333 return IRQ_HANDLED;
334 }
335
336 if (dev->vp_client == NULL) {
337 writel_relaxed(irq, VCAP_VP_INT_CLEAR);
338 pr_err("VC: There is no active vp client\n");
339 return IRQ_HANDLED;
340 }
341
Terence Hampson2cba63f2012-08-21 10:54:38 -0400342 vp_act = &dev->vp_client->vp_action;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400343 c_data = dev->vp_client;
344
345 if (vp_act->vp_state == VP_UNKNOWN) {
346 writel_relaxed(irq, VCAP_VP_INT_CLEAR);
347 pr_err("%s: VP is in an unknown state\n",
348 __func__);
349 return -EAGAIN;
350 }
351
352 INIT_WORK(&dev->vp_work.work, vp_wq_fnc);
353 dev->vp_work.cd = c_data;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400354 rc = queue_work(dev->vcap_wq, &dev->vp_work.work);
355
356 disable_irq_nosync(dev->vpirq->start);
357 return IRQ_HANDLED;
358}
359
Terence Hampsonb128b982012-08-16 14:41:19 -0400360int vp_sw_reset(struct vcap_dev *dev)
361{
362 int timeout;
363 writel_iowmb(0x00000010, VCAP_SW_RESET_REQ);
364 timeout = 10000;
365 while (1) {
366 if (!(readl_relaxed(VCAP_SW_RESET_STATUS) & 0x10))
367 break;
368 timeout--;
369 if (timeout == 0) {
370 /* This should not happen */
371 pr_err("VP is not resetting properly\n");
372 writel_iowmb(0x00000000, VCAP_SW_RESET_REQ);
373 return -EINVAL;
374 }
375 }
376 return 0;
377}
378
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400379void vp_stop_capture(struct vcap_client_data *c_data)
380{
381 struct vcap_dev *dev = c_data->dev;
Terence Hampsonb128b982012-08-16 14:41:19 -0400382 int rc;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400383
Terence Hampsonb128b982012-08-16 14:41:19 -0400384 dev->vp_shutdown = true;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400385 flush_workqueue(dev->vcap_wq);
386
Terence Hampsonb128b982012-08-16 14:41:19 -0400387 if (atomic_read(&dev->vp_enabled) == 1) {
388 rc = wait_event_interruptible_timeout(dev->vp_dummy_waitq,
389 !atomic_read(&dev->vp_enabled),
390 msecs_to_jiffies(50));
391 if (rc == 0 && atomic_read(&dev->vp_enabled) == 1) {
392 /* This should not happen, if it does hw is stuck */
393 pr_err("%s: VP Timeout and VP still running\n",
394 __func__);
395 }
396 }
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400397
Terence Hampsonb128b982012-08-16 14:41:19 -0400398 vp_sw_reset(dev);
399 dev->vp_shutdown = false;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400400}
401
402int config_vp_format(struct vcap_client_data *c_data)
403{
404 struct vcap_dev *dev = c_data->dev;
Terence Hampsonb128b982012-08-16 14:41:19 -0400405 int rc;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400406
407 INIT_WORK(&dev->vp_to_vc_work.work, mov_buf_to_vc);
408 dev->vp_to_vc_work.cd = c_data;
409
410 /* SW restart VP */
Terence Hampsonb128b982012-08-16 14:41:19 -0400411 rc = vp_sw_reset(dev);
412 if (rc < 0)
413 return rc;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400414
415 /* Film Mode related settings */
416 writel_iowmb(0x00000000, VCAP_VP_FILM_PROJECTION_T0);
417 writel_relaxed(0x00000000, VCAP_VP_FILM_PROJECTION_T2);
418 writel_relaxed(0x00000000, VCAP_VP_FILM_PAST_MAX_PROJ);
419 writel_relaxed(0x00000000, VCAP_VP_FILM_PAST_MIN_PROJ);
420 writel_relaxed(0x00000000, VCAP_VP_FILM_SEQUENCE_HIST);
421 writel_relaxed(0x00000000, VCAP_VP_FILM_MODE_STATE);
422
423 writel_relaxed(0x00000000, VCAP_VP_BAL_VMOTION_STATE);
424 writel_relaxed(0x00000010, VCAP_VP_REDUCT_AVG_MOTION);
425 writel_relaxed(0x40000000, VCAP_VP_REDUCT_AVG_MOTION2);
426 writel_relaxed(0x40000000, VCAP_VP_NR_AVG_LUMA);
427 writel_relaxed(0x40000000, VCAP_VP_NR_AVG_CHROMA);
428 writel_relaxed(0x40000000, VCAP_VP_NR_CTRL_LUMA);
429 writel_relaxed(0x40000000, VCAP_VP_NR_CTRL_CHROMA);
430 writel_relaxed(0x00000000, VCAP_VP_BAL_AVG_BLEND);
431 writel_relaxed(0x00000000, VCAP_VP_VMOTION_HIST);
432 writel_relaxed(0x05047D19, VCAP_VP_FILM_ANALYSIS_CONFIG);
433 writel_relaxed(0x20260200, VCAP_VP_FILM_STATE_CONFIG);
434 writel_relaxed(0x23A60114, VCAP_VP_FVM_CONFIG);
435 writel_relaxed(0x03043210, VCAP_VP_FILM_ANALYSIS_CONFIG2);
436 writel_relaxed(0x04DB7A51, VCAP_VP_MIXED_ANALYSIS_CONFIG);
437 writel_relaxed(0x14224916, VCAP_VP_SPATIAL_CONFIG);
438 writel_relaxed(0x83270400, VCAP_VP_SPATIAL_CONFIG2);
439 writel_relaxed(0x0F000F92, VCAP_VP_SPATIAL_CONFIG3);
440 writel_relaxed(0x00000000, VCAP_VP_TEMPORAL_CONFIG);
441 writel_relaxed(0x00000000, VCAP_VP_PIXEL_DIFF_CONFIG);
442 writel_relaxed(0x0C090511, VCAP_VP_H_FREQ_CONFIG);
443 writel_relaxed(0x0A000000, VCAP_VP_NR_CONFIG);
444 writel_relaxed(0x008F4149, VCAP_VP_NR_LUMA_CONFIG);
445 writel_relaxed(0x008F4149, VCAP_VP_NR_CHROMA_CONFIG);
446 writel_relaxed(0x43C0FD0C, VCAP_VP_BAL_CONFIG);
447 writel_relaxed(0x00000255, VCAP_VP_BAL_MOTION_CONFIG);
448 writel_relaxed(0x24154252, VCAP_VP_BAL_LIGHT_COMB);
449 writel_relaxed(0x10024414, VCAP_VP_BAL_VMOTION_CONFIG);
450 writel_relaxed(0x00000002, VCAP_VP_NR_CONFIG2);
451 writel_relaxed((c_data->vp_out_fmt.height-1)<<16 |
452 (c_data->vp_out_fmt.width - 1), VCAP_VP_FRAME_SIZE);
453 writel_relaxed(0x00000000, VCAP_VP_SPLIT_SCRN_CTRL);
454
455 return 0;
456}
457
458int init_motion_buf(struct vcap_client_data *c_data)
459{
Terence Hampsona2cba0d2012-08-08 11:39:53 -0400460 int rc;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400461 struct vcap_dev *dev = c_data->dev;
Terence Hampsona2cba0d2012-08-08 11:39:53 -0400462 struct ion_handle *handle = NULL;
463 unsigned long paddr, ionflag = 0;
464 void *vaddr;
465 size_t len;
466 size_t size = ((c_data->vp_out_fmt.width + 63) >> 6) *
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400467 ((c_data->vp_out_fmt.height + 7) >> 3) * 16;
468
Terence Hampson2cba63f2012-08-21 10:54:38 -0400469 if (c_data->vp_action.motionHandle) {
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400470 pr_err("Motion buffer has already been created");
471 return -ENOEXEC;
472 }
473
Terence Hampsona2cba0d2012-08-08 11:39:53 -0400474 handle = ion_alloc(dev->ion_client, size, SZ_4K,
475 ION_HEAP(ION_CP_MM_HEAP_ID));
476 if (IS_ERR_OR_NULL(handle)) {
477 pr_err("%s: ion_alloc failed\n", __func__);
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400478 return -ENOMEM;
Terence Hampsona2cba0d2012-08-08 11:39:53 -0400479 }
480 rc = ion_phys(dev->ion_client, handle, &paddr, &len);
481 if (rc < 0) {
482 pr_err("%s: ion_phys failed\n", __func__);
483 ion_free(dev->ion_client, handle);
484 return rc;
485 }
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400486
Terence Hampsona2cba0d2012-08-08 11:39:53 -0400487 rc = ion_handle_get_flags(dev->ion_client, handle, &ionflag);
488 if (rc) {
489 pr_err("%s: get flags ion handle failed\n", __func__);
490 ion_free(dev->ion_client, handle);
491 return rc;
492 }
493
494 vaddr = ion_map_kernel(dev->ion_client, handle, ionflag);
495 if (IS_ERR(vaddr)) {
496 pr_err("%s: Map motion buffer failed\n", __func__);
497 ion_free(dev->ion_client, handle);
498 rc = -ENOMEM;
499 return rc;
500 }
501
502 memset(vaddr, 0, size);
Terence Hampson2cba63f2012-08-21 10:54:38 -0400503 c_data->vp_action.motionHandle = handle;
Terence Hampsona2cba0d2012-08-08 11:39:53 -0400504
505 vaddr = NULL;
506 ion_unmap_kernel(dev->ion_client, handle);
507
508 writel_iowmb(paddr, VCAP_VP_MOTION_EST_ADDR);
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400509 return 0;
510}
511
512void deinit_motion_buf(struct vcap_client_data *c_data)
513{
514 struct vcap_dev *dev = c_data->dev;
Terence Hampson2cba63f2012-08-21 10:54:38 -0400515 if (!c_data->vp_action.motionHandle) {
Terence Hampsonad33c512012-07-16 17:50:00 -0400516 pr_err("Motion buffer has not been created");
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400517 return;
518 }
519
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400520 writel_iowmb(0x00000000, VCAP_VP_MOTION_EST_ADDR);
Terence Hampson2cba63f2012-08-21 10:54:38 -0400521 ion_free(dev->ion_client, c_data->vp_action.motionHandle);
522 c_data->vp_action.motionHandle = NULL;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400523 return;
524}
525
526int init_nr_buf(struct vcap_client_data *c_data)
527{
528 struct vcap_dev *dev = c_data->dev;
Terence Hampsona2cba0d2012-08-08 11:39:53 -0400529 struct ion_handle *handle = NULL;
530 size_t frame_size, tot_size, len;
531 unsigned long paddr;
532 int rc;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400533
Terence Hampson2cba63f2012-08-21 10:54:38 -0400534 if (c_data->vp_action.bufNR.nr_handle) {
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400535 pr_err("NR buffer has already been created");
536 return -ENOEXEC;
537 }
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400538
539 frame_size = c_data->vp_in_fmt.width * c_data->vp_in_fmt.height;
540 if (c_data->vp_in_fmt.pixfmt == V4L2_PIX_FMT_NV16)
541 tot_size = frame_size * 2;
542 else
543 tot_size = frame_size / 2 * 3;
544
Terence Hampsona2cba0d2012-08-08 11:39:53 -0400545 handle = ion_alloc(dev->ion_client, tot_size, SZ_4K,
546 ION_HEAP(ION_CP_MM_HEAP_ID));
547 if (IS_ERR_OR_NULL(handle)) {
548 pr_err("%s: ion_alloc failed\n", __func__);
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400549 return -ENOMEM;
Terence Hampsona2cba0d2012-08-08 11:39:53 -0400550 }
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400551
Terence Hampsona2cba0d2012-08-08 11:39:53 -0400552 rc = ion_phys(dev->ion_client, handle, &paddr, &len);
553 if (rc < 0) {
554 pr_err("%s: ion_phys failed\n", __func__);
555 ion_free(dev->ion_client, handle);
556 return rc;
557 }
558
Terence Hampson2cba63f2012-08-21 10:54:38 -0400559 c_data->vp_action.bufNR.nr_handle = handle;
Terence Hampson616762d2012-08-16 17:47:44 -0400560 update_nr_value(dev);
Terence Hampson3dff4ef2012-06-13 15:20:59 -0400561
Terence Hampson2cba63f2012-08-21 10:54:38 -0400562 c_data->vp_action.bufNR.paddr = paddr;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400563 rc = readl_relaxed(VCAP_VP_NR_CONFIG2);
Terence Hampsona2cba0d2012-08-08 11:39:53 -0400564 rc |= (((c_data->vp_out_fmt.width / 16) << 20) | 0x1);
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400565 writel_relaxed(rc, VCAP_VP_NR_CONFIG2);
Terence Hampsona2cba0d2012-08-08 11:39:53 -0400566 writel_relaxed(paddr, VCAP_VP_NR_T2_Y_BASE_ADDR);
567 writel_relaxed(paddr + frame_size, VCAP_VP_NR_T2_C_BASE_ADDR);
Terence Hampson2cba63f2012-08-21 10:54:38 -0400568 c_data->vp_action.bufNR.nr_pos = NRT2_BUF;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400569 return 0;
570}
571
572void deinit_nr_buf(struct vcap_client_data *c_data)
573{
574 struct vcap_dev *dev = c_data->dev;
575 struct nr_buffer *buf;
576 uint32_t rc;
577
Terence Hampson2cba63f2012-08-21 10:54:38 -0400578 if (!c_data->vp_action.bufNR.nr_handle) {
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400579 pr_err("NR buffer has not been created");
580 return;
581 }
Terence Hampson2cba63f2012-08-21 10:54:38 -0400582 buf = &c_data->vp_action.bufNR;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400583
584 rc = readl_relaxed(VCAP_VP_NR_CONFIG2);
Terence Hampsona2cba0d2012-08-08 11:39:53 -0400585 rc &= !(0x0FF00001);
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400586 writel_relaxed(rc, VCAP_VP_NR_CONFIG2);
587
Terence Hampsona2cba0d2012-08-08 11:39:53 -0400588 ion_free(dev->ion_client, buf->nr_handle);
589 buf->nr_handle = NULL;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400590 buf->paddr = 0;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400591 return;
592}
593
Terence Hampson3dff4ef2012-06-13 15:20:59 -0400594int nr_s_param(struct vcap_client_data *c_data, struct nr_param *param)
595{
596 if (param->mode != NR_MANUAL)
597 return 0;
598
599 /* Verify values in range */
Terence Hampson616762d2012-08-16 17:47:44 -0400600 if (param->window > VP_NR_MAX_WINDOW)
Terence Hampson3dff4ef2012-06-13 15:20:59 -0400601 return -EINVAL;
Terence Hampson616762d2012-08-16 17:47:44 -0400602 if (param->luma.max_blend_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->luma.scale_diff_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->luma.diff_limit_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_motion_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.blend_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->chroma.max_blend_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->chroma.scale_diff_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.diff_limit_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_motion_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.blend_limit_ratio > VP_NR_MAX_RATIO)
Terence Hampson3dff4ef2012-06-13 15:20:59 -0400621 return -EINVAL;
622 return 0;
623}
624
625void nr_g_param(struct vcap_client_data *c_data, struct nr_param *param)
626{
627 struct vcap_dev *dev = c_data->dev;
628 uint32_t rc;
629 rc = readl_relaxed(VCAP_VP_NR_CONFIG);
630 param->window = BITS_VALUE(rc, 24, 4);
631 param->decay_ratio = BITS_VALUE(rc, 20, 3);
632
633 rc = readl_relaxed(VCAP_VP_NR_LUMA_CONFIG);
634 param->luma.max_blend_ratio = BITS_VALUE(rc, 24, 4);
635 param->luma.scale_diff_ratio = BITS_VALUE(rc, 12, 4);
636 param->luma.diff_limit_ratio = BITS_VALUE(rc, 8, 4);
637 param->luma.scale_motion_ratio = BITS_VALUE(rc, 4, 4);
638 param->luma.blend_limit_ratio = BITS_VALUE(rc, 0, 4);
639
640 rc = readl_relaxed(VCAP_VP_NR_CHROMA_CONFIG);
641 param->chroma.max_blend_ratio = BITS_VALUE(rc, 24, 4);
642 param->chroma.scale_diff_ratio = BITS_VALUE(rc, 12, 4);
643 param->chroma.diff_limit_ratio = BITS_VALUE(rc, 8, 4);
644 param->chroma.scale_motion_ratio = BITS_VALUE(rc, 4, 4);
645 param->chroma.blend_limit_ratio = BITS_VALUE(rc, 0, 4);
646}
647
648void s_default_nr_val(struct nr_param *param)
649{
650 param->window = 10;
651 param->decay_ratio = 0;
652 param->luma.max_blend_ratio = 0;
653 param->luma.scale_diff_ratio = 4;
654 param->luma.diff_limit_ratio = 1;
655 param->luma.scale_motion_ratio = 4;
656 param->luma.blend_limit_ratio = 9;
657 param->chroma.max_blend_ratio = 0;
658 param->chroma.scale_diff_ratio = 4;
659 param->chroma.diff_limit_ratio = 1;
660 param->chroma.scale_motion_ratio = 4;
661 param->chroma.blend_limit_ratio = 9;
662}
663
Terence Hampson54d3a6d2012-07-10 14:05:35 -0400664int vp_dummy_event(struct vcap_client_data *c_data)
665{
666 struct vcap_dev *dev = c_data->dev;
667 unsigned int width, height;
Terence Hampsona2cba0d2012-08-08 11:39:53 -0400668 struct ion_handle *handle = NULL;
Terence Hampson54d3a6d2012-07-10 14:05:35 -0400669 unsigned long paddr;
Terence Hampsona2cba0d2012-08-08 11:39:53 -0400670 size_t len;
Terence Hampson54d3a6d2012-07-10 14:05:35 -0400671 uint32_t reg;
672 int rc = 0;
673
674 dprintk(2, "%s: Start VP dummy event\n", __func__);
Terence Hampsona2cba0d2012-08-08 11:39:53 -0400675 handle = ion_alloc(dev->ion_client, 0x1200, SZ_4K,
676 ION_HEAP(ION_CP_MM_HEAP_ID));
677 if (IS_ERR_OR_NULL(handle)) {
678 pr_err("%s: ion_alloc failed\n", __func__);
Terence Hampson54d3a6d2012-07-10 14:05:35 -0400679 return -ENOMEM;
680 }
Terence Hampsona2cba0d2012-08-08 11:39:53 -0400681
682 rc = ion_phys(dev->ion_client, handle, &paddr, &len);
683 if (rc < 0) {
684 pr_err("%s: ion_phys failed\n", __func__);
685 ion_free(dev->ion_client, handle);
686 return rc;
687 }
Terence Hampson54d3a6d2012-07-10 14:05:35 -0400688
689 width = c_data->vp_out_fmt.width;
690 height = c_data->vp_out_fmt.height;
691
692 c_data->vp_out_fmt.width = 0x3F;
693 c_data->vp_out_fmt.height = 0x16;
694
695 config_vp_format(c_data);
696 writel_relaxed(paddr, VCAP_VP_T1_Y_BASE_ADDR);
697 writel_relaxed(paddr + 0x2C0, VCAP_VP_T1_C_BASE_ADDR);
698 writel_relaxed(paddr + 0x440, VCAP_VP_T2_Y_BASE_ADDR);
699 writel_relaxed(paddr + 0x700, VCAP_VP_T2_C_BASE_ADDR);
700 writel_relaxed(paddr + 0x880, VCAP_VP_OUT_Y_BASE_ADDR);
701 writel_relaxed(paddr + 0xB40, VCAP_VP_OUT_C_BASE_ADDR);
702 writel_iowmb(paddr + 0x1100, VCAP_VP_MOTION_EST_ADDR);
703 writel_relaxed(4 << 20 | 0x2 << 4, VCAP_VP_IN_CONFIG);
704 writel_relaxed(4 << 20 | 0x1 << 4, VCAP_VP_OUT_CONFIG);
705
706 dev->vp_dummy_event = true;
707
Terence Hampsonb128b982012-08-16 14:41:19 -0400708 enable_irq(dev->vpirq->start);
Terence Hampson54d3a6d2012-07-10 14:05:35 -0400709 writel_relaxed(0x01100101, VCAP_VP_INTERRUPT_ENABLE);
710 writel_iowmb(0x00000000, VCAP_VP_CTRL);
Terence Hampsona2cba0d2012-08-08 11:39:53 -0400711 writel_iowmb(0x00010000, VCAP_VP_CTRL);
Terence Hampson54d3a6d2012-07-10 14:05:35 -0400712
Terence Hampson54d3a6d2012-07-10 14:05:35 -0400713 rc = wait_event_interruptible_timeout(dev->vp_dummy_waitq,
714 dev->vp_dummy_complete, msecs_to_jiffies(50));
715 if (!rc && !dev->vp_dummy_complete) {
716 pr_err("%s: VP dummy event timeout", __func__);
717 rc = -ETIME;
Terence Hampson54d3a6d2012-07-10 14:05:35 -0400718
Terence Hampsonb128b982012-08-16 14:41:19 -0400719 vp_sw_reset(dev);
Terence Hampson54d3a6d2012-07-10 14:05:35 -0400720 dev->vp_dummy_complete = false;
721 }
722
723 writel_relaxed(0x00000000, VCAP_VP_INTERRUPT_ENABLE);
724 disable_irq(dev->vpirq->start);
725 dev->vp_dummy_event = false;
726
727 reg = readl_relaxed(VCAP_OFFSET(0x0D94));
728 writel_relaxed(reg, VCAP_OFFSET(0x0D9C));
729
730 c_data->vp_out_fmt.width = width;
731 c_data->vp_out_fmt.height = height;
Terence Hampsona2cba0d2012-08-08 11:39:53 -0400732 ion_free(dev->ion_client, handle);
Terence Hampson54d3a6d2012-07-10 14:05:35 -0400733
734 dprintk(2, "%s: Exit VP dummy event\n", __func__);
735 return rc;
736}
737
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400738int kickoff_vp(struct vcap_client_data *c_data)
739{
740 struct vcap_dev *dev;
741 struct vp_action *vp_act;
742 unsigned long flags = 0;
743 unsigned int chroma_fmt = 0;
744 int size;
745#ifndef TOP_FIELD_FIX
746 bool top_field;
747#endif
748
749 if (!c_data->streaming)
750 return -ENOEXEC;
751
752 dev = c_data->dev;
753 dprintk(2, "Start Kickoff\n");
754
755 if (dev->vp_client == NULL) {
756 pr_err("No active vp client\n");
757 return -ENODEV;
758 }
Terence Hampson2cba63f2012-08-21 10:54:38 -0400759 vp_act = &dev->vp_client->vp_action;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400760
761 spin_lock_irqsave(&dev->vp_client->cap_slock, flags);
762 if (list_empty(&vp_act->in_active)) {
763 spin_unlock_irqrestore(&dev->vp_client->cap_slock, flags);
764 pr_err("%s: VP We have no more input buffers\n",
765 __func__);
766 return -EAGAIN;
767 }
768
769 vp_act->bufT1 = list_entry(vp_act->in_active.next,
770 struct vcap_buffer, list);
771 list_del(&vp_act->bufT1->list);
772
773 if (list_empty(&vp_act->in_active)) {
774 spin_unlock_irqrestore(&dev->vp_client->cap_slock, flags);
775 list_add(&vp_act->bufT1->list, &vp_act->in_active);
776 pr_err("%s: VP We have no more input buffers\n",
777 __func__);
778 return -EAGAIN;
779 }
780
781 vp_act->bufT2 = list_entry(vp_act->in_active.next,
782 struct vcap_buffer, list);
783 list_del(&vp_act->bufT2->list);
784
785 if (list_empty(&vp_act->out_active)) {
786 spin_unlock_irqrestore(&dev->vp_client->cap_slock, flags);
787 list_add(&vp_act->bufT2->list, &vp_act->in_active);
788 list_add(&vp_act->bufT1->list, &vp_act->in_active);
789 pr_err("%s: VP We have no more output buffers\n",
790 __func__);
791 return -EAGAIN;
792 }
793
794 vp_act->bufOut = list_entry(vp_act->out_active.next,
795 struct vcap_buffer, list);
796 list_del(&vp_act->bufOut->list);
797 spin_unlock_irqrestore(&dev->vp_client->cap_slock, flags);
798
799 size = c_data->vp_in_fmt.height * c_data->vp_in_fmt.width;
800 writel_relaxed(vp_act->bufT1->paddr, VCAP_VP_T1_Y_BASE_ADDR);
801 writel_relaxed(vp_act->bufT1->paddr + size, VCAP_VP_T1_C_BASE_ADDR);
802
803 config_in_buffer(c_data, vp_act->bufT2);
804 config_out_buffer(c_data, vp_act->bufOut);
805
806 /* Config VP */
807 if (c_data->vp_in_fmt.pixfmt == V4L2_PIX_FMT_NV16)
808 chroma_fmt = 1;
809 writel_relaxed((c_data->vp_in_fmt.width / 16) << 20 |
810 chroma_fmt << 11 | 0x2 << 4, VCAP_VP_IN_CONFIG);
811
812 chroma_fmt = 0;
Terence Hampson779dc762012-06-07 15:59:27 -0400813 if (c_data->vp_out_fmt.pixfmt == V4L2_PIX_FMT_NV16)
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400814 chroma_fmt = 1;
815
Terence Hampsonad33c512012-07-16 17:50:00 -0400816 writel_relaxed((c_data->vp_out_fmt.width / 16) << 20 |
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400817 chroma_fmt << 11 | 0x1 << 4, VCAP_VP_OUT_CONFIG);
818
819 /* Enable Interrupt */
820#ifdef TOP_FIELD_FIX
821 vp_act->top_field = 1;
822#else
823 if (vp_act->bufT2->vb.v4l2_buf.field == V4L2_FIELD_TOP)
824 top_field = 1;
825#endif
826 vp_act->vp_state = VP_FRAME2;
Terence Hampson72452632012-08-13 12:32:24 -0400827 writel_relaxed(0x01100001, VCAP_VP_INTERRUPT_ENABLE);
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400828#ifdef TOP_FIELD_FIX
829 writel_iowmb(0x00000000 | vp_act->top_field << 0, VCAP_VP_CTRL);
Terence Hampsona2cba0d2012-08-08 11:39:53 -0400830 writel_iowmb(0x00010000 | vp_act->top_field << 0, VCAP_VP_CTRL);
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400831#else
832 writel_iowmb(0x00000000 | top_field, VCAP_VP_CTRL);
Terence Hampsona2cba0d2012-08-08 11:39:53 -0400833 writel_iowmb(0x00010000 | top_field, VCAP_VP_CTRL);
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400834#endif
835 atomic_set(&c_data->dev->vp_enabled, 1);
836 enable_irq(dev->vpirq->start);
837 return 0;
838}
839
840int continue_vp(struct vcap_client_data *c_data)
841{
842 struct vcap_dev *dev;
843 struct vp_action *vp_act;
844 int rc;
845#ifndef TOP_FIELD_FIX
846 bool top_field;
847#endif
848
849 dprintk(2, "Start Continue\n");
850 dev = c_data->dev;
851
852 if (dev->vp_client == NULL) {
853 pr_err("No active vp client\n");
854 return -ENODEV;
855 }
Terence Hampson2cba63f2012-08-21 10:54:38 -0400856 vp_act = &dev->vp_client->vp_action;
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400857
858 if (vp_act->vp_state == VP_UNKNOWN) {
859 pr_err("%s: VP is in an unknown state\n",
860 __func__);
861 return -EAGAIN;
862 }
863
864 rc = vp_setup_buffers(c_data);
865 if (rc < 0)
866 return rc;
867
868#ifndef TOP_FIELD_FIX
869 if (vp_act->bufT2->vb.v4l2_buf.field == V4L2_FIELD_TOP)
870 top_field = 1;
871#endif
872
873 /* Config VP & Enable Interrupt */
Terence Hampson72452632012-08-13 12:32:24 -0400874 writel_relaxed(0x01100001, VCAP_VP_INTERRUPT_ENABLE);
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400875#ifdef TOP_FIELD_FIX
876 writel_iowmb(0x00000000 | vp_act->top_field << 0, VCAP_VP_CTRL);
Terence Hampsona2cba0d2012-08-08 11:39:53 -0400877 writel_iowmb(0x00010000 | vp_act->top_field << 0, VCAP_VP_CTRL);
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400878#else
879 writel_iowmb(0x00000000 | top_field, VCAP_VP_CTRL);
Terence Hampsona2cba0d2012-08-08 11:39:53 -0400880 writel_iowmb(0x00010000 | top_field, VCAP_VP_CTRL);
Terence Hampsonaeb793e2012-05-11 11:41:16 -0400881#endif
882
883 atomic_set(&c_data->dev->vp_enabled, 1);
884 enable_irq(dev->vpirq->start);
885 return 0;
886}