Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 1 | /* 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> |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 18 | #include <linux/clk.h> |
Terence Hampson | f1b7b58 | 2012-10-16 11:49:24 -0400 | [diff] [blame] | 19 | #include <linux/io.h> |
| 20 | |
| 21 | #include <mach/camera.h> |
| 22 | #include <mach/clk.h> |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 23 | |
Terence Hampson | 98d1180 | 2012-06-06 18:18:43 -0400 | [diff] [blame] | 24 | #include <media/v4l2-event.h> |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 25 | #include <media/vcap_v4l2.h> |
| 26 | #include <media/vcap_fmt.h> |
Terence Hampson | f1b7b58 | 2012-10-16 11:49:24 -0400 | [diff] [blame] | 27 | |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 28 | #include "vcap_vp.h" |
| 29 | |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 30 | void config_nr_buffer(struct vcap_client_data *c_data, |
| 31 | struct vcap_buffer *buf) |
| 32 | { |
| 33 | struct vcap_dev *dev = c_data->dev; |
| 34 | int size = c_data->vp_in_fmt.height * c_data->vp_in_fmt.width; |
| 35 | |
| 36 | writel_relaxed(buf->paddr, VCAP_VP_NR_T2_Y_BASE_ADDR); |
| 37 | writel_relaxed(buf->paddr + size, VCAP_VP_NR_T2_C_BASE_ADDR); |
| 38 | } |
| 39 | |
| 40 | void config_in_buffer(struct vcap_client_data *c_data, |
| 41 | struct vcap_buffer *buf) |
| 42 | { |
| 43 | struct vcap_dev *dev = c_data->dev; |
| 44 | int size = c_data->vp_in_fmt.height * c_data->vp_in_fmt.width; |
| 45 | |
| 46 | writel_relaxed(buf->paddr, VCAP_VP_T2_Y_BASE_ADDR); |
| 47 | writel_relaxed(buf->paddr + size, VCAP_VP_T2_C_BASE_ADDR); |
| 48 | } |
| 49 | |
| 50 | void config_out_buffer(struct vcap_client_data *c_data, |
| 51 | struct vcap_buffer *buf) |
| 52 | { |
| 53 | struct vcap_dev *dev = c_data->dev; |
| 54 | int size; |
| 55 | size = c_data->vp_out_fmt.height * c_data->vp_out_fmt.width; |
| 56 | writel_relaxed(buf->paddr, VCAP_VP_OUT_Y_BASE_ADDR); |
| 57 | writel_relaxed(buf->paddr + size, VCAP_VP_OUT_C_BASE_ADDR); |
| 58 | } |
| 59 | |
| 60 | int vp_setup_buffers(struct vcap_client_data *c_data) |
| 61 | { |
| 62 | struct vp_action *vp_act; |
| 63 | struct vcap_dev *dev; |
| 64 | unsigned long flags = 0; |
| 65 | |
| 66 | if (!c_data->streaming) |
| 67 | return -ENOEXEC; |
| 68 | dev = c_data->dev; |
Terence Hampson | c4aa4c0 | 2012-08-31 04:49:21 -0400 | [diff] [blame] | 69 | pr_debug("VP: Start setup buffers\n"); |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 70 | |
Terence Hampson | b128b98 | 2012-08-16 14:41:19 -0400 | [diff] [blame] | 71 | if (dev->vp_shutdown) { |
Terence Hampson | c4aa4c0 | 2012-08-31 04:49:21 -0400 | [diff] [blame] | 72 | pr_debug("%s: VP shutting down, no buf setup\n", |
Terence Hampson | b128b98 | 2012-08-16 14:41:19 -0400 | [diff] [blame] | 73 | __func__); |
| 74 | return -EPERM; |
| 75 | } |
| 76 | |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 77 | /* No need to verify vp_client is not NULL caller does so */ |
Terence Hampson | 2cba63f | 2012-08-21 10:54:38 -0400 | [diff] [blame] | 78 | vp_act = &dev->vp_client->vp_action; |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 79 | |
| 80 | spin_lock_irqsave(&dev->vp_client->cap_slock, flags); |
| 81 | if (list_empty(&vp_act->in_active)) { |
| 82 | spin_unlock_irqrestore(&dev->vp_client->cap_slock, flags); |
Terence Hampson | c4aa4c0 | 2012-08-31 04:49:21 -0400 | [diff] [blame] | 83 | pr_debug("%s: VP We have no more input buffers\n", |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 84 | __func__); |
| 85 | return -EAGAIN; |
| 86 | } |
| 87 | |
| 88 | if (list_empty(&vp_act->out_active)) { |
| 89 | spin_unlock_irqrestore(&dev->vp_client->cap_slock, |
| 90 | flags); |
Terence Hampson | c4aa4c0 | 2012-08-31 04:49:21 -0400 | [diff] [blame] | 91 | pr_debug("%s: VP We have no more output buffers\n", |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 92 | __func__); |
| 93 | return -EAGAIN; |
| 94 | } |
| 95 | |
| 96 | vp_act->bufT2 = list_entry(vp_act->in_active.next, |
| 97 | struct vcap_buffer, list); |
| 98 | list_del(&vp_act->bufT2->list); |
| 99 | |
| 100 | vp_act->bufOut = list_entry(vp_act->out_active.next, |
| 101 | struct vcap_buffer, list); |
| 102 | list_del(&vp_act->bufOut->list); |
| 103 | spin_unlock_irqrestore(&dev->vp_client->cap_slock, flags); |
| 104 | |
| 105 | config_in_buffer(c_data, vp_act->bufT2); |
| 106 | config_out_buffer(c_data, vp_act->bufOut); |
| 107 | return 0; |
| 108 | } |
| 109 | |
| 110 | static void mov_buf_to_vc(struct work_struct *work) |
| 111 | { |
| 112 | struct vp_work_t *vp_work = container_of(work, struct vp_work_t, work); |
| 113 | struct v4l2_buffer p; |
| 114 | struct vb2_buffer *vb_vc; |
| 115 | struct vcap_buffer *buf_vc; |
| 116 | struct vb2_buffer *vb_vp; |
| 117 | struct vcap_buffer *buf_vp; |
| 118 | int rc; |
| 119 | |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 120 | p.memory = V4L2_MEMORY_USERPTR; |
| 121 | |
| 122 | /* This loop exits when there is no more buffers left */ |
| 123 | while (1) { |
Terence Hampson | a6c9648 | 2012-07-06 17:53:09 -0400 | [diff] [blame] | 124 | p.type = V4L2_BUF_TYPE_INTERLACED_IN_DECODER; |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 125 | if (!vp_work->cd->streaming) |
| 126 | return; |
Terence Hampson | a6c9648 | 2012-07-06 17:53:09 -0400 | [diff] [blame] | 127 | rc = vcvp_dqbuf(&vp_work->cd->vp_in_vidq, &p); |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 128 | if (rc < 0) |
| 129 | return; |
| 130 | |
| 131 | vb_vc = vp_work->cd->vc_vidq.bufs[p.index]; |
| 132 | if (NULL == vb_vc) { |
Terence Hampson | c4aa4c0 | 2012-08-31 04:49:21 -0400 | [diff] [blame] | 133 | pr_debug("%s: buffer is NULL\n", __func__); |
Terence Hampson | a6c9648 | 2012-07-06 17:53:09 -0400 | [diff] [blame] | 134 | vcvp_qbuf(&vp_work->cd->vp_in_vidq, &p); |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 135 | return; |
| 136 | } |
| 137 | buf_vc = container_of(vb_vc, struct vcap_buffer, vb); |
| 138 | |
| 139 | vb_vp = vp_work->cd->vp_in_vidq.bufs[p.index]; |
| 140 | if (NULL == vb_vp) { |
Terence Hampson | c4aa4c0 | 2012-08-31 04:49:21 -0400 | [diff] [blame] | 141 | pr_debug("%s: buffer is NULL\n", __func__); |
Terence Hampson | a6c9648 | 2012-07-06 17:53:09 -0400 | [diff] [blame] | 142 | vcvp_qbuf(&vp_work->cd->vp_in_vidq, &p); |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 143 | return; |
| 144 | } |
| 145 | buf_vp = container_of(vb_vp, struct vcap_buffer, vb); |
| 146 | buf_vc->ion_handle = buf_vp->ion_handle; |
| 147 | buf_vc->paddr = buf_vp->paddr; |
| 148 | buf_vp->ion_handle = NULL; |
| 149 | buf_vp->paddr = 0; |
| 150 | |
| 151 | p.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
| 152 | /* This call should not fail */ |
Terence Hampson | a6c9648 | 2012-07-06 17:53:09 -0400 | [diff] [blame] | 153 | rc = vcvp_qbuf(&vp_work->cd->vc_vidq, &p); |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 154 | if (rc < 0) { |
Terence Hampson | c4aa4c0 | 2012-08-31 04:49:21 -0400 | [diff] [blame] | 155 | pr_err("%s: qbuf to vc failed\n", __func__); |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 156 | buf_vp->ion_handle = buf_vc->ion_handle; |
| 157 | buf_vp->paddr = buf_vc->paddr; |
| 158 | buf_vc->ion_handle = NULL; |
| 159 | buf_vc->paddr = 0; |
| 160 | p.type = V4L2_BUF_TYPE_INTERLACED_IN_DECODER; |
Terence Hampson | a6c9648 | 2012-07-06 17:53:09 -0400 | [diff] [blame] | 161 | vcvp_qbuf(&vp_work->cd->vp_in_vidq, &p); |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 162 | } |
| 163 | } |
| 164 | } |
| 165 | |
Terence Hampson | 616762d | 2012-08-16 17:47:44 -0400 | [diff] [blame] | 166 | void update_nr_value(struct vcap_dev *dev) |
Terence Hampson | 3dff4ef | 2012-06-13 15:20:59 -0400 | [diff] [blame] | 167 | { |
Terence Hampson | 3dff4ef | 2012-06-13 15:20:59 -0400 | [diff] [blame] | 168 | struct nr_param *par; |
Terence Hampson | 6a744e3 | 2012-12-07 15:50:32 -0500 | [diff] [blame] | 169 | uint32_t val = 0; |
Terence Hampson | 616762d | 2012-08-16 17:47:44 -0400 | [diff] [blame] | 170 | par = &dev->nr_param; |
Terence Hampson | 3dff4ef | 2012-06-13 15:20:59 -0400 | [diff] [blame] | 171 | if (par->mode == NR_MANUAL) { |
| 172 | writel_relaxed(par->window << 24 | par->decay_ratio << 20, |
| 173 | VCAP_VP_NR_CONFIG); |
Terence Hampson | 6a744e3 | 2012-12-07 15:50:32 -0500 | [diff] [blame] | 174 | if (par->threshold) |
| 175 | val = VP_NR_DYNAMIC_THRESHOLD; |
| 176 | writel_relaxed(val | |
| 177 | par->luma.max_blend_ratio << 24 | |
Terence Hampson | 3dff4ef | 2012-06-13 15:20:59 -0400 | [diff] [blame] | 178 | par->luma.scale_diff_ratio << 12 | |
| 179 | par->luma.diff_limit_ratio << 8 | |
| 180 | par->luma.scale_motion_ratio << 4 | |
| 181 | par->luma.blend_limit_ratio << 0, |
| 182 | VCAP_VP_NR_LUMA_CONFIG); |
Terence Hampson | 6a744e3 | 2012-12-07 15:50:32 -0500 | [diff] [blame] | 183 | writel_relaxed(val | |
| 184 | par->chroma.max_blend_ratio << 24 | |
Terence Hampson | 3dff4ef | 2012-06-13 15:20:59 -0400 | [diff] [blame] | 185 | par->chroma.scale_diff_ratio << 12 | |
| 186 | par->chroma.diff_limit_ratio << 8 | |
| 187 | par->chroma.scale_motion_ratio << 4 | |
| 188 | par->chroma.blend_limit_ratio << 0, |
| 189 | VCAP_VP_NR_CHROMA_CONFIG); |
| 190 | } |
Terence Hampson | 616762d | 2012-08-16 17:47:44 -0400 | [diff] [blame] | 191 | dev->nr_update = false; |
Terence Hampson | 3dff4ef | 2012-06-13 15:20:59 -0400 | [diff] [blame] | 192 | } |
| 193 | |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 194 | static void vp_wq_fnc(struct work_struct *work) |
| 195 | { |
| 196 | struct vp_work_t *vp_work = container_of(work, struct vp_work_t, work); |
| 197 | struct vcap_dev *dev; |
| 198 | struct vp_action *vp_act; |
Terence Hampson | c4aa4c0 | 2012-08-31 04:49:21 -0400 | [diff] [blame] | 199 | struct timeval tv; |
Terence Hampson | 3dff4ef | 2012-06-13 15:20:59 -0400 | [diff] [blame] | 200 | unsigned long flags = 0; |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 201 | uint32_t irq; |
| 202 | int rc; |
Terence Hampson | 9c4f8a2 | 2012-09-12 10:25:50 -0400 | [diff] [blame] | 203 | bool top_field = 0; |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 204 | |
| 205 | if (vp_work && vp_work->cd && vp_work->cd->dev) |
| 206 | dev = vp_work->cd->dev; |
| 207 | else |
| 208 | return; |
| 209 | |
Terence Hampson | 2cba63f | 2012-08-21 10:54:38 -0400 | [diff] [blame] | 210 | vp_act = &dev->vp_client->vp_action; |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 211 | |
| 212 | rc = readl_relaxed(VCAP_OFFSET(0x048)); |
| 213 | while (!(rc & 0x00000100)) |
| 214 | rc = readl_relaxed(VCAP_OFFSET(0x048)); |
| 215 | |
Terence Hampson | ad33c51 | 2012-07-16 17:50:00 -0400 | [diff] [blame] | 216 | irq = readl_relaxed(VCAP_VP_INT_STATUS); |
| 217 | |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 218 | writel_relaxed(0x00000000, VCAP_VP_BAL_VMOTION_STATE); |
| 219 | writel_relaxed(0x40000000, VCAP_VP_REDUCT_AVG_MOTION2); |
| 220 | |
Terence Hampson | 3dff4ef | 2012-06-13 15:20:59 -0400 | [diff] [blame] | 221 | spin_lock_irqsave(&dev->vp_client->cap_slock, flags); |
Terence Hampson | 616762d | 2012-08-16 17:47:44 -0400 | [diff] [blame] | 222 | if (dev->nr_update == true) |
| 223 | update_nr_value(dev); |
Terence Hampson | 3dff4ef | 2012-06-13 15:20:59 -0400 | [diff] [blame] | 224 | spin_unlock_irqrestore(&dev->vp_client->cap_slock, flags); |
| 225 | |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 226 | /* 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 Hampson | 3af95c0 | 2012-09-18 16:43:38 -0400 | [diff] [blame] | 234 | 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 Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 238 | 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 Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 243 | |
| 244 | /* Cycle Buffers*/ |
Terence Hampson | 616762d | 2012-08-16 17:47:44 -0400 | [diff] [blame] | 245 | if (dev->nr_param.mode) { |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 246 | 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 Hampson | b128b98 | 2012-08-16 14:41:19 -0400 | [diff] [blame] | 269 | if (dev->vp_shutdown) |
| 270 | wake_up(&dev->vp_dummy_waitq); |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 271 | return; |
| 272 | } |
| 273 | |
| 274 | /* Config VP */ |
Terence Hampson | aa64d3a | 2012-10-29 13:05:37 -0400 | [diff] [blame] | 275 | if (vp_act->bufT2->vb.v4l2_buf.field == V4L2_FIELD_BOTTOM) |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 276 | top_field = 1; |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 277 | |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 278 | writel_iowmb(0x00000000 | top_field, VCAP_VP_CTRL); |
Terence Hampson | a2cba0d | 2012-08-08 11:39:53 -0400 | [diff] [blame] | 279 | writel_iowmb(0x00010000 | top_field, VCAP_VP_CTRL); |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 280 | enable_irq(dev->vpirq->start); |
Terence Hampson | c4aa4c0 | 2012-08-31 04:49:21 -0400 | [diff] [blame] | 281 | |
| 282 | do_gettimeofday(&tv); |
| 283 | dev->dbg_p.vp_timestamp = (uint32_t) (tv.tv_sec * VCAP_USEC + |
| 284 | tv.tv_usec); |
| 285 | |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 286 | writel_iowmb(irq, VCAP_VP_INT_CLEAR); |
| 287 | } |
| 288 | |
| 289 | irqreturn_t vp_handler(struct vcap_dev *dev) |
| 290 | { |
| 291 | struct vcap_client_data *c_data; |
| 292 | struct vp_action *vp_act; |
Terence Hampson | 98d1180 | 2012-06-06 18:18:43 -0400 | [diff] [blame] | 293 | struct v4l2_event v4l2_evt; |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 294 | uint32_t irq; |
| 295 | int rc; |
Terence Hampson | c4aa4c0 | 2012-08-31 04:49:21 -0400 | [diff] [blame] | 296 | struct timeval tv; |
| 297 | uint32_t new_ts; |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 298 | |
| 299 | irq = readl_relaxed(VCAP_VP_INT_STATUS); |
Terence Hampson | 54d3a6d | 2012-07-10 14:05:35 -0400 | [diff] [blame] | 300 | if (dev->vp_dummy_event == true) { |
| 301 | writel_relaxed(irq, VCAP_VP_INT_CLEAR); |
| 302 | dev->vp_dummy_complete = true; |
| 303 | wake_up(&dev->vp_dummy_waitq); |
| 304 | return IRQ_HANDLED; |
| 305 | } |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 306 | |
Terence Hampson | 98d1180 | 2012-06-06 18:18:43 -0400 | [diff] [blame] | 307 | if (irq & 0x02000000) { |
| 308 | v4l2_evt.type = V4L2_EVENT_PRIVATE_START + |
| 309 | VCAP_VP_REG_R_ERR_EVENT; |
| 310 | v4l2_event_queue(dev->vfd, &v4l2_evt); |
| 311 | } |
| 312 | if (irq & 0x01000000) { |
| 313 | v4l2_evt.type = V4L2_EVENT_PRIVATE_START + |
Terence Hampson | f3cd9a1 | 2012-09-21 11:18:02 -0400 | [diff] [blame] | 314 | VCAP_VP_REG_W_ERR_EVENT; |
Terence Hampson | 98d1180 | 2012-06-06 18:18:43 -0400 | [diff] [blame] | 315 | v4l2_event_queue(dev->vfd, &v4l2_evt); |
| 316 | } |
| 317 | if (irq & 0x00020000) { |
| 318 | v4l2_evt.type = V4L2_EVENT_PRIVATE_START + |
| 319 | VCAP_VP_IN_HEIGHT_ERR_EVENT; |
| 320 | v4l2_event_queue(dev->vfd, &v4l2_evt); |
| 321 | } |
| 322 | if (irq & 0x00010000) { |
| 323 | v4l2_evt.type = V4L2_EVENT_PRIVATE_START + |
| 324 | VCAP_VP_IN_WIDTH_ERR_EVENT; |
| 325 | v4l2_event_queue(dev->vfd, &v4l2_evt); |
| 326 | } |
| 327 | |
Terence Hampson | c4aa4c0 | 2012-08-31 04:49:21 -0400 | [diff] [blame] | 328 | pr_debug("%s: irq=0x%08x\n", __func__, irq); |
Terence Hampson | 7245263 | 2012-08-13 12:32:24 -0400 | [diff] [blame] | 329 | if (!(irq & (VP_PIC_DONE | VP_MODE_CHANGE))) { |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 330 | writel_relaxed(irq, VCAP_VP_INT_CLEAR); |
| 331 | pr_err("VP IRQ shows some error\n"); |
| 332 | return IRQ_HANDLED; |
| 333 | } |
| 334 | |
| 335 | if (dev->vp_client == NULL) { |
| 336 | writel_relaxed(irq, VCAP_VP_INT_CLEAR); |
| 337 | pr_err("VC: There is no active vp client\n"); |
| 338 | return IRQ_HANDLED; |
| 339 | } |
| 340 | |
Terence Hampson | 2cba63f | 2012-08-21 10:54:38 -0400 | [diff] [blame] | 341 | vp_act = &dev->vp_client->vp_action; |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 342 | c_data = dev->vp_client; |
| 343 | |
| 344 | if (vp_act->vp_state == VP_UNKNOWN) { |
| 345 | writel_relaxed(irq, VCAP_VP_INT_CLEAR); |
| 346 | pr_err("%s: VP is in an unknown state\n", |
| 347 | __func__); |
| 348 | return -EAGAIN; |
| 349 | } |
| 350 | |
Terence Hampson | c4aa4c0 | 2012-08-31 04:49:21 -0400 | [diff] [blame] | 351 | do_gettimeofday(&tv); |
| 352 | new_ts = (uint32_t) (tv.tv_sec * VCAP_USEC + |
| 353 | tv.tv_usec); |
| 354 | if (new_ts > dev->dbg_p.vp_timestamp) { |
| 355 | dev->dbg_p.vp_ewma = ((new_ts - dev->dbg_p.vp_timestamp) / |
| 356 | 10 + (dev->dbg_p.vp_ewma / 10 * 9)); |
| 357 | } |
| 358 | |
| 359 | dev->dbg_p.vp_timestamp = (uint32_t) (tv.tv_sec * VCAP_USEC + |
| 360 | tv.tv_usec); |
| 361 | |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 362 | INIT_WORK(&dev->vp_work.work, vp_wq_fnc); |
| 363 | dev->vp_work.cd = c_data; |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 364 | rc = queue_work(dev->vcap_wq, &dev->vp_work.work); |
| 365 | |
| 366 | disable_irq_nosync(dev->vpirq->start); |
| 367 | return IRQ_HANDLED; |
| 368 | } |
| 369 | |
Terence Hampson | b128b98 | 2012-08-16 14:41:19 -0400 | [diff] [blame] | 370 | int vp_sw_reset(struct vcap_dev *dev) |
| 371 | { |
| 372 | int timeout; |
| 373 | writel_iowmb(0x00000010, VCAP_SW_RESET_REQ); |
| 374 | timeout = 10000; |
| 375 | while (1) { |
| 376 | if (!(readl_relaxed(VCAP_SW_RESET_STATUS) & 0x10)) |
| 377 | break; |
| 378 | timeout--; |
| 379 | if (timeout == 0) { |
| 380 | /* This should not happen */ |
| 381 | pr_err("VP is not resetting properly\n"); |
| 382 | writel_iowmb(0x00000000, VCAP_SW_RESET_REQ); |
| 383 | return -EINVAL; |
| 384 | } |
| 385 | } |
| 386 | return 0; |
| 387 | } |
| 388 | |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 389 | void vp_stop_capture(struct vcap_client_data *c_data) |
| 390 | { |
| 391 | struct vcap_dev *dev = c_data->dev; |
Terence Hampson | b128b98 | 2012-08-16 14:41:19 -0400 | [diff] [blame] | 392 | int rc; |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 393 | |
Terence Hampson | b128b98 | 2012-08-16 14:41:19 -0400 | [diff] [blame] | 394 | dev->vp_shutdown = true; |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 395 | flush_workqueue(dev->vcap_wq); |
| 396 | |
Terence Hampson | b128b98 | 2012-08-16 14:41:19 -0400 | [diff] [blame] | 397 | if (atomic_read(&dev->vp_enabled) == 1) { |
| 398 | rc = wait_event_interruptible_timeout(dev->vp_dummy_waitq, |
| 399 | !atomic_read(&dev->vp_enabled), |
| 400 | msecs_to_jiffies(50)); |
| 401 | if (rc == 0 && atomic_read(&dev->vp_enabled) == 1) { |
| 402 | /* This should not happen, if it does hw is stuck */ |
Terence Hampson | f1b7b58 | 2012-10-16 11:49:24 -0400 | [diff] [blame] | 403 | disable_irq_nosync(dev->vpirq->start); |
Terence Hampson | 14600e5 | 2012-11-07 17:16:27 -0500 | [diff] [blame] | 404 | atomic_set(&dev->vp_enabled, 0); |
Terence Hampson | b128b98 | 2012-08-16 14:41:19 -0400 | [diff] [blame] | 405 | pr_err("%s: VP Timeout and VP still running\n", |
| 406 | __func__); |
| 407 | } |
| 408 | } |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 409 | |
Terence Hampson | b128b98 | 2012-08-16 14:41:19 -0400 | [diff] [blame] | 410 | vp_sw_reset(dev); |
| 411 | dev->vp_shutdown = false; |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 412 | } |
| 413 | |
| 414 | int config_vp_format(struct vcap_client_data *c_data) |
| 415 | { |
| 416 | struct vcap_dev *dev = c_data->dev; |
Terence Hampson | b128b98 | 2012-08-16 14:41:19 -0400 | [diff] [blame] | 417 | int rc; |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 418 | |
| 419 | INIT_WORK(&dev->vp_to_vc_work.work, mov_buf_to_vc); |
| 420 | dev->vp_to_vc_work.cd = c_data; |
| 421 | |
| 422 | /* SW restart VP */ |
Terence Hampson | b128b98 | 2012-08-16 14:41:19 -0400 | [diff] [blame] | 423 | rc = vp_sw_reset(dev); |
| 424 | if (rc < 0) |
| 425 | return rc; |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 426 | |
| 427 | /* Film Mode related settings */ |
| 428 | writel_iowmb(0x00000000, VCAP_VP_FILM_PROJECTION_T0); |
| 429 | writel_relaxed(0x00000000, VCAP_VP_FILM_PROJECTION_T2); |
| 430 | writel_relaxed(0x00000000, VCAP_VP_FILM_PAST_MAX_PROJ); |
| 431 | writel_relaxed(0x00000000, VCAP_VP_FILM_PAST_MIN_PROJ); |
| 432 | writel_relaxed(0x00000000, VCAP_VP_FILM_SEQUENCE_HIST); |
| 433 | writel_relaxed(0x00000000, VCAP_VP_FILM_MODE_STATE); |
| 434 | |
| 435 | writel_relaxed(0x00000000, VCAP_VP_BAL_VMOTION_STATE); |
| 436 | writel_relaxed(0x00000010, VCAP_VP_REDUCT_AVG_MOTION); |
| 437 | writel_relaxed(0x40000000, VCAP_VP_REDUCT_AVG_MOTION2); |
| 438 | writel_relaxed(0x40000000, VCAP_VP_NR_AVG_LUMA); |
| 439 | writel_relaxed(0x40000000, VCAP_VP_NR_AVG_CHROMA); |
| 440 | writel_relaxed(0x40000000, VCAP_VP_NR_CTRL_LUMA); |
| 441 | writel_relaxed(0x40000000, VCAP_VP_NR_CTRL_CHROMA); |
| 442 | writel_relaxed(0x00000000, VCAP_VP_BAL_AVG_BLEND); |
| 443 | writel_relaxed(0x00000000, VCAP_VP_VMOTION_HIST); |
| 444 | writel_relaxed(0x05047D19, VCAP_VP_FILM_ANALYSIS_CONFIG); |
| 445 | writel_relaxed(0x20260200, VCAP_VP_FILM_STATE_CONFIG); |
| 446 | writel_relaxed(0x23A60114, VCAP_VP_FVM_CONFIG); |
| 447 | writel_relaxed(0x03043210, VCAP_VP_FILM_ANALYSIS_CONFIG2); |
| 448 | writel_relaxed(0x04DB7A51, VCAP_VP_MIXED_ANALYSIS_CONFIG); |
| 449 | writel_relaxed(0x14224916, VCAP_VP_SPATIAL_CONFIG); |
| 450 | writel_relaxed(0x83270400, VCAP_VP_SPATIAL_CONFIG2); |
| 451 | writel_relaxed(0x0F000F92, VCAP_VP_SPATIAL_CONFIG3); |
| 452 | writel_relaxed(0x00000000, VCAP_VP_TEMPORAL_CONFIG); |
| 453 | writel_relaxed(0x00000000, VCAP_VP_PIXEL_DIFF_CONFIG); |
| 454 | writel_relaxed(0x0C090511, VCAP_VP_H_FREQ_CONFIG); |
| 455 | writel_relaxed(0x0A000000, VCAP_VP_NR_CONFIG); |
| 456 | writel_relaxed(0x008F4149, VCAP_VP_NR_LUMA_CONFIG); |
| 457 | writel_relaxed(0x008F4149, VCAP_VP_NR_CHROMA_CONFIG); |
| 458 | writel_relaxed(0x43C0FD0C, VCAP_VP_BAL_CONFIG); |
| 459 | writel_relaxed(0x00000255, VCAP_VP_BAL_MOTION_CONFIG); |
| 460 | writel_relaxed(0x24154252, VCAP_VP_BAL_LIGHT_COMB); |
| 461 | writel_relaxed(0x10024414, VCAP_VP_BAL_VMOTION_CONFIG); |
| 462 | writel_relaxed(0x00000002, VCAP_VP_NR_CONFIG2); |
| 463 | writel_relaxed((c_data->vp_out_fmt.height-1)<<16 | |
| 464 | (c_data->vp_out_fmt.width - 1), VCAP_VP_FRAME_SIZE); |
| 465 | writel_relaxed(0x00000000, VCAP_VP_SPLIT_SCRN_CTRL); |
| 466 | |
| 467 | return 0; |
| 468 | } |
| 469 | |
| 470 | int init_motion_buf(struct vcap_client_data *c_data) |
| 471 | { |
Terence Hampson | a2cba0d | 2012-08-08 11:39:53 -0400 | [diff] [blame] | 472 | int rc; |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 473 | struct vcap_dev *dev = c_data->dev; |
Terence Hampson | a2cba0d | 2012-08-08 11:39:53 -0400 | [diff] [blame] | 474 | struct ion_handle *handle = NULL; |
Terence Hampson | 8d1c327 | 2012-07-27 16:36:31 -0400 | [diff] [blame] | 475 | unsigned long paddr, len, ionflag = 0; |
Terence Hampson | a2cba0d | 2012-08-08 11:39:53 -0400 | [diff] [blame] | 476 | void *vaddr; |
Terence Hampson | a2cba0d | 2012-08-08 11:39:53 -0400 | [diff] [blame] | 477 | size_t size = ((c_data->vp_out_fmt.width + 63) >> 6) * |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 478 | ((c_data->vp_out_fmt.height + 7) >> 3) * 16; |
| 479 | |
Terence Hampson | 2cba63f | 2012-08-21 10:54:38 -0400 | [diff] [blame] | 480 | if (c_data->vp_action.motionHandle) { |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 481 | pr_err("Motion buffer has already been created"); |
| 482 | return -ENOEXEC; |
| 483 | } |
| 484 | |
Terence Hampson | a2cba0d | 2012-08-08 11:39:53 -0400 | [diff] [blame] | 485 | handle = ion_alloc(dev->ion_client, size, SZ_4K, |
Hanumant Singh | 7d72bad | 2012-08-29 18:39:44 -0700 | [diff] [blame] | 486 | ION_HEAP(ION_CP_MM_HEAP_ID), 0); |
Terence Hampson | a2cba0d | 2012-08-08 11:39:53 -0400 | [diff] [blame] | 487 | if (IS_ERR_OR_NULL(handle)) { |
| 488 | pr_err("%s: ion_alloc failed\n", __func__); |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 489 | return -ENOMEM; |
Terence Hampson | a2cba0d | 2012-08-08 11:39:53 -0400 | [diff] [blame] | 490 | } |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 491 | |
Terence Hampson | a2cba0d | 2012-08-08 11:39:53 -0400 | [diff] [blame] | 492 | rc = ion_handle_get_flags(dev->ion_client, handle, &ionflag); |
| 493 | if (rc) { |
| 494 | pr_err("%s: get flags ion handle failed\n", __func__); |
| 495 | ion_free(dev->ion_client, handle); |
| 496 | return rc; |
| 497 | } |
| 498 | |
Mitchel Humpherys | 911b4b7 | 2012-09-12 14:42:50 -0700 | [diff] [blame] | 499 | vaddr = ion_map_kernel(dev->ion_client, handle); |
Terence Hampson | a2cba0d | 2012-08-08 11:39:53 -0400 | [diff] [blame] | 500 | if (IS_ERR(vaddr)) { |
| 501 | pr_err("%s: Map motion buffer failed\n", __func__); |
| 502 | ion_free(dev->ion_client, handle); |
| 503 | rc = -ENOMEM; |
| 504 | return rc; |
| 505 | } |
| 506 | |
| 507 | memset(vaddr, 0, size); |
Terence Hampson | 8d1c327 | 2012-07-27 16:36:31 -0400 | [diff] [blame] | 508 | ion_unmap_kernel(dev->ion_client, handle); |
| 509 | |
| 510 | rc = ion_map_iommu(dev->ion_client, handle, |
| 511 | dev->domain_num, 0, SZ_4K, 0, &paddr, &len, |
| 512 | 0, 0); |
| 513 | if (rc < 0) { |
| 514 | pr_err("%s: map_iommu failed\n", __func__); |
| 515 | ion_free(dev->ion_client, handle); |
| 516 | return rc; |
| 517 | } |
| 518 | |
Terence Hampson | 2cba63f | 2012-08-21 10:54:38 -0400 | [diff] [blame] | 519 | c_data->vp_action.motionHandle = handle; |
Terence Hampson | a2cba0d | 2012-08-08 11:39:53 -0400 | [diff] [blame] | 520 | |
| 521 | vaddr = NULL; |
Terence Hampson | a2cba0d | 2012-08-08 11:39:53 -0400 | [diff] [blame] | 522 | |
| 523 | writel_iowmb(paddr, VCAP_VP_MOTION_EST_ADDR); |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 524 | return 0; |
| 525 | } |
| 526 | |
| 527 | void deinit_motion_buf(struct vcap_client_data *c_data) |
| 528 | { |
| 529 | struct vcap_dev *dev = c_data->dev; |
Terence Hampson | 2cba63f | 2012-08-21 10:54:38 -0400 | [diff] [blame] | 530 | if (!c_data->vp_action.motionHandle) { |
Terence Hampson | ad33c51 | 2012-07-16 17:50:00 -0400 | [diff] [blame] | 531 | pr_err("Motion buffer has not been created"); |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 532 | return; |
| 533 | } |
| 534 | |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 535 | writel_iowmb(0x00000000, VCAP_VP_MOTION_EST_ADDR); |
Terence Hampson | 8d1c327 | 2012-07-27 16:36:31 -0400 | [diff] [blame] | 536 | ion_unmap_iommu(dev->ion_client, c_data->vp_action.motionHandle, |
| 537 | dev->domain_num, 0); |
Terence Hampson | 2cba63f | 2012-08-21 10:54:38 -0400 | [diff] [blame] | 538 | ion_free(dev->ion_client, c_data->vp_action.motionHandle); |
| 539 | c_data->vp_action.motionHandle = NULL; |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 540 | return; |
| 541 | } |
| 542 | |
| 543 | int init_nr_buf(struct vcap_client_data *c_data) |
| 544 | { |
| 545 | struct vcap_dev *dev = c_data->dev; |
Terence Hampson | a2cba0d | 2012-08-08 11:39:53 -0400 | [diff] [blame] | 546 | struct ion_handle *handle = NULL; |
Terence Hampson | 8d1c327 | 2012-07-27 16:36:31 -0400 | [diff] [blame] | 547 | size_t frame_size, tot_size; |
| 548 | unsigned long paddr, len; |
Terence Hampson | a2cba0d | 2012-08-08 11:39:53 -0400 | [diff] [blame] | 549 | int rc; |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 550 | |
Terence Hampson | 2cba63f | 2012-08-21 10:54:38 -0400 | [diff] [blame] | 551 | if (c_data->vp_action.bufNR.nr_handle) { |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 552 | pr_err("NR buffer has already been created"); |
| 553 | return -ENOEXEC; |
| 554 | } |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 555 | |
| 556 | frame_size = c_data->vp_in_fmt.width * c_data->vp_in_fmt.height; |
| 557 | if (c_data->vp_in_fmt.pixfmt == V4L2_PIX_FMT_NV16) |
| 558 | tot_size = frame_size * 2; |
| 559 | else |
| 560 | tot_size = frame_size / 2 * 3; |
| 561 | |
Terence Hampson | a2cba0d | 2012-08-08 11:39:53 -0400 | [diff] [blame] | 562 | handle = ion_alloc(dev->ion_client, tot_size, SZ_4K, |
Hanumant Singh | 7d72bad | 2012-08-29 18:39:44 -0700 | [diff] [blame] | 563 | ION_HEAP(ION_CP_MM_HEAP_ID), 0); |
Terence Hampson | a2cba0d | 2012-08-08 11:39:53 -0400 | [diff] [blame] | 564 | if (IS_ERR_OR_NULL(handle)) { |
| 565 | pr_err("%s: ion_alloc failed\n", __func__); |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 566 | return -ENOMEM; |
Terence Hampson | a2cba0d | 2012-08-08 11:39:53 -0400 | [diff] [blame] | 567 | } |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 568 | |
Terence Hampson | 8d1c327 | 2012-07-27 16:36:31 -0400 | [diff] [blame] | 569 | rc = ion_map_iommu(dev->ion_client, handle, |
| 570 | dev->domain_num, 0, SZ_4K, 0, &paddr, &len, |
| 571 | 0, 0); |
Terence Hampson | a2cba0d | 2012-08-08 11:39:53 -0400 | [diff] [blame] | 572 | if (rc < 0) { |
Terence Hampson | 8d1c327 | 2012-07-27 16:36:31 -0400 | [diff] [blame] | 573 | pr_err("%s: map_iommu failed\n", __func__); |
Terence Hampson | a2cba0d | 2012-08-08 11:39:53 -0400 | [diff] [blame] | 574 | ion_free(dev->ion_client, handle); |
| 575 | return rc; |
| 576 | } |
| 577 | |
Terence Hampson | 2cba63f | 2012-08-21 10:54:38 -0400 | [diff] [blame] | 578 | c_data->vp_action.bufNR.nr_handle = handle; |
Terence Hampson | 616762d | 2012-08-16 17:47:44 -0400 | [diff] [blame] | 579 | update_nr_value(dev); |
Terence Hampson | 3dff4ef | 2012-06-13 15:20:59 -0400 | [diff] [blame] | 580 | |
Terence Hampson | 2cba63f | 2012-08-21 10:54:38 -0400 | [diff] [blame] | 581 | c_data->vp_action.bufNR.paddr = paddr; |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 582 | rc = readl_relaxed(VCAP_VP_NR_CONFIG2); |
Terence Hampson | a2cba0d | 2012-08-08 11:39:53 -0400 | [diff] [blame] | 583 | rc |= (((c_data->vp_out_fmt.width / 16) << 20) | 0x1); |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 584 | writel_relaxed(rc, VCAP_VP_NR_CONFIG2); |
Terence Hampson | a2cba0d | 2012-08-08 11:39:53 -0400 | [diff] [blame] | 585 | writel_relaxed(paddr, VCAP_VP_NR_T2_Y_BASE_ADDR); |
| 586 | writel_relaxed(paddr + frame_size, VCAP_VP_NR_T2_C_BASE_ADDR); |
Terence Hampson | 2cba63f | 2012-08-21 10:54:38 -0400 | [diff] [blame] | 587 | c_data->vp_action.bufNR.nr_pos = NRT2_BUF; |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 588 | return 0; |
| 589 | } |
| 590 | |
| 591 | void deinit_nr_buf(struct vcap_client_data *c_data) |
| 592 | { |
| 593 | struct vcap_dev *dev = c_data->dev; |
| 594 | struct nr_buffer *buf; |
| 595 | uint32_t rc; |
| 596 | |
Terence Hampson | 2cba63f | 2012-08-21 10:54:38 -0400 | [diff] [blame] | 597 | if (!c_data->vp_action.bufNR.nr_handle) { |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 598 | pr_err("NR buffer has not been created"); |
| 599 | return; |
| 600 | } |
Terence Hampson | 2cba63f | 2012-08-21 10:54:38 -0400 | [diff] [blame] | 601 | buf = &c_data->vp_action.bufNR; |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 602 | |
| 603 | rc = readl_relaxed(VCAP_VP_NR_CONFIG2); |
Terence Hampson | a2cba0d | 2012-08-08 11:39:53 -0400 | [diff] [blame] | 604 | rc &= !(0x0FF00001); |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 605 | writel_relaxed(rc, VCAP_VP_NR_CONFIG2); |
| 606 | |
Terence Hampson | 8d1c327 | 2012-07-27 16:36:31 -0400 | [diff] [blame] | 607 | ion_unmap_iommu(dev->ion_client, buf->nr_handle, dev->domain_num, 0); |
Terence Hampson | a2cba0d | 2012-08-08 11:39:53 -0400 | [diff] [blame] | 608 | ion_free(dev->ion_client, buf->nr_handle); |
| 609 | buf->nr_handle = NULL; |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 610 | buf->paddr = 0; |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 611 | return; |
| 612 | } |
| 613 | |
Terence Hampson | 3dff4ef | 2012-06-13 15:20:59 -0400 | [diff] [blame] | 614 | int nr_s_param(struct vcap_client_data *c_data, struct nr_param *param) |
| 615 | { |
| 616 | if (param->mode != NR_MANUAL) |
| 617 | return 0; |
| 618 | |
| 619 | /* Verify values in range */ |
Terence Hampson | 616762d | 2012-08-16 17:47:44 -0400 | [diff] [blame] | 620 | if (param->window > VP_NR_MAX_WINDOW) |
Terence Hampson | 3dff4ef | 2012-06-13 15:20:59 -0400 | [diff] [blame] | 621 | return -EINVAL; |
Terence Hampson | 616762d | 2012-08-16 17:47:44 -0400 | [diff] [blame] | 622 | if (param->luma.max_blend_ratio > VP_NR_MAX_RATIO) |
Terence Hampson | 3dff4ef | 2012-06-13 15:20:59 -0400 | [diff] [blame] | 623 | return -EINVAL; |
Terence Hampson | 616762d | 2012-08-16 17:47:44 -0400 | [diff] [blame] | 624 | if (param->luma.scale_diff_ratio > VP_NR_MAX_RATIO) |
Terence Hampson | 3dff4ef | 2012-06-13 15:20:59 -0400 | [diff] [blame] | 625 | return -EINVAL; |
Terence Hampson | 616762d | 2012-08-16 17:47:44 -0400 | [diff] [blame] | 626 | if (param->luma.diff_limit_ratio > VP_NR_MAX_RATIO) |
Terence Hampson | 3dff4ef | 2012-06-13 15:20:59 -0400 | [diff] [blame] | 627 | return -EINVAL; |
Terence Hampson | 616762d | 2012-08-16 17:47:44 -0400 | [diff] [blame] | 628 | if (param->luma.scale_motion_ratio > VP_NR_MAX_RATIO) |
Terence Hampson | 3dff4ef | 2012-06-13 15:20:59 -0400 | [diff] [blame] | 629 | return -EINVAL; |
Terence Hampson | 616762d | 2012-08-16 17:47:44 -0400 | [diff] [blame] | 630 | if (param->luma.blend_limit_ratio > VP_NR_MAX_RATIO) |
Terence Hampson | 3dff4ef | 2012-06-13 15:20:59 -0400 | [diff] [blame] | 631 | return -EINVAL; |
Terence Hampson | 616762d | 2012-08-16 17:47:44 -0400 | [diff] [blame] | 632 | if (param->chroma.max_blend_ratio > VP_NR_MAX_RATIO) |
Terence Hampson | 3dff4ef | 2012-06-13 15:20:59 -0400 | [diff] [blame] | 633 | return -EINVAL; |
Terence Hampson | 616762d | 2012-08-16 17:47:44 -0400 | [diff] [blame] | 634 | if (param->chroma.scale_diff_ratio > VP_NR_MAX_RATIO) |
Terence Hampson | 3dff4ef | 2012-06-13 15:20:59 -0400 | [diff] [blame] | 635 | return -EINVAL; |
Terence Hampson | 616762d | 2012-08-16 17:47:44 -0400 | [diff] [blame] | 636 | if (param->chroma.diff_limit_ratio > VP_NR_MAX_RATIO) |
Terence Hampson | 3dff4ef | 2012-06-13 15:20:59 -0400 | [diff] [blame] | 637 | return -EINVAL; |
Terence Hampson | 616762d | 2012-08-16 17:47:44 -0400 | [diff] [blame] | 638 | if (param->chroma.scale_motion_ratio > VP_NR_MAX_RATIO) |
Terence Hampson | 3dff4ef | 2012-06-13 15:20:59 -0400 | [diff] [blame] | 639 | return -EINVAL; |
Terence Hampson | 616762d | 2012-08-16 17:47:44 -0400 | [diff] [blame] | 640 | if (param->chroma.blend_limit_ratio > VP_NR_MAX_RATIO) |
Terence Hampson | 3dff4ef | 2012-06-13 15:20:59 -0400 | [diff] [blame] | 641 | return -EINVAL; |
| 642 | return 0; |
| 643 | } |
| 644 | |
| 645 | void nr_g_param(struct vcap_client_data *c_data, struct nr_param *param) |
| 646 | { |
| 647 | struct vcap_dev *dev = c_data->dev; |
| 648 | uint32_t rc; |
| 649 | rc = readl_relaxed(VCAP_VP_NR_CONFIG); |
| 650 | param->window = BITS_VALUE(rc, 24, 4); |
| 651 | param->decay_ratio = BITS_VALUE(rc, 20, 3); |
| 652 | |
| 653 | rc = readl_relaxed(VCAP_VP_NR_LUMA_CONFIG); |
Terence Hampson | 6a744e3 | 2012-12-07 15:50:32 -0500 | [diff] [blame] | 654 | param->threshold = NR_THRESHOLD_STATIC; |
| 655 | if (BITS_VALUE(rc, 16, 1)) |
| 656 | param->threshold = NR_THRESHOLD_DYNAMIC; |
Terence Hampson | 3dff4ef | 2012-06-13 15:20:59 -0400 | [diff] [blame] | 657 | param->luma.max_blend_ratio = BITS_VALUE(rc, 24, 4); |
| 658 | param->luma.scale_diff_ratio = BITS_VALUE(rc, 12, 4); |
| 659 | param->luma.diff_limit_ratio = BITS_VALUE(rc, 8, 4); |
| 660 | param->luma.scale_motion_ratio = BITS_VALUE(rc, 4, 4); |
| 661 | param->luma.blend_limit_ratio = BITS_VALUE(rc, 0, 4); |
| 662 | |
| 663 | rc = readl_relaxed(VCAP_VP_NR_CHROMA_CONFIG); |
| 664 | param->chroma.max_blend_ratio = BITS_VALUE(rc, 24, 4); |
| 665 | param->chroma.scale_diff_ratio = BITS_VALUE(rc, 12, 4); |
| 666 | param->chroma.diff_limit_ratio = BITS_VALUE(rc, 8, 4); |
| 667 | param->chroma.scale_motion_ratio = BITS_VALUE(rc, 4, 4); |
| 668 | param->chroma.blend_limit_ratio = BITS_VALUE(rc, 0, 4); |
| 669 | } |
| 670 | |
| 671 | void s_default_nr_val(struct nr_param *param) |
| 672 | { |
Terence Hampson | 6a744e3 | 2012-12-07 15:50:32 -0500 | [diff] [blame] | 673 | param->threshold = NR_THRESHOLD_STATIC; |
Terence Hampson | 3dff4ef | 2012-06-13 15:20:59 -0400 | [diff] [blame] | 674 | param->window = 10; |
| 675 | param->decay_ratio = 0; |
| 676 | param->luma.max_blend_ratio = 0; |
| 677 | param->luma.scale_diff_ratio = 4; |
| 678 | param->luma.diff_limit_ratio = 1; |
| 679 | param->luma.scale_motion_ratio = 4; |
| 680 | param->luma.blend_limit_ratio = 9; |
| 681 | param->chroma.max_blend_ratio = 0; |
| 682 | param->chroma.scale_diff_ratio = 4; |
| 683 | param->chroma.diff_limit_ratio = 1; |
| 684 | param->chroma.scale_motion_ratio = 4; |
| 685 | param->chroma.blend_limit_ratio = 9; |
| 686 | } |
| 687 | |
Terence Hampson | 54d3a6d | 2012-07-10 14:05:35 -0400 | [diff] [blame] | 688 | int vp_dummy_event(struct vcap_client_data *c_data) |
| 689 | { |
| 690 | struct vcap_dev *dev = c_data->dev; |
| 691 | unsigned int width, height; |
Terence Hampson | a2cba0d | 2012-08-08 11:39:53 -0400 | [diff] [blame] | 692 | struct ion_handle *handle = NULL; |
Terence Hampson | 8d1c327 | 2012-07-27 16:36:31 -0400 | [diff] [blame] | 693 | unsigned long paddr, len; |
Terence Hampson | 54d3a6d | 2012-07-10 14:05:35 -0400 | [diff] [blame] | 694 | uint32_t reg; |
| 695 | int rc = 0; |
| 696 | |
Terence Hampson | c4aa4c0 | 2012-08-31 04:49:21 -0400 | [diff] [blame] | 697 | pr_debug("%s: Start VP dummy event\n", __func__); |
Terence Hampson | a2cba0d | 2012-08-08 11:39:53 -0400 | [diff] [blame] | 698 | handle = ion_alloc(dev->ion_client, 0x1200, SZ_4K, |
Hanumant Singh | 7d72bad | 2012-08-29 18:39:44 -0700 | [diff] [blame] | 699 | ION_HEAP(ION_CP_MM_HEAP_ID), 0); |
Terence Hampson | a2cba0d | 2012-08-08 11:39:53 -0400 | [diff] [blame] | 700 | if (IS_ERR_OR_NULL(handle)) { |
| 701 | pr_err("%s: ion_alloc failed\n", __func__); |
Terence Hampson | 54d3a6d | 2012-07-10 14:05:35 -0400 | [diff] [blame] | 702 | return -ENOMEM; |
| 703 | } |
Terence Hampson | a2cba0d | 2012-08-08 11:39:53 -0400 | [diff] [blame] | 704 | |
Terence Hampson | 8d1c327 | 2012-07-27 16:36:31 -0400 | [diff] [blame] | 705 | rc = ion_map_iommu(dev->ion_client, handle, |
| 706 | dev->domain_num, 0, SZ_4K, 0, &paddr, &len, |
| 707 | 0, 0); |
Terence Hampson | a2cba0d | 2012-08-08 11:39:53 -0400 | [diff] [blame] | 708 | if (rc < 0) { |
Terence Hampson | 8d1c327 | 2012-07-27 16:36:31 -0400 | [diff] [blame] | 709 | pr_err("%s: map_iommu failed\n", __func__); |
Terence Hampson | a2cba0d | 2012-08-08 11:39:53 -0400 | [diff] [blame] | 710 | ion_free(dev->ion_client, handle); |
| 711 | return rc; |
| 712 | } |
Terence Hampson | 54d3a6d | 2012-07-10 14:05:35 -0400 | [diff] [blame] | 713 | |
| 714 | width = c_data->vp_out_fmt.width; |
| 715 | height = c_data->vp_out_fmt.height; |
| 716 | |
| 717 | c_data->vp_out_fmt.width = 0x3F; |
| 718 | c_data->vp_out_fmt.height = 0x16; |
| 719 | |
| 720 | config_vp_format(c_data); |
| 721 | writel_relaxed(paddr, VCAP_VP_T1_Y_BASE_ADDR); |
| 722 | writel_relaxed(paddr + 0x2C0, VCAP_VP_T1_C_BASE_ADDR); |
| 723 | writel_relaxed(paddr + 0x440, VCAP_VP_T2_Y_BASE_ADDR); |
| 724 | writel_relaxed(paddr + 0x700, VCAP_VP_T2_C_BASE_ADDR); |
| 725 | writel_relaxed(paddr + 0x880, VCAP_VP_OUT_Y_BASE_ADDR); |
| 726 | writel_relaxed(paddr + 0xB40, VCAP_VP_OUT_C_BASE_ADDR); |
| 727 | writel_iowmb(paddr + 0x1100, VCAP_VP_MOTION_EST_ADDR); |
| 728 | writel_relaxed(4 << 20 | 0x2 << 4, VCAP_VP_IN_CONFIG); |
| 729 | writel_relaxed(4 << 20 | 0x1 << 4, VCAP_VP_OUT_CONFIG); |
| 730 | |
| 731 | dev->vp_dummy_event = true; |
| 732 | |
Terence Hampson | b128b98 | 2012-08-16 14:41:19 -0400 | [diff] [blame] | 733 | enable_irq(dev->vpirq->start); |
Terence Hampson | 54d3a6d | 2012-07-10 14:05:35 -0400 | [diff] [blame] | 734 | writel_relaxed(0x01100101, VCAP_VP_INTERRUPT_ENABLE); |
| 735 | writel_iowmb(0x00000000, VCAP_VP_CTRL); |
Terence Hampson | a2cba0d | 2012-08-08 11:39:53 -0400 | [diff] [blame] | 736 | writel_iowmb(0x00010000, VCAP_VP_CTRL); |
Terence Hampson | 54d3a6d | 2012-07-10 14:05:35 -0400 | [diff] [blame] | 737 | |
Terence Hampson | 54d3a6d | 2012-07-10 14:05:35 -0400 | [diff] [blame] | 738 | rc = wait_event_interruptible_timeout(dev->vp_dummy_waitq, |
| 739 | dev->vp_dummy_complete, msecs_to_jiffies(50)); |
| 740 | if (!rc && !dev->vp_dummy_complete) { |
| 741 | pr_err("%s: VP dummy event timeout", __func__); |
| 742 | rc = -ETIME; |
Terence Hampson | 54d3a6d | 2012-07-10 14:05:35 -0400 | [diff] [blame] | 743 | |
Terence Hampson | b128b98 | 2012-08-16 14:41:19 -0400 | [diff] [blame] | 744 | vp_sw_reset(dev); |
Terence Hampson | 54d3a6d | 2012-07-10 14:05:35 -0400 | [diff] [blame] | 745 | dev->vp_dummy_complete = false; |
| 746 | } |
| 747 | |
| 748 | writel_relaxed(0x00000000, VCAP_VP_INTERRUPT_ENABLE); |
| 749 | disable_irq(dev->vpirq->start); |
| 750 | dev->vp_dummy_event = false; |
| 751 | |
| 752 | reg = readl_relaxed(VCAP_OFFSET(0x0D94)); |
| 753 | writel_relaxed(reg, VCAP_OFFSET(0x0D9C)); |
| 754 | |
| 755 | c_data->vp_out_fmt.width = width; |
| 756 | c_data->vp_out_fmt.height = height; |
Terence Hampson | 8d1c327 | 2012-07-27 16:36:31 -0400 | [diff] [blame] | 757 | ion_unmap_iommu(dev->ion_client, handle, dev->domain_num, 0); |
Terence Hampson | a2cba0d | 2012-08-08 11:39:53 -0400 | [diff] [blame] | 758 | ion_free(dev->ion_client, handle); |
Terence Hampson | 54d3a6d | 2012-07-10 14:05:35 -0400 | [diff] [blame] | 759 | |
Terence Hampson | c4aa4c0 | 2012-08-31 04:49:21 -0400 | [diff] [blame] | 760 | pr_debug("%s: Exit VP dummy event\n", __func__); |
Terence Hampson | 54d3a6d | 2012-07-10 14:05:35 -0400 | [diff] [blame] | 761 | return rc; |
| 762 | } |
| 763 | |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 764 | int kickoff_vp(struct vcap_client_data *c_data) |
| 765 | { |
| 766 | struct vcap_dev *dev; |
| 767 | struct vp_action *vp_act; |
Terence Hampson | c4aa4c0 | 2012-08-31 04:49:21 -0400 | [diff] [blame] | 768 | struct timeval tv; |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 769 | unsigned long flags = 0; |
| 770 | unsigned int chroma_fmt = 0; |
| 771 | int size; |
Terence Hampson | 9c4f8a2 | 2012-09-12 10:25:50 -0400 | [diff] [blame] | 772 | bool top_field = 0; |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 773 | |
| 774 | if (!c_data->streaming) |
| 775 | return -ENOEXEC; |
| 776 | |
| 777 | dev = c_data->dev; |
Terence Hampson | c4aa4c0 | 2012-08-31 04:49:21 -0400 | [diff] [blame] | 778 | pr_debug("Start VP Kickoff\n"); |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 779 | |
| 780 | if (dev->vp_client == NULL) { |
| 781 | pr_err("No active vp client\n"); |
| 782 | return -ENODEV; |
| 783 | } |
Terence Hampson | 2cba63f | 2012-08-21 10:54:38 -0400 | [diff] [blame] | 784 | vp_act = &dev->vp_client->vp_action; |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 785 | |
| 786 | spin_lock_irqsave(&dev->vp_client->cap_slock, flags); |
| 787 | if (list_empty(&vp_act->in_active)) { |
| 788 | spin_unlock_irqrestore(&dev->vp_client->cap_slock, flags); |
| 789 | pr_err("%s: VP We have no more input buffers\n", |
| 790 | __func__); |
| 791 | return -EAGAIN; |
| 792 | } |
| 793 | |
| 794 | vp_act->bufT1 = list_entry(vp_act->in_active.next, |
| 795 | struct vcap_buffer, list); |
| 796 | list_del(&vp_act->bufT1->list); |
| 797 | |
| 798 | if (list_empty(&vp_act->in_active)) { |
| 799 | spin_unlock_irqrestore(&dev->vp_client->cap_slock, flags); |
| 800 | list_add(&vp_act->bufT1->list, &vp_act->in_active); |
| 801 | pr_err("%s: VP We have no more input buffers\n", |
| 802 | __func__); |
| 803 | return -EAGAIN; |
| 804 | } |
| 805 | |
| 806 | vp_act->bufT2 = list_entry(vp_act->in_active.next, |
| 807 | struct vcap_buffer, list); |
| 808 | list_del(&vp_act->bufT2->list); |
| 809 | |
| 810 | if (list_empty(&vp_act->out_active)) { |
| 811 | spin_unlock_irqrestore(&dev->vp_client->cap_slock, flags); |
| 812 | list_add(&vp_act->bufT2->list, &vp_act->in_active); |
| 813 | list_add(&vp_act->bufT1->list, &vp_act->in_active); |
| 814 | pr_err("%s: VP We have no more output buffers\n", |
| 815 | __func__); |
| 816 | return -EAGAIN; |
| 817 | } |
| 818 | |
| 819 | vp_act->bufOut = list_entry(vp_act->out_active.next, |
| 820 | struct vcap_buffer, list); |
| 821 | list_del(&vp_act->bufOut->list); |
| 822 | spin_unlock_irqrestore(&dev->vp_client->cap_slock, flags); |
| 823 | |
| 824 | size = c_data->vp_in_fmt.height * c_data->vp_in_fmt.width; |
| 825 | writel_relaxed(vp_act->bufT1->paddr, VCAP_VP_T1_Y_BASE_ADDR); |
| 826 | writel_relaxed(vp_act->bufT1->paddr + size, VCAP_VP_T1_C_BASE_ADDR); |
| 827 | |
| 828 | config_in_buffer(c_data, vp_act->bufT2); |
| 829 | config_out_buffer(c_data, vp_act->bufOut); |
| 830 | |
| 831 | /* Config VP */ |
| 832 | if (c_data->vp_in_fmt.pixfmt == V4L2_PIX_FMT_NV16) |
| 833 | chroma_fmt = 1; |
| 834 | writel_relaxed((c_data->vp_in_fmt.width / 16) << 20 | |
| 835 | chroma_fmt << 11 | 0x2 << 4, VCAP_VP_IN_CONFIG); |
| 836 | |
| 837 | chroma_fmt = 0; |
Terence Hampson | 779dc76 | 2012-06-07 15:59:27 -0400 | [diff] [blame] | 838 | if (c_data->vp_out_fmt.pixfmt == V4L2_PIX_FMT_NV16) |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 839 | chroma_fmt = 1; |
| 840 | |
Terence Hampson | ad33c51 | 2012-07-16 17:50:00 -0400 | [diff] [blame] | 841 | writel_relaxed((c_data->vp_out_fmt.width / 16) << 20 | |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 842 | chroma_fmt << 11 | 0x1 << 4, VCAP_VP_OUT_CONFIG); |
| 843 | |
| 844 | /* Enable Interrupt */ |
Terence Hampson | aa64d3a | 2012-10-29 13:05:37 -0400 | [diff] [blame] | 845 | if (vp_act->bufT2->vb.v4l2_buf.field == V4L2_FIELD_BOTTOM) |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 846 | top_field = 1; |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 847 | vp_act->vp_state = VP_FRAME2; |
Terence Hampson | 7245263 | 2012-08-13 12:32:24 -0400 | [diff] [blame] | 848 | writel_relaxed(0x01100001, VCAP_VP_INTERRUPT_ENABLE); |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 849 | writel_iowmb(0x00000000 | top_field, VCAP_VP_CTRL); |
Terence Hampson | a2cba0d | 2012-08-08 11:39:53 -0400 | [diff] [blame] | 850 | writel_iowmb(0x00010000 | top_field, VCAP_VP_CTRL); |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 851 | atomic_set(&c_data->dev->vp_enabled, 1); |
| 852 | enable_irq(dev->vpirq->start); |
Terence Hampson | c4aa4c0 | 2012-08-31 04:49:21 -0400 | [diff] [blame] | 853 | |
| 854 | do_gettimeofday(&tv); |
| 855 | dev->dbg_p.vp_timestamp = (uint32_t) (tv.tv_sec * VCAP_USEC + |
| 856 | tv.tv_usec); |
| 857 | |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 858 | return 0; |
| 859 | } |
| 860 | |
| 861 | int continue_vp(struct vcap_client_data *c_data) |
| 862 | { |
| 863 | struct vcap_dev *dev; |
| 864 | struct vp_action *vp_act; |
Terence Hampson | c4aa4c0 | 2012-08-31 04:49:21 -0400 | [diff] [blame] | 865 | struct timeval tv; |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 866 | int rc; |
Terence Hampson | 9c4f8a2 | 2012-09-12 10:25:50 -0400 | [diff] [blame] | 867 | bool top_field = 0; |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 868 | |
Terence Hampson | c4aa4c0 | 2012-08-31 04:49:21 -0400 | [diff] [blame] | 869 | pr_debug("Start VP Continue\n"); |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 870 | dev = c_data->dev; |
| 871 | |
| 872 | if (dev->vp_client == NULL) { |
| 873 | pr_err("No active vp client\n"); |
| 874 | return -ENODEV; |
| 875 | } |
Terence Hampson | 2cba63f | 2012-08-21 10:54:38 -0400 | [diff] [blame] | 876 | vp_act = &dev->vp_client->vp_action; |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 877 | |
| 878 | if (vp_act->vp_state == VP_UNKNOWN) { |
| 879 | pr_err("%s: VP is in an unknown state\n", |
| 880 | __func__); |
| 881 | return -EAGAIN; |
| 882 | } |
| 883 | |
| 884 | rc = vp_setup_buffers(c_data); |
| 885 | if (rc < 0) |
| 886 | return rc; |
| 887 | |
Terence Hampson | aa64d3a | 2012-10-29 13:05:37 -0400 | [diff] [blame] | 888 | if (vp_act->bufT2->vb.v4l2_buf.field == V4L2_FIELD_BOTTOM) |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 889 | top_field = 1; |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 890 | |
| 891 | /* Config VP & Enable Interrupt */ |
Terence Hampson | 7245263 | 2012-08-13 12:32:24 -0400 | [diff] [blame] | 892 | writel_relaxed(0x01100001, VCAP_VP_INTERRUPT_ENABLE); |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 893 | writel_iowmb(0x00000000 | top_field, VCAP_VP_CTRL); |
Terence Hampson | a2cba0d | 2012-08-08 11:39:53 -0400 | [diff] [blame] | 894 | writel_iowmb(0x00010000 | top_field, VCAP_VP_CTRL); |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 895 | |
| 896 | atomic_set(&c_data->dev->vp_enabled, 1); |
| 897 | enable_irq(dev->vpirq->start); |
Terence Hampson | c4aa4c0 | 2012-08-31 04:49:21 -0400 | [diff] [blame] | 898 | |
| 899 | do_gettimeofday(&tv); |
| 900 | dev->dbg_p.vp_timestamp = (uint32_t) (tv.tv_sec * VCAP_USEC + |
| 901 | tv.tv_usec); |
| 902 | |
Terence Hampson | aeb793e | 2012-05-11 11:41:16 -0400 | [diff] [blame] | 903 | return 0; |
| 904 | } |