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