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